13
13
import android .view .View ;
14
14
import android .view .ViewGroup ;
15
15
import android .widget .TextView ;
16
- import android .widget .Toast ;
17
16
18
17
import org .fossasia .openevent .R ;
19
18
import org .fossasia .openevent .common .network .NetworkUtils ;
@@ -37,6 +36,8 @@ public class FAQFragment extends BaseFragment {
37
36
protected TextView tvEmptyFaqs ;
38
37
@ BindView (R .id .faq_swiperefreshlayout )
39
38
protected SwipeRefreshLayout swipeRefreshLayout ;
39
+ @ BindView (R .id .btn_login )
40
+ protected TextView loginBtn ;
40
41
41
42
private ArrayList <FAQ > faqArrayList ;
42
43
private FAQListAdapter faqListAdapter ;
@@ -47,26 +48,28 @@ public class FAQFragment extends BaseFragment {
47
48
public View onCreateView (@ NonNull LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState ) {
48
49
// setHasOptionsMenu(true); TODO : ADD SEARCH OPTION
49
50
View view = super .onCreateView (inflater , container , savedInstanceState );
50
- Utils .registerIfUrlValid (swipeRefreshLayout , this , this ::refresh );
51
- faqArrayList = new ArrayList <>();
52
51
faqViewModel = ViewModelProviders .of (this ).get (FAQViewModel .class );
53
- setUpRecyclerView ();
54
52
55
53
if (AuthUtil .isUserLoggedIn ()) {
56
54
if (NetworkUtils .haveNetworkConnection (getContext ())) {
57
55
downloadFAQS ();
58
56
}
57
+ showFaqLayout (true );
58
+ Utils .registerIfUrlValid (swipeRefreshLayout , this , this ::refresh );
59
+ faqArrayList = new ArrayList <>();
60
+ setUpRecyclerView ();
59
61
loadFAQs ();
60
62
handleVisibility ();
61
63
} else {
62
- redirectToLogin ();
64
+ showFaqLayout (false );
65
+ tvEmptyFaqs .setText (R .string .login_to_continue );
66
+ loginBtn .setOnClickListener (v -> redirectToLogin ());
63
67
}
64
68
65
69
return view ;
66
70
}
67
71
68
72
private void redirectToLogin () {
69
- Toast .makeText (getContext (), R .string .login_to_see_faqs , Toast .LENGTH_SHORT ).show ();
70
73
Intent intent = new Intent (getActivity (), LoginActivity .class );
71
74
startActivity (intent );
72
75
}
@@ -122,11 +125,13 @@ private void handleVisibility() {
122
125
}
123
126
}
124
127
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 );
130
135
}
131
136
}
132
137
0 commit comments