Reset notification preference when resume
This commit is contained in:
parent
cb32c70951
commit
cf05ea4160
|
|
@ -134,6 +134,25 @@ public class SettingsFragment extends BaseFragment {
|
||||||
parentFragment = null;
|
parentFragment = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
MaterialSwitchPreference notificationPreference = findPreference("enable_status_notification");
|
||||||
|
if (notificationPreference != null && notificationPreference.isVisible()) {
|
||||||
|
setNotificationPreferenceEnabled(notificationPreference, ShortcutUtil.isLaunchShortcutPinned());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setNotificationPreferenceEnabled(MaterialSwitchPreference notificationPreference, boolean enabled) {
|
||||||
|
if (notificationPreference != null) {
|
||||||
|
notificationPreference.setEnabled(!ConfigManager.enableStatusNotification() || enabled);
|
||||||
|
notificationPreference.setSummaryOn(enabled ?
|
||||||
|
notificationPreference.getContext().getString(R.string.settings_enable_status_notification_summary) :
|
||||||
|
notificationPreference.getContext().getString(R.string.settings_enable_status_notification_summary) + "\n" +
|
||||||
|
notificationPreference.getContext().getString(R.string.disable_status_notification_error));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||||
final String SYSTEM = "SYSTEM";
|
final String SYSTEM = "SYSTEM";
|
||||||
|
|
@ -158,18 +177,16 @@ public class SettingsFragment extends BaseFragment {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialSwitchPreference notification = findPreference("enable_status_notification");
|
MaterialSwitchPreference notificationPreference = findPreference("enable_status_notification");
|
||||||
if (notification != null) {
|
if (notificationPreference != null) {
|
||||||
if (App.isParasitic && !ShortcutUtil.isLaunchShortcutPinned()) {
|
if (App.isParasitic && !ShortcutUtil.isLaunchShortcutPinned()) {
|
||||||
var s = notification.getContext().getString(R.string.disable_status_notification_error);
|
setNotificationPreferenceEnabled(notificationPreference, false);
|
||||||
notification.setSummaryOn(notification.getSummary() + "\n" + s);
|
|
||||||
if (ConfigManager.enableStatusNotification()) notification.setEnabled(false);
|
|
||||||
}
|
}
|
||||||
notification.setVisible(installed);
|
notificationPreference.setVisible(installed);
|
||||||
notification.setChecked(installed && ConfigManager.enableStatusNotification());
|
notificationPreference.setChecked(installed && ConfigManager.enableStatusNotification());
|
||||||
notification.setOnPreferenceChangeListener((p, v) -> {
|
notificationPreference.setOnPreferenceChangeListener((p, v) -> {
|
||||||
if ((boolean) v && App.isParasitic && !ShortcutUtil.isLaunchShortcutPinned()) {
|
if ((boolean) v && App.isParasitic && !ShortcutUtil.isLaunchShortcutPinned()) {
|
||||||
p.setEnabled(false);
|
setNotificationPreferenceEnabled(notificationPreference, false);
|
||||||
}
|
}
|
||||||
return ConfigManager.setEnableStatusNotification((boolean) v);
|
return ConfigManager.setEnableStatusNotification((boolean) v);
|
||||||
});
|
});
|
||||||
|
|
@ -188,10 +205,7 @@ public class SettingsFragment extends BaseFragment {
|
||||||
if (!ShortcutUtil.requestPinLaunchShortcut(() -> {
|
if (!ShortcutUtil.requestPinLaunchShortcut(() -> {
|
||||||
shortcut.setEnabled(false);
|
shortcut.setEnabled(false);
|
||||||
shortcut.setSummary(R.string.settings_created_shortcut_summary);
|
shortcut.setSummary(R.string.settings_created_shortcut_summary);
|
||||||
if (notification != null) {
|
setNotificationPreferenceEnabled(notificationPreference, true);
|
||||||
notification.setEnabled(true);
|
|
||||||
notification.setSummaryOn(R.string.settings_enable_status_notification_summary);
|
|
||||||
}
|
|
||||||
App.getPreferences().edit().putBoolean("never_show_welcome", true).apply();
|
App.getPreferences().edit().putBoolean("never_show_welcome", true).apply();
|
||||||
parentFragment.showHint(R.string.settings_shortcut_pinned_hint, false);
|
parentFragment.showHint(R.string.settings_shortcut_pinned_hint, false);
|
||||||
})) {
|
})) {
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.Icon;
|
import android.graphics.drawable.Icon;
|
||||||
import android.graphics.drawable.LayerDrawable;
|
import android.graphics.drawable.LayerDrawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
|
@ -106,26 +107,33 @@ public class ShortcutUtil {
|
||||||
|
|
||||||
@SuppressLint("InlinedApi")
|
@SuppressLint("InlinedApi")
|
||||||
private static IntentSender registerReceiver(Context context, Runnable task) {
|
private static IntentSender registerReceiver(Context context, Runnable task) {
|
||||||
|
Log.d(App.TAG, "registerReceiver called");
|
||||||
if (task == null) return null;
|
if (task == null) return null;
|
||||||
|
Log.d(App.TAG, "registerReceiver: task=" + task);
|
||||||
var uuid = UUID.randomUUID().toString();
|
var uuid = UUID.randomUUID().toString();
|
||||||
var filter = new IntentFilter(uuid);
|
var filter = new IntentFilter(uuid);
|
||||||
var permission = "android.permission.CREATE_USERS";
|
var permission = "android.permission.CREATE_USERS";
|
||||||
var receiver = new BroadcastReceiver() {
|
var receiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context c, Intent intent) {
|
public void onReceive(Context c, Intent intent) {
|
||||||
|
Log.d(App.TAG, "registerReceiver: onReceive: " + intent.getAction());
|
||||||
if (!uuid.equals(intent.getAction())) return;
|
if (!uuid.equals(intent.getAction())) return;
|
||||||
|
Log.d(App.TAG, "registerReceiver: onReceive: unregisterReceiver");
|
||||||
context.unregisterReceiver(this);
|
context.unregisterReceiver(this);
|
||||||
|
Log.d(App.TAG, "registerReceiver: onReceive: task.run()");
|
||||||
task.run();
|
task.run();
|
||||||
defaultLauncherPackageName = getDefaultLauncherPackageName(context);
|
defaultLauncherPackageName = getDefaultLauncherPackageName(context);
|
||||||
shortcutPinned = true;
|
shortcutPinned = true;
|
||||||
|
Log.d(App.TAG, "registerReceiver: onReceive: shortcutPinned=" + shortcutPinned + " defaultLauncherPackageName=" + defaultLauncherPackageName);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Log.d(App.TAG, "registerReceiver: filterAction=" + filter.getAction(0) + " permission=" + permission + " receiver=" + receiver);
|
||||||
context.registerReceiver(receiver, filter, permission,
|
context.registerReceiver(receiver, filter, permission,
|
||||||
null/* main thread */, Context.RECEIVER_NOT_EXPORTED);
|
null/* main thread */, Context.RECEIVER_NOT_EXPORTED);
|
||||||
|
|
||||||
var intent = new Intent(uuid);
|
var intent = new Intent(uuid);
|
||||||
int flags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE;
|
int flags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE;
|
||||||
|
Log.d(App.TAG, "registerReceiver: intent=" + intent + " flags=" + flags);
|
||||||
return PendingIntent.getBroadcast(context, 0, intent, flags).getIntentSender();
|
return PendingIntent.getBroadcast(context, 0, intent, flags).getIntentSender();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -194,6 +202,10 @@ public class ShortcutUtil {
|
||||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||||
intent.addCategory(Intent.CATEGORY_HOME);
|
intent.addCategory(Intent.CATEGORY_HOME);
|
||||||
var resolveInfo = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
|
var resolveInfo = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
|
||||||
return resolveInfo.activityInfo.packageName;
|
if (resolveInfo != null) {
|
||||||
|
return resolveInfo.activityInfo.packageName;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue