Bugprone version of Profilefragment.

This commit is contained in:
Niels Zwemmer
2017-06-23 11:44:43 +02:00
parent 66221c4393
commit b0a99b3ab1
3 changed files with 64 additions and 5 deletions

View File

@@ -71,6 +71,8 @@ public class MainActivity extends AppCompatActivity implements CameraFragment.On
goToLogin(); goToLogin();
} }
Log.d(TAG, "onCreate: " + mAuth.getCurrentUser().getPhotoUrl() );
TimelineFragment fragment = new TimelineFragment(); TimelineFragment fragment = new TimelineFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction(); FragmentTransaction transaction = getFragmentManager().beginTransaction();
@@ -98,5 +100,6 @@ public class MainActivity extends AppCompatActivity implements CameraFragment.On
protected void goToLogin() { protected void goToLogin() {
Intent goToLogIn = new Intent(this, LoginActivity.class); Intent goToLogIn = new Intent(this, LoginActivity.class);
startActivity(goToLogIn); startActivity(goToLogIn);
this.finish();
} }
} }

View File

@@ -1,10 +1,13 @@
package nl.myhyvesbookplus.tagram; package nl.myhyvesbookplus.tagram;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.app.Fragment; import android.app.Fragment;
import android.provider.MediaStore;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@@ -22,11 +25,13 @@ import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth; import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser; import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.UserProfileChangeRequest;
import com.google.firebase.storage.FirebaseStorage; import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference; import com.google.firebase.storage.StorageReference;
import org.w3c.dom.Text; import java.net.URI;
import static android.app.Activity.RESULT_OK;
import static android.content.ContentValues.TAG; import static android.content.ContentValues.TAG;
/** /**
@@ -42,6 +47,8 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1"; private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2"; private static final String ARG_PARAM2 = "param2";
static final int REQUEST_IMAGE_CAPTURE = 1;
private static Uri downloadUrl;
// TODO: Rename and change types of parameters // TODO: Rename and change types of parameters
private String mParam1; private String mParam1;
@@ -124,7 +131,6 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
Glide.with(this).using(new FirebaseImageLoader()).load(httpsReference).into(profilePicture); Glide.with(this).using(new FirebaseImageLoader()).load(httpsReference).into(profilePicture);
} }
// TODO Remove check for getDisplayName if all users are required to enter a displayName anyways.
if (user != null && user.getDisplayName() != null) { if (user != null && user.getDisplayName() != null) {
profileName.setText(user.getDisplayName()); profileName.setText(user.getDisplayName());
} }
@@ -161,9 +167,55 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
* Performs profile picture change action. * Performs profile picture change action.
*/ */
public void profilePicOnClick() { public void profilePicOnClick() {
Log.d(TAG, "profilePicOnClick: JE KAN NOG GEEN FOTO UPLOADEN"); // 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);
}
}
/**
* Grabs the image just taken by the built-in camera and pushes this image to the user account.
* @param requestCode
* @param resultCode
* @param data
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
UploadClass uploadClass = new UploadClass();
uploadClass.uploadPicture(imageBitmap);
downloadUrl = uploadClass.getDownloadUrl();
updateUserProfilePic(user);
}
}
protected void updateUserProfilePic(final FirebaseUser user) {
UserProfileChangeRequest request = new UserProfileChangeRequest.Builder()
.setPhotoUri(downloadUrl)
.build();
user.updateProfile(request)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "User profile updated!");
}
}
});
}
// TODO Make this function into its own class for modularity. // TODO Make this function into its own class for modularity.
/** /**
* Performs password reset action. * Performs password reset action.

View File

@@ -21,7 +21,7 @@ import java.io.ByteArrayOutputStream;
public class UploadClass { public class UploadClass {
private StorageReference mStorageRef; private StorageReference mStorageRef;
private static Uri downloadUrl;
public UploadClass() { public UploadClass() {
mStorageRef = FirebaseStorage.getInstance().getReference().child("images"); mStorageRef = FirebaseStorage.getInstance().getReference().child("images");
@@ -45,11 +45,15 @@ public class UploadClass {
@Override @Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Handle successful uploads on complete // Handle successful uploads on complete
Uri downloadUrl = taskSnapshot.getMetadata().getDownloadUrl(); downloadUrl = taskSnapshot.getMetadata().getDownloadUrl();
} }
}); });
} }
public Uri getDownloadUrl() {
return downloadUrl;
}
private String getUserUid() { private String getUserUid() {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) { if (user != null) {