Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit 39cfa8c

Browse files
Allow user to permanently dismiss notifications request
Also handles pre-13 devices that have blocked notifications Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent 37b19f0 commit 39cfa8c

File tree

6 files changed

+145
-110
lines changed

6 files changed

+145
-110
lines changed

app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ android {
2929
applicationIdSuffix '.debug'
3030
debuggable true
3131
// ONLY FOR TESTING SENTRY
32-
minifyEnabled true
33-
shrinkResources true
34-
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
32+
// minifyEnabled true
33+
// shrinkResources true
34+
// proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'
3535
}
3636
}
3737

app/src/main/java/com/fox2code/mmm/MainActivity.java

Lines changed: 100 additions & 106 deletions
Large diffs are not rendered by default.

app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
import android.content.Context;
1010
import android.content.Intent;
1111
import android.content.SharedPreferences;
12+
import android.net.Uri;
1213
import android.os.Build;
1314
import android.os.Bundle;
1415
import android.os.Handler;
1516
import android.os.Looper;
17+
import android.provider.Settings;
1618
import android.util.Log;
1719
import android.view.inputmethod.EditorInfo;
1820
import android.widget.AutoCompleteTextView;
@@ -271,8 +273,29 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
271273
backgroundUpdateCheck.setVisible(!MainApplication.isWrapped());
272274
// Make uncheckable if POST_NOTIFICATIONS permission is not granted
273275
if (!MainApplication.isNotificationPermissionGranted()) {
276+
// Instead of disabling the preference, we make it uncheckable and when the user
277+
// clicks on it, we show a dialog explaining why the permission is needed
278+
backgroundUpdateCheck.setOnPreferenceClickListener(preference -> {
279+
// set the box to unchecked
280+
((SwitchPreferenceCompat) backgroundUpdateCheck).setChecked(false);
281+
// ensure that the preference is false
282+
MainApplication.getSharedPreferences().edit().putBoolean("pref_background_update_check", false).apply();
283+
new MaterialAlertDialogBuilder(this.requireContext())
284+
.setTitle(R.string.permission_notification_title)
285+
.setMessage(R.string.permission_notification_message)
286+
.setPositiveButton(R.string.ok, (dialog, which) -> {
287+
// Open the app settings
288+
Intent intent = new Intent();
289+
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
290+
Uri uri = Uri.fromParts("package", this.requireContext().getPackageName(), null);
291+
intent.setData(uri);
292+
this.startActivity(intent);
293+
})
294+
.setNegativeButton(R.string.cancel, (dialog, which) -> {})
295+
.show();
296+
return true;
297+
});
274298
backgroundUpdateCheck.setSummary(R.string.background_update_check_permission_required);
275-
backgroundUpdateCheck.setEnabled(false);
276299
}
277300
backgroundUpdateCheck.setOnPreferenceChangeListener((preference, newValue) -> {
278301
boolean enabled = Boolean.parseBoolean(String.valueOf(newValue));
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_marginStart="8dp"
5+
android:layout_marginEnd="8dp"
6+
android:layout_height="wrap_content" >
7+
8+
<CheckBox
9+
android:id="@+id/checkbox"
10+
style="?android:attr/smallIcon"
11+
android:layout_width="match_parent"
12+
android:layout_height="wrap_content"
13+
android:layout_marginStart="16dp"
14+
android:layout_marginEnd="16dp"/>
15+
16+
</FrameLayout>

app/src/main/res/values/arrays.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
<item>Dark</item>
1212
<item>Light</item>
1313
</string-array>
14+
<string-array name="permission_notification_dont_ask_again">Don't prompt again</string-array>
1415
</resources>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,5 @@
187187
<string name="permission_notification_message">We need the notifications permission to notify you on app and module updates. If you don\'t grant this permission, background update checks will not run.</string>
188188
<string name="permission_notification_grant">Grant permission</string>
189189
<string name="background_update_check_permission_required">Please enable notifications to enable this option.</string>
190+
<string name="dont_ask_again">Don\'t ask again</string>
190191
</resources>

0 commit comments

Comments
 (0)