Merge branch 'niels-profile' into 'master'

Niels profile

See merge request !26
This commit was merged in pull request #26.
This commit is contained in:
Niels Zwemmer
2017-06-28 13:16:12 +02:00
11 changed files with 246 additions and 102 deletions

View File

@@ -3,9 +3,8 @@
package="nl.myhyvesbookplus.tagram"> package="nl.myhyvesbookplus.tagram">
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
android:maxSdkVersion="18"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application <application
android:allowBackup="true" android:allowBackup="true"

View File

@@ -122,8 +122,11 @@ public class MainActivity extends AppCompatActivity implements
public void PostDownloaded() { public void PostDownloaded() {
FragmentManager fragmentManager = getFragmentManager(); FragmentManager fragmentManager = getFragmentManager();
Fragment frag = fragmentManager.findFragmentById(R.id.content); Fragment frag = fragmentManager.findFragmentById(R.id.content);
Log.d(TAG, "PostDownloaded: " + R.id.content);
if (frag instanceof TimelineFragment) { if (frag instanceof ProfileFragment) {
((ProfileFragment) frag).startList();
} else if (frag instanceof TimelineFragment) {
((TimelineFragment) frag).startList(); ((TimelineFragment) frag).startList();
} }
} }

View File

@@ -0,0 +1,79 @@
package nl.myhyvesbookplus.tagram;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.firebase.ui.storage.images.FirebaseImageLoader;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import java.util.ArrayList;
import nl.myhyvesbookplus.tagram.model.UriPost;
/**
* Created by niels on 27-6-17.
*/
public class ProfileAdapter extends BaseAdapter {
private static final String TAG = "ProfileAdapter";
private LayoutInflater mInflater;
private Context mContext;
private ArrayList<UriPost> mData;
private TextView comment;
private TextView nietSlechts;
private ImageView photo;
ProfileAdapter(Context context, ArrayList<UriPost> data) {
mContext = context;
mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mData = data;
}
@Override
public int getCount() {
return mData.size();
}
@Override
public Object getItem(int position) {
return mData.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = mInflater.inflate(R.layout.list_item_timeline_profile, parent, false);
View newRowView = findViews(rowView);
UriPost post = (UriPost) getItem(position);
comment.setText(post.getComment());
StorageReference ref = FirebaseStorage.getInstance().getReferenceFromUrl(post.getUri());
Glide.with(mContext)
.using(new FirebaseImageLoader())
.load(ref)
.into(photo);
return newRowView;
}
protected View findViews(View rowView) {
comment = (TextView) rowView.findViewById(R.id.comment_timeline_profile);
nietSlechts = (TextView) rowView.findViewById(R.id.niet_slecht_count_profile);
photo = (ImageView) rowView.findViewById(R.id.timeline_image_profile);
return rowView;
}
}

View File

@@ -9,12 +9,14 @@ import android.os.Environment;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.content.FileProvider; import android.support.v4.content.FileProvider;
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.ImageView; import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
@@ -29,6 +31,7 @@ import com.google.firebase.storage.StorageReference;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import nl.myhyvesbookplus.tagram.controller.DownloadClass;
import nl.myhyvesbookplus.tagram.controller.ProfilePictureUploader; import nl.myhyvesbookplus.tagram.controller.ProfilePictureUploader;
import static android.app.Activity.RESULT_OK; import static android.app.Activity.RESULT_OK;
@@ -44,6 +47,8 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
protected ImageView profilePicture; protected ImageView profilePicture;
protected FirebaseUser user; protected FirebaseUser user;
protected File photoFile = null; protected File photoFile = null;
private ListView listView;
private DownloadClass downloadClass;
ProgressDialog progressDialog; ProgressDialog progressDialog;
@@ -81,8 +86,14 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_profile, container, false); View viewTimeline = inflater.inflate(R.layout.fragment_profile_timeline, container, false);
findViews(view);
listView = (ListView) viewTimeline.findViewById(R.id.listview_profile);
View viewHeader = inflater.inflate(R.layout.fragment_profile_header, listView, false);
findViews(viewHeader);
listView.addHeaderView(viewHeader);
if (user != null) { if (user != null) {
if(user.getPhotoUrl() != null) { if(user.getPhotoUrl() != null) {
@@ -100,7 +111,10 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
profilePicture.invalidate(); profilePicture.invalidate();
return view; downloadClass = new DownloadClass(getActivity());
downloadClass.getPostsFromServer();
return viewTimeline;
} }
/** /**
@@ -131,7 +145,7 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
try { try {
photoFile = createImageFile(); photoFile = createImageFile();
} catch (IOException ex) { } catch (IOException ex) {
Toast.makeText(getActivity(), getString(R.string.image_save_error), Toast.LENGTH_LONG); Toast.makeText(getActivity(), getString(R.string.image_save_error), Toast.LENGTH_LONG).show();
} }
if (photoFile != null) { if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(getActivity(), Uri photoURI = FileProvider.getUriForFile(getActivity(),
@@ -143,6 +157,11 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
} }
} }
public void startList() {
ProfileAdapter adapter = new ProfileAdapter(getActivity(), downloadClass.getmList());
listView.setAdapter(adapter);
}
/** /**
* Grabs the image just taken by the built-in camera and pushes this image to the user account. * Grabs the image just taken by the built-in camera and pushes this image to the user account.
* @param requestCode The code which corresponds to REQUEST_TAKE_PHOTO. Used as indicator. * @param requestCode The code which corresponds to REQUEST_TAKE_PHOTO. Used as indicator.
@@ -154,11 +173,10 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) { if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
progressDialog = ProgressDialog.show(getActivity(), getString(R.string.please_wait), getString(R.string.upload_profile_pic), false, false); progressDialog = ProgressDialog.show(getActivity(), getString(R.string.please_wait), getString(R.string.upload_profile_pic), false, false);
ProfilePictureUploader profilePictureUploader = new ProfilePictureUploader(getActivity()); ProfilePictureUploader profilePictureUploader = new ProfilePictureUploader(getActivity());
profilePictureUploader.uploadProfilePicture(photoFile.getAbsoluteFile()); profilePictureUploader.uploadProfilePicture(photoFile);
} }
} }
private File createImageFile() throws IOException { private File createImageFile() throws IOException {
// Create an image file name // Create an image file name
String imageFileName = "JPEG_" + user.getUid(); String imageFileName = "JPEG_" + user.getUid();
@@ -183,8 +201,8 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
@Override @Override
public void onComplete(@NonNull Task<Void> task) { public void onComplete(@NonNull Task<Void> task) {
Toast.makeText(getActivity(), task.isSuccessful() Toast.makeText(getActivity(), task.isSuccessful()
? "An e-mail was sent, please follow its instructions." ? getString(R.string.mail_successful)
: "An error occurred, please check internet connection.", : getString(R.string.mail_failed),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} }
}); });

View File

@@ -40,7 +40,9 @@ public class DownloadClass {
mDataRef.child("posts").addListenerForSingleValueEvent(new ValueEventListener() { mDataRef.child("posts").addListenerForSingleValueEvent(new ValueEventListener() {
@Override @Override
public void onDataChange(DataSnapshot dataSnapshot) { public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot data : dataSnapshot.getChildren()) { for (DataSnapshot data : dataSnapshot.getChildren()) {
mList.add(data.getValue(UriPost.class)); mList.add(data.getValue(UriPost.class));
} }
Collections.reverse(mList); Collections.reverse(mList);

View File

@@ -1,81 +0,0 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="nl.myhyvesbookplus.tagram.ProfileFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<Space
android:layout_width="match_parent"
android:layout_height="5dp" />
<TextView
android:id="@+id/profile_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Name:"
android:textSize="25sp"
android:textStyle="bold" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<ImageButton
android:id="@+id/profile_pic_button"
android:layout_width="60dp"
android:layout_height="80dp"
android:layout_marginStart="110dp"
android:background="@android:color/transparent"
android:elevation="1dp"
app:srcCompat="@android:drawable/ic_menu_camera" />
<ImageView
android:id="@+id/imageView_profile_picture"
android:contentDescription="@string/profile_picture_description"
android:layout_width="match_parent"
android:layout_height="300dp"
app:srcCompat="@drawable/avatar_standard"
android:layout_marginTop="-70dp"/>
<Space
android:layout_width="match_parent"
android:layout_height="25dp" />
<Button
android:id="@+id/change_psw_button"
android:layout_width="300dp"
android:layout_height="50dp"
android:background="?attr/colorPrimary"
android:text="@string/change_psw_button"
android:textColor="@android:color/white"
android:textSize="16sp" />
<Space
android:layout_width="match_parent"
android:layout_height="20dp" />
<Button
android:id="@+id/logout_button"
android:layout_width="300dp"
android:layout_height="50dp"
android:background="?attr/colorPrimary"
android:onClick="logOutOnClick"
android:text="@string/logout_button"
android:textColor="@android:color/white"
android:textSize="16sp" />
</LinearLayout>
</ScrollView>
</FrameLayout>

View File

@@ -0,0 +1,76 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<Space
android:layout_width="match_parent"
android:layout_height="5dp" />
<TextView
android:id="@+id/profile_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Name:"
android:textSize="25sp"
android:textStyle="bold" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<ImageButton
android:id="@+id/profile_pic_button"
android:layout_width="60dp"
android:layout_height="80dp"
android:layout_marginStart="110dp"
android:background="@android:color/transparent"
android:elevation="1dp"
app:srcCompat="@android:drawable/ic_menu_camera" />
<ImageView
android:id="@+id/imageView_profile_picture"
android:contentDescription="@string/profile_picture_description"
android:layout_width="match_parent"
android:layout_height="300dp"
app:srcCompat="@drawable/avatar_standard"
android:layout_marginTop="-70dp"/>
<Space
android:layout_width="match_parent"
android:layout_height="25dp" />
<Button
android:id="@+id/change_psw_button"
android:layout_width="300dp"
android:layout_height="50dp"
android:background="?attr/colorPrimary"
android:text="@string/change_psw_button"
android:textColor="@android:color/white"
android:textSize="16sp" />
<Space
android:layout_width="match_parent"
android:layout_height="20dp" />
<Button
android:id="@+id/logout_button"
android:layout_width="300dp"
android:layout_height="50dp"
android:background="?attr/colorPrimary"
android:onClick="logOutOnClick"
android:text="@string/logout_button"
android:textColor="@android:color/white"
android:textSize="16sp" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
</LinearLayout>

View File

@@ -0,0 +1,14 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="nl.myhyvesbookplus.tagram.TimelineFragment">
<ListView
android:id="@+id/listview_profile"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>

View File

@@ -0,0 +1,33 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/timeline_image_profile"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_height="250dp" />
<TextView
android:id="@+id/comment_timeline_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hallo Ik ben een comment!" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/niet_slecht" />
<TextView
android:id="@+id/niet_slecht_count_profile"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="10" />
</LinearLayout>
</LinearLayout>

View File

@@ -30,6 +30,7 @@
<string name="image_save_error">Foto opslaan mislukt. Zorg a.u.b. dat er genoeg ruimte op uw telefoon beschikbaar is.</string> <string name="image_save_error">Foto opslaan mislukt. Zorg a.u.b. dat er genoeg ruimte op uw telefoon beschikbaar is.</string>
<string name="update_profile_pic_error">Het updaten van de profielfoto is mislukt. Controleer uw internetverbinding.</string> <string name="update_profile_pic_error">Het updaten van de profielfoto is mislukt. Controleer uw internetverbinding.</string>
<string name="upload_profile_pic">Profielfoto aan het uploaden…</string> <string name="upload_profile_pic">Profielfoto aan het uploaden…</string>
<string name="mail_success">An e-mail was sent, please follow its instructions.</string>
<string name="niet_slecht">Niet Slecht.</string> <string name="niet_slecht">Niet Slecht.</string>
<string name="comment">Bijschrift:</string> <string name="comment">Bijschrift:</string>
<string name="cancel">Annuleer</string> <string name="cancel">Annuleer</string>

View File

@@ -29,7 +29,7 @@
<string name="mail_failed">An error occurred. Please check internet connection.</string> <string name="mail_failed">An error occurred. Please check internet connection.</string>
<string name="image_save_error">Saving image to storage failed. Please make sure there is space available on the device.</string> <string name="image_save_error">Saving image to storage failed. Please make sure there is space available on the device.</string>
<string name="update_profile_pic_error">Updating the profile picture failed. Please check network connection.</string> <string name="update_profile_pic_error">Updating the profile picture failed. Please check network connection.</string>
<string name="upload_profile_pic">Uploading profile picture...</string> <string name="upload_profile_pic">Uploading profile picture</string>
<string name="comment">Comment:</string> <string name="comment">Comment:</string>
<string name="cancel">Cancel</string> <string name="cancel">Cancel</string>
</resources> </resources>