Skip to content

Commit eafac29

Browse files
ParthivMangukiyaiamareebjamal
authored andcommitted
fix: Fix navigation flow of faq Fragment (fossasia#2377)
1 parent f97a9b6 commit eafac29

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

android/app/src/main/java/org/fossasia/openevent/core/faqs/FAQFragment.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import android.view.View;
1414
import android.view.ViewGroup;
1515
import android.widget.TextView;
16-
import android.widget.Toast;
1716

1817
import org.fossasia.openevent.R;
1918
import org.fossasia.openevent.common.network.NetworkUtils;
@@ -37,6 +36,8 @@ public class FAQFragment extends BaseFragment {
3736
protected TextView tvEmptyFaqs;
3837
@BindView(R.id.faq_swiperefreshlayout)
3938
protected SwipeRefreshLayout swipeRefreshLayout;
39+
@BindView(R.id.btn_login)
40+
protected TextView loginBtn;
4041

4142
private ArrayList<FAQ> faqArrayList;
4243
private FAQListAdapter faqListAdapter;
@@ -47,26 +48,28 @@ public class FAQFragment extends BaseFragment {
4748
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
4849
// setHasOptionsMenu(true); TODO : ADD SEARCH OPTION
4950
View view = super.onCreateView(inflater, container, savedInstanceState);
50-
Utils.registerIfUrlValid(swipeRefreshLayout, this, this::refresh);
51-
faqArrayList = new ArrayList<>();
5251
faqViewModel = ViewModelProviders.of(this).get(FAQViewModel.class);
53-
setUpRecyclerView();
5452

5553
if (AuthUtil.isUserLoggedIn()) {
5654
if (NetworkUtils.haveNetworkConnection(getContext())) {
5755
downloadFAQS();
5856
}
57+
showFaqLayout(true);
58+
Utils.registerIfUrlValid(swipeRefreshLayout, this, this::refresh);
59+
faqArrayList = new ArrayList<>();
60+
setUpRecyclerView();
5961
loadFAQs();
6062
handleVisibility();
6163
} else {
62-
redirectToLogin();
64+
showFaqLayout(false);
65+
tvEmptyFaqs.setText(R.string.login_to_continue);
66+
loginBtn.setOnClickListener(v -> redirectToLogin());
6367
}
6468

6569
return view;
6670
}
6771

6872
private void redirectToLogin() {
69-
Toast.makeText(getContext(), R.string.login_to_see_faqs, Toast.LENGTH_SHORT).show();
7073
Intent intent = new Intent(getActivity(), LoginActivity.class);
7174
startActivity(intent);
7275
}
@@ -122,11 +125,13 @@ private void handleVisibility() {
122125
}
123126
}
124127

125-
@Override
126-
public void onResume() {
127-
super.onResume();
128-
if (!AuthUtil.isUserLoggedIn()) {
129-
tvEmptyFaqs.setText(R.string.login_to_view_faqs);
128+
private void showFaqLayout(boolean showLayout) {
129+
if (showLayout) {
130+
swipeRefreshLayout.setVisibility(View.VISIBLE);
131+
loginBtn.setVisibility(View.GONE);
132+
} else {
133+
swipeRefreshLayout.setVisibility(View.GONE);
134+
loginBtn.setVisibility(View.VISIBLE);
130135
}
131136
}
132137

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
android:layout_width="wrap_content"
2121
android:layout_height="wrap_content"
2222
android:layout_centerInParent="true"
23-
android:text="No FAQs to display." />
23+
android:text="@string/no_faqs"/>
24+
25+
<Button
26+
android:id="@+id/btn_login"
27+
android:layout_width="match_parent"
28+
android:layout_height="wrap_content"
29+
android:minHeight="?android:actionBarSize"
30+
android:layout_alignParentBottom="true"
31+
android:background="@color/color_accent"
32+
android:text="@string/login"
33+
android:textColor="@color/white"/>
2434

2535
</RelativeLayout>

android/app/src/main/res/values/strings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@
209209
<string name="noTracks">No Tracks yet!</string>
210210
<string name="noFeed">No Posts yet!</string>
211211
<string name="no_notification">No notifications yet!</string>
212+
<string name="no_faqs">No faqs yet!</string>
212213
<string name="charges_warning">Data charges may apply</string>
213214
<string name="tracks">Track</string>
214215
<string name="type">Type</string>
@@ -334,8 +335,7 @@
334335

335336
<string name="twitter_feed">Twitter Feed</string>
336337
<string name="featured_speakers_header">Featured Speakers</string>
337-
<string name="login_to_see_faqs">Please login to see faqs!</string>
338-
<string name="login_to_view_faqs">Sorry you need to log in to view the FAQs.</string>
338+
<string name="login_to_continue">Please login to continue</string>
339339

340340

341341
</resources>

0 commit comments

Comments
 (0)