From a83aaa671a1c930c4402345783839b0db66118b3 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sun, 18 Aug 2019 23:51:27 +0800 Subject: Mark message as read when clicking the message in ViewMessageActivity. --- .../MessageRecyclerViewAdapter.java | 34 ++++++++++++++---- .../infinityforreddit/NotificationUtils.java | 7 +--- .../infinityforreddit/PullNotificationWorker.java | 32 ++++++++++++----- .../infinityforreddit/ReadMessage.java | 40 ++++++++++++++++++++++ .../infinityforreddit/RedditAPI.java | 4 +++ .../infinityforreddit/ViewMessageActivity.java | 2 +- 6 files changed, 96 insertions(+), 23 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/ReadMessage.java (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MessageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MessageRecyclerViewAdapter.java index 3865123b..3807a413 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/MessageRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MessageRecyclerViewAdapter.java @@ -18,6 +18,7 @@ import androidx.recyclerview.widget.RecyclerView; import CustomView.CustomMarkwonView; import butterknife.BindView; import butterknife.ButterKnife; +import retrofit2.Retrofit; class MessageRecyclerViewAdapter extends PagedListAdapter { private static final int VIEW_TYPE_DATA = 0; @@ -25,7 +26,9 @@ class MessageRecyclerViewAdapter extends PagedListAdapter DIFF_CALLBACK = new DiffUtil.ItemCallback() { @@ -71,11 +76,11 @@ class MessageRecyclerViewAdapter extends PagedListAdapter { @@ -134,9 +154,9 @@ class MessageRecyclerViewAdapter extends PagedListAdapter params = new HashMap<>(); + params.put(RedditUtils.ID_KEY, commaSeparatedFullnames); + oauthRetrofit.create(RedditAPI.class).readMessage(RedditUtils.getOAuthHeader(accessToken), params) + .enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if(response.isSuccessful()) { + readMessageListener.readSuccess(); + } else { + readMessageListener.readFailed(); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + readMessageListener.readFailed(); + } + }); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java index a187b521..519bc0ec 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java @@ -159,4 +159,8 @@ public interface RedditAPI { @GET("/message/{where}.json?raw_json=1") Call getMessages(@HeaderMap Map headers, @Path("where") String where, @Query("after") String after); + + @FormUrlEncoded + @POST("/api/read_message") + Call readMessage(@HeaderMap Map headers, @FieldMap Map ids); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java index b61438f4..3f6d5960 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java @@ -156,7 +156,7 @@ public class ViewMessageActivity extends AppCompatActivity { } private void bindView() { - mAdapter = new MessageRecyclerViewAdapter(this); + mAdapter = new MessageRecyclerViewAdapter(this, mOauthRetrofit, mAccessToken); LinearLayoutManager layoutManager = new LinearLayoutManager(this); recyclerView.setLayoutManager(layoutManager); recyclerView.setAdapter(mAdapter); -- cgit v1.2.3