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("");
|
||||
|
||||
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();
|
||||
|
||||
|
||||
@@ -122,7 +122,6 @@ public class MainActivity extends AppCompatActivity implements
|
||||
public void PostDownloaded() {
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
Fragment frag = fragmentManager.findFragmentById(R.id.content);
|
||||
Log.d(TAG, "PostDownloaded: " + R.id.content);
|
||||
|
||||
if (frag instanceof ProfileFragment) {
|
||||
((ProfileFragment) frag).startList();
|
||||
|
||||
@@ -9,7 +9,6 @@ import android.os.Environment;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.FileProvider;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -49,7 +48,6 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
|
||||
protected File photoFile = null;
|
||||
private ListView listView;
|
||||
private DownloadClass downloadClass;
|
||||
|
||||
ProgressDialog progressDialog;
|
||||
|
||||
/// Required empty public constructor ///
|
||||
@@ -87,14 +85,13 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View viewTimeline = inflater.inflate(R.layout.fragment_profile_timeline, container, false);
|
||||
|
||||
|
||||
|
||||
listView = (ListView) viewTimeline.findViewById(R.id.listview_profile);
|
||||
listView = (ListView) viewTimeline.findViewById(R.id.list);
|
||||
View viewHeader = inflater.inflate(R.layout.fragment_profile_header, listView, false);
|
||||
findViews(viewHeader);
|
||||
listView.addHeaderView(viewHeader);
|
||||
|
||||
profilePicture.invalidate();
|
||||
|
||||
if (user != null) {
|
||||
if(user.getPhotoUrl() != null) {
|
||||
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);
|
||||
}
|
||||
|
||||
profilePicture.invalidate();
|
||||
|
||||
downloadClass = new DownloadClass(getActivity());
|
||||
|
||||
downloadClass = new DownloadClass(getActivity(), "profile");
|
||||
downloadClass.getPostsFromServer();
|
||||
|
||||
return viewTimeline;
|
||||
}
|
||||
|
||||
@@ -158,8 +154,8 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
|
||||
}
|
||||
|
||||
public void startList() {
|
||||
ProfileAdapter adapter = new ProfileAdapter(getActivity(), downloadClass.getmList());
|
||||
listView.setAdapter(adapter);
|
||||
ProfileAdapter adapter = new ProfileAdapter(getActivity(), downloadClass.getOwnPosts());
|
||||
listView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -58,7 +58,7 @@ public class TimeLineAdapter extends BaseAdapter implements AdapterView.OnItemCl
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
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 nietSlechts = (TextView) rowView.findViewById(R.id.niet_slecht_count);
|
||||
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);
|
||||
|
||||
// userName.setText();
|
||||
userName.setText(post.getPoster());
|
||||
nietSlechts.setText(Integer.toString(post.getNietSlechts()));
|
||||
comment.setText(post.getComment());
|
||||
|
||||
|
||||
@@ -2,11 +2,16 @@ package nl.myhyvesbookplus.tagram;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.ListView;
|
||||
|
||||
|
||||
|
||||
import nl.myhyvesbookplus.tagram.controller.DownloadClass;
|
||||
|
||||
|
||||
@@ -23,11 +28,41 @@ public class TimelineFragment extends Fragment {
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
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();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,9 @@ public class DownloadClass {
|
||||
private DatabaseReference mDataRef;
|
||||
private ArrayList<UriPost> mList;
|
||||
private PostDownloadListener mListener;
|
||||
private String fragmentName;
|
||||
|
||||
public DownloadClass(Context context) {
|
||||
public DownloadClass(Context context, String fragmentName) {
|
||||
if (context instanceof DownloadClass.PostDownloadListener) {
|
||||
mListener = (PostDownloadListener) context;
|
||||
} else {
|
||||
@@ -34,6 +35,7 @@ public class DownloadClass {
|
||||
}
|
||||
mDataRef = FirebaseDatabase.getInstance().getReference();
|
||||
mList = new ArrayList<>();
|
||||
this.fragmentName = fragmentName;
|
||||
}
|
||||
|
||||
public void getPostsFromServer() {
|
||||
@@ -46,6 +48,7 @@ public class DownloadClass {
|
||||
mList.add(data.getValue(UriPost.class));
|
||||
}
|
||||
Collections.reverse(mList);
|
||||
|
||||
mListener.PostDownloaded();
|
||||
}
|
||||
|
||||
@@ -62,13 +65,14 @@ public class DownloadClass {
|
||||
|
||||
public ArrayList<UriPost> getOwnPosts() {
|
||||
String currentUid = FirebaseAuth.getInstance().getCurrentUser().getUid();
|
||||
ArrayList<UriPost> posts = new ArrayList<UriPost>();
|
||||
ArrayList<UriPost> posts = new ArrayList<>();
|
||||
|
||||
for (UriPost post : mList) {
|
||||
if (post.getPoster().equals(currentUid)) {
|
||||
posts.add(post);
|
||||
}
|
||||
}
|
||||
|
||||
return posts;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,8 @@
|
||||
tools:context="nl.myhyvesbookplus.tagram.TimelineFragment">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/listview_profile"
|
||||
android:id="@+id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
</ListView>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -5,11 +5,21 @@
|
||||
android:orientation="vertical"
|
||||
tools:context="nl.myhyvesbookplus.tagram.TimelineFragment">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/listview"
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/swipe"
|
||||
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>
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
@@ -9,13 +9,11 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="15dp" />
|
||||
|
||||
<!--
|
||||
<TextView
|
||||
android:id="@+id/username_timeline"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"/>
|
||||
-->
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/timeline_image"
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<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_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="save">Opslaan</string>
|
||||
<string name="upload">Uploaden</string>
|
||||
|
||||
Reference in New Issue
Block a user