mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-14 06:22:50 +01:00
Mark message as read when clicking the message in ViewMessageActivity.
This commit is contained in:
parent
ffd1d6e204
commit
a83aaa671a
@ -18,6 +18,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
import CustomView.CustomMarkwonView;
|
import CustomView.CustomMarkwonView;
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
class MessageRecyclerViewAdapter extends PagedListAdapter<Message, RecyclerView.ViewHolder> {
|
class MessageRecyclerViewAdapter extends PagedListAdapter<Message, RecyclerView.ViewHolder> {
|
||||||
private static final int VIEW_TYPE_DATA = 0;
|
private static final int VIEW_TYPE_DATA = 0;
|
||||||
@ -25,7 +26,9 @@ class MessageRecyclerViewAdapter extends PagedListAdapter<Message, RecyclerView.
|
|||||||
private static final int VIEW_TYPE_LOADING = 2;
|
private static final int VIEW_TYPE_LOADING = 2;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private Resources resources;
|
private Retrofit mOauthRetrofit;
|
||||||
|
private String mAccessToken;
|
||||||
|
private Resources mResources;
|
||||||
|
|
||||||
private NetworkState networkState;
|
private NetworkState networkState;
|
||||||
private CommentsListingRecyclerViewAdapter.RetryLoadingMoreCallback mRetryLoadingMoreCallback;
|
private CommentsListingRecyclerViewAdapter.RetryLoadingMoreCallback mRetryLoadingMoreCallback;
|
||||||
@ -34,10 +37,12 @@ class MessageRecyclerViewAdapter extends PagedListAdapter<Message, RecyclerView.
|
|||||||
void retryLoadingMore();
|
void retryLoadingMore();
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageRecyclerViewAdapter(Context context) {
|
MessageRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, String accessToken) {
|
||||||
super(DIFF_CALLBACK);
|
super(DIFF_CALLBACK);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
resources = context.getResources();
|
mOauthRetrofit = oauthRetrofit;
|
||||||
|
mAccessToken = accessToken;
|
||||||
|
mResources = context.getResources();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final DiffUtil.ItemCallback<Message> DIFF_CALLBACK = new DiffUtil.ItemCallback<Message>() {
|
private static final DiffUtil.ItemCallback<Message> DIFF_CALLBACK = new DiffUtil.ItemCallback<Message>() {
|
||||||
@ -71,11 +76,11 @@ class MessageRecyclerViewAdapter extends PagedListAdapter<Message, RecyclerView.
|
|||||||
if(message != null) {
|
if(message != null) {
|
||||||
if(message.isNew()) {
|
if(message.isNew()) {
|
||||||
((DataViewHolder) holder).itemView.setBackgroundColor(
|
((DataViewHolder) holder).itemView.setBackgroundColor(
|
||||||
resources.getColor(R.color.unreadMessageBackgroundColor));
|
mResources.getColor(R.color.unreadMessageBackgroundColor));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(message.wasComment()) {
|
if(message.wasComment()) {
|
||||||
((DataViewHolder) holder).authorTextView.setTextColor(resources.getColor(R.color.colorPrimaryDarkDayNightTheme));
|
((DataViewHolder) holder).authorTextView.setTextColor(mResources.getColor(R.color.colorPrimaryDarkDayNightTheme));
|
||||||
((DataViewHolder) holder).titleTextView.setText(message.getTitle());
|
((DataViewHolder) holder).titleTextView.setText(message.getTitle());
|
||||||
} else {
|
} else {
|
||||||
((DataViewHolder) holder).titleTextView.setVisibility(View.GONE);
|
((DataViewHolder) holder).titleTextView.setVisibility(View.GONE);
|
||||||
@ -93,6 +98,21 @@ class MessageRecyclerViewAdapter extends PagedListAdapter<Message, RecyclerView.
|
|||||||
intent.setData(uri);
|
intent.setData(uri);
|
||||||
mContext.startActivity(intent);
|
mContext.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(message.isNew()) {
|
||||||
|
((DataViewHolder) holder).itemView.setBackgroundColor(mResources.getColor(android.R.color.white));
|
||||||
|
|
||||||
|
ReadMessage.readMessage(mOauthRetrofit, mAccessToken, message.getFullname(),
|
||||||
|
new ReadMessage.ReadMessageListener() {
|
||||||
|
@Override
|
||||||
|
public void readSuccess() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readFailed() {
|
||||||
|
((DataViewHolder) holder).itemView.setBackgroundColor(mResources.getColor(R.color.unreadMessageBackgroundColor));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
((DataViewHolder) holder).authorTextView.setOnClickListener(view -> {
|
((DataViewHolder) holder).authorTextView.setOnClickListener(view -> {
|
||||||
@ -134,9 +154,9 @@ class MessageRecyclerViewAdapter extends PagedListAdapter<Message, RecyclerView.
|
|||||||
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
||||||
super.onViewRecycled(holder);
|
super.onViewRecycled(holder);
|
||||||
if(holder instanceof DataViewHolder) {
|
if(holder instanceof DataViewHolder) {
|
||||||
((DataViewHolder) holder).itemView.setBackgroundColor(resources.getColor(android.R.color.white));
|
((DataViewHolder) holder).itemView.setBackgroundColor(mResources.getColor(android.R.color.white));
|
||||||
((DataViewHolder) holder).titleTextView.setVisibility(View.VISIBLE);
|
((DataViewHolder) holder).titleTextView.setVisibility(View.VISIBLE);
|
||||||
((DataViewHolder) holder).authorTextView.setTextColor(resources.getColor(R.color.primaryTextColor));
|
((DataViewHolder) holder).authorTextView.setTextColor(mResources.getColor(R.color.primaryTextColor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,12 +14,7 @@ class NotificationUtils {
|
|||||||
static final String GROUP_NEW_COMMENTS = "ml.docilealligator.infinityforreddit.NEW_COMMENTS";
|
static final String GROUP_NEW_COMMENTS = "ml.docilealligator.infinityforreddit.NEW_COMMENTS";
|
||||||
static final int SUMMARY_ID_NEW_COMMENTS = 0;
|
static final int SUMMARY_ID_NEW_COMMENTS = 0;
|
||||||
|
|
||||||
static final int BASE_ID_COMMENT = 1;
|
static final int BASE_ID_UNREAD_MESSAGE = 1;
|
||||||
static final int BASE_ID_ACCOUNT = 1000;
|
|
||||||
static final int BASE_ID_POST = 2000;
|
|
||||||
static final int BASE_ID_MESSAGE = 3000;
|
|
||||||
static final int BASE_ID_SUBREDDIT = 4000;
|
|
||||||
static final int BASE_ID_AWARD = 5000;
|
|
||||||
|
|
||||||
static NotificationCompat.Builder buildNotification(NotificationManagerCompat notificationManager,
|
static NotificationCompat.Builder buildNotification(NotificationManagerCompat notificationManager,
|
||||||
Context context, String title, String content,
|
Context context, String title, String content,
|
||||||
|
@ -75,15 +75,13 @@ public class PullNotificationWorker extends Worker {
|
|||||||
String kind = message.getKind();
|
String kind = message.getKind();
|
||||||
String title;
|
String title;
|
||||||
String summary;
|
String summary;
|
||||||
if(kind.equals(Message.TYPE_COMMENT)) {
|
if(kind.equals(Message.TYPE_COMMENT) || kind.equals(Message.TYPE_LINK)) {
|
||||||
title = message.getAuthor();
|
title = message.getAuthor();
|
||||||
summary = context.getString(R.string.notification_summary_comment);
|
summary = context.getString(R.string.notification_summary_comment);
|
||||||
} else {
|
} else {
|
||||||
title = message.getTitle();
|
title = message.getTitle();
|
||||||
if(kind.equals(Message.TYPE_ACCOUNT)) {
|
if(kind.equals(Message.TYPE_ACCOUNT)) {
|
||||||
summary = context.getString(R.string.notification_summary_account);
|
summary = context.getString(R.string.notification_summary_account);
|
||||||
} else if(kind.equals(Message.TYPE_LINK)) {
|
|
||||||
summary = context.getString(R.string.notification_summary_post);
|
|
||||||
} else if(kind.equals(Message.TYPE_MESSAGE)) {
|
} else if(kind.equals(Message.TYPE_MESSAGE)) {
|
||||||
summary = context.getString(R.string.notification_summary_message);
|
summary = context.getString(R.string.notification_summary_message);
|
||||||
} else if(kind.equals(Message.TYPE_SUBREDDIT)) {
|
} else if(kind.equals(Message.TYPE_SUBREDDIT)) {
|
||||||
@ -104,18 +102,30 @@ public class PullNotificationWorker extends Worker {
|
|||||||
intent.setData(uri);
|
intent.setData(uri);
|
||||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
builder.setContentIntent(pendingIntent);
|
builder.setContentIntent(pendingIntent);
|
||||||
notificationManager.notify(NotificationUtils.BASE_ID_COMMENT + i, builder.build());
|
|
||||||
} else if(kind.equals(Message.TYPE_ACCOUNT)) {
|
} else if(kind.equals(Message.TYPE_ACCOUNT)) {
|
||||||
notificationManager.notify(NotificationUtils.BASE_ID_ACCOUNT + i, builder.build());
|
Intent intent = new Intent(context, ViewMessageActivity.class);
|
||||||
|
PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
|
builder.setContentIntent(summaryPendingIntent);
|
||||||
} else if(kind.equals(Message.TYPE_LINK)) {
|
} else if(kind.equals(Message.TYPE_LINK)) {
|
||||||
notificationManager.notify(NotificationUtils.BASE_ID_POST + i, builder.build());
|
Intent intent = new Intent(context, LinkResolverActivity.class);
|
||||||
|
Uri uri = LinkResolverActivity.getRedditUriByPath(message.getContext());
|
||||||
|
intent.setData(uri);
|
||||||
|
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
|
builder.setContentIntent(pendingIntent);
|
||||||
} else if(kind.equals(Message.TYPE_MESSAGE)) {
|
} else if(kind.equals(Message.TYPE_MESSAGE)) {
|
||||||
notificationManager.notify(NotificationUtils.BASE_ID_MESSAGE + i, builder.build());
|
Intent intent = new Intent(context, ViewMessageActivity.class);
|
||||||
|
PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
|
builder.setContentIntent(summaryPendingIntent);
|
||||||
} else if(kind.equals(Message.TYPE_SUBREDDIT)) {
|
} else if(kind.equals(Message.TYPE_SUBREDDIT)) {
|
||||||
notificationManager.notify(NotificationUtils.BASE_ID_SUBREDDIT + i, builder.build());
|
Intent intent = new Intent(context, ViewMessageActivity.class);
|
||||||
|
PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
|
builder.setContentIntent(summaryPendingIntent);
|
||||||
} else {
|
} else {
|
||||||
notificationManager.notify(NotificationUtils.BASE_ID_AWARD + i, builder.build());
|
Intent intent = new Intent(context, ViewMessageActivity.class);
|
||||||
|
PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
|
builder.setContentIntent(summaryPendingIntent);
|
||||||
}
|
}
|
||||||
|
notificationManager.notify(NotificationUtils.BASE_ID_UNREAD_MESSAGE + i, builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
inboxStyle.setBigContentTitle(messages.size() + " New Messages")
|
inboxStyle.setBigContentTitle(messages.size() + " New Messages")
|
||||||
@ -123,6 +133,10 @@ public class PullNotificationWorker extends Worker {
|
|||||||
|
|
||||||
summaryBuilder.setStyle(inboxStyle);
|
summaryBuilder.setStyle(inboxStyle);
|
||||||
|
|
||||||
|
Intent summaryIntent = new Intent(context, ViewMessageActivity.class);
|
||||||
|
PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, 0, summaryIntent, 0);
|
||||||
|
summaryBuilder.setContentIntent(summaryPendingIntent);
|
||||||
|
|
||||||
notificationManager.notify(NotificationUtils.SUMMARY_ID_NEW_COMMENTS, summaryBuilder.build());
|
notificationManager.notify(NotificationUtils.SUMMARY_ID_NEW_COMMENTS, summaryBuilder.build());
|
||||||
|
|
||||||
Log.i("workmanager", "message size " + messages.size());
|
Log.i("workmanager", "message size " + messages.size());
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
import retrofit2.Response;
|
||||||
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
|
class ReadMessage {
|
||||||
|
interface ReadMessageListener {
|
||||||
|
void readSuccess();
|
||||||
|
void readFailed();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void readMessage(Retrofit oauthRetrofit, String accessToken, String commaSeparatedFullnames,
|
||||||
|
ReadMessageListener readMessageListener) {
|
||||||
|
Map<String, String> params = new HashMap<>();
|
||||||
|
params.put(RedditUtils.ID_KEY, commaSeparatedFullnames);
|
||||||
|
oauthRetrofit.create(RedditAPI.class).readMessage(RedditUtils.getOAuthHeader(accessToken), params)
|
||||||
|
.enqueue(new Callback<String>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||||
|
if(response.isSuccessful()) {
|
||||||
|
readMessageListener.readSuccess();
|
||||||
|
} else {
|
||||||
|
readMessageListener.readFailed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||||
|
readMessageListener.readFailed();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -159,4 +159,8 @@ public interface RedditAPI {
|
|||||||
|
|
||||||
@GET("/message/{where}.json?raw_json=1")
|
@GET("/message/{where}.json?raw_json=1")
|
||||||
Call<String> getMessages(@HeaderMap Map<String, String> headers, @Path("where") String where, @Query("after") String after);
|
Call<String> getMessages(@HeaderMap Map<String, String> headers, @Path("where") String where, @Query("after") String after);
|
||||||
|
|
||||||
|
@FormUrlEncoded
|
||||||
|
@POST("/api/read_message")
|
||||||
|
Call<String> readMessage(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> ids);
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ public class ViewMessageActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void bindView() {
|
private void bindView() {
|
||||||
mAdapter = new MessageRecyclerViewAdapter(this);
|
mAdapter = new MessageRecyclerViewAdapter(this, mOauthRetrofit, mAccessToken);
|
||||||
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
||||||
recyclerView.setLayoutManager(layoutManager);
|
recyclerView.setLayoutManager(layoutManager);
|
||||||
recyclerView.setAdapter(mAdapter);
|
recyclerView.setAdapter(mAdapter);
|
||||||
|
@ -224,10 +224,10 @@
|
|||||||
|
|
||||||
<string name="view_all_comments">Click here to browse all comments</string>
|
<string name="view_all_comments">Click here to browse all comments</string>
|
||||||
|
|
||||||
<string name="notification_summary_comment">New Comments</string>
|
<string name="notification_summary_comment">New Comment</string>
|
||||||
<string name="notification_summary_account">Account</string>
|
<string name="notification_summary_account">Account</string>
|
||||||
<string name="notification_summary_post">Post</string>
|
<string name="notification_summary_post">New Post Comment</string>
|
||||||
<string name="notification_summary_message">New Messages</string>
|
<string name="notification_summary_message">New Message</string>
|
||||||
<string name="notification_summary_subreddit">Subreddit</string>
|
<string name="notification_summary_subreddit">Subreddit</string>
|
||||||
<string name="notification_summary_award">Award</string>
|
<string name="notification_summary_award">Award</string>
|
||||||
<string name="notification_new_messages">%1$d New Messages</string>
|
<string name="notification_new_messages">%1$d New Messages</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user