fix: Allow disabling the smartspace feature
This commit is contained in:
@@ -38,6 +38,7 @@ Compatibility list:
|
||||
* [Lawnchair/AllApps] Reimplement app drawer opacity
|
||||
* [Lawnchair/Recents] Reimplement recents overview opacity
|
||||
* [Lawnchair/Preference] Misaligned slider and text preference
|
||||
* [Lawnchair/Smartspace] Allow disabling the smartspace feature
|
||||
|
||||
### 🥞 Development 3 Release 2
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ class AddFoldersWithItemsTask(
|
||||
val addedWorkspaceScreensFinal = IntArray()
|
||||
|
||||
synchronized(dataModel) {
|
||||
val workspaceScreens = dataModel.collectWorkspaceScreens()
|
||||
val workspaceScreens = dataModel.collectWorkspaceScreens(context)
|
||||
val modelWriter = taskController.getModelWriter()
|
||||
|
||||
folders.forEach { folderInfo ->
|
||||
@@ -57,6 +57,7 @@ class AddFoldersWithItemsTask(
|
||||
addedWorkspaceScreensFinal,
|
||||
folderInfo.spanX,
|
||||
folderInfo.spanY,
|
||||
context,
|
||||
)
|
||||
val screenId = coords[0]
|
||||
val cellX = coords[1]
|
||||
|
||||
@@ -654,15 +654,12 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
|
||||
* Initializes and binds the first page
|
||||
*/
|
||||
public void bindAndInitFirstWorkspaceScreen() {
|
||||
if ((!FeatureFlags.QSB_ON_FIRST_SCREEN
|
||||
|| !mLauncher.getIsFirstPagePinnedItemEnabled())
|
||||
|| SHOULD_SHOW_FIRST_PAGE_WIDGET) {
|
||||
// Add the first page
|
||||
CellLayout firstPage = insertNewWorkspaceScreen(Workspace.FIRST_SCREEN_ID, getChildCount());
|
||||
if (!PreferenceExtensionsKt.firstBlocking(mPreferenceManager2.getEnableSmartspace())) {
|
||||
mFirstPagePinnedItem = null;
|
||||
return;
|
||||
}
|
||||
|
||||
// Add the first page
|
||||
CellLayout firstPage = insertNewWorkspaceScreen(Workspace.FIRST_SCREEN_ID, getChildCount());
|
||||
if (mFirstPagePinnedItem == null) {
|
||||
SmartspaceMode smartspaceMode = PreferenceExtensionsKt
|
||||
.firstBlocking(mPreferenceManager2.getSmartspaceMode());
|
||||
@@ -1102,9 +1099,7 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
|
||||
int id = mWorkspaceScreens.keyAt(i);
|
||||
CellLayout cl = mWorkspaceScreens.valueAt(i);
|
||||
// FIRST_SCREEN_ID can never be removed.
|
||||
if (((!FeatureFlags.QSB_ON_FIRST_SCREEN
|
||||
|| SHOULD_SHOW_FIRST_PAGE_WIDGET)
|
||||
|| id > FIRST_SCREEN_ID)
|
||||
if ((!PreferenceExtensionsKt.firstBlocking(PreferenceManager2.INSTANCE.get(getContext()).getEnableSmartspace()) || id > FIRST_SCREEN_ID)
|
||||
&& cl.getShortcutsAndWidgets().getChildCount() == 0) {
|
||||
removeScreens.add(id);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public class AddWorkspaceItemsTask implements ModelUpdateTask {
|
||||
final Context context = taskController.getContext();
|
||||
|
||||
synchronized (dataModel) {
|
||||
IntArray workspaceScreens = dataModel.collectWorkspaceScreens();
|
||||
IntArray workspaceScreens = dataModel.collectWorkspaceScreens(context);
|
||||
|
||||
List<ItemInfo> filteredItems = new ArrayList<>();
|
||||
for (Pair<ItemInfo, Object> entry : mItemList) {
|
||||
@@ -127,7 +127,7 @@ public class AddWorkspaceItemsTask implements ModelUpdateTask {
|
||||
for (ItemInfo item : filteredItems) {
|
||||
// Find appropriate space for the item.
|
||||
int[] coords = mItemSpaceFinder.findSpaceForItem(
|
||||
workspaceScreens, addedWorkspaceScreensFinal, item.spanX, item.spanY);
|
||||
workspaceScreens, addedWorkspaceScreensFinal, item.spanX, item.spanY, context);
|
||||
int screenId = coords[0];
|
||||
|
||||
ItemInfo itemInfo;
|
||||
|
||||
@@ -35,6 +35,7 @@ import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import app.lawnchair.preferences2.PreferenceManager2;
|
||||
import com.android.launcher3.AutoInstallsLayout;
|
||||
import com.android.launcher3.AutoInstallsLayout.LayoutParserCallback;
|
||||
import com.android.launcher3.LauncherSettings;
|
||||
@@ -52,6 +53,7 @@ import com.android.launcher3.util.PackageManagerHelper;
|
||||
import com.android.launcher3.util.Thunk;
|
||||
import com.android.launcher3.widget.LauncherWidgetHolder;
|
||||
|
||||
import com.patrykmichalik.opto.core.PreferenceExtensionsKt;
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
@@ -263,7 +265,7 @@ public class DatabaseHelper extends NoLocaleSQLiteHelper implements
|
||||
Favorites.SCREEN, IntArray.wrap(-777, -778)), null);
|
||||
}
|
||||
case 30: {
|
||||
if (FeatureFlags.QSB_ON_FIRST_SCREEN) {
|
||||
if (PreferenceExtensionsKt.firstBlocking(PreferenceManager2.INSTANCE.get(mContext).getEnableSmartspace())) {
|
||||
// Clean up first row in screen 0 as it might contain junk data.
|
||||
Log.d(TAG, "Cleaning up first row");
|
||||
db.delete(Favorites.TABLE_NAME,
|
||||
|
||||
@@ -45,6 +45,7 @@ import android.util.Log;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import app.lawnchair.preferences2.PreferenceManager2;
|
||||
import com.android.launcher3.Flags;
|
||||
import com.android.launcher3.InvariantDeviceProfile;
|
||||
import com.android.launcher3.LauncherPrefs;
|
||||
@@ -58,6 +59,7 @@ import com.android.launcher3.util.IntArray;
|
||||
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
|
||||
import com.android.launcher3.widget.WidgetManagerHelper;
|
||||
|
||||
import com.patrykmichalik.opto.core.PreferenceExtensionsKt;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -283,7 +285,8 @@ public class GridSizeMigrationDBController {
|
||||
Log.d(TAG, "Migrating " + screenId);
|
||||
}
|
||||
solveGridPlacement(helper, srcReader,
|
||||
destReader, screenId, trgX, trgY, workspaceToBeAdded, idsInUse);
|
||||
destReader, screenId, trgX, trgY, workspaceToBeAdded, idsInUse,
|
||||
srcReader.mContext);
|
||||
if (workspaceToBeAdded.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
@@ -295,7 +298,7 @@ public class GridSizeMigrationDBController {
|
||||
while (!workspaceToBeAdded.isEmpty()) {
|
||||
solveGridPlacement(helper, srcReader, destReader, screenId, trgX, trgY,
|
||||
workspaceToBeAdded,
|
||||
srcWorkspaceItems.stream().map(entry -> entry.id).collect(Collectors.toList()));
|
||||
srcWorkspaceItems.stream().map(entry -> entry.id).collect(Collectors.toList()), srcReader.mContext);
|
||||
screenId++;
|
||||
}
|
||||
|
||||
@@ -398,15 +401,15 @@ public class GridSizeMigrationDBController {
|
||||
private static void solveGridPlacement(@NonNull final DatabaseHelper helper,
|
||||
@NonNull final DbReader srcReader, @NonNull final DbReader destReader,
|
||||
final int screenId, final int trgX, final int trgY,
|
||||
@NonNull final List<DbEntry> sortedItemsToPlace, List<Integer> idsInUse) {
|
||||
@NonNull final List<DbEntry> sortedItemsToPlace, List<Integer> idsInUse, Context context) {
|
||||
PreferenceManager2 prefs2 = PreferenceManager2.INSTANCE.get(context);
|
||||
|
||||
boolean smartspaceEnabled = PreferenceExtensionsKt.firstBlocking(prefs2.getEnableSmartspace());
|
||||
|
||||
final GridOccupancy occupied = new GridOccupancy(trgX, trgY);
|
||||
final Point trg = new Point(trgX, trgY);
|
||||
final Point next = new Point(0, screenId == 0
|
||||
&& (FeatureFlags.QSB_ON_FIRST_SCREEN
|
||||
&& (!enableSmartspaceRemovalToggle() || LauncherPrefs.getPrefs(destReader.mContext)
|
||||
.getBoolean(SMARTSPACE_ON_HOME_SCREEN, true))
|
||||
&& !SHOULD_SHOW_FIRST_PAGE_WIDGET)
|
||||
? 1 /* smartspace */ : 0);
|
||||
final Point next = new Point(0,
|
||||
screenId == 0 && smartspaceEnabled ? 1 /* smartspace */ : 0);
|
||||
List<DbEntry> existedEntries = destReader.mWorkspaceEntriesByScreenId.get(screenId);
|
||||
if (existedEntries != null) {
|
||||
for (DbEntry entry : existedEntries) {
|
||||
|
||||
@@ -20,6 +20,9 @@ import android.database.sqlite.SQLiteDatabase
|
||||
import android.graphics.Point
|
||||
import android.util.Log
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import app.lawnchair.preferences2.PreferenceManager2
|
||||
import com.android.launcher3.BuildConfig
|
||||
import com.android.launcher3.BuildConfigs
|
||||
import com.android.launcher3.Flags
|
||||
import com.android.launcher3.LauncherPrefs
|
||||
import com.android.launcher3.LauncherPrefs.Companion.get
|
||||
@@ -44,6 +47,7 @@ import com.android.launcher3.provider.LauncherDbUtils.shiftWorkspaceByXCells
|
||||
import com.android.launcher3.util.CellAndSpan
|
||||
import com.android.launcher3.util.GridOccupancy
|
||||
import com.android.launcher3.util.IntArray
|
||||
import com.patrykmichalik.opto.core.firstBlocking
|
||||
|
||||
class GridSizeMigrationLogic {
|
||||
/**
|
||||
@@ -502,15 +506,11 @@ class GridSizeMigrationLogic {
|
||||
val itemsToPlace = WorkspaceItemsToPlace(sortedItemsToPlace, mutableListOf())
|
||||
val occupied = GridOccupancy(trgX, trgY)
|
||||
val trg = Point(trgX, trgY)
|
||||
|
||||
val prefs2 = PreferenceManager2.INSTANCE.get(context)
|
||||
|
||||
val next: Point =
|
||||
if (
|
||||
screenId == 0 &&
|
||||
(FeatureFlags.QSB_ON_FIRST_SCREEN &&
|
||||
(!Flags.enableSmartspaceRemovalToggle() ||
|
||||
getPrefs(context)
|
||||
.getBoolean(LoaderTask.SMARTSPACE_ON_HOME_SCREEN, true)) &&
|
||||
!Utilities.SHOULD_SHOW_FIRST_PAGE_WIDGET)
|
||||
) {
|
||||
if (screenId == 0 && prefs2.enableSmartspace.firstBlocking()) {
|
||||
Point(0, 1 /* smartspace */)
|
||||
} else {
|
||||
Point(0, 0)
|
||||
|
||||
@@ -644,9 +644,7 @@ public class LoaderCursor extends CursorWrapper {
|
||||
|
||||
if (!mOccupied.containsKey(item.screenId)) {
|
||||
GridOccupancy screen = new GridOccupancy(countX + 1, countY + 1);
|
||||
if (item.screenId == Workspace.FIRST_SCREEN_ID && (FeatureFlags.QSB_ON_FIRST_SCREEN
|
||||
&& !SHOULD_SHOW_FIRST_PAGE_WIDGET
|
||||
&& isFirstPagePinnedItemEnabled)) {
|
||||
if (item.screenId == Workspace.FIRST_SCREEN_ID && PreferenceExtensionsKt.firstBlocking(preferenceManager2.getEnableSmartspace())) {
|
||||
// Mark the first X columns (X is width of the search container) in the first row as
|
||||
// occupied (if the feature is enabled) in order to account for the search
|
||||
// container.
|
||||
|
||||
@@ -229,7 +229,7 @@ public class LoaderTask implements Runnable {
|
||||
|
||||
private void sendFirstScreenActiveInstallsBroadcast() {
|
||||
// Screen set is never empty
|
||||
IntArray allScreens = mBgDataModel.collectWorkspaceScreens();
|
||||
IntArray allScreens = mBgDataModel.collectWorkspaceScreens(mContext);
|
||||
final int firstScreen = allScreens.get(0);
|
||||
IntSet firstScreens = IntSet.wrap(firstScreen);
|
||||
|
||||
|
||||
@@ -18,8 +18,12 @@ package com.android.launcher3.model;
|
||||
import static com.android.launcher3.Utilities.SHOULD_SHOW_FIRST_PAGE_WIDGET;
|
||||
import static com.android.launcher3.WorkspaceLayoutManager.FIRST_SCREEN_ID;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.LongSparseArray;
|
||||
|
||||
import app.lawnchair.preferences2.PreferenceManager2;
|
||||
import com.android.launcher3.BuildConfig;
|
||||
import com.android.launcher3.BuildConfigs;
|
||||
import com.android.launcher3.InvariantDeviceProfile;
|
||||
import com.android.launcher3.LauncherModel;
|
||||
import com.android.launcher3.LauncherSettings;
|
||||
@@ -29,6 +33,7 @@ import com.android.launcher3.util.GridOccupancy;
|
||||
import com.android.launcher3.util.IntArray;
|
||||
import com.android.launcher3.util.IntSet;
|
||||
|
||||
import com.patrykmichalik.opto.core.PreferenceExtensionsKt;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -56,7 +61,7 @@ public class WorkspaceItemSpaceFinder {
|
||||
* @return screenId and the coordinates for the item in an int array of size 3.
|
||||
*/
|
||||
public int[] findSpaceForItem(
|
||||
IntArray workspaceScreens, IntArray addedWorkspaceScreensFinal, int spanX, int spanY) {
|
||||
IntArray workspaceScreens, IntArray addedWorkspaceScreensFinal, int spanX, int spanY, Context context) {
|
||||
LongSparseArray<ArrayList<ItemInfo>> screenItems = new LongSparseArray<>();
|
||||
|
||||
// Use sBgItemsIdMap as all the items are already loaded.
|
||||
@@ -81,7 +86,9 @@ public class WorkspaceItemSpaceFinder {
|
||||
int screenCount = workspaceScreens.size();
|
||||
// First check the preferred screen.
|
||||
IntSet screensToExclude = new IntSet();
|
||||
if (FeatureFlags.QSB_ON_FIRST_SCREEN) {
|
||||
|
||||
boolean smartspaceEnabled = PreferenceExtensionsKt.firstBlocking(PreferenceManager2.INSTANCE.get(context).getEnableSmartspace());
|
||||
if (smartspaceEnabled) {
|
||||
screensToExclude.add(FIRST_SCREEN_ID);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user