55import android .content .Intent ;
66import android .net .Uri ;
77import android .os .Bundle ;
8- import android .support .constraint .ConstraintLayout ;
98import android .support .design .widget .Snackbar ;
109import android .support .v7 .widget .DividerItemDecoration ;
1110import android .support .v7 .widget .LinearLayoutManager ;
1211import android .support .v7 .widget .RecyclerView ;
12+ import android .view .Menu ;
13+ import android .view .MenuInflater ;
14+ import android .view .MenuItem ;
1315import android .view .View ;
1416import android .widget .ProgressBar ;
1517import android .widget .RelativeLayout ;
18+ import android .widget .TextView ;
1619import android .widget .Toast ;
20+ import android .support .v7 .widget .Toolbar ;
1721
1822import com .pedrogomez .renderers .RVRendererAdapter ;
1923
@@ -47,7 +51,9 @@ public class NotificationActivity extends NavigationBaseActivity {
4751 @ BindView (R .id .container )
4852 RelativeLayout relativeLayout ;
4953 @ BindView (R .id .no_notification_background )
50- ConstraintLayout no_notification ;
54+ RelativeLayout no_notification ;
55+ @ BindView (R .id .toolbar )
56+ Toolbar toolbar ;
5157 /* @BindView(R.id.swipe_bg)
5258 TextView swipe_bg;*/
5359 @ Inject
@@ -57,6 +63,8 @@ public class NotificationActivity extends NavigationBaseActivity {
5763 private NotificationWorkerFragment mNotificationWorkerFragment ;
5864 private RVRendererAdapter <Notification > adapter ;
5965 private List <Notification > notificationList ;
66+ MenuItem notificationmenuitem ;
67+ TextView nonotificationtext ;
6068
6169 @ Override
6270 protected void onCreate (Bundle savedInstanceState ) {
@@ -67,6 +75,8 @@ protected void onCreate(Bundle savedInstanceState) {
6775 .findFragmentByTag (TAG_NOTIFICATION_WORKER_FRAGMENT );
6876 initListView ();
6977 initDrawer ();
78+ nonotificationtext = (TextView )this .findViewById (R .id .no_notification_text );
79+ setPageTitle ();
7080 }
7181
7282 @ SuppressLint ("CheckResult" )
@@ -84,6 +94,7 @@ public void removeNotification(Notification notification) {
8494
8595 snackbar .show ();
8696 if (notificationList .size ()==0 ){
97+ setEmptyView ();
8798 relativeLayout .setVisibility (View .GONE );
8899 no_notification .setVisibility (View .VISIBLE );
89100 }
@@ -108,27 +119,34 @@ private void initListView() {
108119 recyclerView .setLayoutManager (new LinearLayoutManager (this ));
109120 DividerItemDecoration itemDecor = new DividerItemDecoration (recyclerView .getContext (), DividerItemDecoration .VERTICAL );
110121 recyclerView .addItemDecoration (itemDecor );
111- refresh ();
122+ if (getIntent ().getStringExtra ("title" ).equals ("read" )) {
123+ refresh (true );
124+ } else {
125+ refresh (false );
126+ }
112127 }
113128
114- private void refresh () {
129+ private void refresh (boolean archived ) {
115130 if (!NetworkUtils .isInternetConnectionEstablished (this )) {
116131 progressBar .setVisibility (View .GONE );
117132 Snackbar .make (relativeLayout , R .string .no_internet , Snackbar .LENGTH_INDEFINITE )
118- .setAction (R .string .retry , view -> refresh ()).show ();
133+ .setAction (R .string .retry , view -> refresh (archived )).show ();
119134 } else {
120- progressBar .setVisibility (View .VISIBLE );
121- addNotifications ();
135+ addNotifications (archived );
122136 }
137+ progressBar .setVisibility (View .VISIBLE );
138+ no_notification .setVisibility (View .GONE );
139+ relativeLayout .setVisibility (View .VISIBLE );
123140 }
124141
125142 @ SuppressLint ("CheckResult" )
126- private void addNotifications () {
143+ private void addNotifications (boolean archived ) {
127144 Timber .d ("Add notifications" );
128145 if (mNotificationWorkerFragment == null ) {
129146 Observable .fromCallable (() -> {
130147 progressBar .setVisibility (View .VISIBLE );
131- return controller .getNotifications ();
148+ return controller .getNotifications (archived );
149+
132150 })
133151 .subscribeOn (Schedulers .io ())
134152 .observeOn (AndroidSchedulers .mainThread ())
@@ -137,10 +155,12 @@ private void addNotifications() {
137155 Timber .d ("Number of notifications is %d" , notificationList .size ());
138156 this .notificationList = notificationList ;
139157 if (notificationList .size ()==0 ){
158+ setEmptyView ();
140159 relativeLayout .setVisibility (View .GONE );
141160 no_notification .setVisibility (View .VISIBLE );
142161 } else {
143162 setAdapter (notificationList );
163+ } if (notificationmenuitem != null ) {
144164 }
145165 progressBar .setVisibility (View .GONE );
146166 }, throwable -> {
@@ -154,6 +174,31 @@ private void addNotifications() {
154174 }
155175 }
156176
177+ @ Override
178+ public boolean onCreateOptionsMenu (Menu menu ) {
179+ MenuInflater inflater = getMenuInflater ();
180+ inflater .inflate (R .menu .menu_notifications , menu );
181+ notificationmenuitem = menu .findItem (R .id .archived );
182+ setMenuItemTitle ();
183+ return true ;
184+ }
185+
186+ @ Override
187+ public boolean onOptionsItemSelected (MenuItem item ) {
188+ // Handle item selection
189+ switch (item .getItemId ()) {
190+ case R .id .archived :
191+ if (item .getTitle ().equals (getString (R .string .menu_option_archived ))) {
192+ NotificationActivity .startYourself (NotificationActivity .this , "read" );
193+ }else if (item .getTitle ().equals (getString (R .string .menu_option_unread ))) {
194+ onBackPressed ();
195+ }
196+ return true ;
197+ default :
198+ return super .onOptionsItemSelected (item );
199+ }
200+ }
201+
157202 private void handleUrl (String url ) {
158203 if (url == null || url .equals ("" )) {
159204 return ;
@@ -167,9 +212,18 @@ private void setAdapter(List<Notification> notificationList) {
167212 /*progressBar.setVisibility(View.GONE);
168213 recyclerView.setVisibility(View.GONE);*/
169214 relativeLayout .setVisibility (View .GONE );
215+ setEmptyView ();
170216 no_notification .setVisibility (View .VISIBLE );
171217 return ;
172218 }
219+
220+ boolean isarchivedvisible ;
221+ if (getIntent ().getStringExtra ("title" ).equals ("read" )) {
222+ isarchivedvisible = true ;
223+ } else {
224+ isarchivedvisible = false ;
225+ }
226+
173227 notificationAdapterFactory = new NotificationAdapterFactory (new NotificationRenderer .NotificationClicked () {
174228 @ Override
175229 public void notificationClicked (Notification notification ) {
@@ -182,16 +236,45 @@ public void markNotificationAsRead(Notification notification) {
182236 Timber .d ("Notification to mark as read %s" , notification .notificationId );
183237 removeNotification (notification );
184238 }
185- });
239+ }, isarchivedvisible );
186240 adapter = notificationAdapterFactory .create (notificationList );
187241 relativeLayout .setVisibility (View .VISIBLE );
188242 no_notification .setVisibility (View .GONE );
189243 recyclerView .setAdapter (adapter );
190244 }
191245
192- public static void startYourself (Context context ) {
246+ public static void startYourself (Context context , String title ) {
193247 Intent intent = new Intent (context , NotificationActivity .class );
194- intent .addFlags (Intent .FLAG_ACTIVITY_REORDER_TO_FRONT | Intent .FLAG_ACTIVITY_SINGLE_TOP );
248+ intent .putExtra ("title" , title );
249+
195250 context .startActivity (intent );
196251 }
252+
253+ private void setPageTitle () {
254+ if (getSupportActionBar () != null ) {
255+ if (getIntent ().getStringExtra ("title" ).equals ("read" )) {
256+ getSupportActionBar ().setTitle (R .string .archived_notifications );
257+ } else {
258+ getSupportActionBar ().setTitle (R .string .notifications );
259+ }
260+ }
261+ }
262+
263+ private void setEmptyView () {
264+ if (getIntent ().getStringExtra ("title" ).equals ("read" )) {
265+ nonotificationtext .setText (R .string .no_archived_notification );
266+ }else {
267+ nonotificationtext .setText (R .string .no_notification );
268+ }
269+ }
270+
271+ private void setMenuItemTitle () {
272+ if (getIntent ().getStringExtra ("title" ).equals ("read" )) {
273+ notificationmenuitem .setTitle (R .string .menu_option_unread );
274+
275+ }else {
276+ notificationmenuitem .setTitle (R .string .menu_option_archived );
277+
278+ }
279+ }
197280}
0 commit comments