fixed #4230 'Opening notifications in "Read" section still marks them read and removes them from the list'. (#4249)

* notifications fixed

* refractored

* javadoc
This commit is contained in:
Aditya-Srivastav 2021-02-20 06:30:22 +05:30 committed by GitHub
parent b8cdc5a537
commit 68689980ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -65,10 +65,15 @@ public class NotificationActivity extends BaseActivity {
private NotificatinAdapter adapter; private NotificatinAdapter adapter;
private List<Notification> notificationList; private List<Notification> notificationList;
MenuItem notificationMenuItem; MenuItem notificationMenuItem;
/**
* Boolean isRead is true if this notification activity is for read section of notification.
*/
private boolean isRead;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
isRead = getIntent().getStringExtra("title").equals("read");
setContentView(R.layout.activity_notification); setContentView(R.layout.activity_notification);
ButterKnife.bind(this); ButterKnife.bind(this);
mNotificationWorkerFragment = (NotificationWorkerFragment) getFragmentManager() mNotificationWorkerFragment = (NotificationWorkerFragment) getFragmentManager()
@ -85,8 +90,21 @@ public class NotificationActivity extends BaseActivity {
return true; return true;
} }
/**
* If this is unread section of the notifications, removeNotification method
* Marks the notification as read,
* Removes the notification from unread,
* Displays the Snackbar.
*
* Otherwise returns (read section).
*
* @param notification
*/
@SuppressLint("CheckResult") @SuppressLint("CheckResult")
public void removeNotification(Notification notification) { public void removeNotification(Notification notification) {
if (isRead) {
return;
}
Disposable disposable = Observable.defer((Callable<ObservableSource<Boolean>>) Disposable disposable = Observable.defer((Callable<ObservableSource<Boolean>>)
() -> controller.markAsRead(notification)) () -> controller.markAsRead(notification))
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -126,7 +144,7 @@ public class NotificationActivity extends BaseActivity {
recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setLayoutManager(new LinearLayoutManager(this));
DividerItemDecoration itemDecor = new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL); DividerItemDecoration itemDecor = new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL);
recyclerView.addItemDecoration(itemDecor); recyclerView.addItemDecoration(itemDecor);
if (getIntent().getStringExtra("title").equals("read")) { if (isRead) {
refresh(true); refresh(true);
} else { } else {
refresh(false); refresh(false);
@ -240,7 +258,7 @@ public class NotificationActivity extends BaseActivity {
private void setPageTitle() { private void setPageTitle() {
if (getSupportActionBar() != null) { if (getSupportActionBar() != null) {
if (getIntent().getStringExtra("title").equals("read")) { if (isRead) {
getSupportActionBar().setTitle(R.string.read_notifications); getSupportActionBar().setTitle(R.string.read_notifications);
} else { } else {
getSupportActionBar().setTitle(R.string.notifications); getSupportActionBar().setTitle(R.string.notifications);
@ -249,7 +267,7 @@ public class NotificationActivity extends BaseActivity {
} }
private void setEmptyView() { private void setEmptyView() {
if (getIntent().getStringExtra("title").equals("read")) { if (isRead) {
noNotificationText.setText(R.string.no_read_notification); noNotificationText.setText(R.string.no_read_notification);
}else { }else {
noNotificationText.setText(R.string.no_notification); noNotificationText.setText(R.string.no_notification);
@ -257,7 +275,7 @@ public class NotificationActivity extends BaseActivity {
} }
private void setMenuItemTitle() { private void setMenuItemTitle() {
if (getIntent().getStringExtra("title").equals("read")) { if (isRead) {
notificationMenuItem.setTitle(R.string.menu_option_unread); notificationMenuItem.setTitle(R.string.menu_option_unread);
}else { }else {