Profile pics working!
This commit is contained in:
@@ -1,22 +1,20 @@
|
|||||||
package nl.myhyvesbookplus.tagram;
|
package nl.myhyvesbookplus.tagram;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Fragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
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.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
@@ -25,14 +23,10 @@ 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 java.net.URI;
|
|
||||||
|
|
||||||
import static android.app.Activity.RESULT_OK;
|
import static android.app.Activity.RESULT_OK;
|
||||||
import static android.content.ContentValues.TAG;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple {@link Fragment} subclass.
|
* A simple {@link Fragment} subclass.
|
||||||
@@ -43,27 +37,24 @@ import static android.content.ContentValues.TAG;
|
|||||||
* create an instance of this fragment.
|
* create an instance of this fragment.
|
||||||
*/
|
*/
|
||||||
public class ProfileFragment extends Fragment implements View.OnClickListener {
|
public class ProfileFragment extends Fragment implements View.OnClickListener {
|
||||||
|
static final int REQUEST_IMAGE_CAPTURE = 1;
|
||||||
// TODO: Rename parameter arguments, choose names that match
|
// TODO: Rename parameter arguments, choose names that match
|
||||||
// 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;
|
private static Uri downloadUrl;
|
||||||
|
|
||||||
// TODO: Rename and change types of parameters
|
|
||||||
private String mParam1;
|
|
||||||
private String mParam2;
|
|
||||||
|
|
||||||
/// Views ///
|
|
||||||
|
|
||||||
protected Button changePwdButton;
|
protected Button changePwdButton;
|
||||||
protected ImageButton profilePicButton;
|
protected ImageButton profilePicButton;
|
||||||
|
|
||||||
|
/// Views ///
|
||||||
protected StorageReference httpsReference;
|
protected StorageReference httpsReference;
|
||||||
protected TextView profileName;
|
protected TextView profileName;
|
||||||
protected ImageView profilePicture;
|
protected ImageView profilePicture;
|
||||||
|
|
||||||
private OnFragmentInteractionListener mListener;
|
|
||||||
protected FirebaseUser user;
|
protected FirebaseUser user;
|
||||||
|
// TODO: Rename and change types of parameters
|
||||||
|
private String mParam1;
|
||||||
|
private String mParam2;
|
||||||
|
private OnFragmentInteractionListener mListener;
|
||||||
|
|
||||||
/// Required empty public constructor ///
|
/// Required empty public constructor ///
|
||||||
|
|
||||||
@@ -193,27 +184,28 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
|
|||||||
Bundle extras = data.getExtras();
|
Bundle extras = data.getExtras();
|
||||||
Bitmap imageBitmap = (Bitmap) extras.get("data");
|
Bitmap imageBitmap = (Bitmap) extras.get("data");
|
||||||
UploadClass uploadClass = new UploadClass();
|
UploadClass uploadClass = new UploadClass();
|
||||||
uploadClass.uploadPicture(imageBitmap);
|
uploadClass.uploadProfilePicture(imageBitmap);
|
||||||
downloadUrl = uploadClass.getDownloadUrl();
|
// uploadClass.uploadPicture(new BitmapPost(imageBitmap, "Ik ben een heel mooi comment"));
|
||||||
updateUserProfilePic(user);
|
// downloadUrl = uploadClass.getDownloadUrl();
|
||||||
|
// updateUserProfilePic(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateUserProfilePic(final FirebaseUser user) {
|
// protected void updateUserProfilePic(final FirebaseUser user) {
|
||||||
UserProfileChangeRequest request = new UserProfileChangeRequest.Builder()
|
// UserProfileChangeRequest request = new UserProfileChangeRequest.Builder()
|
||||||
.setPhotoUri(downloadUrl)
|
// .setPhotoUri(downloadUrl)
|
||||||
.build();
|
// .build();
|
||||||
|
//
|
||||||
user.updateProfile(request)
|
// user.updateProfile(request)
|
||||||
.addOnCompleteListener(new OnCompleteListener<Void>() {
|
// .addOnCompleteListener(new OnCompleteListener<Void>() {
|
||||||
@Override
|
// @Override
|
||||||
public void onComplete(@NonNull Task<Void> task) {
|
// public void onComplete(@NonNull Task<Void> task) {
|
||||||
if (task.isSuccessful()) {
|
// if (task.isSuccessful()) {
|
||||||
Log.d(TAG, "User profile updated!");
|
// 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.
|
||||||
|
|||||||
@@ -29,12 +29,10 @@ import nl.myhyvesbookplus.tagram.model.UriPost;
|
|||||||
|
|
||||||
public class UploadClass {
|
public class UploadClass {
|
||||||
|
|
||||||
|
private static final String TAG = "UploadClass";
|
||||||
private StorageReference mStorageRef;
|
private StorageReference mStorageRef;
|
||||||
private DatabaseReference mDataRef;
|
private DatabaseReference mDataRef;
|
||||||
|
|
||||||
private static final String TAG = "UploadClass";
|
|
||||||
private static Uri downloadUrl;
|
|
||||||
|
|
||||||
public UploadClass() {
|
public UploadClass() {
|
||||||
mStorageRef = FirebaseStorage.getInstance().getReference();
|
mStorageRef = FirebaseStorage.getInstance().getReference();
|
||||||
mDataRef = FirebaseDatabase.getInstance().getReference();
|
mDataRef = FirebaseDatabase.getInstance().getReference();
|
||||||
@@ -53,7 +51,7 @@ public class UploadClass {
|
|||||||
public void uploadPicture(final BitmapPost post) {
|
public void uploadPicture(final BitmapPost post) {
|
||||||
|
|
||||||
|
|
||||||
UploadTask uploadTask = mStorageRef.child("posts").child("UniquePostName").putBytes(bitmapToBytes(post.getBitmap()));
|
UploadTask uploadTask = mStorageRef.child("posts").child("UniquePostName" + ".jpg").putBytes(bitmapToBytes(post.getBitmap()));
|
||||||
uploadTask.addOnFailureListener(new OnFailureListener() {
|
uploadTask.addOnFailureListener(new OnFailureListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Exception e) {
|
public void onFailure(@NonNull Exception e) {
|
||||||
@@ -66,13 +64,13 @@ public class UploadClass {
|
|||||||
// Handle successful uploads on complete
|
// Handle successful uploads on complete
|
||||||
Log.d(TAG, "onSuccess: Upload Success!");
|
Log.d(TAG, "onSuccess: Upload Success!");
|
||||||
Uri downloadUrl = taskSnapshot.getMetadata().getDownloadUrl();
|
Uri downloadUrl = taskSnapshot.getMetadata().getDownloadUrl();
|
||||||
// putPostInDatabase(post.getUriPost(downloadUrl));
|
putPostInDatabase(post.getUriPost(downloadUrl));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void putPostInDatabase(UriPost post) {
|
private void putPostInDatabase(UriPost post) {
|
||||||
DatabaseReference ref = mDataRef.child("posts").child("UniquePostName" + ".jpg"); // TODO: Naam voor post.
|
DatabaseReference ref = mDataRef.child("posts").child("UniquePostName"); // TODO: Naam voor post.
|
||||||
ref.setValue(post) // FIXME: Grote boos veroorzaker
|
ref.setValue(post) // FIXME: Grote boos veroorzaker
|
||||||
.addOnCompleteListener(new OnCompleteListener<Void>() {
|
.addOnCompleteListener(new OnCompleteListener<Void>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -82,15 +80,10 @@ public class UploadClass {
|
|||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "onComplete: " + task.getException().getLocalizedMessage());
|
Log.d(TAG, "onComplete: " + task.getException().getLocalizedMessage());
|
||||||
}
|
}
|
||||||
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) {
|
||||||
|
|||||||
@@ -25,4 +25,8 @@ public class BitmapPost extends Post {
|
|||||||
public UriPost getUriPost(Uri url) {
|
public UriPost getUriPost(Uri url) {
|
||||||
return new UriPost(url, getComment(), getDate(), getNietSlechts(), getPoster());
|
return new UriPost(url, getComment(), getDate(), getNietSlechts(), getPoster());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPhoto(Bitmap photo) {
|
||||||
|
this.photo = photo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,10 @@ abstract class Post {
|
|||||||
private int nietSlechts;
|
private int nietSlechts;
|
||||||
private String poster;
|
private String poster;
|
||||||
|
|
||||||
|
Post() {
|
||||||
|
// Default constructor required for calls to Post.getValue(User.class)
|
||||||
|
}
|
||||||
|
|
||||||
Post(String comment, Date date, int nietSlechts, String poster) {
|
Post(String comment, Date date, int nietSlechts, String poster) {
|
||||||
this.date = date;
|
this.date = date;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
@@ -30,15 +34,31 @@ abstract class Post {
|
|||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDate(Date date) {
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
|
||||||
public String getComment() {
|
public String getComment() {
|
||||||
return comment;
|
return comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setComment(String comment) {
|
||||||
|
this.comment = comment;
|
||||||
|
}
|
||||||
|
|
||||||
public int getNietSlechts() {
|
public int getNietSlechts() {
|
||||||
return nietSlechts;
|
return nietSlechts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setNietSlechts(int nietSlechts) {
|
||||||
|
this.nietSlechts = nietSlechts;
|
||||||
|
}
|
||||||
|
|
||||||
public String getPoster() {
|
public String getPoster() {
|
||||||
return poster;
|
return poster;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPoster(String poster) {
|
||||||
|
this.poster = poster;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,23 +5,28 @@ import android.net.Uri;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class UriPost extends Post {
|
public class UriPost extends Post {
|
||||||
private Uri photo;
|
private String photo;
|
||||||
|
|
||||||
public UriPost() {
|
public UriPost() {
|
||||||
|
// Default constructor required for calls to DataSnapshot.getValue(UriPost.class)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public UriPost(Uri photo, String comment, Date date, int nietSlechts, String poster) {
|
public UriPost(Uri photo, String comment, Date date, int nietSlechts, String poster) {
|
||||||
super(comment, date, nietSlechts, poster);
|
super(comment, date, nietSlechts, poster);
|
||||||
this.photo = photo;
|
this.photo = photo.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public UriPost(Uri photo, String comment) {
|
public UriPost(String photo, String comment) {
|
||||||
super(comment);
|
super(comment);
|
||||||
this.photo = photo;
|
this.photo = photo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Uri getUri() {
|
public String getUri() {
|
||||||
return photo;
|
return photo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPhoto(String photo) {
|
||||||
|
this.photo = photo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,4 @@
|
|||||||
<string name="profile_picture_description">profile picture</string>
|
<string name="profile_picture_description">profile picture</string>
|
||||||
<string name="change_psw_button">Change Password</string>
|
<string name="change_psw_button">Change Password</string>
|
||||||
<string name="please_wait">Please Wait</string>
|
<string name="please_wait">Please Wait</string>
|
||||||
<string name="login_error">Please fill in email and password</string>
|
|
||||||
<string name="register_error">Please fill in all the fields.</string>
|
|
||||||
<string name="password_match_error">Passwords do not match</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user