mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-21 05:45:13 +00:00
Added favourite icons.
This commit is contained in:
parent
803d3e370e
commit
dbf62ec296
4 changed files with 30 additions and 19 deletions
|
@ -46,8 +46,6 @@
|
||||||
android:contentDescription="@string/description_comment_user"
|
android:contentDescription="@string/description_comment_user"
|
||||||
android:scaleType="fitCenter" />
|
android:scaleType="fitCenter" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/comment_user_reshare_image"
|
android:id="@+id/comment_user_reshare_image"
|
||||||
android:layout_width="50dp"
|
android:layout_width="50dp"
|
||||||
|
@ -86,15 +84,14 @@
|
||||||
android:scaleType="fitCenter"
|
android:scaleType="fitCenter"
|
||||||
android:src="@drawable/favourite" />
|
android:src="@drawable/favourite" />
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:id="@+id/comment_favourite_count"
|
android:id="@+id/comment_favourite_avatars"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignBottom="@id/comment_shareddate"
|
android:layout_alignBaseline="@id/comment_shareddate"
|
||||||
android:layout_marginRight="4dp"
|
android:layout_marginRight="4dp"
|
||||||
android:layout_toLeftOf="@id/comment_favourite_icon"
|
android:layout_toLeftOf="@id/comment_favourite_icon"
|
||||||
android:textColor="@color/darkgray"
|
android:gravity="right" />
|
||||||
android:textSize="11dp" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/comment_username"
|
android:id="@+id/comment_username"
|
||||||
|
|
|
@ -16,7 +16,6 @@ public class LikeCommentTask extends AsyncTask<Void, Void, Boolean>{
|
||||||
|
|
||||||
private static final String TAG = "LikeCommentTask";
|
private static final String TAG = "LikeCommentTask";
|
||||||
final WeakReference<ImageView> favouriteIconViewHolder;
|
final WeakReference<ImageView> favouriteIconViewHolder;
|
||||||
final WeakReference<View> favouriteCountViewHolder;
|
|
||||||
|
|
||||||
private final APIManager apiManager;
|
private final APIManager apiManager;
|
||||||
private final String storyId;
|
private final String storyId;
|
||||||
|
@ -25,7 +24,7 @@ public class LikeCommentTask extends AsyncTask<Void, Void, Boolean>{
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private final String userId;
|
private final String userId;
|
||||||
|
|
||||||
public LikeCommentTask(final Context context, final APIManager apiManager, final View favouriteCount, final ImageView favouriteIcon, final String storyId, final Comment comment, final String feedId, final String userId) {
|
public LikeCommentTask(final Context context, final APIManager apiManager, final ImageView favouriteIcon, final String storyId, final Comment comment, final String feedId, final String userId) {
|
||||||
this.apiManager = apiManager;
|
this.apiManager = apiManager;
|
||||||
this.storyId = storyId;
|
this.storyId = storyId;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
|
@ -34,7 +33,6 @@ public class LikeCommentTask extends AsyncTask<Void, Void, Boolean>{
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
|
|
||||||
favouriteIconViewHolder = new WeakReference<ImageView>(favouriteIcon);
|
favouriteIconViewHolder = new WeakReference<ImageView>(favouriteIcon);
|
||||||
favouriteCountViewHolder = new WeakReference<View>(favouriteCount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -53,7 +51,6 @@ public class LikeCommentTask extends AsyncTask<Void, Void, Boolean>{
|
||||||
newArray[newArray.length - 1] = userId;
|
newArray[newArray.length - 1] = userId;
|
||||||
comment.likingUsers = newArray;
|
comment.likingUsers = newArray;
|
||||||
|
|
||||||
((TextView) favouriteCountViewHolder.get()).setText(Integer.toString(comment.likingUsers.length));
|
|
||||||
Toast.makeText(context, "Comment liked", Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, "Comment liked", Toast.LENGTH_SHORT).show();
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(context, "Error liking comment", Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, "Error liking comment", Toast.LENGTH_SHORT).show();
|
||||||
|
|
|
@ -18,7 +18,9 @@ import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
import android.view.ViewGroup.LayoutParams;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.ImageView.ScaleType;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
@ -104,7 +106,7 @@ public class SetupCommentSectionTask extends AsyncTask<Void, Void, Void> {
|
||||||
TextView commentSharedDate = (TextView) commentView.findViewById(R.id.comment_shareddate);
|
TextView commentSharedDate = (TextView) commentView.findViewById(R.id.comment_shareddate);
|
||||||
commentSharedDate.setText(comment.sharedDate);
|
commentSharedDate.setText(comment.sharedDate);
|
||||||
|
|
||||||
final TextView favouriteCount = (TextView) commentView.findViewById(R.id.comment_favourite_count);
|
final LinearLayout favouriteContainer = (LinearLayout) commentView.findViewById(R.id.comment_favourite_avatars);
|
||||||
final ImageView favouriteIcon = (ImageView) commentView.findViewById(R.id.comment_favourite_icon);
|
final ImageView favouriteIcon = (ImageView) commentView.findViewById(R.id.comment_favourite_icon);
|
||||||
final ImageView replyIcon = (ImageView) commentView.findViewById(R.id.comment_reply_icon);
|
final ImageView replyIcon = (ImageView) commentView.findViewById(R.id.comment_reply_icon);
|
||||||
|
|
||||||
|
@ -112,14 +114,32 @@ public class SetupCommentSectionTask extends AsyncTask<Void, Void, Void> {
|
||||||
if (Arrays.asList(comment.likingUsers).contains(user.id)) {
|
if (Arrays.asList(comment.likingUsers).contains(user.id)) {
|
||||||
favouriteIcon.setImageResource(R.drawable.have_favourite);
|
favouriteIcon.setImageResource(R.drawable.have_favourite);
|
||||||
}
|
}
|
||||||
favouriteCount.setText(Integer.toString(comment.likingUsers.length));
|
|
||||||
|
for (String id : comment.likingUsers) {
|
||||||
|
ImageView favouriteImage = new ImageView(context);
|
||||||
|
UserProfile favouriteUser = null;
|
||||||
|
favouriteImage.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
||||||
|
favouriteImage.setScaleType(ScaleType.FIT_CENTER);
|
||||||
|
|
||||||
|
if (publicUserMap.containsKey(id)) {
|
||||||
|
favouriteUser = publicUserMap.get(id);
|
||||||
|
} else if (friendUserMap.containsKey(id)) {
|
||||||
|
favouriteUser = friendUserMap.get(id);
|
||||||
|
} else {
|
||||||
|
favouriteUser = apiManager.getUser(id).user;
|
||||||
|
}
|
||||||
|
|
||||||
|
imageLoader.displayImage(favouriteUser.photoUrl, favouriteImage);
|
||||||
|
favouriteContainer.addView(favouriteImage);
|
||||||
|
}
|
||||||
|
|
||||||
favouriteIcon.setOnClickListener(new OnClickListener() {
|
favouriteIcon.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (!Arrays.asList(comment.likingUsers).contains(user.id)) {
|
if (!Arrays.asList(comment.likingUsers).contains(user.id)) {
|
||||||
new LikeCommentTask(context, apiManager, favouriteCount, favouriteIcon, story.id, comment, story.feedId, user.id).execute();
|
new LikeCommentTask(context, apiManager, favouriteIcon, story.id, comment, story.feedId, user.id).execute();
|
||||||
} else {
|
} else {
|
||||||
new UnLikeCommentTask(context, apiManager, favouriteCount, favouriteIcon, story.id, comment, story.feedId, user.id).execute();
|
new UnLikeCommentTask(context, apiManager, favouriteIcon, story.id, comment, story.feedId, user.id).execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,7 +18,6 @@ public class UnLikeCommentTask extends AsyncTask<Void, Void, Boolean>{
|
||||||
|
|
||||||
private static final String TAG = "LikeCommentTask";
|
private static final String TAG = "LikeCommentTask";
|
||||||
final WeakReference<ImageView> favouriteIconViewHolder;
|
final WeakReference<ImageView> favouriteIconViewHolder;
|
||||||
final WeakReference<View> favouriteCountViewHolder;
|
|
||||||
private final APIManager apiManager;
|
private final APIManager apiManager;
|
||||||
private final String storyId;
|
private final String storyId;
|
||||||
private final Comment comment;
|
private final Comment comment;
|
||||||
|
@ -26,7 +25,7 @@ public class UnLikeCommentTask extends AsyncTask<Void, Void, Boolean>{
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private final String userId;
|
private final String userId;
|
||||||
|
|
||||||
public UnLikeCommentTask(final Context context, final APIManager apiManager, final View favouriteCount, final ImageView favouriteIcon, final String storyId, final Comment comment, final String feedId, final String userId) {
|
public UnLikeCommentTask(final Context context, final APIManager apiManager, final ImageView favouriteIcon, final String storyId, final Comment comment, final String feedId, final String userId) {
|
||||||
this.apiManager = apiManager;
|
this.apiManager = apiManager;
|
||||||
this.storyId = storyId;
|
this.storyId = storyId;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
|
@ -35,7 +34,6 @@ public class UnLikeCommentTask extends AsyncTask<Void, Void, Boolean>{
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
|
|
||||||
favouriteIconViewHolder = new WeakReference<ImageView>(favouriteIcon);
|
favouriteIconViewHolder = new WeakReference<ImageView>(favouriteIcon);
|
||||||
favouriteCountViewHolder = new WeakReference<View>(favouriteCount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,7 +57,6 @@ public class UnLikeCommentTask extends AsyncTask<Void, Void, Boolean>{
|
||||||
likingUsers.toArray(newArray);
|
likingUsers.toArray(newArray);
|
||||||
comment.likingUsers = newArray;
|
comment.likingUsers = newArray;
|
||||||
|
|
||||||
((TextView) favouriteCountViewHolder.get()).setText(Integer.toString(comment.likingUsers.length));
|
|
||||||
Toast.makeText(context, "Removed like", Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, "Removed like", Toast.LENGTH_SHORT).show();
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(context, "Error removing like from comment", Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, "Error removing like from comment", Toast.LENGTH_SHORT).show();
|
||||||
|
|
Loading…
Add table
Reference in a new issue