Merge branch 'marijn-appje' into 'master'
Marijn appje See merge request !11
This commit was merged in pull request #11.
This commit is contained in:
@@ -4,12 +4,10 @@ import android.app.FragmentManager;
|
|||||||
import android.app.FragmentTransaction;
|
import android.app.FragmentTransaction;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.hardware.Camera;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.design.widget.BottomNavigationView;
|
import android.support.design.widget.BottomNavigationView;
|
||||||
import android.app.Fragment;
|
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@@ -17,9 +15,10 @@ import android.view.View;
|
|||||||
|
|
||||||
import com.google.firebase.auth.FirebaseAuth;
|
import com.google.firebase.auth.FirebaseAuth;
|
||||||
|
|
||||||
|
import nl.myhyvesbookplus.tagram.controller.UploadClass;
|
||||||
import nl.myhyvesbookplus.tagram.model.BitmapPost;
|
import nl.myhyvesbookplus.tagram.model.BitmapPost;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements CameraFragment.OnFragmentInteractionListener, ProfileFragment.OnFragmentInteractionListener, TimelineFragment.OnFragmentInteractionListener {
|
public class MainActivity extends AppCompatActivity implements CameraFragment.OnFragmentInteractionListener, ProfileFragment.OnFragmentInteractionListener, TimelineFragment.OnFragmentInteractionListener, UploadClass.ProfilePictureUpdatedListener {
|
||||||
final static private String TAG = "MainScreen";
|
final static private String TAG = "MainScreen";
|
||||||
|
|
||||||
FirebaseAuth mAuth;
|
FirebaseAuth mAuth;
|
||||||
@@ -35,25 +34,25 @@ public class MainActivity extends AppCompatActivity implements CameraFragment.On
|
|||||||
case nl.myhyvesbookplus.tagram.R.id.navigation_timeline:
|
case nl.myhyvesbookplus.tagram.R.id.navigation_timeline:
|
||||||
Log.d(TAG, "onNavigationItemSelected: Timeline");
|
Log.d(TAG, "onNavigationItemSelected: Timeline");
|
||||||
TimelineFragment timeline = new TimelineFragment();
|
TimelineFragment timeline = new TimelineFragment();
|
||||||
transaction.replace(R.id.content, timeline);
|
transaction.replace(R.id.content, timeline)
|
||||||
transaction.addToBackStack(null);
|
.addToBackStack(null)
|
||||||
transaction.commit();
|
.commit();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case nl.myhyvesbookplus.tagram.R.id.navigation_camera:
|
case nl.myhyvesbookplus.tagram.R.id.navigation_camera:
|
||||||
Log.d(TAG, "onNavigationItemSelected: Camera");
|
Log.d(TAG, "onNavigationItemSelected: Camera");
|
||||||
CameraFragment camera = new CameraFragment();
|
CameraFragment camera = new CameraFragment();
|
||||||
transaction.replace(R.id.content, camera);
|
transaction.replace(R.id.content, camera)
|
||||||
transaction.addToBackStack(null);
|
.addToBackStack(null)
|
||||||
transaction.commit();
|
.commit();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case nl.myhyvesbookplus.tagram.R.id.navigation_profile:
|
case nl.myhyvesbookplus.tagram.R.id.navigation_profile:
|
||||||
Log.d(TAG, "onNavigationItemSelected: Profile");
|
Log.d(TAG, "onNavigationItemSelected: Profile");
|
||||||
ProfileFragment profile = new ProfileFragment();
|
ProfileFragment profile = new ProfileFragment();
|
||||||
transaction.replace(R.id.content, profile);
|
transaction.replace(R.id.content, profile)
|
||||||
transaction.addToBackStack(null);
|
.addToBackStack(null)
|
||||||
transaction.commit();
|
.commit();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -74,14 +73,11 @@ 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();
|
||||||
transaction.replace(R.id.content, fragment);
|
transaction.replace(R.id.content, fragment);
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -106,9 +102,22 @@ public class MainActivity extends AppCompatActivity implements CameraFragment.On
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testCreatePost(View view) {
|
public void testCreatePost(View view) {
|
||||||
UploadClass uploadClass = new UploadClass();
|
UploadClass uploadClass = new UploadClass(this);
|
||||||
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ALPHA_8);
|
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ALPHA_8);
|
||||||
BitmapPost bitmapPost = new BitmapPost(bitmap, "Dit is een Test!");
|
BitmapPost bitmapPost = new BitmapPost(bitmap, "Dit is een Test!");
|
||||||
uploadClass.uploadPicture(bitmapPost);
|
uploadClass.uploadPicture(bitmapPost);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import com.google.firebase.auth.FirebaseUser;
|
|||||||
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 nl.myhyvesbookplus.tagram.controller.UploadClass;
|
||||||
|
|
||||||
import static android.app.Activity.RESULT_OK;
|
import static android.app.Activity.RESULT_OK;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,6 +40,7 @@ import static android.app.Activity.RESULT_OK;
|
|||||||
*/
|
*/
|
||||||
public class ProfileFragment extends Fragment implements View.OnClickListener {
|
public class ProfileFragment extends Fragment implements View.OnClickListener {
|
||||||
static final int REQUEST_IMAGE_CAPTURE = 1;
|
static final int REQUEST_IMAGE_CAPTURE = 1;
|
||||||
|
final static private String TAG = "ProfileFragment";
|
||||||
// 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";
|
||||||
@@ -88,9 +91,6 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
user = FirebaseAuth.getInstance().getCurrentUser();
|
user = FirebaseAuth.getInstance().getCurrentUser();
|
||||||
if (user != null && user.getPhotoUrl() != null) {
|
|
||||||
httpsReference = FirebaseStorage.getInstance().getReferenceFromUrl(user.getPhotoUrl().toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,10 +118,16 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
|
|||||||
View view = inflater.inflate(R.layout.fragment_profile, container, false);
|
View view = inflater.inflate(R.layout.fragment_profile, container, false);
|
||||||
findViews(view);
|
findViews(view);
|
||||||
|
|
||||||
|
if (user != null && user.getPhotoUrl() != null) {
|
||||||
|
httpsReference = FirebaseStorage.getInstance().getReferenceFromUrl(user.getPhotoUrl().toString());
|
||||||
|
}
|
||||||
|
|
||||||
if (httpsReference != null) {
|
if (httpsReference != null) {
|
||||||
Glide.with(this).using(new FirebaseImageLoader()).load(httpsReference).into(profilePicture);
|
Glide.with(this).using(new FirebaseImageLoader()).load(httpsReference).into(profilePicture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
profilePicture.invalidate();
|
||||||
|
|
||||||
if (user != null && user.getDisplayName() != null) {
|
if (user != null && user.getDisplayName() != null) {
|
||||||
profileName.setText(user.getDisplayName());
|
profileName.setText(user.getDisplayName());
|
||||||
}
|
}
|
||||||
@@ -183,29 +189,11 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
|
|||||||
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
|
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
|
||||||
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(getActivity());
|
||||||
uploadClass.uploadProfilePicture(imageBitmap);
|
uploadClass.uploadProfilePicture(imageBitmap);
|
||||||
// uploadClass.uploadPicture(new BitmapPost(imageBitmap, "Ik ben een heel mooi comment"));
|
|
||||||
// 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.
|
||||||
@@ -265,4 +253,6 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
|
|||||||
// TODO: Update argument type and name
|
// TODO: Update argument type and name
|
||||||
void onFragmentInteraction(Uri uri);
|
void onFragmentInteraction(Uri uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package nl.myhyvesbookplus.tagram.controller;
|
||||||
|
|
||||||
|
import com.google.firebase.database.DatabaseReference;
|
||||||
|
import com.google.firebase.database.FirebaseDatabase;
|
||||||
|
import com.google.firebase.storage.FirebaseStorage;
|
||||||
|
import com.google.firebase.storage.StorageReference;
|
||||||
|
|
||||||
|
import nl.myhyvesbookplus.tagram.model.UriPost;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by marijnjansen on 23/06/2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class DownloadClass {
|
||||||
|
private static final String TAG = "DownloadClass";
|
||||||
|
private StorageReference mStorageRef;
|
||||||
|
private DatabaseReference mDataRef;
|
||||||
|
|
||||||
|
public DownloadClass() {
|
||||||
|
mStorageRef = FirebaseStorage.getInstance().getReference();
|
||||||
|
mDataRef = FirebaseDatabase.getInstance().getReference();
|
||||||
|
}
|
||||||
|
|
||||||
|
public UriPost[] getPosts() {
|
||||||
|
UriPost[] posts = new UriPost[10];
|
||||||
|
return posts;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package nl.myhyvesbookplus.tagram;
|
package nl.myhyvesbookplus.tagram.controller;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
@@ -23,19 +24,23 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import nl.myhyvesbookplus.tagram.model.BitmapPost;
|
import nl.myhyvesbookplus.tagram.model.BitmapPost;
|
||||||
import nl.myhyvesbookplus.tagram.model.UriPost;
|
import nl.myhyvesbookplus.tagram.model.UriPost;
|
||||||
|
|
||||||
/**
|
import static java.lang.System.currentTimeMillis;
|
||||||
* Created by marijnjansen on 20/06/2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class that does all the photo uploading things.
|
||||||
|
*/
|
||||||
public class UploadClass {
|
public class UploadClass {
|
||||||
|
|
||||||
private static final String TAG = "UploadClass";
|
private static final String TAG = "UploadClass";
|
||||||
private StorageReference mStorageRef;
|
private StorageReference mStorageRef;
|
||||||
private DatabaseReference mDataRef;
|
private DatabaseReference mDataRef;
|
||||||
|
|
||||||
public UploadClass() {
|
private ProfilePictureUpdatedListener mListener;
|
||||||
|
|
||||||
|
public UploadClass(Context context) {
|
||||||
mStorageRef = FirebaseStorage.getInstance().getReference();
|
mStorageRef = FirebaseStorage.getInstance().getReference();
|
||||||
mDataRef = FirebaseDatabase.getInstance().getReference();
|
mDataRef = FirebaseDatabase.getInstance().getReference();
|
||||||
|
mListener = (ProfilePictureUpdatedListener) context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helpers ///
|
/// Helpers ///
|
||||||
@@ -46,12 +51,20 @@ public class UploadClass {
|
|||||||
return baos.toByteArray();
|
return baos.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getUserUid() {
|
||||||
|
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
|
||||||
|
if (user != null) {
|
||||||
|
return user.getUid();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
/// Post Uploads ///
|
/// Post Uploads ///
|
||||||
|
|
||||||
public void uploadPicture(final BitmapPost post) {
|
public void uploadPicture(final BitmapPost post) {
|
||||||
|
final String name = getUserUid() + currentTimeMillis();
|
||||||
|
|
||||||
|
UploadTask uploadTask = mStorageRef.child("posts").child(name + ".jpg").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) {
|
||||||
@@ -64,14 +77,14 @@ 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), name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void putPostInDatabase(UriPost post) {
|
private void putPostInDatabase(UriPost post, String name) {
|
||||||
DatabaseReference ref = mDataRef.child("posts").child("UniquePostName"); // TODO: Naam voor post.
|
DatabaseReference ref = mDataRef.child("posts").child(name);
|
||||||
ref.setValue(post) // FIXME: Grote boos veroorzaker
|
ref.setValue(post)
|
||||||
.addOnCompleteListener(new OnCompleteListener<Void>() {
|
.addOnCompleteListener(new OnCompleteListener<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public void onComplete(@NonNull Task<Void> task) {
|
public void onComplete(@NonNull Task<Void> task) {
|
||||||
@@ -84,19 +97,11 @@ public class UploadClass {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getUserUid() {
|
|
||||||
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
|
|
||||||
if (user != null) {
|
|
||||||
return user.getUid();
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Profile picture ///
|
/// Profile picture ///
|
||||||
|
|
||||||
protected void uploadProfilePicture(Bitmap picture) {
|
public void uploadProfilePicture(Bitmap picture) {
|
||||||
byte[] uploadPhoto = bitmapToBytes(picture);
|
byte[] uploadPhoto = bitmapToBytes(picture);
|
||||||
UploadTask photoUpload = mStorageRef.child("profile").child(getUserUid()).putBytes(uploadPhoto);
|
UploadTask photoUpload = mStorageRef.child("profile").child(getUserUid() + "_" + currentTimeMillis()).putBytes(uploadPhoto);
|
||||||
photoUpload.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
|
photoUpload.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
|
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
|
||||||
@@ -116,7 +121,12 @@ public class UploadClass {
|
|||||||
@Override
|
@Override
|
||||||
public void onComplete(@NonNull Task<Void> task) {
|
public void onComplete(@NonNull Task<Void> task) {
|
||||||
Log.d(TAG, "onComplete: Updated profile picture");
|
Log.d(TAG, "onComplete: Updated profile picture");
|
||||||
|
mListener.ProfilePictureUpdated(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface ProfilePictureUpdatedListener {
|
||||||
|
void ProfilePictureUpdated(Boolean success);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,9 @@ import android.net.Uri;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BitmapPost is a Class for a Post with a Bitmap as an image.
|
||||||
|
*/
|
||||||
public class BitmapPost extends Post {
|
public class BitmapPost extends Post {
|
||||||
private Bitmap photo;
|
private Bitmap photo;
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,8 @@ import com.google.firebase.auth.FirebaseAuth;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by marijnjansen on 22/06/2017.
|
* Post is a Class for a Post with a Bitmap as an image.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
abstract class Post {
|
abstract class Post {
|
||||||
|
|
||||||
private Date date;
|
private Date date;
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import android.net.Uri;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UriPost is a Class for a Post with a Uri as an image.
|
||||||
|
*/
|
||||||
public class UriPost extends Post {
|
public class UriPost extends Post {
|
||||||
private String photo;
|
private String photo;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user