Add option to allow empty home screen pages

This commit is contained in:
Patryk Michalik committed 2021-03-11 18:59:14 +01:00
1 parent cfd14e9b9e
commit 2e1b4f1b39
7 files changed
+48

No files matched your search

+1
View File
@@ -32,4 +32,5 @@
<string name="icons">Icons</string>
<string name="icon_size">Icon Size</string>
<string name="label_size">Label Size</string>
<string name="allow_empty_pages_label">Allow Empty Pages</string>
</resources>
@@ -14,6 +14,11 @@ fun HomeScreenPreferences(interactor: PreferenceInteractor) {
onCheckedChange = { interactor.setAddIconToHome(it) },
label = stringResource(id = R.string.auto_add_shortcuts_label)
)
SwitchPreference(
checked = interactor.allowEmptyPages.value,
onCheckedChange = { interactor.setAllowEmptyPages(it) },
label = stringResource(id = R.string.allow_empty_pages_label)
)
}
PreferenceGroup(heading = stringResource(id = R.string.grid), showDivider = true) {
SliderPreference(
@@ -17,6 +17,7 @@ interface PreferenceInteractor {
val allAppsIconSizeFactor: State<Float>
val allAppsTextSizeFactor: State<Float>
val allAppsColumns: State<Float>
val allowEmptyPages: State<Boolean>
fun setIconPackPackage(iconPackPackage: String)
fun setAllowRotation(allowRotation: Boolean)
@@ -32,6 +33,7 @@ interface PreferenceInteractor {
fun setAllAppsIconSizeFactor(allAppsIconSizeFactor: Float)
fun setAllAppsTextSizeFactor(allAppsTextSizeFactor: Float)
fun setAllAppsColumns(allAppsColumns: Float)
fun setAllowEmptyPages(allowEmptyPages: Boolean)
fun getIconPacks(): MutableMap<String, IconPackInfo>
}
@@ -40,6 +40,7 @@ class PreferenceViewModel(application: Application) : AndroidViewModel(applicati
override val allAppsIconSizeFactor: MutableState<Float> = mutableStateOf(pm.allAppsIconSizeFactor)
override val allAppsTextSizeFactor: MutableState<Float> = mutableStateOf(pm.allAppsTextSizeFactor)
override val allAppsColumns: MutableState<Float> = mutableStateOf(pm.allAppsColumns)
override val allowEmptyPages: MutableState<Boolean> = mutableStateOf(pm.allowEmptyPages)
override fun setIconPackPackage(iconPackPackage: String) {
pm.iconPackPackage = iconPackPackage
@@ -111,6 +112,11 @@ class PreferenceViewModel(application: Application) : AndroidViewModel(applicati
this.allAppsColumns.value = allAppsColumns
}
override fun setAllowEmptyPages(allowEmptyPages: Boolean) {
pm.allowEmptyPages = allowEmptyPages
this.allowEmptyPages.value = allowEmptyPages
}
override fun getIconPacks(): MutableMap<String, IconPackInfo> {
val pm = getApplication<Application>().packageManager
val iconPacks: MutableMap<String, IconPackInfo> = HashMap()
@@ -6,6 +6,10 @@ import com.android.launcher3.LauncherAppState
import com.android.launcher3.Utilities
class LawnchairPreferences(val context: Context) {
/**
* TODO: Fix grid and empty page preferences not taking effect until Lawnchair is restarted.
* `forceReload` doesn’t appear to help in this respect.
*/
val listener: SharedPreferences.OnSharedPreferenceChangeListener =
SharedPreferences.OnSharedPreferenceChangeListener { _: SharedPreferences?, key: String? ->
when (key) {
@@ -41,6 +45,8 @@ class LawnchairPreferences(val context: Context) {
@kotlin.jvm.JvmField
var FOLDER_ROWS: String = "pref_folderRows"
// TODO: Fix the four following preferences not taking effect.
@kotlin.jvm.JvmField
var ICON_SIZE_FACTOR: String = "pref_iconSizeFactor"
@@ -56,6 +62,10 @@ class LawnchairPreferences(val context: Context) {
@kotlin.jvm.JvmField
var WRAP_ADAPTIVE_ICONS: String = "prefs_wrapAdaptive"
// TODO: Add the ability to manually delete empty pages.
@kotlin.jvm.JvmField
var ALLOW_EMPTY_PAGES: String = "pref_allowEmptyPages"
fun getInstance(context: Context?): SharedPreferences? = when {
context == null -> null
INSTANCE == null -> Utilities.getPrefs(context)
@@ -21,4 +21,5 @@ class PrefManager(context: Context) {
var allAppsIconSizeFactor by FloatPrefDelegate(lp.ALL_APPS_ICON_SIZE_FACTOR, 1F)
var allAppsTextSizeFactor by FloatPrefDelegate(lp.ALL_APPS_TEXT_SIZE_FACTOR, 1F)
var allAppsColumns by FloatPrefDelegate(lp.ALL_APPS_COLUMNS, 5F)
var allowEmptyPages by BoolPrefDelegate(lp.ALLOW_EMPTY_PAGES, false)
}
+23
View File
@@ -42,6 +42,7 @@ import android.app.WallpaperManager;
import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetProviderInfo;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Point;
@@ -117,6 +118,8 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.function.Predicate;
import ch.deletescape.lawnchair.sharedprefs.LawnchairPreferences;
/**
* The workspace is a wide area with a wallpaper and a finite number of pages.
* Each page contains a number of icons, folders or widgets the user can
@@ -255,6 +258,9 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
private final StatsLogManager mStatsLogManager;
// Lawnchair: Create boolean to indicate if empty pages are allowed.
Boolean emptyScreensAllowed;
/**
* Used to inflate the Workspace from XML.
*
@@ -288,6 +294,12 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
setMotionEventSplittingEnabled(true);
setOnTouchListener(new WorkspaceTouchListener(mLauncher, this));
mStatsLogManager = StatsLogManager.newInstance(context);
// Lawnchair: Get instance of `SharedPreferences`, assign value to `emptyScreensAllowed`.
SharedPreferences prefs = LawnchairPreferences.Companion.getInstance(getContext());
if (prefs != null) {
emptyScreensAllowed = prefs.getBoolean(LawnchairPreferences.ALLOW_EMPTY_PAGES, false);
}
}
@Override
@@ -621,6 +633,12 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
}
if (hasExtraEmptyScreen() || mScreenOrder.size() == 0) return;
// Lawnchair: Stop execution if empty pages are allowed.
if (emptyScreensAllowed) {
return;
}
int finalScreenId = mScreenOrder.get(mScreenOrder.size() - 1);
CellLayout finalScreen = mWorkspaceScreens.get(finalScreenId);
@@ -741,6 +759,11 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
return;
}
// Lawnchair: Stop execution if empty pages are allowed.
if (emptyScreensAllowed) {
return;
}
if (isPageInTransition()) {
mStripScreensOnPageStopMoving = true;
return;