From 821dad81591362fbc91a217ae12c1e961bd63ae3 Mon Sep 17 00:00:00 2001 From: Kosh Date: Tue, 4 Apr 2017 16:37:41 +0800 Subject: [PATCH] this commit adds the possibility to mark notification as read by long clicking it. --- .../notification/NotificationsMvp.java | 8 +++++++- .../notification/NotificationsPresenter.java | 20 ++++++++++++++++++- .../notification/NotificationsView.java | 19 ++++++++++++++++++ .../layout/notifications_row_item.xml | 3 +-- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/fastaccess/ui/modules/notification/NotificationsMvp.java b/app/src/main/java/com/fastaccess/ui/modules/notification/NotificationsMvp.java index 8f23280a9..f439e313d 100644 --- a/app/src/main/java/com/fastaccess/ui/modules/notification/NotificationsMvp.java +++ b/app/src/main/java/com/fastaccess/ui/modules/notification/NotificationsMvp.java @@ -1,5 +1,7 @@ package com.fastaccess.ui.modules.notification; +import android.content.Context; +import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.widget.SwipeRefreshLayout; @@ -22,11 +24,13 @@ interface View extends BaseMvp.FAView, SwipeRefreshLayout.OnRefreshListener { @NonNull OnLoadMore getLoadMore(); - @CallOnMainThread void onNotifyAdapter(); + @CallOnMainThread void onNotifyAdapter(); void onTypeChanged(boolean unread); void onClick(@NonNull String url); + + void onAskMarkAsReadPermission(int position, long id); } interface Presenter extends BaseViewHolder.OnItemClickListener, @@ -37,5 +41,7 @@ interface Presenter extends BaseViewHolder.OnItemClickListener, @NonNull ArrayList getNotifications(); void showAllNotifications(boolean showAll); + + void onReadNotification(@NonNull Context context, @NonNull Bundle bundle); } } diff --git a/app/src/main/java/com/fastaccess/ui/modules/notification/NotificationsPresenter.java b/app/src/main/java/com/fastaccess/ui/modules/notification/NotificationsPresenter.java index d75ed918e..7391601d1 100644 --- a/app/src/main/java/com/fastaccess/ui/modules/notification/NotificationsPresenter.java +++ b/app/src/main/java/com/fastaccess/ui/modules/notification/NotificationsPresenter.java @@ -1,11 +1,14 @@ package com.fastaccess.ui.modules.notification; +import android.content.Context; +import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.view.View; import com.fastaccess.data.dao.Pageable; import com.fastaccess.data.dao.model.Notification; +import com.fastaccess.helper.BundleConstant; import com.fastaccess.helper.PrefGetter; import com.fastaccess.helper.RxHelper; import com.fastaccess.provider.rest.RestProvider; @@ -42,7 +45,9 @@ public class NotificationsPresenter extends BasePresenter } @Override public void onItemLongClick(int position, View v, Notification item) { - onItemClick(position, v, item); + if (getView() != null) { + getView().onAskMarkAsReadPermission(position, item.getId()); + } } @Override public void onError(@NonNull Throwable throwable) { @@ -72,6 +77,19 @@ public class NotificationsPresenter extends BasePresenter this.showAll = showAll; } + @Override public void onReadNotification(@NonNull Context context, @NonNull Bundle bundle) { + long id = bundle.getLong(BundleConstant.ID); + int position = bundle.getInt(BundleConstant.EXTRA); + Notification notification = notifications.get(position); + if (notification != null && notification.getId() == id) { + ReadNotificationService.start(context, id); + notifications.remove(position); + notification.setUnread(true); + manageSubscription(notification.save(notification).subscribe()); + sendToView(NotificationsMvp.View::onNotifyAdapter); + } + } + @Override public int getCurrentPage() { return page; } diff --git a/app/src/main/java/com/fastaccess/ui/modules/notification/NotificationsView.java b/app/src/main/java/com/fastaccess/ui/modules/notification/NotificationsView.java index 58f45c567..8942b6ff7 100644 --- a/app/src/main/java/com/fastaccess/ui/modules/notification/NotificationsView.java +++ b/app/src/main/java/com/fastaccess/ui/modules/notification/NotificationsView.java @@ -13,6 +13,8 @@ import com.annimon.stream.Stream; import com.fastaccess.R; import com.fastaccess.data.dao.model.Notification; +import com.fastaccess.helper.BundleConstant; +import com.fastaccess.helper.Bundler; import com.fastaccess.helper.Logger; import com.fastaccess.provider.rest.loadmore.OnLoadMore; import com.fastaccess.provider.scheme.SchemeParser; @@ -22,6 +24,7 @@ import com.fastaccess.ui.base.BaseFragment; import com.fastaccess.ui.widgets.AppbarRefreshLayout; import com.fastaccess.ui.widgets.StateLayout; +import com.fastaccess.ui.widgets.dialog.MessageDialogView; import com.fastaccess.ui.widgets.recyclerview.DynamicRecyclerView; import butterknife.BindView; @@ -79,6 +82,22 @@ public static NotificationsView newInstance() { } } + @Override public void onAskMarkAsReadPermission(int position, long id) { + MessageDialogView.newInstance(getString(R.string.marking_as_read), getString(R.string.confirm_message), + Bundler.start().put(BundleConstant.YES_NO_EXTRA, true) + .put(BundleConstant.ID, id) + .put(BundleConstant.EXTRA, position) + .end()) + .show(getChildFragmentManager(), MessageDialogView.TAG); + } + + @Override public void onMessageDialogActionClicked(boolean isOk, @Nullable Bundle bundle) { + super.onMessageDialogActionClicked(isOk, bundle); + if (isOk && bundle != null) { + getPresenter().onReadNotification(getContext(), bundle); + } + } + @Override protected int fragmentLayout() { return R.layout.small_grid_refresh_list; } diff --git a/app/src/main/res/layouts/row_layouts/layout/notifications_row_item.xml b/app/src/main/res/layouts/row_layouts/layout/notifications_row_item.xml index da76dee91..4c0298137 100644 --- a/app/src/main/res/layouts/row_layouts/layout/notifications_row_item.xml +++ b/app/src/main/res/layouts/row_layouts/layout/notifications_row_item.xml @@ -10,8 +10,7 @@ android:paddingBottom="@dimen/spacing_normal" android:paddingEnd="@dimen/spacing_xs_large" android:paddingStart="@dimen/spacing_xs_large" - android:paddingTop="@dimen/spacing_normal" - > + android:paddingTop="@dimen/spacing_normal">