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");
|
||||
if (shortcut != null) {
|
||||
shortcut.setEnabled(ShortcutUtil.shouldAllowPinShortcut(requireContext()));
|
||||
shortcut.setVisible(App.isParasitic);
|
||||
if (!ShortcutUtil.isRequestPinShortcutSupported(requireContext())) {
|
||||
shortcut.setEnabled(false);
|
||||
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 -> {
|
||||
if (!ShortcutUtil.requestPinLaunchShortcut(() -> {
|
||||
shortcut.setEnabled(false);
|
||||
shortcut.setSummary(R.string.settings_created_shortcut_summary);
|
||||
setNotificationPreferenceEnabled(notificationPreference, true);
|
||||
App.getPreferences().edit().putBoolean("never_show_welcome", true).apply();
|
||||
parentFragment.showHint(R.string.settings_shortcut_pinned_hint, false);
|
||||
|
|
@ -390,8 +386,7 @@ public class SettingsFragment extends BaseFragment {
|
|||
RecyclerViewKt.fixEdgeEffect(recyclerView, false, true);
|
||||
recyclerView.getBorderViewDelegate().setBorderVisibilityChangedListener((top, oldTop, bottom, oldBottom) -> parentFragment.binding.appBar.setLifted(!top));
|
||||
var fragment = getParentFragment();
|
||||
if (fragment instanceof SettingsFragment) {
|
||||
var settingsFragment = (SettingsFragment) fragment;
|
||||
if (fragment instanceof SettingsFragment settingsFragment) {
|
||||
View.OnClickListener l = v -> {
|
||||
settingsFragment.binding.appBar.setExpanded(true, true);
|
||||
recyclerView.smoothScrollToPosition(0);
|
||||
|
|
|
|||
|
|
@ -39,8 +39,6 @@ import android.graphics.drawable.Icon;
|
|||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.lsposed.manager.App;
|
||||
import org.lsposed.manager.R;
|
||||
|
||||
|
|
@ -50,8 +48,6 @@ import java.util.UUID;
|
|||
|
||||
public class ShortcutUtil {
|
||||
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) {
|
||||
var r = context.getResources();
|
||||
|
|
@ -116,8 +112,6 @@ public class ShortcutUtil {
|
|||
if (!uuid.equals(intent.getAction())) return;
|
||||
context.unregisterReceiver(this);
|
||||
task.run();
|
||||
defaultLauncherPackageName = getDefaultLauncherPackageName(context);
|
||||
shortcutPinned = true;
|
||||
}
|
||||
};
|
||||
context.registerReceiver(receiver, filter, permission,
|
||||
|
|
@ -176,25 +170,4 @@ public class ShortcutUtil {
|
|||
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_create_shortcut_summary">Create a shortcut that can open parasitic manager</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_enable_status_notification">Status Notification</string>
|
||||
<string name="settings_enable_status_notification_summary">Show a notification that can open parasitic manager</string>
|
||||
|
|
|
|||
Loading…
Reference in New Issue