Added NietSlechts!
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package nl.myhyvesbookplus.tagram;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -13,6 +14,9 @@ import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.firebase.ui.storage.images.FirebaseImageLoader;
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
import com.google.firebase.database.FirebaseDatabase;
|
||||
import com.google.firebase.storage.FirebaseStorage;
|
||||
import com.google.firebase.storage.StorageReference;
|
||||
|
||||
@@ -52,26 +56,34 @@ public class TimeLineAdapter extends BaseAdapter implements AdapterView.OnItemCl
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
View rowView = mInflater.inflate(R.layout.list_item_timeline, parent, false);
|
||||
|
||||
TextView comment = (TextView) rowView.findViewById(R.id.comment_timeline);
|
||||
TextView nietSlechts = (TextView) rowView.findViewById(R.id.niet_slecht_count);
|
||||
final TextView nietSlechts = (TextView) rowView.findViewById(R.id.niet_slecht_count);
|
||||
TextView dateTime = (TextView) rowView.findViewById(R.id.timeline_date);
|
||||
ImageView photo = (ImageView) rowView.findViewById(R.id.timeline_image);
|
||||
ImageButton nietSlechtButton = (ImageButton) rowView.findViewById(R.id.niet_slecht_button);
|
||||
final ImageButton nietSlechtButton = (ImageButton) rowView.findViewById(R.id.niet_slecht_button);
|
||||
|
||||
final UriPost post = (UriPost) getItem(position);
|
||||
|
||||
nietSlechts.setText(Integer.toString(post.getNietSlechts()));
|
||||
comment.setText(post.getComment());
|
||||
|
||||
nietSlechtButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Log.d(TAG, "onClick: " + position);
|
||||
FirebaseDatabase.getInstance().getReference().child("posts").child(post.getDatabaseEntryName()).child("nietSlechts").setValue(post.getNietSlechts() + 1)
|
||||
.addOnCompleteListener(new OnCompleteListener<Void>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<Void> task) {
|
||||
nietSlechts.setText(Integer.toString(post.getNietSlechts() + 1));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
UriPost post = (UriPost) getItem(position);
|
||||
|
||||
nietSlechts.setText(Integer.toString(post.getNietSlechts()));
|
||||
comment.setText(post.getComment());
|
||||
|
||||
StorageReference ref = FirebaseStorage.getInstance().getReferenceFromUrl(post.getUri());
|
||||
Glide.with(mContext)
|
||||
.using(new FirebaseImageLoader())
|
||||
@@ -82,7 +94,6 @@ public class TimeLineAdapter extends BaseAdapter implements AdapterView.OnItemCl
|
||||
return rowView;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Callback method to be invoked when an item in this AdapterView has
|
||||
* been clicked.
|
||||
|
||||
@@ -41,7 +41,9 @@ public class DownloadClass {
|
||||
@Override
|
||||
public void onDataChange(DataSnapshot dataSnapshot) {
|
||||
for (DataSnapshot data : dataSnapshot.getChildren()) {
|
||||
mList.add(data.getValue(UriPost.class));
|
||||
UriPost tempPost = data.getValue(UriPost.class);
|
||||
tempPost.setDatabaseEntryName(data.getKey());
|
||||
mList.add(tempPost);
|
||||
}
|
||||
Collections.reverse(mList);
|
||||
mListener.PostDownloaded();
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.Date;
|
||||
*/
|
||||
public class UriPost extends Post {
|
||||
private String uri;
|
||||
private String databaseEntryName;
|
||||
|
||||
public UriPost() {
|
||||
// Default constructor required for calls to DataSnapshot.getValue(UriPost.class)
|
||||
@@ -33,4 +34,12 @@ public class UriPost extends Post {
|
||||
public void setUri(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public String getDatabaseEntryName() {
|
||||
return databaseEntryName;
|
||||
}
|
||||
|
||||
public void setDatabaseEntryName(String databaseEntryName) {
|
||||
this.databaseEntryName = databaseEntryName;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/timeline_image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_height="250dp" />
|
||||
android:layout_height="250dp"
|
||||
android:layout_gravity="center" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/comment_timeline"
|
||||
@@ -17,6 +16,11 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hallo Ik ben een comment!" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/timeline_date"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="date/time" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp">
|
||||
@@ -29,12 +33,14 @@
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:text="@string/niet_slecht" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/niet_slecht_count"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:text="10" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user