Working refresh, working user-specific posts in profile.
This commit is contained in:
@@ -161,7 +161,10 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL
|
|||||||
mComment.setText("");
|
mComment.setText("");
|
||||||
|
|
||||||
PostUploader upload = new PostUploader(getActivity());
|
PostUploader upload = new PostUploader(getActivity());
|
||||||
upload.uploadPicture(new BitmapPost(((PicturePreview)view.findViewById(R.id.pic_preview)).getPicture(), comment));
|
if (R.id.pic_preview == 0) {
|
||||||
|
upload.uploadPicture(new BitmapPost(((PicturePreview)view.findViewById(R.id.pic_preview)).getPicture(), comment));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
mPhoto.recycle();
|
mPhoto.recycle();
|
||||||
|
|
||||||
|
|||||||
@@ -122,7 +122,6 @@ 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 ProfileFragment) {
|
if (frag instanceof ProfileFragment) {
|
||||||
((ProfileFragment) frag).startList();
|
((ProfileFragment) frag).startList();
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ 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;
|
||||||
@@ -49,7 +48,6 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
|
|||||||
protected File photoFile = null;
|
protected File photoFile = null;
|
||||||
private ListView listView;
|
private ListView listView;
|
||||||
private DownloadClass downloadClass;
|
private DownloadClass downloadClass;
|
||||||
|
|
||||||
ProgressDialog progressDialog;
|
ProgressDialog progressDialog;
|
||||||
|
|
||||||
/// Required empty public constructor ///
|
/// Required empty public constructor ///
|
||||||
@@ -87,14 +85,13 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
|
|||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
View viewTimeline = inflater.inflate(R.layout.fragment_profile_timeline, container, false);
|
View viewTimeline = inflater.inflate(R.layout.fragment_profile_timeline, container, false);
|
||||||
|
listView = (ListView) viewTimeline.findViewById(R.id.list);
|
||||||
|
|
||||||
|
|
||||||
listView = (ListView) viewTimeline.findViewById(R.id.listview_profile);
|
|
||||||
View viewHeader = inflater.inflate(R.layout.fragment_profile_header, listView, false);
|
View viewHeader = inflater.inflate(R.layout.fragment_profile_header, listView, false);
|
||||||
findViews(viewHeader);
|
findViews(viewHeader);
|
||||||
listView.addHeaderView(viewHeader);
|
listView.addHeaderView(viewHeader);
|
||||||
|
|
||||||
|
profilePicture.invalidate();
|
||||||
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
if(user.getPhotoUrl() != null) {
|
if(user.getPhotoUrl() != null) {
|
||||||
httpsReference = FirebaseStorage.getInstance().getReferenceFromUrl(user.getPhotoUrl().toString());
|
httpsReference = FirebaseStorage.getInstance().getReferenceFromUrl(user.getPhotoUrl().toString());
|
||||||
@@ -109,11 +106,10 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
profilePicture.invalidate();
|
|
||||||
|
|
||||||
downloadClass = new DownloadClass(getActivity());
|
|
||||||
|
downloadClass = new DownloadClass(getActivity(), "profile");
|
||||||
downloadClass.getPostsFromServer();
|
downloadClass.getPostsFromServer();
|
||||||
|
|
||||||
return viewTimeline;
|
return viewTimeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,8 +154,8 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void startList() {
|
public void startList() {
|
||||||
ProfileAdapter adapter = new ProfileAdapter(getActivity(), downloadClass.getmList());
|
ProfileAdapter adapter = new ProfileAdapter(getActivity(), downloadClass.getOwnPosts());
|
||||||
listView.setAdapter(adapter);
|
listView.setAdapter(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class TimeLineAdapter extends BaseAdapter implements AdapterView.OnItemCl
|
|||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
View rowView = mInflater.inflate(R.layout.list_item_timeline, parent, false);
|
View rowView = mInflater.inflate(R.layout.list_item_timeline, parent, false);
|
||||||
|
|
||||||
// TextView userName = (TextView) rowView.findViewById(R.id.username_timeline);
|
TextView userName = (TextView) rowView.findViewById(R.id.username_timeline);
|
||||||
TextView comment = (TextView) rowView.findViewById(R.id.comment_timeline);
|
TextView comment = (TextView) rowView.findViewById(R.id.comment_timeline);
|
||||||
TextView nietSlechts = (TextView) rowView.findViewById(R.id.niet_slecht_count);
|
TextView nietSlechts = (TextView) rowView.findViewById(R.id.niet_slecht_count);
|
||||||
ImageView photo = (ImageView) rowView.findViewById(R.id.timeline_image);
|
ImageView photo = (ImageView) rowView.findViewById(R.id.timeline_image);
|
||||||
@@ -73,7 +73,7 @@ public class TimeLineAdapter extends BaseAdapter implements AdapterView.OnItemCl
|
|||||||
|
|
||||||
UriPost post = (UriPost) getItem(position);
|
UriPost post = (UriPost) getItem(position);
|
||||||
|
|
||||||
// userName.setText();
|
userName.setText(post.getPoster());
|
||||||
nietSlechts.setText(Integer.toString(post.getNietSlechts()));
|
nietSlechts.setText(Integer.toString(post.getNietSlechts()));
|
||||||
comment.setText(post.getComment());
|
comment.setText(post.getComment());
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,16 @@ package nl.myhyvesbookplus.tagram;
|
|||||||
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
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.AbsListView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import nl.myhyvesbookplus.tagram.controller.DownloadClass;
|
import nl.myhyvesbookplus.tagram.controller.DownloadClass;
|
||||||
|
|
||||||
|
|
||||||
@@ -23,11 +28,41 @@ public class TimelineFragment extends Fragment {
|
|||||||
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_timeline, container, false);
|
View view = inflater.inflate(R.layout.fragment_timeline, container, false);
|
||||||
listView = (ListView) view.findViewById(R.id.listview);
|
listView = (ListView) view.findViewById(R.id.list);
|
||||||
|
final SwipeRefreshLayout swipeView = (SwipeRefreshLayout) view.findViewById(R.id.swipe);
|
||||||
|
|
||||||
downloadClass = new DownloadClass(getActivity());
|
swipeView.setEnabled(false);
|
||||||
|
downloadClass = new DownloadClass(getActivity(), "timeline");
|
||||||
downloadClass.getPostsFromServer();
|
downloadClass.getPostsFromServer();
|
||||||
|
|
||||||
|
swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||||
|
@Override
|
||||||
|
public void onRefresh() {
|
||||||
|
downloadClass = new DownloadClass(getActivity(), "timeline");
|
||||||
|
downloadClass.getPostsFromServer();
|
||||||
|
swipeView.setRefreshing(true);
|
||||||
|
( new Handler()).postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
swipeView.setRefreshing(false);
|
||||||
|
}
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||||
|
@Override
|
||||||
|
public void onScrollStateChanged(AbsListView absListView, int i) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
||||||
|
if (firstVisibleItem == 0)
|
||||||
|
swipeView.setEnabled(true);
|
||||||
|
else
|
||||||
|
swipeView.setEnabled(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,9 @@ public class DownloadClass {
|
|||||||
private DatabaseReference mDataRef;
|
private DatabaseReference mDataRef;
|
||||||
private ArrayList<UriPost> mList;
|
private ArrayList<UriPost> mList;
|
||||||
private PostDownloadListener mListener;
|
private PostDownloadListener mListener;
|
||||||
|
private String fragmentName;
|
||||||
|
|
||||||
public DownloadClass(Context context) {
|
public DownloadClass(Context context, String fragmentName) {
|
||||||
if (context instanceof DownloadClass.PostDownloadListener) {
|
if (context instanceof DownloadClass.PostDownloadListener) {
|
||||||
mListener = (PostDownloadListener) context;
|
mListener = (PostDownloadListener) context;
|
||||||
} else {
|
} else {
|
||||||
@@ -34,6 +35,7 @@ public class DownloadClass {
|
|||||||
}
|
}
|
||||||
mDataRef = FirebaseDatabase.getInstance().getReference();
|
mDataRef = FirebaseDatabase.getInstance().getReference();
|
||||||
mList = new ArrayList<>();
|
mList = new ArrayList<>();
|
||||||
|
this.fragmentName = fragmentName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getPostsFromServer() {
|
public void getPostsFromServer() {
|
||||||
@@ -46,6 +48,7 @@ public class DownloadClass {
|
|||||||
mList.add(data.getValue(UriPost.class));
|
mList.add(data.getValue(UriPost.class));
|
||||||
}
|
}
|
||||||
Collections.reverse(mList);
|
Collections.reverse(mList);
|
||||||
|
|
||||||
mListener.PostDownloaded();
|
mListener.PostDownloaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,13 +65,14 @@ public class DownloadClass {
|
|||||||
|
|
||||||
public ArrayList<UriPost> getOwnPosts() {
|
public ArrayList<UriPost> getOwnPosts() {
|
||||||
String currentUid = FirebaseAuth.getInstance().getCurrentUser().getUid();
|
String currentUid = FirebaseAuth.getInstance().getCurrentUser().getUid();
|
||||||
ArrayList<UriPost> posts = new ArrayList<UriPost>();
|
ArrayList<UriPost> posts = new ArrayList<>();
|
||||||
|
|
||||||
for (UriPost post : mList) {
|
for (UriPost post : mList) {
|
||||||
if (post.getPoster().equals(currentUid)) {
|
if (post.getPoster().equals(currentUid)) {
|
||||||
posts.add(post);
|
posts.add(post);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return posts;
|
return posts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,8 @@
|
|||||||
tools:context="nl.myhyvesbookplus.tagram.TimelineFragment">
|
tools:context="nl.myhyvesbookplus.tagram.TimelineFragment">
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
android:id="@+id/listview_profile"
|
android:id="@+id/list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
</ListView>
|
</ListView>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -5,11 +5,21 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:context="nl.myhyvesbookplus.tagram.TimelineFragment">
|
tools:context="nl.myhyvesbookplus.tagram.TimelineFragment">
|
||||||
|
|
||||||
<ListView
|
<android.support.v4.widget.SwipeRefreshLayout
|
||||||
android:id="@+id/listview"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/swipe"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
>
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
</ListView>
|
</ListView>
|
||||||
|
|
||||||
|
</android.support.v4.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -9,13 +9,11 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="15dp" />
|
android:layout_height="15dp" />
|
||||||
|
|
||||||
<!--
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/username_timeline"
|
android:id="@+id/username_timeline"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"/>
|
android:layout_gravity="center"/>
|
||||||
-->
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/timeline_image"
|
android:id="@+id/timeline_image"
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
<string name="login_error">Voer alstublieft email en wachtwoord in</string>
|
<string name="login_error">Voer alstublieft email en wachtwoord in</string>
|
||||||
<string name="mail_failed">Er is een fout opgetreden. Controleer internetverbinding.</string>
|
<string name="mail_failed">Er is een fout opgetreden. Controleer internetverbinding.</string>
|
||||||
<string name="mail_successful">Er is een e-mail verzonden. Volg a.u.b. de instructies.</string>
|
<string name="mail_successful">Er is een e-mail verzonden. Volg a.u.b. de instructies.</string>
|
||||||
<string name="password_match_error">Wachtwoorden komen niet overeen</string>
|
<string name="password_match_error">Wachtwoorden komoen niet overeen</string>
|
||||||
<string name="register_error">Vul alstublieft alle velden in</string>
|
<string name="register_error">Vul alstublieft alle velden in</string>
|
||||||
<string name="save">Opslaan</string>
|
<string name="save">Opslaan</string>
|
||||||
<string name="upload">Uploaden</string>
|
<string name="upload">Uploaden</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user