Skip to content

Commit

Permalink
Add option to disable dock (#3880)
Browse files Browse the repository at this point in the history
* Add option to disable dock

* Fixed styling

* Apply suggestion by @Goooler

* Apply suggestion by @SuperDragonXD

* Fixed shrink layout

* Apply suggestion by @suphon-t
  • Loading branch information
MrSluffy committed Dec 19, 2023
1 parent 0d64cd3 commit afb5e37
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 39 deletions.
1 change: 1 addition & 0 deletions lawnchair/res/values/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<!-- which hotseat mode to use by default -->
<string name="config_default_hotseat_mode" translatable="false">lawnchair</string>

<bool name="config_default_show_hotseat">true</bool>
<bool name="config_default_always_reload_icons">true</bool>
<bool name="config_default_dark_status_bar">false</bool>
<bool name="config_default_show_notification_count">false</bool>
Expand Down
1 change: 1 addition & 0 deletions lawnchair/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@

<!-- DockPreferences -->
<!-- <string name="dock_label" /> -->
<string name="show_hotseat_title">Enable Dock</string>
<string name="hotseat_mode_label">Search Bar Widget</string>
<string name="hotseat_mode_disabled">Disabled</string>
<string name="hotseat_mode_lawnchair">Lawnchair</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ class PreferenceManager2 private constructor(private val context: Context) : Pre
defaultValue = context.resources.getBoolean(R.bool.config_default_themed_hotseat_qsb),
)

val isHotseatEnabled = preference(
key = booleanPreferencesKey(name = "pref_show_hotseat"),
defaultValue = context.resources.getBoolean(R.bool.config_default_show_hotseat),
onSet = {
reloadHelper.recreate()
reloadHelper.reloadGrid()
},
)

val hotseatQsbProvider = preference(
key = stringPreferencesKey(name = "dock_search_bar_provider"),
defaultValue = QsbSearchProvider.resolveDefault(context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package app.lawnchair.ui.preferences.destinations

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.navigation.NavGraphBuilder
Expand Down Expand Up @@ -57,47 +58,58 @@ fun DockPreferences() {
val prefs = preferenceManager()
val prefs2 = preferenceManager2()
PreferenceLayout(label = stringResource(id = R.string.dock_label)) {
PreferenceGroup(heading = stringResource(id = R.string.search_bar_label)) {
DividerColumn {
val hotseatModeAdapter = prefs2.hotseatMode.getAdapter()
HotseatModePreference(
adapter = hotseatModeAdapter,
)
ExpandAndShrink(visible = hotseatModeAdapter.state.value == LawnchairHotseat) {
val isHotseatEnabled = prefs2.isHotseatEnabled.getAdapter()
val hotseatModeAdapter = prefs2.hotseatMode.getAdapter()
PreferenceGroup(heading = stringResource(id = R.string.general_label)) {
SwitchPreference(
adapter = isHotseatEnabled,
label = stringResource(id = R.string.show_hotseat_title),
)
}
ExpandAndShrink(visible = isHotseatEnabled.state.value) {
DividerColumn(color = Color.Transparent) {
PreferenceGroup(heading = stringResource(id = R.string.search_bar_label)) {
DividerColumn {
SwitchPreference(
adapter = prefs2.themedHotseatQsb.getAdapter(),
label = stringResource(id = R.string.apply_accent_color_label),
)
SliderPreference(
label = stringResource(id = R.string.corner_radius_label),
adapter = prefs.hotseatQsbCornerRadius.getAdapter(),
step = 0.05F,
valueRange = 0F..1F,
showAsPercentage = true,
)
val hotseatQsbProviderAdapter by preferenceManager2().hotseatQsbProvider.getAdapter()
NavigationActionPreference(
label = stringResource(R.string.search_provider),
destination = subRoute(DockRoutes.SEARCH_PROVIDER),
subtitle = stringResource(
id = QsbSearchProvider.values()
.first { it == hotseatQsbProviderAdapter }
.name,
),
HotseatModePreference(
adapter = hotseatModeAdapter,
)
ExpandAndShrink(visible = hotseatModeAdapter.state.value == LawnchairHotseat) {
DividerColumn {
SwitchPreference(
adapter = prefs2.themedHotseatQsb.getAdapter(),
label = stringResource(id = R.string.apply_accent_color_label),
)
SliderPreference(
label = stringResource(id = R.string.corner_radius_label),
adapter = prefs.hotseatQsbCornerRadius.getAdapter(),
step = 0.05F,
valueRange = 0F..1F,
showAsPercentage = true,
)
val hotseatQsbProviderAdapter by preferenceManager2().hotseatQsbProvider.getAdapter()
NavigationActionPreference(
label = stringResource(R.string.search_provider),
destination = subRoute(DockRoutes.SEARCH_PROVIDER),
subtitle = stringResource(
id = QsbSearchProvider.values()
.first { it == hotseatQsbProviderAdapter }
.name,
),
)
}
}
}
}
PreferenceGroup(heading = stringResource(id = R.string.grid)) {
SliderPreference(
label = stringResource(id = R.string.dock_icons),
adapter = prefs.hotseatColumns.getAdapter(),
step = 1,
valueRange = 3..10,
)
}
}
}
PreferenceGroup(heading = stringResource(id = R.string.grid)) {
SliderPreference(
label = stringResource(id = R.string.dock_icons),
adapter = prefs.hotseatColumns.getAdapter(),
step = 1,
valueRange = 3..10,
)
}
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/com/android/launcher3/DeviceProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ public class DeviceProfile {

private final DeviceProfileOverrides.TextFactors mTextFactors;

private final PreferenceManager2 preferenceManager2;

/** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Expand All @@ -323,7 +325,7 @@ public class DeviceProfile {

mTextFactors = DeviceProfileOverrides.INSTANCE.get(context).getTextFactors();

PreferenceManager2 preferenceManager2 = PreferenceManager2.INSTANCE.get(context);
preferenceManager2 = PreferenceManager2.INSTANCE.get(context);
allAppsCellHeightMultiplier = PreferenceExtensionsKt
.firstBlocking(preferenceManager2.getDrawerCellHeightFactor());

Expand Down Expand Up @@ -795,7 +797,7 @@ private void updateHotseatSizes(int hotseatIconSizePx) {
// radius.
hotseatCellHeightPx = getIconSizeWithOverlap(hotseatIconSizePx);

var space = Math.abs(hotseatCellHeightPx / 2);
var space = Math.abs(hotseatCellHeightPx / 2) - 10;

if (isVerticalBarLayout()) {
hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
Expand All @@ -810,6 +812,10 @@ private void updateHotseatSizes(int hotseatIconSizePx) {
+ hotseatBarBottomSpacePx
+ space;
}
var isHotseatEnabled = PreferenceExtensionsKt.firstBlocking(preferenceManager2.isHotseatEnabled());
if (!isHotseatEnabled) {
hotseatBarSizePx = 0;
}
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/com/android/launcher3/Hotseat.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import android.content.Context;
import android.graphics.Rect;
import android.os.Build;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
Expand All @@ -32,9 +31,9 @@

import com.patrykmichalik.opto.core.PreferenceExtensionsKt;

import app.lawnchair.hotseat.DisabledHotseat;
import app.lawnchair.hotseat.HotseatMode;
import app.lawnchair.hotseat.LawnchairHotseat;
import app.lawnchair.preferences.PreferenceManager;
import app.lawnchair.preferences2.PreferenceManager2;

/**
Expand Down Expand Up @@ -67,6 +66,12 @@ public Hotseat(Context context, AttributeSet attrs, int defStyle) {

preferenceManager2 = PreferenceManager2.getInstance(context);
HotseatMode hotseatMode = PreferenceExtensionsKt.firstBlocking(preferenceManager2.getHotseatMode());
var hotseatEnabled = PreferenceExtensionsKt.firstBlocking(preferenceManager2.isHotseatEnabled());

if (!hotseatEnabled) {
hotseatMode = DisabledHotseat.INSTANCE;
}

if (!hotseatMode.isAvailable(context)) {
// The current hotseat mode is not available,
// setting the hotseat mode to one that is always available
Expand Down
2 changes: 2 additions & 0 deletions src/com/android/launcher3/Workspace.java
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,8 @@ protected void onScrollChanged(int l, int t, int oldl, int oldt) {
public void showPageIndicatorAtCurrentScroll() {
if (mPageIndicator != null) {
mPageIndicator.setScroll(getScrollX(), computeMaxScroll());
var isHotseatEnabled = PreferenceExtensionsKt.firstBlocking(mPreferenceManager2.isHotseatEnabled());
mPageIndicator.setVisibility(isHotseatEnabled ? VISIBLE : INVISIBLE);
}
}

Expand Down

0 comments on commit afb5e37

Please sign in to comment.