Working profile page with Adapter. Need Marijn to fix the downloadclass to show user-only content instead of entire timeline.

This commit is contained in:
Niels Zwemmer
2017-06-27 16:12:42 +02:00
parent 7ed5c36884
commit 16c3b727fc
6 changed files with 36 additions and 92 deletions

View File

@@ -122,8 +122,11 @@ 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 TimelineFragment) {
if (frag instanceof ProfileFragment) {
((ProfileFragment) frag).startList();
} else if (frag instanceof TimelineFragment) {
((TimelineFragment) frag).startList();
}
}

View File

@@ -30,9 +30,9 @@ public class ProfileAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private Context mContext;
private ArrayList<UriPost> mData;
protected TextView comment;
protected TextView nietSlechts;
protected ImageView photo;
private TextView comment;
private TextView nietSlechts;
private ImageView photo;
ProfileAdapter(Context context, ArrayList<UriPost> data) {
mContext = context;
@@ -74,5 +74,6 @@ public class ProfileAdapter extends BaseAdapter {
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,6 +9,7 @@ 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;
@@ -70,7 +71,6 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
profilePicture = (ImageView) view.findViewById(R.id.imageView_profile_picture);
profileName = (TextView) view.findViewById(R.id.profile_name);
changePwdButton = (Button) view.findViewById(R.id.change_psw_button);
listView = (ListView) view.findViewById(R.id.listview);
bindOnClick();
}
@@ -87,8 +87,14 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_profile, container, false);
findViews(view);
View viewTimeline = inflater.inflate(R.layout.fragment_profile_timeline, container, false);
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.getPhotoUrl() != null) {
@@ -105,10 +111,11 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
}
profilePicture.invalidate();
downloadClass = new DownloadClass(getActivity());
downloadClass.getPostsFromServer();
return view;
return viewTimeline;
}
/**
@@ -153,8 +160,13 @@ public class ProfileFragment extends Fragment implements View.OnClickListener {
public void startList() {
ProfileAdapter adapter = new ProfileAdapter(getActivity(), downloadClass.getmList());
listView.setAdapter(adapter);
listView.addHeaderView(adapter);
if (listView != null) {
listView.setAdapter(adapter);
} else {
Log.d("Jemoeder", "startList: Halloooooooo");
}
// listView.addHeaderView(adapter);
}
/**

View File

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

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

@@ -65,5 +65,12 @@
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>