Skip to content

Commit 7849925

Browse files
Simplify help screen and remove feedback fragment
1 parent b0fed7f commit 7849925

File tree

5 files changed

+82
-97
lines changed

5 files changed

+82
-97
lines changed

app/src/main/java/com/d4rk/androidtutorials/java/ui/screens/help/HelpActivity.java

Lines changed: 48 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,18 @@
44
import android.content.Intent;
55
import android.net.Uri;
66
import android.os.Bundle;
7+
import android.os.Handler;
8+
import android.os.Looper;
79
import android.view.LayoutInflater;
810
import android.view.Menu;
911
import android.view.MenuItem;
1012
import android.view.View;
11-
import android.view.ViewGroup;
12-
import android.widget.FrameLayout;
1313
import androidx.annotation.NonNull;
14-
import androidx.annotation.Nullable;
1514
import androidx.annotation.StringRes;
1615
import androidx.appcompat.app.AlertDialog;
1716
import androidx.appcompat.widget.LinearLayoutCompat;
1817
import androidx.core.view.ViewCompat;
1918
import androidx.lifecycle.ViewModelProvider;
20-
import androidx.preference.Preference;
21-
import androidx.preference.PreferenceFragmentCompat;
22-
import androidx.recyclerview.widget.RecyclerView;
2319

2420
import com.d4rk.androidtutorials.java.BuildConfig;
2521
import com.d4rk.androidtutorials.java.R;
@@ -44,6 +40,7 @@ public class HelpActivity extends BaseActivity {
4440

4541
private ActivityHelpBinding binding;
4642
private HelpViewModel helpViewModel;
43+
private final Handler handler = new Handler(Looper.getMainLooper());
4744
private static final List<FaqItem> FAQ_ITEMS = Arrays.asList(
4845
new FaqItem(R.string.question_1, R.string.summary_preference_faq_1),
4946
new FaqItem(R.string.question_2, R.string.summary_preference_faq_2),
@@ -68,12 +65,8 @@ protected void onCreate(Bundle savedInstanceState) {
6865
.build();
6966
bindFaqItems(binding);
7067
setupContactSupportCard();
71-
72-
if (savedInstanceState == null) {
73-
getSupportFragmentManager().beginTransaction()
74-
.replace(R.id.frame_layout_feedback, new FeedbackFragment())
75-
.commit();
76-
}
68+
setupFeedbackFab();
69+
handler.postDelayed(() -> binding.fabContactSupport.shrink(), 5000L);
7770
}
7871

7972
@Override
@@ -144,6 +137,11 @@ private void setupContactSupportCard() {
144137
binding.contactSupportCard.setOnClickListener(v -> openSupportEmail());
145138
}
146139

140+
private void setupFeedbackFab() {
141+
binding.fabContactSupport.setOnClickListener(v -> requestReview());
142+
binding.fabContactSupport.setContentDescription(getString(R.string.send_feedback));
143+
}
144+
147145
private void openSupportEmail() {
148146
String supportEmail = getString(R.string.contact_support_email);
149147
Intent intent = new Intent(Intent.ACTION_SENDTO);
@@ -160,6 +158,37 @@ private void openSupportEmail() {
160158
}
161159
}
162160

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);
168+
}
169+
170+
@Override
171+
public void onFailure(Exception e) {
172+
binding.fabContactSupport.setEnabled(true);
173+
launchGooglePlayReviews();
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();
189+
}
190+
}
191+
163192
public HelpViewModel getHelpViewModel() {
164193
return helpViewModel;
165194
}
@@ -206,73 +235,6 @@ private void toggleFaqItem(ItemHelpFaqBinding binding) {
206235
ViewCompat.setStateDescription(binding.questionContainer, stateDescription);
207236
}
208237

209-
public static class FeedbackFragment extends PreferenceFragmentCompat {
210-
211-
@Override
212-
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
213-
setPreferencesFromResource(R.xml.preferences_feedback, rootKey);
214-
215-
Preference feedbackPreference = findPreference(getString(R.string.key_feedback));
216-
if (feedbackPreference != null) {
217-
feedbackPreference.setOnPreferenceClickListener(preference -> {
218-
if (requireActivity() instanceof HelpActivity helpActivity) {
219-
HelpViewModel vm = helpActivity.getHelpViewModel();
220-
221-
vm.requestReviewFlow(new HelpRepository.OnReviewInfoListener() {
222-
@Override
223-
public void onSuccess(ReviewInfo info) {
224-
vm.launchReviewFlow(helpActivity, info);
225-
}
226-
227-
@Override
228-
public void onFailure(Exception e) {
229-
launchGooglePlayReviews();
230-
}
231-
});
232-
}
233-
return true;
234-
});
235-
}
236-
}
237-
238-
@Override
239-
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
240-
super.onViewCreated(view, savedInstanceState);
241-
RecyclerView listView = getListView();
242-
listView.setNestedScrollingEnabled(false);
243-
listView.setOverScrollMode(View.OVER_SCROLL_NEVER);
244-
listView.setClipToPadding(false);
245-
246-
ViewGroup.LayoutParams layoutParams = listView.getLayoutParams();
247-
FrameLayout.LayoutParams frameLayoutParams;
248-
if (layoutParams instanceof FrameLayout.LayoutParams) {
249-
frameLayoutParams = (FrameLayout.LayoutParams) layoutParams;
250-
} else {
251-
frameLayoutParams = new FrameLayout.LayoutParams(
252-
ViewGroup.LayoutParams.MATCH_PARENT,
253-
ViewGroup.LayoutParams.WRAP_CONTENT
254-
);
255-
}
256-
frameLayoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
257-
frameLayoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
258-
listView.setLayoutParams(frameLayoutParams);
259-
}
260-
261-
private void launchGooglePlayReviews() {
262-
Uri uri = Uri.parse("https://play.google.com/store/apps/details?id=" + requireActivity().getPackageName() + "&showAllReviews=true");
263-
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
264-
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
265-
try {
266-
startActivity(intent);
267-
} catch (ActivityNotFoundException e) {
268-
Snackbar.make(requireView(),
269-
R.string.snack_unable_to_open_google_play_store,
270-
Snackbar.LENGTH_SHORT)
271-
.show();
272-
}
273-
}
274-
}
275-
276238
private static final class FaqItem {
277239
@StringRes
278240
private final int questionResId;
@@ -284,4 +246,10 @@ private FaqItem(@StringRes int questionResId, @StringRes int answerResId) {
284246
this.answerResId = answerResId;
285247
}
286248
}
287-
}
249+
250+
@Override
251+
protected void onDestroy() {
252+
handler.removeCallbacksAndMessages(null);
253+
super.onDestroy();
254+
}
255+
}
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:shape="oval">
4-
<solid android:color="?attr/colorSecondaryContainer" />
5-
</shape>
2+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:width="289dp"
4+
android:height="289dp"
5+
android:viewportWidth="289"
6+
android:viewportHeight="289">
7+
8+
<path
9+
android:fillColor="?attr/colorSecondaryContainer"
10+
android:pathData="M3.2,160.9c-3.9-6.6-4.2-14.7-0.8-21.6l4.8-9.7c2-4.1,2.8-8.8,2.1-13.3l-1.6-10.7C6.6,98,9.4,90.4,15.2,85.3 l8.1-7.1c3.4-3,5.9-7,7-11.5L33,56.2c1.9-7.5,7.4-13.4,14.7-15.9l10.2-3.5c4.4-1.5,8.2-4.2,10.9-7.9l6.4-8.7 c4.6-6.2,12-9.6,19.7-9.1l10.8,0.7c4.6,0.3,9.2-0.8,13.1-3.1l9.3-5.5c6.6-3.9,14.7-4.3,21.6-0.8l9.7,4.8c4.1,2,8.8,2.8,13.3,2.1 l10.7-1.6c7.6-1.1,15.2,1.7,20.3,7.5l7.1,8.1c3,3.4,7,5.9,11.5,7l10.5,2.7c7.5,1.9,13.4,7.4,15.9,14.7l3.5,10.2 c1.5,4.4,4.2,8.2,7.9,10.9l8.7,6.4c6.2,4.6,9.6,12,9.1,19.7l-0.7,10.8c-0.3,4.6,0.8,9.2,3.1,13.1l5.5,9.3c3.9,6.6,4.2,14.7,0.8,21.6 l-4.8,9.7c-2,4.1-2.8,8.8-2.1,13.3l1.6,10.7c1.1,7.6-1.7,15.2-7.5,20.3l-8.1,7.1c-3.4,3-5.9,7-7,11.5l-2.7,10.5 c-1.9,7.5-7.4,13.4-14.7,15.9l-10.2,3.5c-4.4,1.5-8.2,4.2-10.9,7.9l-6.4,8.7c-4.6,6.2-12,9.6-19.7,9.1l-10.8-0.7 c-4.6-0.3-9.2,0.8-13.1,3.1l-9.3,5.5c-6.6,3.9-14.7,4.3-21.6,0.8l-9.7-4.8c-4.1-2-8.8-2.8-13.3-2.1l-10.7,1.6 c-7.6,1.1-15.2-1.7-20.3-7.5l-7.1-8.1c-3-3.4-7-5.9-11.5-7L56.2,256c-7.5-1.9-13.4-7.4-15.9-14.7l-3.5-10.2 c-1.5-4.4-4.2-8.2-7.9-10.9l-8.7-6.4c-6.2-4.6-9.6-12-9.1-19.7l0.7-10.8c0.3-4.6-0.8-9.2-3.1-13.1L3.2,160.9L3.2,160.9z" />
11+
</vector>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:width="24dp"
4+
android:height="24dp"
5+
android:viewportWidth="24"
6+
android:viewportHeight="24">
7+
8+
<path
9+
android:fillColor="#000000"
10+
android:pathData="M12,2C6.48,2,2,6.48,2,12c0,5.52,4.48,10,10,10s10-4.48,10-10C22,6.48,17.52,2,12,2z M19.46,9.12l-2.78,1.15 c-0.51-1.36-1.58-2.44-2.95-2.94l1.15-2.78C16.98,5.35,18.65,7.02,19.46,9.12z M12,15c-1.66,0-3-1.34-3-3s1.34-3,3-3s3,1.34,3,3 S13.66,15,12,15z M9.13,4.54l1.17,2.78c-1.38,0.5-2.47,1.59-2.98,2.97L4.54,9.13C5.35,7.02,7.02,5.35,9.13,4.54z M4.54,14.87 l2.78-1.15c0.51,1.38,1.59,2.46,2.97,2.96l-1.17,2.78C7.02,18.65,5.35,16.98,4.54,14.87z M14.88,19.46l-1.15-2.78 c1.37-0.51,2.45-1.59,2.95-2.97l2.78,1.17C18.65,16.98,16.98,18.65,14.88,19.46z" />
11+
</vector>

app/src/main/res/layout/activity_help.xml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@
8686
android:layout_width="match_parent"
8787
android:layout_height="match_parent"
8888
android:contentDescription="@null"
89-
android:src="@drawable/ic_feedback" />
89+
android:src="@drawable/ic_contact_support"
90+
android:tint="?attr/colorOnSecondaryContainer" />
9091

9192
</FrameLayout>
9293

@@ -114,24 +115,22 @@
114115

115116
</androidx.appcompat.widget.LinearLayoutCompat>
116117

117-
<androidx.appcompat.widget.AppCompatImageView
118-
android:layout_width="wrap_content"
119-
android:layout_height="wrap_content"
120-
android:contentDescription="@null"
121-
android:src="@drawable/ic_arrow_forward"
122-
android:tint="?attr/colorOnSurfaceVariant" />
123-
124118
</androidx.appcompat.widget.LinearLayoutCompat>
125119

126120
</com.google.android.material.card.MaterialCardView>
127121

128-
<FrameLayout
129-
android:id="@+id/frame_layout_feedback"
130-
android:layout_width="match_parent"
131-
android:layout_height="wrap_content" />
132-
133122
</androidx.appcompat.widget.LinearLayoutCompat>
134123

135124
</me.zhanghai.android.fastscroll.FastScrollScrollView>
136125

126+
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
127+
android:id="@+id/fab_contact_support"
128+
android:layout_width="wrap_content"
129+
android:layout_height="wrap_content"
130+
android:layout_margin="16dp"
131+
android:text="@string/send_feedback"
132+
app:icon="@drawable/ic_rate_review"
133+
app:layout_constraintBottom_toBottomOf="parent"
134+
app:layout_constraintEnd_toEndOf="parent" />
135+
137136
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/layout/ad_help.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
android:layout_height="wrap_content">
66

77
<com.google.android.material.card.MaterialCardView
8+
android:id="@+id/ad_card"
89
style="@style/Widget.Material3.CardView.Filled"
910
android:layout_width="match_parent"
1011
android:layout_height="wrap_content"

0 commit comments

Comments
 (0)