Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

Commit

Permalink
this commit adds the possibility to mark notification as read by long…
Browse files Browse the repository at this point in the history
… clicking it.
  • Loading branch information
Kosh committed Apr 4, 2017
1 parent 7535901 commit 821dad8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<Notification>,
Expand All @@ -37,5 +41,7 @@ interface Presenter extends BaseViewHolder.OnItemClickListener<Notification>,
@NonNull ArrayList<Notification> getNotifications();

void showAllNotifications(boolean showAll);

void onReadNotification(@NonNull Context context, @NonNull Bundle bundle);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -42,7 +45,9 @@ public class NotificationsPresenter extends BasePresenter<NotificationsMvp.View>
}

@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) {
Expand Down Expand Up @@ -72,6 +77,19 @@ public class NotificationsPresenter extends BasePresenter<NotificationsMvp.View>
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<LinearLayout
android:layout_width="match_parent"
Expand Down

0 comments on commit 821dad8

Please sign in to comment.