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