Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a switch to control suggested apps showing #3803

Merged
merged 5 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lawnchair/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions lawnchair/res/values/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions lawnchair/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be confusing if the user's device doesn't have a suggestions service and this toggle appears. A better way would be to investigate why your device has a suggestion service but not the activity.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this issue when I set Lawnchair as the QS provider, even if I fallback to the default QS provider, suggested apps are still showing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably merge this first, for the ones who need this. Look back on this later.


val prefs2 = preferenceManager2()
val showRecentAppsInDrawer = prefs2.showSuggestedAppsInDrawer.getAdapter()
SwitchPreference(
label = stringResource(id = R.string.show_suggested_apps_at_drawer_top),
adapter = showRecentAppsInDrawer,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@
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 {
Expand All @@ -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);
}
Expand Down Expand Up @@ -97,9 +102,10 @@ public void setup(FloatingHeaderView parent, FloatingHeaderRow[] rows, boolean t
}

private void updateVisibility() {
setVisibility(mPredictionsEnabled ? VISIBLE : GONE);
boolean enabled = mPredictionsEnabled && PreferenceExtensionsKt.firstBlocking(prefs2.getShowSuggestedAppsInDrawer());
setVisibility(enabled ? VISIBLE : GONE);
Goooler marked this conversation as resolved.
Show resolved Hide resolved
if (mActivityContext.getAppsView() != null) {
if (mPredictionsEnabled) {
if (enabled) {
MrSluffy marked this conversation as resolved.
Show resolved Hide resolved
mActivityContext.getAppsView().getAppsStore().registerIconContainer(this);
} else {
mActivityContext.getAppsView().getAppsStore().unregisterIconContainer(this);
Expand Down