Commit 76098da6 authored by Varun Patil's avatar Varun Patil

Mark notification read on click

parent 3c4771b5
...@@ -32,6 +32,7 @@ public class Constants { ...@@ -32,6 +32,7 @@ public class Constants {
public static final String FCM_BUNDLE_TYPE = "type"; public static final String FCM_BUNDLE_TYPE = "type";
public static final String FCM_BUNDLE_ID = "id"; public static final String FCM_BUNDLE_ID = "id";
public static final String FCM_BUNDLE_EXTRA = "extra"; public static final String FCM_BUNDLE_EXTRA = "extra";
public static final String FCM_BUNDLE_NOTIFICATION_ID = "notification_id";
public static final String DATA_TYPE_EVENT = "event"; public static final String DATA_TYPE_EVENT = "event";
public static final String DATA_TYPE_BODY = "body"; public static final String DATA_TYPE_BODY = "body";
......
...@@ -43,6 +43,7 @@ import java.util.List; ...@@ -43,6 +43,7 @@ import java.util.List;
import app.insti.Constants; import app.insti.Constants;
import app.insti.R; import app.insti.R;
import app.insti.SessionManager; import app.insti.SessionManager;
import app.insti.api.EmptyCallback;
import app.insti.api.RetrofitInterface; import app.insti.api.RetrofitInterface;
import app.insti.api.ServiceGenerator; import app.insti.api.ServiceGenerator;
import app.insti.data.Body; import app.insti.data.Body;
...@@ -78,6 +79,7 @@ import static app.insti.Constants.DATA_TYPE_EVENT; ...@@ -78,6 +79,7 @@ import static app.insti.Constants.DATA_TYPE_EVENT;
import static app.insti.Constants.DATA_TYPE_NEWS; import static app.insti.Constants.DATA_TYPE_NEWS;
import static app.insti.Constants.DATA_TYPE_PT; import static app.insti.Constants.DATA_TYPE_PT;
import static app.insti.Constants.DATA_TYPE_USER; import static app.insti.Constants.DATA_TYPE_USER;
import static app.insti.Constants.FCM_BUNDLE_NOTIFICATION_ID;
import static app.insti.Constants.MY_PERMISSIONS_REQUEST_ACCESS_LOCATION; import static app.insti.Constants.MY_PERMISSIONS_REQUEST_ACCESS_LOCATION;
import static app.insti.Constants.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE; import static app.insti.Constants.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE;
import static app.insti.Constants.RESULT_LOAD_IMAGE; import static app.insti.Constants.RESULT_LOAD_IMAGE;
...@@ -261,6 +263,13 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -261,6 +263,13 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
/** Handle opening event/body/blog from FCM notification */ /** Handle opening event/body/blog from FCM notification */
private void handleFCMIntent(Bundle bundle) { private void handleFCMIntent(Bundle bundle) {
/* Mark the notification read */
final String notificationId = bundle.getString(FCM_BUNDLE_NOTIFICATION_ID);
if (notificationId != null) {
getRetrofitInterface().markNotificationRead(getSessionIDHeader(), notificationId).enqueue(new EmptyCallback<Void>());
}
/* Follow the notification */
chooseIntent( chooseIntent(
bundle.getString(Constants.FCM_BUNDLE_TYPE), bundle.getString(Constants.FCM_BUNDLE_TYPE),
bundle.getString(Constants.FCM_BUNDLE_ID), bundle.getString(Constants.FCM_BUNDLE_ID),
......
package app.insti.api;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class EmptyCallback<T> implements Callback<T> {
@Override
public void onResponse(Call<T> call, Response<T> response) {}
@Override
public void onFailure(Call<T> call, Throwable t) {}
}
...@@ -100,7 +100,7 @@ public interface RetrofitInterface { ...@@ -100,7 +100,7 @@ public interface RetrofitInterface {
Call<List<Notification>> getNotifications(@Header("Cookie") String sessionID); Call<List<Notification>> getNotifications(@Header("Cookie") String sessionID);
@GET("notifications/read/{notificationID}") @GET("notifications/read/{notificationID}")
Call<Void> markNotificationRead(@Header("Cookie") String sessionID, @Path("notificationID") Integer notificationID); Call<Void> markNotificationRead(@Header("Cookie") String sessionID, @Path("notificationID") String notificationID);
@GET("logout") @GET("logout")
Call<Void> logout(@Header("Cookie") String sessionID); Call<Void> logout(@Header("Cookie") String sessionID);
......
...@@ -89,7 +89,7 @@ public class NotificationsFragment extends BaseFragment { ...@@ -89,7 +89,7 @@ public class NotificationsFragment extends BaseFragment {
/* Mark notification read */ /* Mark notification read */
RetrofitInterface retrofitInterface = ((MainActivity) getActivity()).getRetrofitInterface(); RetrofitInterface retrofitInterface = ((MainActivity) getActivity()).getRetrofitInterface();
String sessId = ((MainActivity) getActivity()).getSessionIDHeader(); String sessId = ((MainActivity) getActivity()).getSessionIDHeader();
retrofitInterface.markNotificationRead(sessId, notification.getNotificationId()).enqueue(new Callback<Void>() { retrofitInterface.markNotificationRead(sessId, notification.getNotificationId().toString()).enqueue(new Callback<Void>() {
@Override @Override
public void onResponse(Call<Void> call, Response<Void> response) { public void onResponse(Call<Void> call, Response<Void> response) {
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment