mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-18 18:28:20 +00:00
Add a switch to control suggested apps showing (#3803)
This commit is contained in:
@@ -361,6 +361,7 @@
|
||||
<string name="label">标签</string>
|
||||
<string name="hide_from_drawer">从应用抽屉隐藏</string>
|
||||
<string name="suggestion_pref_screen_title">建议</string>
|
||||
<string name="show_suggested_apps_at_drawer_top">在抽屉顶部展示建议的应用</string>
|
||||
<!-- Bug reporting -->
|
||||
<string name="lawnchair_bug_report">Lawnchair 错误报告</string>
|
||||
<string name="crash_report_notif_title">%1$s 已崩溃</string>
|
||||
|
||||
@@ -96,6 +96,7 @@
|
||||
<bool name="config_default_hide_app_drawer_search_bar">false</bool>
|
||||
<bool name="config_default_show_hidden_apps_in_search">false</bool>
|
||||
<bool name="config_default_enable_smart_hide">false</bool>
|
||||
<bool name="config_default_show_suggested_apps_at_drawer_top">true</bool>
|
||||
<bool name="config_default_enable_font_selection">true</bool>
|
||||
<bool name="config_default_enable_smartspace_calendar_selection">true</bool>
|
||||
<bool name="config_default_dts2">true</bool>
|
||||
|
||||
@@ -450,6 +450,8 @@
|
||||
<string name="hide_from_drawer">Hide from App Drawer</string>
|
||||
|
||||
<string name="suggestion_pref_screen_title">Suggestions</string>
|
||||
<string name="show_suggested_apps_at_drawer_top">Show suggested apps at drawer top</string>
|
||||
|
||||
<string name="n_percent" translatable="false">%1$d%%</string>
|
||||
|
||||
<!-- Bug reporting -->
|
||||
|
||||
@@ -227,6 +227,12 @@ class PreferenceManager2 private constructor(private val context: Context) : Pre
|
||||
onSet = { reloadHelper.recreate() },
|
||||
)
|
||||
|
||||
val showSuggestedAppsInDrawer = preference(
|
||||
key = booleanPreferencesKey(name = "show_suggested_apps_at_drawer_top"),
|
||||
defaultValue = context.resources.getBoolean(R.bool.config_default_show_suggested_apps_at_drawer_top),
|
||||
onSet = { reloadHelper.recreate() },
|
||||
)
|
||||
|
||||
val enableFontSelection = preference(
|
||||
key = booleanPreferencesKey(name = "enable_font_selection"),
|
||||
defaultValue = context.resources.getBoolean(R.bool.config_default_enable_font_selection),
|
||||
|
||||
@@ -6,6 +6,8 @@ import android.content.pm.PackageManager
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import app.lawnchair.preferences.getAdapter
|
||||
import app.lawnchair.preferences2.preferenceManager2
|
||||
import com.android.launcher3.R
|
||||
|
||||
@SuppressLint("WrongConstant")
|
||||
@@ -23,5 +25,14 @@ fun SuggestionsPreference() {
|
||||
context.startActivity(intent)
|
||||
},
|
||||
)
|
||||
} else {
|
||||
// On some devices, the Suggestions activity could not be found or PACKAGE_USAGE_STATS is not granted.
|
||||
|
||||
val prefs2 = preferenceManager2()
|
||||
val showRecentAppsInDrawer = prefs2.showSuggestedAppsInDrawer.getAdapter()
|
||||
SwitchPreference(
|
||||
label = stringResource(id = R.string.show_suggested_apps_at_drawer_top),
|
||||
adapter = showRecentAppsInDrawer,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,11 +43,14 @@ import com.android.launcher3.model.data.ItemInfoWithIcon;
|
||||
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
||||
import com.android.launcher3.touch.ItemLongClickListener;
|
||||
import com.android.launcher3.views.ActivityContext;
|
||||
import com.patrykmichalik.opto.core.PreferenceExtensionsKt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import app.lawnchair.preferences2.PreferenceManager2;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.P)
|
||||
public class PredictionRowView<T extends Context & ActivityContext>
|
||||
extends LinearLayout implements OnDeviceProfileChangeListener, FloatingHeaderRow {
|
||||
@@ -66,6 +69,8 @@ public class PredictionRowView<T extends Context & ActivityContext>
|
||||
private boolean mPredictionsEnabled = false;
|
||||
private OnLongClickListener mOnIconLongClickListener = ItemLongClickListener.INSTANCE_ALL_APPS;
|
||||
|
||||
private final PreferenceManager2 prefs2 = PreferenceManager2.getInstance(getContext());
|
||||
|
||||
public PredictionRowView(@NonNull Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
@@ -97,9 +102,10 @@ public class PredictionRowView<T extends Context & ActivityContext>
|
||||
}
|
||||
|
||||
private void updateVisibility() {
|
||||
setVisibility(mPredictionsEnabled ? VISIBLE : GONE);
|
||||
boolean enabled = mPredictionsEnabled && PreferenceExtensionsKt.firstBlocking(prefs2.getShowSuggestedAppsInDrawer());
|
||||
setVisibility(enabled ? VISIBLE : GONE);
|
||||
if (mActivityContext.getAppsView() != null) {
|
||||
if (mPredictionsEnabled) {
|
||||
if (enabled) {
|
||||
mActivityContext.getAppsView().getAppsStore().registerIconContainer(this);
|
||||
} else {
|
||||
mActivityContext.getAppsView().getAppsStore().unregisterIconContainer(this);
|
||||
|
||||
Reference in New Issue
Block a user