From 0e25ff63ccedc5a4814e12bace863620fe7aded7 Mon Sep 17 00:00:00 2001 From: Niels Zwemmer Date: Fri, 23 Jun 2017 14:35:25 +0200 Subject: [PATCH 1/4] Cleaned code, added an invalidate. Needs testing. --- .../tagram/ProfileFragment.java | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/ProfileFragment.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/ProfileFragment.java index 27ab142..7b251aa 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/ProfileFragment.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/ProfileFragment.java @@ -185,29 +185,10 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { Bitmap imageBitmap = (Bitmap) extras.get("data"); UploadClass uploadClass = new UploadClass(); uploadClass.uploadProfilePicture(imageBitmap); -// uploadClass.uploadPicture(new BitmapPost(imageBitmap, "Ik ben een heel mooi comment")); -// downloadUrl = uploadClass.getDownloadUrl(); -// updateUserProfilePic(user); + profilePicture.invalidate(); } } -// protected void updateUserProfilePic(final FirebaseUser user) { -// UserProfileChangeRequest request = new UserProfileChangeRequest.Builder() -// .setPhotoUri(downloadUrl) -// .build(); -// -// user.updateProfile(request) -// .addOnCompleteListener(new OnCompleteListener() { -// @Override -// public void onComplete(@NonNull Task task) { -// if (task.isSuccessful()) { -// Log.d(TAG, "User profile updated!"); -// } -// } -// }); -// } - - // TODO Make this function into its own class for modularity. /** * Performs password reset action. From 3855d9d917d6c63feb129291bfc12b3cc856e5b9 Mon Sep 17 00:00:00 2001 From: Niels Zwemmer Date: Fri, 23 Jun 2017 17:30:29 +0200 Subject: [PATCH 2/4] Cleared up code and made first (failed) attempt at progressDialog. --- .../myhyvesbookplus/tagram/MainActivity.java | 4 +- .../tagram/ProfileFragment.java | 100 ++---------------- .../app/src/main/res/values/strings.xml | 2 + 3 files changed, 14 insertions(+), 92 deletions(-) diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/MainActivity.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/MainActivity.java index 51b3a3b..2ce7f04 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/MainActivity.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/MainActivity.java @@ -18,7 +18,7 @@ import com.google.firebase.auth.FirebaseAuth; import nl.myhyvesbookplus.tagram.controller.UploadClass; import nl.myhyvesbookplus.tagram.model.BitmapPost; -public class MainActivity extends AppCompatActivity implements CameraFragment.OnFragmentInteractionListener, ProfileFragment.OnFragmentInteractionListener, TimelineFragment.OnFragmentInteractionListener, UploadClass.ProfilePictureUpdatedListener { +public class MainActivity extends AppCompatActivity implements CameraFragment.OnFragmentInteractionListener, TimelineFragment.OnFragmentInteractionListener, UploadClass.ProfilePictureUpdatedListener { final static private String TAG = "MainScreen"; FirebaseAuth mAuth; @@ -110,14 +110,12 @@ public class MainActivity extends AppCompatActivity implements CameraFragment.On @Override public void ProfilePictureUpdated(Boolean success) { - Log.d(TAG, "ProfilePictureUpdated: Ja ik luister naar je!"); FragmentManager man = getFragmentManager(); ProfileFragment frag = (ProfileFragment) man.findFragmentById(R.id.content); FragmentTransaction transaction = man.beginTransaction(); transaction.detach(frag) .attach(frag) .commit(); - Log.d(TAG, "ProfilePictureUpdated: Done reloading fragment"); } } diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/ProfileFragment.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/ProfileFragment.java index 31e1fdb..2692d29 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/ProfileFragment.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/ProfileFragment.java @@ -1,6 +1,7 @@ package nl.myhyvesbookplus.tagram; import android.app.Fragment; +import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; @@ -32,64 +33,25 @@ import static android.app.Activity.RESULT_OK; /** * A simple {@link Fragment} subclass. - * Activities that contain this fragment must implement the - * {@link ProfileFragment.OnFragmentInteractionListener} interface - * to handle interaction events. - * Use the {@link ProfileFragment#newInstance} factory method to - * create an instance of this fragment. */ public class ProfileFragment extends Fragment implements View.OnClickListener { static final int REQUEST_IMAGE_CAPTURE = 1; - final static private String TAG = "ProfileFragment"; - // TODO: Rename parameter arguments, choose names that match - // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER - private static final String ARG_PARAM1 = "param1"; - private static final String ARG_PARAM2 = "param2"; - private static Uri downloadUrl; protected Button changePwdButton; protected ImageButton profilePicButton; - - /// Views /// protected StorageReference httpsReference; protected TextView profileName; protected ImageView profilePicture; protected FirebaseUser user; - // TODO: Rename and change types of parameters - private String mParam1; - private String mParam2; - private OnFragmentInteractionListener mListener; + private ProgressDialog progressDialog; /// Required empty public constructor /// - public ProfileFragment() {} - - - /** - * Use this factory method to create a new instance of - * this fragment using the provided parameters. - * - * @param param1 Parameter 1. - * @param param2 Parameter 2. - * @return A new instance of fragment ProfileFragment. - */ - // TODO: Rename and change types and number of parameters - public static ProfileFragment newInstance(String param1, String param2) { - ProfileFragment fragment = new ProfileFragment(); - Bundle args = new Bundle(); - args.putString(ARG_PARAM1, param1); - args.putString(ARG_PARAM2, param2); - fragment.setArguments(args); - return fragment; + public ProfileFragment() { } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (getArguments() != null) { - mParam1 = getArguments().getString(ARG_PARAM1); - mParam2 = getArguments().getString(ARG_PARAM2); - } - user = FirebaseAuth.getInstance().getCurrentUser(); } @@ -126,7 +88,7 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { Glide.with(this).using(new FirebaseImageLoader()).load(httpsReference).into(profilePicture); } - profilePicture.invalidate(); + profilePicture.invalidate(); // To display the profile picture after it has been updated. if (user != null && user.getDisplayName() != null) { profileName.setText(user.getDisplayName()); @@ -135,13 +97,6 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { return view; } - // TODO: Rename method, update argument and hook method into UI event - public void onButtonPressed(Uri uri) { - if (mListener != null) { - mListener.onFragmentInteraction(uri); - } - } - /** * Called when a view has been clicked. * @@ -160,11 +115,11 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { } // TODO Make the function actually do something. + /** * Performs profile picture change action. */ public void profilePicOnClick() { -// Log.d(TAG, "profilePicOnClick: JE KAN NOG GEEN FOTO UPLOADEN"); dispatchTakePictureIntent(); } @@ -180,6 +135,7 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { /** * Grabs the image just taken by the built-in camera and pushes this image to the user account. + * * @param requestCode * @param resultCode * @param data @@ -189,12 +145,15 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) { Bundle extras = data.getExtras(); Bitmap imageBitmap = (Bitmap) extras.get("data"); + progressDialog = ProgressDialog.show(getActivity(), getString(R.string.please_wait), "Uploading...", true, false); UploadClass uploadClass = new UploadClass(getActivity()); uploadClass.uploadProfilePicture(imageBitmap); + progressDialog.dismiss(); } } // TODO Make this function into its own class for modularity. + /** * Performs password reset action. */ @@ -205,8 +164,8 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { @Override public void onComplete(@NonNull Task task) { Toast.makeText(getActivity(), task.isSuccessful() - ? "An e-mail was sent, please follow its instructions." - : "An error occurred, please check internet connection.", + ? getString(R.string.mail_successful) + : getString(R.string.mail_failed), Toast.LENGTH_SHORT).show(); } }); @@ -214,41 +173,4 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { // TODO Add code here for when there is no currently active user. } } - - /** - * Obligatory onAttach function included in fragments. - * @param context provided context for the function to operate on. - */ - @Override - public void onAttach(Context context) { - super.onAttach(context); - if (context instanceof OnFragmentInteractionListener) { - mListener = (OnFragmentInteractionListener) context; - } else { - throw new RuntimeException(context.toString() - + " must implement OnFragmentInteractionListener"); - } - } - - /** - * Obligatory onDetach function included in fragments. - */ - @Override - public void onDetach() { - super.onDetach(); - mListener = null; - } - - /** - * This interface must be implemented by activities that contain this - * fragment to allow an interaction in this fragment to be communicated - * to the activity and potentially other fragments contained in that - * activity. - * See the Android Training lesson http://developer.android.com/training/basics/fragments/communicating.html - * for more information. - */ - public interface OnFragmentInteractionListener { - // TODO: Update argument type and name - void onFragmentInteraction(Uri uri); - } } diff --git a/app/MyHyvesBookPlusStagram/app/src/main/res/values/strings.xml b/app/MyHyvesBookPlusStagram/app/src/main/res/values/strings.xml index a5f3ee1..8986643 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/res/values/strings.xml +++ b/app/MyHyvesBookPlusStagram/app/src/main/res/values/strings.xml @@ -24,4 +24,6 @@ profile picture Change Password Please Wait + An e-mail was sent. Please follow its instructions. + An error occurred. Please check internet connection. From 5181128504243df8775434f30223e938c5739e6a Mon Sep 17 00:00:00 2001 From: Niels Zwemmer Date: Sat, 24 Jun 2017 13:40:02 +0200 Subject: [PATCH 3/4] Committed files for others to look at and improve: Photo upload does not work properly. --- .../app/src/main/AndroidManifest.xml | 3 + .../myhyvesbookplus/tagram/MainActivity.java | 4 +- .../tagram/ProfileFragment.java | 166 ++++++++++++++++-- .../tagram/controller/UploadClass.java | 33 ++-- 4 files changed, 178 insertions(+), 28 deletions(-) diff --git a/app/MyHyvesBookPlusStagram/app/src/main/AndroidManifest.xml b/app/MyHyvesBookPlusStagram/app/src/main/AndroidManifest.xml index dff6028..e3615d5 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/AndroidManifest.xml +++ b/app/MyHyvesBookPlusStagram/app/src/main/AndroidManifest.xml @@ -3,6 +3,9 @@ package="nl.myhyvesbookplus.tagram"> + + + task) { Toast.makeText(getActivity(), task.isSuccessful() - ? getString(R.string.mail_successful) - : getString(R.string.mail_failed), + ? "An e-mail was sent, please follow its instructions." + : "An error occurred, please check internet connection.", Toast.LENGTH_SHORT).show(); } }); @@ -174,4 +269,43 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { // TODO Add code here for when there is no currently active user. } } + + /** + * Obligatory onAttach function included in fragments. + * @param context provided context for the function to operate on. + */ + @Override + public void onAttach(Context context) { + super.onAttach(context); + if (context instanceof OnFragmentInteractionListener) { + mListener = (OnFragmentInteractionListener) context; + } else { + throw new RuntimeException(context.toString() + + " must implement OnFragmentInteractionListener"); + } + } + + /** + * Obligatory onDetach function included in fragments. + */ + @Override + public void onDetach() { + super.onDetach(); + mListener = null; + } + + /** + * This interface must be implemented by activities that contain this + * fragment to allow an interaction in this fragment to be communicated + * to the activity and potentially other fragments contained in that + * activity. + * See the Android Training lesson http://developer.android.com/training/basics/fragments/communicating.html + * for more information. + */ + public interface OnFragmentInteractionListener { + // TODO: Update argument type and name + void onFragmentInteraction(Uri uri); + } + + } diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/controller/UploadClass.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/controller/UploadClass.java index c3e7c8b..f46b18e 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/controller/UploadClass.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/controller/UploadClass.java @@ -6,6 +6,7 @@ import android.net.Uri; import android.support.annotation.NonNull; import android.util.Log; + import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.OnFailureListener; import com.google.android.gms.tasks.OnSuccessListener; @@ -20,6 +21,9 @@ import com.google.firebase.storage.StorageReference; import com.google.firebase.storage.UploadTask; import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import nl.myhyvesbookplus.tagram.model.BitmapPost; import nl.myhyvesbookplus.tagram.model.UriPost; @@ -100,17 +104,24 @@ public class UploadClass { /// Profile picture /// - public void uploadProfilePicture(Bitmap picture) { - byte[] uploadPhoto = bitmapToBytes(picture); - oldPicture = mUser.getPhotoUrl(); - UploadTask photoUpload = mStorageRef.child("profile").child(getUserUid() + "_" + currentTimeMillis()).putBytes(uploadPhoto); - photoUpload.addOnSuccessListener(new OnSuccessListener() { - @Override - public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { - Uri downloadUrl = taskSnapshot.getDownloadUrl(); - updateProfilePictureInUser(downloadUrl); - } - }); + public void uploadProfilePicture(File picture) { + try { + FileInputStream stream = new FileInputStream(picture); +// Uri uri = Uri.fromFile(picture); + Log.d(TAG, "uploadProfilePicture: This is the uri:" + stream.toString()); + oldPicture = mUser.getPhotoUrl(); + + UploadTask photoUpload = mStorageRef.child("profile").child(getUserUid() + "_" + currentTimeMillis()).putStream(stream); + photoUpload.addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { + Uri downloadUrl = taskSnapshot.getDownloadUrl(); + updateProfilePictureInUser(downloadUrl); + } + }); + } catch (FileNotFoundException fnfe) { + Log.d(TAG, "uploadProfilePicture: FIle niet gevonden"); + } } private void updateProfilePictureInUser(Uri url) { From d4d10e3f6fd4edce13863056bd071126aa92715f Mon Sep 17 00:00:00 2001 From: Niels Zwemmer Date: Mon, 26 Jun 2017 16:13:44 +0200 Subject: [PATCH 4/4] Profile page working, better quality picture aswell. Only needs personal feed. --- .../app/src/main/AndroidManifest.xml | 16 +- .../myhyvesbookplus/tagram/MainActivity.java | 2 +- .../tagram/ProfileFragment.java | 180 +++--------------- .../controller/ProfilePictureUploader.java | 17 +- .../app/src/main/res/values-nl/strings.xml | 14 +- .../app/src/main/res/values/strings.xml | 5 +- .../app/src/main/res/xml/file_paths.xml | 6 + 7 files changed, 81 insertions(+), 159 deletions(-) create mode 100644 app/MyHyvesBookPlusStagram/app/src/main/res/xml/file_paths.xml diff --git a/app/MyHyvesBookPlusStagram/app/src/main/AndroidManifest.xml b/app/MyHyvesBookPlusStagram/app/src/main/AndroidManifest.xml index e3615d5..63bdf6e 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/AndroidManifest.xml +++ b/app/MyHyvesBookPlusStagram/app/src/main/AndroidManifest.xml @@ -3,8 +3,8 @@ package="nl.myhyvesbookplus.tagram"> - - + + + + + + + diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/MainActivity.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/MainActivity.java index b8d1e62..a687f00 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/MainActivity.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/MainActivity.java @@ -17,7 +17,7 @@ import com.google.firebase.auth.FirebaseAuth; import nl.myhyvesbookplus.tagram.controller.DownloadClass; import nl.myhyvesbookplus.tagram.controller.ProfilePictureUploader; -public class MainActivity extends AppCompatActivity implements CameraFragment.OnFragmentInteractionListener, ProfileFragment.OnFragmentInteractionListener, TimelineFragment.OnFragmentInteractionListener, ProfilePictureUploader.ProfilePictureUpdatedListener { +public class MainActivity extends AppCompatActivity implements CameraFragment.OnFragmentInteractionListener, TimelineFragment.OnFragmentInteractionListener, ProfilePictureUploader.ProfilePictureUpdatedListener { final static private String TAG = "MainScreen"; FirebaseAuth mAuth; diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/ProfileFragment.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/ProfileFragment.java index dd4df22..eb40f3d 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/ProfileFragment.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/ProfileFragment.java @@ -1,19 +1,14 @@ package nl.myhyvesbookplus.tagram; -import android.app.Activity; import android.app.Fragment; import android.app.ProgressDialog; -import android.content.Context; import android.content.Intent; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore; import android.support.annotation.NonNull; import android.support.v4.content.FileProvider; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -32,88 +27,38 @@ import com.google.firebase.storage.FirebaseStorage; import com.google.firebase.storage.StorageReference; import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; -import nl.myhyvesbookplus.tagram.controller.UploadClass; import nl.myhyvesbookplus.tagram.controller.ProfilePictureUploader; import static android.app.Activity.RESULT_OK; -import static java.lang.System.currentTimeMillis; -/** - * A simple {@link Fragment} subclass. - * Activities that contain this fragment must implement the - * {@link ProfileFragment.OnFragmentInteractionListener} interface - * to handle interaction events. - * Use the {@link ProfileFragment#newInstance} factory method to - * create an instance of this fragment. - */ public class ProfileFragment extends Fragment implements View.OnClickListener { -// static final int REQUEST_IMAGE_CAPTURE = 1; static final int REQUEST_TAKE_PHOTO = 1; - final static private String TAG = "ProfileFragment"; - // TODO: Rename parameter arguments, choose names that match - // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER - private static final String ARG_PARAM1 = "param1"; - private static final String ARG_PARAM2 = "param2"; - private static Uri downloadUrl; + + /// Views, buttons and other protected declarations /// protected Button changePwdButton; protected ImageButton profilePicButton; - - /// Views /// protected StorageReference httpsReference; protected TextView profileName; protected ImageView profilePicture; protected FirebaseUser user; + protected File photoFile = null; ProgressDialog progressDialog; - String mCurrentPhotoPath; - - File photoFile = null; - - // TODO: Rename and change types of parameters - private String mParam1; - private String mParam2; - private OnFragmentInteractionListener mListener; /// Required empty public constructor /// public ProfileFragment() {} - - /** - * Use this factory method to create a new instance of - * this fragment using the provided parameters. - * - * @param param1 Parameter 1. - * @param param2 Parameter 2. - * @return A new instance of fragment ProfileFragment. - */ - // TODO: Rename and change types and number of parameters - public static ProfileFragment newInstance(String param1, String param2) { - ProfileFragment fragment = new ProfileFragment(); - Bundle args = new Bundle(); - args.putString(ARG_PARAM1, param1); - args.putString(ARG_PARAM2, param2); - fragment.setArguments(args); - return fragment; - } - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (getArguments() != null) { - mParam1 = getArguments().getString(ARG_PARAM1); - mParam2 = getArguments().getString(ARG_PARAM2); - } - user = FirebaseAuth.getInstance().getCurrentUser(); } /** - * Assigns all views. + * Assigns all views and buttons. */ protected void findViews(View view) { profilePicButton = (ImageButton) view.findViewById(R.id.profile_pic_button); @@ -123,22 +68,30 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { bindOnClick(); } + /** + * Bind the buttons to their listeners. + */ protected void bindOnClick() { profilePicButton.setOnClickListener(this); changePwdButton.setOnClickListener(this); } - /// Setup /// + /// Page setup /// @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_profile, container, false); findViews(view); - if (user != null && user.getPhotoUrl() != null) { - httpsReference = FirebaseStorage.getInstance().getReferenceFromUrl(user.getPhotoUrl().toString()); + if (user != null) { + if(user.getPhotoUrl() != null) { + httpsReference = FirebaseStorage.getInstance().getReferenceFromUrl(user.getPhotoUrl().toString()); + } + + if (user.getDisplayName() != null) { + profileName.setText(user.getDisplayName()); + } } if (httpsReference != null) { @@ -147,20 +100,9 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { profilePicture.invalidate(); - if (user != null && user.getDisplayName() != null) { - profileName.setText(user.getDisplayName()); - } - return view; } - // TODO: Rename method, update argument and hook method into UI event - public void onButtonPressed(Uri uri) { - if (mListener != null) { - mListener.onFragmentInteraction(uri); - } - } - /** * Called when a view has been clicked. * @@ -178,39 +120,24 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { } } - // TODO Make the function actually do something. - /** - * Performs profile picture change action. - */ - public void profilePicOnClick() { -// Log.d(TAG, "profilePicOnClick: JE KAN NOG GEEN FOTO UPLOADEN"); - dispatchTakePictureIntent(); - } - /** * Starts new intent for access to the built-in camera of device. */ -// private void dispatchTakePictureIntent() { -// Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); -// if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) { -// startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); -// } -// } - - private void dispatchTakePictureIntent() { + private void profilePicOnClick() { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - // Ensure that there's a camera activity to handle the intent + /* Ensure that there's a camera activity to handle the intent */ if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) { - // Create the File where the photo should go + /* Create the File where the photo should go */ try { photoFile = createImageFile(); } catch (IOException ex) { - // Error occurred while creating the File + Toast.makeText(getActivity(), getString(R.string.image_save_error), Toast.LENGTH_LONG); } - // Continue only if the File was successfully created if (photoFile != null) { -// Uri uri = Uri.fromFile(photoFile); //TODO Als je dit in takePictureIntent zet ipv photoFile, grote boos. - takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoFile); + Uri photoURI = FileProvider.getUriForFile(getActivity(), + "nl.myhyvesbookplus.tagram.fileprovider", + photoFile); + takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); } } @@ -218,35 +145,29 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { /** * Grabs the image just taken by the built-in camera and pushes this image to the user account. - * @param requestCode - * @param resultCode - * @param data + * @param requestCode The code which corresponds to REQUEST_TAKE_PHOTO. Used as indicator. + * @param resultCode Code should be RESULT_OK to allow camera to proceed. + * @param data The image data from the camera. */ @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) { - Bundle extras = data.getExtras(); - progressDialog = ProgressDialog.show(getActivity(), getString(R.string.please_wait), "bezig met uploaden", false, false); -// Bitmap imageBitmap = Bitmap.createBitmap(); + progressDialog = ProgressDialog.show(getActivity(), getString(R.string.please_wait), getString(R.string.upload_profile_pic), false, false); ProfilePictureUploader profilePictureUploader = new ProfilePictureUploader(getActivity()); -// profilePictureUploader.uploadProfilePicture(imageBitmap); + profilePictureUploader.uploadProfilePicture(photoFile.getAbsoluteFile()); } } private File createImageFile() throws IOException { // Create an image file name - String imageFileName = "JPEG_" + currentTimeMillis(); + String imageFileName = "JPEG_" + user.getUid(); File storageDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES); - File image = File.createTempFile( + return File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); - - // Save a file: path for use with ACTION_VIEW intents - mCurrentPhotoPath = image.getAbsolutePath(); - return image; } @@ -271,43 +192,4 @@ public class ProfileFragment extends Fragment implements View.OnClickListener { // TODO Add code here for when there is no currently active user. } } - - /** - * Obligatory onAttach function included in fragments. - * @param context provided context for the function to operate on. - */ - @Override - public void onAttach(Context context) { - super.onAttach(context); - if (context instanceof OnFragmentInteractionListener) { - mListener = (OnFragmentInteractionListener) context; - } else { - throw new RuntimeException(context.toString() - + " must implement OnFragmentInteractionListener"); - } - } - - /** - * Obligatory onDetach function included in fragments. - */ - @Override - public void onDetach() { - super.onDetach(); - mListener = null; - } - - /** - * This interface must be implemented by activities that contain this - * fragment to allow an interaction in this fragment to be communicated - * to the activity and potentially other fragments contained in that - * activity. - * See the Android Training lesson http://developer.android.com/training/basics/fragments/communicating.html - * for more information. - */ - public interface OnFragmentInteractionListener { - // TODO: Update argument type and name - void onFragmentInteraction(Uri uri); - } - - } diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/controller/ProfilePictureUploader.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/controller/ProfilePictureUploader.java index 1137d5d..3264976 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/controller/ProfilePictureUploader.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/controller/ProfilePictureUploader.java @@ -5,6 +5,7 @@ import android.graphics.Bitmap; import android.net.Uri; import android.support.annotation.NonNull; import android.util.Log; +import android.widget.Toast; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.OnFailureListener; @@ -12,9 +13,12 @@ import com.google.android.gms.tasks.OnSuccessListener; import com.google.android.gms.tasks.Task; import com.google.firebase.auth.UserProfileChangeRequest; import com.google.firebase.storage.FirebaseStorage; +import com.google.firebase.storage.StorageMetadata; import com.google.firebase.storage.StorageReference; import com.google.firebase.storage.UploadTask; +import java.io.File; + import static java.lang.System.currentTimeMillis; /** @@ -39,10 +43,13 @@ public class ProfilePictureUploader extends UploadClass { } } - public void uploadProfilePicture(Bitmap picture) { - byte[] uploadPhoto = bitmapToBytes(picture); + public void uploadProfilePicture(File picture) { oldPicture = mUser.getPhotoUrl(); - UploadTask photoUpload = mStorageRef.child("profile").child(getUserUid() + "_" + currentTimeMillis()).putBytes(uploadPhoto); + StorageMetadata metadata = new StorageMetadata.Builder() + .setContentType("image/jpg") + .build(); + + UploadTask photoUpload = mStorageRef.child("profile").child(getUserUid() + "_" + currentTimeMillis()).putFile(Uri.fromFile(picture), metadata); photoUpload.addOnSuccessListener(new OnSuccessListener() { @Override public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { @@ -80,9 +87,9 @@ public class ProfilePictureUploader extends UploadClass { @Override public void onComplete(@NonNull Task task) { if (task.isSuccessful()) { - Log.d(TAG, "onComplete: Delete successfull"); + Log.v(TAG, "onComplete: Delete successful"); } else { - Log.d(TAG, "onComplete: " + task.getException().getLocalizedMessage()); + Log.v(TAG, "onComplete: " + task.getException().getLocalizedMessage()); } } }); diff --git a/app/MyHyvesBookPlusStagram/app/src/main/res/values-nl/strings.xml b/app/MyHyvesBookPlusStagram/app/src/main/res/values-nl/strings.xml index d59c333..696d213 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/res/values-nl/strings.xml +++ b/app/MyHyvesBookPlusStagram/app/src/main/res/values-nl/strings.xml @@ -17,5 +17,17 @@ Wijzig Profiel Foto profiel foto Wachtwoord wijzigen - Wacht a.u.b. + Momentje + Hallo leeg fragment + Hallo Camera fragment + Voer alstublieft email en wachtwoord in + Er is een fout opgetreden. Controleer internetverbinding. + Er is een e-mail verzonden. Volg a.u.b. de instructies. + Wachtwoorden komen niet overeen + Vul alstublieft alle velden in + Opslaan + Uploaden + Foto opslaan mislukt. Zorg a.u.b. dat er genoeg ruimte op uw telefoon beschikbaar is. + Het updaten van de profielfoto is mislukt. Controleer uw internetverbinding. + Profielfoto aan het uploaden... \ No newline at end of file diff --git a/app/MyHyvesBookPlusStagram/app/src/main/res/values/strings.xml b/app/MyHyvesBookPlusStagram/app/src/main/res/values/strings.xml index fdeef48..9597f43 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/res/values/strings.xml +++ b/app/MyHyvesBookPlusStagram/app/src/main/res/values/strings.xml @@ -19,7 +19,7 @@ Hello blank fragment Hello Camera MyHyvesBookPlusTagram logo - LogOut + Logout Change Profile Picture profile picture Change Password @@ -29,4 +29,7 @@ Upload Save + Saving image to storage failed. Please make sure there is space available on the device. + Updating the profile picture failed. Please check network connection. + Uploading profile picture... diff --git a/app/MyHyvesBookPlusStagram/app/src/main/res/xml/file_paths.xml b/app/MyHyvesBookPlusStagram/app/src/main/res/xml/file_paths.xml new file mode 100644 index 0000000..c87d3ee --- /dev/null +++ b/app/MyHyvesBookPlusStagram/app/src/main/res/xml/file_paths.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file