Skip to content

Commit 2acd5c6

Browse files
ParthivMangukiyaiamareebjamal
authored andcommitted
fix: Fix navigation flow of notificationsFragment (fossasia#2378)
1 parent eafac29 commit 2acd5c6

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

android/app/src/main/java/org/fossasia/openevent/core/notifications/NotificationsFragment.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import android.view.View;
1212
import android.view.ViewGroup;
1313
import android.widget.TextView;
14-
import android.widget.Toast;
1514

1615
import org.fossasia.openevent.R;
1716
import org.fossasia.openevent.common.network.NetworkUtils;
@@ -40,6 +39,8 @@ public class NotificationsFragment extends BaseFragment {
4039
protected RecyclerView notificationRecyclerView;
4140
@BindView(R.id.txt_no_notification)
4241
protected TextView noNotificationView;
42+
@BindView(R.id.btn_login)
43+
protected TextView loginBtn;
4344

4445
public static NotificationsFragment getInstance() {
4546
return new NotificationsFragment();
@@ -50,21 +51,23 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
5051
setHasOptionsMenu(true);
5152
View view = super.onCreateView(inflater, container, savedInstanceState);
5253

53-
Utils.registerIfUrlValid(swipeRefreshLayout, this, this::refresh);
54-
55-
notificationsList = new ArrayList<>();
5654
notificationsFragmentViewModel = ViewModelProviders.of(this).get(NotificationsFragmentViewModel.class);
57-
setUpRecyclerView();
5855

5956
if(AuthUtil.isUserLoggedIn()) {
6057
if (NetworkUtils.haveNetworkConnection(getContext())) {
6158
swipeRefreshLayout.setRefreshing(true);
6259
downloadNotifications();
6360
}
61+
showNotificationLayout(true);
62+
Utils.registerIfUrlValid(swipeRefreshLayout, this, this::refresh);
63+
notificationsList = new ArrayList<>();
64+
setUpRecyclerView();
6465
loadNotifications();
6566
handleVisibility();
6667
} else {
67-
redirectToLogin();
68+
noNotificationView.setText(R.string.login_to_continue);
69+
showNotificationLayout(false);
70+
loginBtn.setOnClickListener(v -> redirectToLogin());
6871
}
6972

7073
return view;
@@ -96,6 +99,16 @@ private void handleVisibility() {
9699
}
97100
}
98101

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+
99112
public void onNotificationsDownloadDone(boolean status) {
100113
if (!status) {
101114
Timber.d("Notifications download failed");
@@ -142,7 +155,6 @@ public void onDestroyView() {
142155
}
143156

144157
private void redirectToLogin() {
145-
Toast.makeText(getContext(), "Please login to see notifications!", Toast.LENGTH_SHORT).show();
146158
Intent intent = new Intent(getActivity(), LoginActivity.class);
147159
startActivity(intent);
148160
}

android/app/src/main/res/layout/list_notification.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,15 @@
2929
tools:listitem="@layout/item_notification" />
3030

3131
</android.support.v4.widget.SwipeRefreshLayout>
32+
33+
<Button
34+
android:id="@+id/btn_login"
35+
android:layout_width="match_parent"
36+
android:layout_height="wrap_content"
37+
android:minHeight="?android:actionBarSize"
38+
android:layout_alignParentBottom="true"
39+
android:background="@color/color_accent"
40+
android:text="@string/login"
41+
android:textColor="@color/white"/>
42+
3243
</RelativeLayout>

0 commit comments

Comments
 (0)