Added option in the action bar menu to view archived notifications (#2422)

* changed layout and implemented archived notificaitons feature

* set different texts for toolbar,menu option and no notification text in archived

* modified the startup intent for NotificationsActivity

* disabled swipe on archived

* commit

* fixed navigation drawer on notification activity

* handled on back pressed

* updated strings.xml

* removed TODO

* some minor changes

* set progress bar visibility

* some code quality changes

* commit

* some code quality changes

* removing unused import statements
This commit is contained in:
Shubham Pinjwani 2019-02-10 16:10:08 +05:30 committed by Vivek Maskara
parent cb3a570090
commit a9629c6f99
10 changed files with 186 additions and 80 deletions

View file

@ -5,15 +5,19 @@ import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.support.v7.widget.Toolbar;
import com.pedrogomez.renderers.RVRendererAdapter;
@ -47,7 +51,9 @@ public class NotificationActivity extends NavigationBaseActivity {
@BindView(R.id.container)
RelativeLayout relativeLayout;
@BindView(R.id.no_notification_background)
ConstraintLayout no_notification;
RelativeLayout no_notification;
@BindView(R.id.toolbar)
Toolbar toolbar;
/* @BindView(R.id.swipe_bg)
TextView swipe_bg;*/
@Inject
@ -57,6 +63,8 @@ public class NotificationActivity extends NavigationBaseActivity {
private NotificationWorkerFragment mNotificationWorkerFragment;
private RVRendererAdapter<Notification> adapter;
private List<Notification> notificationList;
MenuItem notificationmenuitem;
TextView nonotificationtext;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -67,6 +75,8 @@ public class NotificationActivity extends NavigationBaseActivity {
.findFragmentByTag(TAG_NOTIFICATION_WORKER_FRAGMENT);
initListView();
initDrawer();
nonotificationtext = (TextView)this.findViewById(R.id.no_notification_text);
setPageTitle();
}
@SuppressLint("CheckResult")
@ -84,6 +94,7 @@ public class NotificationActivity extends NavigationBaseActivity {
snackbar.show();
if (notificationList.size()==0){
setEmptyView();
relativeLayout.setVisibility(View.GONE);
no_notification.setVisibility(View.VISIBLE);
}
@ -108,27 +119,34 @@ public class NotificationActivity extends NavigationBaseActivity {
recyclerView.setLayoutManager(new LinearLayoutManager(this));
DividerItemDecoration itemDecor = new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL);
recyclerView.addItemDecoration(itemDecor);
refresh();
}
private void refresh() {
if (!NetworkUtils.isInternetConnectionEstablished(this)) {
progressBar.setVisibility(View.GONE);
Snackbar.make(relativeLayout, R.string.no_internet, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.retry, view -> refresh()).show();
if (getIntent().getStringExtra("title").equals("read")) {
refresh(true);
} else {
progressBar.setVisibility(View.VISIBLE);
addNotifications();
refresh(false);
}
}
private void refresh(boolean archived) {
if (!NetworkUtils.isInternetConnectionEstablished(this)) {
progressBar.setVisibility(View.GONE);
Snackbar.make(relativeLayout, R.string.no_internet, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.retry, view -> refresh(archived)).show();
} else {
addNotifications(archived);
}
progressBar.setVisibility(View.VISIBLE);
no_notification.setVisibility(View.GONE);
relativeLayout.setVisibility(View.VISIBLE);
}
@SuppressLint("CheckResult")
private void addNotifications() {
private void addNotifications(boolean archived) {
Timber.d("Add notifications");
if (mNotificationWorkerFragment == null) {
Observable.fromCallable(() -> {
progressBar.setVisibility(View.VISIBLE);
return controller.getNotifications();
return controller.getNotifications(archived);
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
@ -137,10 +155,12 @@ public class NotificationActivity extends NavigationBaseActivity {
Timber.d("Number of notifications is %d", notificationList.size());
this.notificationList = notificationList;
if (notificationList.size()==0){
setEmptyView();
relativeLayout.setVisibility(View.GONE);
no_notification.setVisibility(View.VISIBLE);
} else {
setAdapter(notificationList);
} if (notificationmenuitem != null) {
}
progressBar.setVisibility(View.GONE);
}, throwable -> {
@ -154,6 +174,31 @@ public class NotificationActivity extends NavigationBaseActivity {
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_notifications, menu);
notificationmenuitem = menu.findItem(R.id.archived);
setMenuItemTitle();
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.archived:
if (item.getTitle().equals(getString(R.string.menu_option_archived))) {
NotificationActivity.startYourself(NotificationActivity.this, "read");
}else if (item.getTitle().equals(getString(R.string.menu_option_unread))) {
onBackPressed();
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void handleUrl(String url) {
if (url == null || url.equals("")) {
return;
@ -167,9 +212,18 @@ public class NotificationActivity extends NavigationBaseActivity {
/*progressBar.setVisibility(View.GONE);
recyclerView.setVisibility(View.GONE);*/
relativeLayout.setVisibility(View.GONE);
setEmptyView();
no_notification.setVisibility(View.VISIBLE);
return;
}
boolean isarchivedvisible;
if (getIntent().getStringExtra("title").equals("read")) {
isarchivedvisible = true;
} else {
isarchivedvisible = false;
}
notificationAdapterFactory = new NotificationAdapterFactory(new NotificationRenderer.NotificationClicked() {
@Override
public void notificationClicked(Notification notification) {
@ -182,16 +236,45 @@ public class NotificationActivity extends NavigationBaseActivity {
Timber.d("Notification to mark as read %s", notification.notificationId);
removeNotification(notification);
}
});
}, isarchivedvisible);
adapter = notificationAdapterFactory.create(notificationList);
relativeLayout.setVisibility(View.VISIBLE);
no_notification.setVisibility(View.GONE);
recyclerView.setAdapter(adapter);
}
public static void startYourself(Context context) {
public static void startYourself(Context context, String title) {
Intent intent = new Intent(context, NotificationActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("title", title);
context.startActivity(intent);
}
private void setPageTitle() {
if (getSupportActionBar() != null) {
if (getIntent().getStringExtra("title").equals("read")) {
getSupportActionBar().setTitle(R.string.archived_notifications);
} else {
getSupportActionBar().setTitle(R.string.notifications);
}
}
}
private void setEmptyView() {
if (getIntent().getStringExtra("title").equals("read")) {
nonotificationtext.setText(R.string.no_archived_notification);
}else {
nonotificationtext.setText(R.string.no_notification);
}
}
private void setMenuItemTitle() {
if (getIntent().getStringExtra("title").equals("read")) {
notificationmenuitem.setTitle(R.string.menu_option_unread);
}else {
notificationmenuitem.setTitle(R.string.menu_option_archived);
}
}
}

View file

@ -15,14 +15,16 @@ import java.util.List;
class NotificationAdapterFactory {
private NotificationRenderer.NotificationClicked listener;
private boolean isarchivedvisible = false;
NotificationAdapterFactory(@NonNull NotificationRenderer.NotificationClicked listener) {
NotificationAdapterFactory(@NonNull NotificationRenderer.NotificationClicked listener, boolean isarchivedvisible) {
this.listener = listener;
this.isarchivedvisible = isarchivedvisible;
}
public RVRendererAdapter<Notification> create(List<Notification> notifications) {
RendererBuilder<Notification> builder = new RendererBuilder<Notification>()
.bind(Notification.class, new NotificationRenderer(listener));
.bind(Notification.class, new NotificationRenderer(listener, isarchivedvisible));
ListAdapteeCollection<Notification> collection = new ListAdapteeCollection<>(
notifications != null ? notifications : Collections.<Notification>emptyList());
return new RVRendererAdapter<>(builder, collection);

View file

@ -25,13 +25,13 @@ public class NotificationController {
this.sessionManager = sessionManager;
}
public List<Notification> getNotifications() throws IOException {
public List<Notification> getNotifications(boolean archived) throws IOException {
if (mediaWikiApi.validateLogin()) {
return mediaWikiApi.getNotifications();
return mediaWikiApi.getNotifications(archived);
} else {
Boolean authTokenValidated = sessionManager.revalidateAuthToken();
if (authTokenValidated != null && authTokenValidated) {
return mediaWikiApi.getNotifications();
return mediaWikiApi.getNotifications(archived);
}
}
return new ArrayList<>();

View file

@ -35,10 +35,12 @@ public class NotificationRenderer extends Renderer<Notification> {
LinearLayout bottomLayout;
private NotificationClicked listener;
private boolean isarchivedvisible = false;
NotificationRenderer(NotificationClicked listener) {
NotificationRenderer(NotificationClicked listener, boolean isarchivedvisible) {
this.listener = listener;
this.isarchivedvisible = isarchivedvisible;
}
@OnClick(R.id.bottom)
void onBottomLayoutClicked(){
@ -59,7 +61,11 @@ public class NotificationRenderer extends Renderer<Notification> {
protected View inflate(LayoutInflater layoutInflater, ViewGroup viewGroup) {
View inflatedView = layoutInflater.inflate(R.layout.item_notification, viewGroup, false);
ButterKnife.bind(this, inflatedView);
if (isarchivedvisible) {
swipeLayout.setSwipeEnabled(false);
}else {
swipeLayout.setSwipeEnabled(true);
}
swipeLayout.addDrag(SwipeLayout.DragEdge.Top, bottomLayout);
swipeLayout.addRevealListener(R.id.bottom_wrapper_child1, (child, edge, fraction, distance) -> {
View star = child.findViewById(R.id.star);