4
4
import android .content .Intent ;
5
5
import android .net .Uri ;
6
6
import android .os .Bundle ;
7
+ import android .view .LayoutInflater ;
7
8
import android .view .Menu ;
8
9
import android .view .MenuItem ;
9
10
import android .view .View ;
10
11
import android .view .ViewGroup ;
11
12
import android .widget .FrameLayout ;
12
13
13
- import androidx .annotation .NonNull ;
14
14
import androidx .annotation .Nullable ;
15
+ import androidx .appcompat .widget .LinearLayoutCompat ;
16
+
17
+ import androidx .annotation .NonNull ;
18
+ import androidx .annotation .StringRes ;
15
19
import androidx .appcompat .app .AlertDialog ;
16
20
import androidx .lifecycle .ViewModelProvider ;
17
21
import androidx .preference .Preference ;
23
27
import com .d4rk .androidtutorials .java .ads .AdUtils ;
24
28
import com .d4rk .androidtutorials .java .databinding .ActivityHelpBinding ;
25
29
import com .d4rk .androidtutorials .java .databinding .DialogVersionInfoBinding ;
30
+ import com .d4rk .androidtutorials .java .databinding .ItemHelpFaqBinding ;
26
31
import com .d4rk .androidtutorials .java .ui .components .navigation .BaseActivity ;
27
32
import com .d4rk .androidtutorials .java .ui .screens .help .repository .HelpRepository ;
28
- import com .d4rk .androidtutorials .java .utils .EdgeToEdgeDelegate ;
29
33
import com .d4rk .androidtutorials .java .utils .OpenSourceLicensesUtils ;
30
34
import com .google .android .material .snackbar .Snackbar ;
31
35
import com .google .android .play .core .review .ReviewInfo ;
32
36
33
37
import dagger .hilt .android .AndroidEntryPoint ;
34
38
import me .zhanghai .android .fastscroll .FastScrollerBuilder ;
35
39
40
+ import java .util .Arrays ;
41
+ import java .util .List ;
42
+
36
43
@ AndroidEntryPoint
37
44
public class HelpActivity extends BaseActivity {
38
45
39
46
private HelpViewModel helpViewModel ;
47
+ private static final List <FaqItem > FAQ_ITEMS = Arrays .asList (
48
+ new FaqItem (R .string .question_1 , R .string .summary_preference_faq_1 ),
49
+ new FaqItem (R .string .question_2 , R .string .summary_preference_faq_2 ),
50
+ new FaqItem (R .string .question_3 , R .string .summary_preference_faq_3 ),
51
+ new FaqItem (R .string .question_4 , R .string .summary_preference_faq_4 ),
52
+ new FaqItem (R .string .question_5 , R .string .summary_preference_faq_5 ),
53
+ new FaqItem (R .string .question_6 , R .string .summary_preference_faq_6 ),
54
+ new FaqItem (R .string .question_7 , R .string .summary_preference_faq_7 ),
55
+ new FaqItem (R .string .question_8 , R .string .summary_preference_faq_8 ),
56
+ new FaqItem (R .string .question_9 , R .string .summary_preference_faq_9 )
57
+ );
40
58
41
59
@ Override
42
60
protected void onCreate (Bundle savedInstanceState ) {
43
61
super .onCreate (savedInstanceState );
44
62
ActivityHelpBinding binding = ActivityHelpBinding .inflate (getLayoutInflater ());
45
63
setContentView (binding .getRoot ());
46
- setSupportActionBar (binding .topAppBar );
47
- binding .topAppBar .setNavigationOnClickListener (v -> getOnBackPressedDispatcher ().onBackPressed ());
48
- EdgeToEdgeDelegate .apply (this , binding .helpContainer );
49
64
AdUtils .loadBanner (binding .faqNativeAd );
50
65
helpViewModel = new ViewModelProvider (this ).get (HelpViewModel .class );
51
- new FastScrollerBuilder (binding .scrollContainer )
66
+ new FastScrollerBuilder (binding .scrollView )
52
67
.useMd2Style ()
53
68
.build ();
54
- getSupportFragmentManager ().beginTransaction ()
55
- .replace (R .id .frame_layout_faq , new FaqFragment ())
56
- .commit ();
69
+ bindFaqItems (binding );
57
70
58
71
getSupportFragmentManager ().beginTransaction ()
59
72
.replace (R .id .frame_layout_feedback , new FeedbackFragment ())
@@ -128,36 +141,6 @@ private void openLink(String url) {
128
141
startActivity (browserIntent );
129
142
}
130
143
131
- public static class FaqFragment extends PreferenceFragmentCompat {
132
- @ Override
133
- public void onCreatePreferences (Bundle savedInstanceState , String rootKey ) {
134
- setPreferencesFromResource (R .xml .preferences_faq , rootKey );
135
- }
136
-
137
- @ Override
138
- public void onViewCreated (@ NonNull View view , @ Nullable Bundle savedInstanceState ) {
139
- super .onViewCreated (view , savedInstanceState );
140
- RecyclerView listView = getListView ();
141
- listView .setNestedScrollingEnabled (false );
142
- listView .setOverScrollMode (View .OVER_SCROLL_NEVER );
143
- listView .setClipToPadding (false );
144
-
145
- ViewGroup .LayoutParams layoutParams = listView .getLayoutParams ();
146
- FrameLayout .LayoutParams frameLayoutParams ;
147
- if (layoutParams instanceof FrameLayout .LayoutParams ) {
148
- frameLayoutParams = (FrameLayout .LayoutParams ) layoutParams ;
149
- } else {
150
- frameLayoutParams = new FrameLayout .LayoutParams (
151
- ViewGroup .LayoutParams .MATCH_PARENT ,
152
- ViewGroup .LayoutParams .WRAP_CONTENT
153
- );
154
- }
155
- frameLayoutParams .height = ViewGroup .LayoutParams .WRAP_CONTENT ;
156
- frameLayoutParams .width = ViewGroup .LayoutParams .MATCH_PARENT ;
157
- listView .setLayoutParams (frameLayoutParams );
158
- }
159
- }
160
-
161
144
public static class FeedbackFragment extends PreferenceFragmentCompat {
162
145
163
146
@ Override
@@ -187,6 +170,29 @@ public void onFailure(Exception e) {
187
170
}
188
171
}
189
172
173
+ @ Override
174
+ public void onViewCreated (@ NonNull View view , @ Nullable Bundle savedInstanceState ) {
175
+ super .onViewCreated (view , savedInstanceState );
176
+ RecyclerView listView = getListView ();
177
+ listView .setNestedScrollingEnabled (false );
178
+ listView .setOverScrollMode (View .OVER_SCROLL_NEVER );
179
+ listView .setClipToPadding (false );
180
+
181
+ ViewGroup .LayoutParams layoutParams = listView .getLayoutParams ();
182
+ FrameLayout .LayoutParams frameLayoutParams ;
183
+ if (layoutParams instanceof FrameLayout .LayoutParams ) {
184
+ frameLayoutParams = (FrameLayout .LayoutParams ) layoutParams ;
185
+ } else {
186
+ frameLayoutParams = new FrameLayout .LayoutParams (
187
+ ViewGroup .LayoutParams .MATCH_PARENT ,
188
+ ViewGroup .LayoutParams .WRAP_CONTENT
189
+ );
190
+ }
191
+ frameLayoutParams .height = ViewGroup .LayoutParams .WRAP_CONTENT ;
192
+ frameLayoutParams .width = ViewGroup .LayoutParams .MATCH_PARENT ;
193
+ listView .setLayoutParams (frameLayoutParams );
194
+ }
195
+
190
196
private void launchGooglePlayReviews () {
191
197
Uri uri = Uri .parse ("https://play.google.com/store/apps/details?id=" + requireActivity ().getPackageName () + "&showAllReviews=true" );
192
198
Intent intent = new Intent (Intent .ACTION_VIEW , uri );
@@ -201,4 +207,31 @@ private void launchGooglePlayReviews() {
201
207
}
202
208
}
203
209
}
210
+
211
+ private void bindFaqItems (ActivityHelpBinding binding ) {
212
+ LinearLayoutCompat faqList = binding .faqList ;
213
+ faqList .removeAllViews ();
214
+ LayoutInflater inflater = LayoutInflater .from (this );
215
+
216
+ for (int i = 0 ; i < FAQ_ITEMS .size (); i ++) {
217
+ FaqItem item = FAQ_ITEMS .get (i );
218
+ ItemHelpFaqBinding itemBinding = ItemHelpFaqBinding .inflate (inflater , faqList , false );
219
+ itemBinding .question .setText (item .questionResId );
220
+ itemBinding .answer .setText (item .answerResId );
221
+ itemBinding .divider .setVisibility (i == FAQ_ITEMS .size () - 1 ? View .GONE : View .VISIBLE );
222
+ faqList .addView (itemBinding .getRoot ());
223
+ }
224
+ }
225
+
226
+ private static final class FaqItem {
227
+ @ StringRes
228
+ private final int questionResId ;
229
+ @ StringRes
230
+ private final int answerResId ;
231
+
232
+ private FaqItem (@ StringRes int questionResId , @ StringRes int answerResId ) {
233
+ this .questionResId = questionResId ;
234
+ this .answerResId = answerResId ;
235
+ }
236
+ }
204
237
}
0 commit comments