11
11
import android .view .View ;
12
12
import android .view .ViewGroup ;
13
13
import android .widget .TextView ;
14
- import android .widget .Toast ;
15
14
16
15
import org .fossasia .openevent .R ;
17
16
import org .fossasia .openevent .common .network .NetworkUtils ;
@@ -40,6 +39,8 @@ public class NotificationsFragment extends BaseFragment {
40
39
protected RecyclerView notificationRecyclerView ;
41
40
@ BindView (R .id .txt_no_notification )
42
41
protected TextView noNotificationView ;
42
+ @ BindView (R .id .btn_login )
43
+ protected TextView loginBtn ;
43
44
44
45
public static NotificationsFragment getInstance () {
45
46
return new NotificationsFragment ();
@@ -50,21 +51,23 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
50
51
setHasOptionsMenu (true );
51
52
View view = super .onCreateView (inflater , container , savedInstanceState );
52
53
53
- Utils .registerIfUrlValid (swipeRefreshLayout , this , this ::refresh );
54
-
55
- notificationsList = new ArrayList <>();
56
54
notificationsFragmentViewModel = ViewModelProviders .of (this ).get (NotificationsFragmentViewModel .class );
57
- setUpRecyclerView ();
58
55
59
56
if (AuthUtil .isUserLoggedIn ()) {
60
57
if (NetworkUtils .haveNetworkConnection (getContext ())) {
61
58
swipeRefreshLayout .setRefreshing (true );
62
59
downloadNotifications ();
63
60
}
61
+ showNotificationLayout (true );
62
+ Utils .registerIfUrlValid (swipeRefreshLayout , this , this ::refresh );
63
+ notificationsList = new ArrayList <>();
64
+ setUpRecyclerView ();
64
65
loadNotifications ();
65
66
handleVisibility ();
66
67
} else {
67
- redirectToLogin ();
68
+ noNotificationView .setText (R .string .login_to_continue );
69
+ showNotificationLayout (false );
70
+ loginBtn .setOnClickListener (v -> redirectToLogin ());
68
71
}
69
72
70
73
return view ;
@@ -96,6 +99,16 @@ private void handleVisibility() {
96
99
}
97
100
}
98
101
102
+ private void showNotificationLayout (boolean showLayout ) {
103
+ if (showLayout ) {
104
+ swipeRefreshLayout .setVisibility (View .VISIBLE );
105
+ loginBtn .setVisibility (View .GONE );
106
+ } else {
107
+ swipeRefreshLayout .setVisibility (View .GONE );
108
+ loginBtn .setVisibility (View .VISIBLE );
109
+ }
110
+ }
111
+
99
112
public void onNotificationsDownloadDone (boolean status ) {
100
113
if (!status ) {
101
114
Timber .d ("Notifications download failed" );
@@ -142,7 +155,6 @@ public void onDestroyView() {
142
155
}
143
156
144
157
private void redirectToLogin () {
145
- Toast .makeText (getContext (), "Please login to see notifications!" , Toast .LENGTH_SHORT ).show ();
146
158
Intent intent = new Intent (getActivity (), LoginActivity .class );
147
159
startActivity (intent );
148
160
}
0 commit comments