4
4
import android .content .Intent ;
5
5
import android .net .Uri ;
6
6
import android .os .Bundle ;
7
+ import android .os .Handler ;
8
+ import android .os .Looper ;
7
9
import android .view .LayoutInflater ;
8
10
import android .view .Menu ;
9
11
import android .view .MenuItem ;
10
12
import android .view .View ;
11
- import android .view .ViewGroup ;
12
- import android .widget .FrameLayout ;
13
-
14
- import androidx .annotation .Nullable ;
15
13
import androidx .annotation .NonNull ;
16
14
import androidx .annotation .StringRes ;
17
15
import androidx .appcompat .app .AlertDialog ;
18
16
import androidx .appcompat .widget .LinearLayoutCompat ;
19
17
import androidx .core .view .ViewCompat ;
20
18
import androidx .lifecycle .ViewModelProvider ;
21
- import androidx .preference .Preference ;
22
- import androidx .preference .PreferenceFragmentCompat ;
23
- import androidx .recyclerview .widget .RecyclerView ;
24
19
25
20
import com .d4rk .androidtutorials .java .BuildConfig ;
26
21
import com .d4rk .androidtutorials .java .R ;
43
38
@ AndroidEntryPoint
44
39
public class HelpActivity extends BaseActivity {
45
40
41
+ private ActivityHelpBinding binding ;
46
42
private HelpViewModel helpViewModel ;
43
+ private final Handler handler = new Handler (Looper .getMainLooper ());
47
44
private static final List <FaqItem > FAQ_ITEMS = Arrays .asList (
48
45
new FaqItem (R .string .question_1 , R .string .summary_preference_faq_1 ),
49
46
new FaqItem (R .string .question_2 , R .string .summary_preference_faq_2 ),
@@ -59,22 +56,17 @@ public class HelpActivity extends BaseActivity {
59
56
@ Override
60
57
protected void onCreate (Bundle savedInstanceState ) {
61
58
super .onCreate (savedInstanceState );
62
- ActivityHelpBinding binding = ActivityHelpBinding .inflate (getLayoutInflater ());
59
+ binding = ActivityHelpBinding .inflate (getLayoutInflater ());
63
60
setContentView (binding .getRoot ());
64
61
AdUtils .loadBanner (binding .faqNativeAd );
65
62
helpViewModel = new ViewModelProvider (this ).get (HelpViewModel .class );
66
63
new FastScrollerBuilder (binding .scrollView )
67
64
.useMd2Style ()
68
65
.build ();
69
66
bindFaqItems (binding );
70
-
71
- getSupportFragmentManager ().beginTransaction ()
72
- .replace (R .id .frame_layout_feedback , new FeedbackFragment ())
73
- .commit ();
74
- }
75
-
76
- public HelpViewModel getHelpViewModel () {
77
- return helpViewModel ;
67
+ setupContactSupportCard ();
68
+ setupFeedbackFab ();
69
+ handler .postDelayed (() -> binding .fabContactSupport .shrink (), 5000L );
78
70
}
79
71
80
72
@ Override
@@ -141,73 +133,66 @@ private void openLink(String url) {
141
133
startActivity (browserIntent );
142
134
}
143
135
144
- public static class FeedbackFragment extends PreferenceFragmentCompat {
145
-
146
- @ Override
147
- public void onCreatePreferences (Bundle savedInstanceState , String rootKey ) {
148
- setPreferencesFromResource (R .xml .preferences_feedback , rootKey );
149
-
150
- Preference feedbackPreference = findPreference (getString (R .string .key_feedback ));
151
- if (feedbackPreference != null ) {
152
- feedbackPreference .setOnPreferenceClickListener (preference -> {
153
- if (requireActivity () instanceof HelpActivity helpActivity ) {
154
- HelpViewModel vm = helpActivity .getHelpViewModel ();
136
+ private void setupContactSupportCard () {
137
+ binding .contactSupportCard .setOnClickListener (v -> openSupportEmail ());
138
+ }
155
139
156
- vm .requestReviewFlow (new HelpRepository .OnReviewInfoListener () {
157
- @ Override
158
- public void onSuccess (ReviewInfo info ) {
159
- vm .launchReviewFlow (helpActivity , info );
160
- }
140
+ private void setupFeedbackFab () {
141
+ binding .fabContactSupport .setOnClickListener (v -> requestReview ());
142
+ binding .fabContactSupport .setContentDescription (getString (R .string .send_feedback ));
143
+ }
161
144
162
- @ Override
163
- public void onFailure (Exception e ) {
164
- launchGooglePlayReviews ();
165
- }
166
- });
167
- }
168
- return true ;
169
- });
170
- }
145
+ private void openSupportEmail () {
146
+ String supportEmail = getString (R .string .contact_support_email );
147
+ Intent intent = new Intent (Intent .ACTION_SENDTO );
148
+ intent .setData (Uri .fromParts ("mailto" , supportEmail , null ));
149
+ intent .putExtra (Intent .EXTRA_EMAIL , new String []{supportEmail });
150
+ intent .putExtra (Intent .EXTRA_SUBJECT ,
151
+ getString (R .string .contact_support_email_subject , getString (R .string .app_name )));
152
+ intent .putExtra (Intent .EXTRA_TEXT , getString (R .string .contact_support_email_body ));
153
+
154
+ if (intent .resolveActivity (getPackageManager ()) != null ) {
155
+ startActivity (Intent .createChooser (intent , getString (R .string .contact_support_title )));
156
+ } else {
157
+ Snackbar .make (binding .getRoot (), R .string .support_link_unavailable , Snackbar .LENGTH_SHORT ).show ();
171
158
}
159
+ }
172
160
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
- );
161
+ private void requestReview () {
162
+ binding .fabContactSupport .setEnabled (false );
163
+ helpViewModel .requestReviewFlow (new HelpRepository .OnReviewInfoListener () {
164
+ @ Override
165
+ public void onSuccess (ReviewInfo info ) {
166
+ helpViewModel .launchReviewFlow (HelpActivity .this , info );
167
+ binding .fabContactSupport .setEnabled (true );
190
168
}
191
- frameLayoutParams .height = ViewGroup .LayoutParams .WRAP_CONTENT ;
192
- frameLayoutParams .width = ViewGroup .LayoutParams .MATCH_PARENT ;
193
- listView .setLayoutParams (frameLayoutParams );
194
- }
195
169
196
- private void launchGooglePlayReviews () {
197
- Uri uri = Uri .parse ("https://play.google.com/store/apps/details?id=" + requireActivity ().getPackageName () + "&showAllReviews=true" );
198
- Intent intent = new Intent (Intent .ACTION_VIEW , uri );
199
- intent .addFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
200
- try {
201
- startActivity (intent );
202
- } catch (ActivityNotFoundException e ) {
203
- Snackbar .make (requireView (),
204
- R .string .snack_unable_to_open_google_play_store ,
205
- Snackbar .LENGTH_SHORT )
206
- .show ();
170
+ @ Override
171
+ public void onFailure (Exception e ) {
172
+ binding .fabContactSupport .setEnabled (true );
173
+ launchGooglePlayReviews ();
207
174
}
175
+ });
176
+ }
177
+
178
+ private void launchGooglePlayReviews () {
179
+ Uri uri = Uri .parse ("https://play.google.com/store/apps/details?id=" + getPackageName () + "&showAllReviews=true" );
180
+ Intent intent = new Intent (Intent .ACTION_VIEW , uri );
181
+ intent .addFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
182
+ try {
183
+ startActivity (intent );
184
+ } catch (ActivityNotFoundException e ) {
185
+ Snackbar .make (binding .getRoot (),
186
+ R .string .snack_unable_to_open_google_play_store ,
187
+ Snackbar .LENGTH_SHORT )
188
+ .show ();
208
189
}
209
190
}
210
191
192
+ public HelpViewModel getHelpViewModel () {
193
+ return helpViewModel ;
194
+ }
195
+
211
196
private void bindFaqItems (ActivityHelpBinding binding ) {
212
197
LinearLayoutCompat faqList = binding .faqList ;
213
198
faqList .removeAllViews ();
@@ -261,4 +246,10 @@ private FaqItem(@StringRes int questionResId, @StringRes int answerResId) {
261
246
this .answerResId = answerResId ;
262
247
}
263
248
}
264
- }
249
+
250
+ @ Override
251
+ protected void onDestroy () {
252
+ handler .removeCallbacksAndMessages (null );
253
+ super .onDestroy ();
254
+ }
255
+ }
0 commit comments