Always allow pinning shortcuts, regardless of whether they are pinned or not (#2668)
This commit is contained in:
parent
ac675cc5f2
commit
c5cadb44f7
|
|
@ -194,17 +194,13 @@ public class SettingsFragment extends BaseFragment {
|
||||||
|
|
||||||
Preference shortcut = findPreference("add_shortcut");
|
Preference shortcut = findPreference("add_shortcut");
|
||||||
if (shortcut != null) {
|
if (shortcut != null) {
|
||||||
shortcut.setEnabled(ShortcutUtil.shouldAllowPinShortcut(requireContext()));
|
|
||||||
shortcut.setVisible(App.isParasitic);
|
shortcut.setVisible(App.isParasitic);
|
||||||
if (!ShortcutUtil.isRequestPinShortcutSupported(requireContext())) {
|
if (!ShortcutUtil.isRequestPinShortcutSupported(requireContext())) {
|
||||||
shortcut.setEnabled(false);
|
shortcut.setEnabled(false);
|
||||||
shortcut.setSummary(R.string.settings_unsupported_pin_shortcut_summary);
|
shortcut.setSummary(R.string.settings_unsupported_pin_shortcut_summary);
|
||||||
} else if (!ShortcutUtil.shouldAllowPinShortcut(requireContext()))
|
}
|
||||||
shortcut.setSummary(R.string.settings_created_shortcut_summary);
|
|
||||||
shortcut.setOnPreferenceClickListener(preference -> {
|
shortcut.setOnPreferenceClickListener(preference -> {
|
||||||
if (!ShortcutUtil.requestPinLaunchShortcut(() -> {
|
if (!ShortcutUtil.requestPinLaunchShortcut(() -> {
|
||||||
shortcut.setEnabled(false);
|
|
||||||
shortcut.setSummary(R.string.settings_created_shortcut_summary);
|
|
||||||
setNotificationPreferenceEnabled(notificationPreference, true);
|
setNotificationPreferenceEnabled(notificationPreference, true);
|
||||||
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);
|
||||||
|
|
@ -390,8 +386,7 @@ public class SettingsFragment extends BaseFragment {
|
||||||
RecyclerViewKt.fixEdgeEffect(recyclerView, false, true);
|
RecyclerViewKt.fixEdgeEffect(recyclerView, false, true);
|
||||||
recyclerView.getBorderViewDelegate().setBorderVisibilityChangedListener((top, oldTop, bottom, oldBottom) -> parentFragment.binding.appBar.setLifted(!top));
|
recyclerView.getBorderViewDelegate().setBorderVisibilityChangedListener((top, oldTop, bottom, oldBottom) -> parentFragment.binding.appBar.setLifted(!top));
|
||||||
var fragment = getParentFragment();
|
var fragment = getParentFragment();
|
||||||
if (fragment instanceof SettingsFragment) {
|
if (fragment instanceof SettingsFragment settingsFragment) {
|
||||||
var settingsFragment = (SettingsFragment) fragment;
|
|
||||||
View.OnClickListener l = v -> {
|
View.OnClickListener l = v -> {
|
||||||
settingsFragment.binding.appBar.setExpanded(true, true);
|
settingsFragment.binding.appBar.setExpanded(true, true);
|
||||||
recyclerView.smoothScrollToPosition(0);
|
recyclerView.smoothScrollToPosition(0);
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,6 @@ import android.graphics.drawable.Icon;
|
||||||
import android.graphics.drawable.LayerDrawable;
|
import android.graphics.drawable.LayerDrawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.lsposed.manager.App;
|
import org.lsposed.manager.App;
|
||||||
import org.lsposed.manager.R;
|
import org.lsposed.manager.R;
|
||||||
|
|
||||||
|
|
@ -50,8 +48,6 @@ import java.util.UUID;
|
||||||
|
|
||||||
public class ShortcutUtil {
|
public class ShortcutUtil {
|
||||||
private static final String SHORTCUT_ID = "org.lsposed.manager.shortcut";
|
private static final String SHORTCUT_ID = "org.lsposed.manager.shortcut";
|
||||||
private static boolean shortcutPinned = false;
|
|
||||||
private static String defaultLauncherPackageName = null;
|
|
||||||
|
|
||||||
private static Bitmap getBitmap(Context context, int id) {
|
private static Bitmap getBitmap(Context context, int id) {
|
||||||
var r = context.getResources();
|
var r = context.getResources();
|
||||||
|
|
@ -116,8 +112,6 @@ public class ShortcutUtil {
|
||||||
if (!uuid.equals(intent.getAction())) return;
|
if (!uuid.equals(intent.getAction())) return;
|
||||||
context.unregisterReceiver(this);
|
context.unregisterReceiver(this);
|
||||||
task.run();
|
task.run();
|
||||||
defaultLauncherPackageName = getDefaultLauncherPackageName(context);
|
|
||||||
shortcutPinned = true;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
context.registerReceiver(receiver, filter, permission,
|
context.registerReceiver(receiver, filter, permission,
|
||||||
|
|
@ -176,25 +170,4 @@ public class ShortcutUtil {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean shouldAllowPinShortcut(Context context) {
|
|
||||||
if (shortcutPinned)
|
|
||||||
if (defaultLauncherPackageName == null
|
|
||||||
|| !defaultLauncherPackageName.equals(getDefaultLauncherPackageName(context)))
|
|
||||||
shortcutPinned = false;
|
|
||||||
defaultLauncherPackageName = getDefaultLauncherPackageName(context);
|
|
||||||
if (!isLaunchShortcutPinned()) return true;
|
|
||||||
return !shortcutPinned;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private static String getDefaultLauncherPackageName(Context context) {
|
|
||||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
|
||||||
intent.addCategory(Intent.CATEGORY_HOME);
|
|
||||||
var resolveInfo = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
|
|
||||||
if (resolveInfo != null) {
|
|
||||||
return resolveInfo.activityInfo.packageName;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -202,7 +202,6 @@
|
||||||
<string name="settings_translation_summary">Help us translate %s into your language</string>
|
<string name="settings_translation_summary">Help us translate %s into your language</string>
|
||||||
<string name="settings_create_shortcut_summary">Create a shortcut that can open parasitic manager</string>
|
<string name="settings_create_shortcut_summary">Create a shortcut that can open parasitic manager</string>
|
||||||
<string name="settings_shortcut_pinned_hint">Shortcut pinned</string>
|
<string name="settings_shortcut_pinned_hint">Shortcut pinned</string>
|
||||||
<string name="settings_created_shortcut_summary">A shortcut has been created to open parasitic manager</string>
|
|
||||||
<string name="settings_unsupported_pin_shortcut_summary">The current default launcher does not support pin shortcuts</string>
|
<string name="settings_unsupported_pin_shortcut_summary">The current default launcher does not support pin shortcuts</string>
|
||||||
<string name="settings_enable_status_notification">Status Notification</string>
|
<string name="settings_enable_status_notification">Status Notification</string>
|
||||||
<string name="settings_enable_status_notification_summary">Show a notification that can open parasitic manager</string>
|
<string name="settings_enable_status_notification_summary">Show a notification that can open parasitic manager</string>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue