mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-11 06:44:00 +00:00
feat: Add option to clear home screen in settings (#6125)
Signed-off-by: abhixv <abhi.sharma1@hotmail.com>
This commit is contained in:
@@ -166,6 +166,8 @@
|
||||
<string name="home_screen_label">Home screen</string>
|
||||
<string name="home_screen_description">Feed, grid, icons</string>
|
||||
|
||||
<string name="home_screen_actions">Home screen actions</string>
|
||||
|
||||
<string name="dock_label">Dock</string>
|
||||
<string name="dock_description">Search bar, icon count</string>
|
||||
|
||||
@@ -262,6 +264,9 @@
|
||||
<string name="reset_custom_icons">Reset custom icons</string>
|
||||
<string name="reset_custom_icons_confirmation">All custom icons will be reset. Do you want to continue?</string>
|
||||
|
||||
<string name="remove_all_views_from_home_screen">Clear home screen</string>
|
||||
<string name="remove_all_views_from_home_screen_desc">Home screen will be cleared. Do you want to continue?</string>
|
||||
|
||||
<!-- Icon picker -->
|
||||
<string name="icon_picker_default_category">Icons</string>
|
||||
<string name="icon_picker_reset_to_default">Reset to default</string>
|
||||
@@ -892,4 +897,6 @@
|
||||
<string name="grant_requested_permissions">Grant permissions</string>
|
||||
<string name="permissions_needed">Permissions needed</string>
|
||||
<string name="grant_requested_permissions_tap">Tap to grant permissions</string>
|
||||
<!-- Message shown when all home screen views are removed -->
|
||||
<string name="home_screen_all_views_removed_msg">Home screen cleared</string>
|
||||
</resources>
|
||||
|
||||
@@ -45,6 +45,7 @@ import app.lawnchair.ui.preferences.components.layout.PreferenceGroup
|
||||
import app.lawnchair.ui.preferences.components.layout.PreferenceLayout
|
||||
import app.lawnchair.ui.preferences.navigation.HomeScreenGrid
|
||||
import app.lawnchair.util.collectAsStateBlocking
|
||||
import com.android.launcher3.LauncherAppState
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.Utilities
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -68,6 +69,7 @@ fun HomeScreenPreferences(
|
||||
) {
|
||||
val lockHomeScreenAdapter = prefs2.lockHomeScreen.getAdapter()
|
||||
val showDeckLayout = prefs2.showDeckLayout.getAdapter().state.value
|
||||
val context = LocalContext.current
|
||||
|
||||
if (showDeckLayout) {
|
||||
HomeLayoutSettings()
|
||||
@@ -95,6 +97,17 @@ fun HomeScreenPreferences(
|
||||
description = stringResource(id = R.string.infinite_scrolling_description),
|
||||
)
|
||||
}
|
||||
PreferenceGroup(heading = stringResource(id = R.string.home_screen_actions)) {
|
||||
ClickablePreference(
|
||||
label = stringResource(id = R.string.remove_all_views_from_home_screen),
|
||||
confirmationText = stringResource(id = R.string.remove_all_views_from_home_screen_desc),
|
||||
onClick = {
|
||||
scope.launch {
|
||||
LauncherAppState.getInstance(context).clearAllViewsFromHomeScreen()
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
PreferenceGroup(heading = stringResource(id = R.string.minus_one)) {
|
||||
val feedAvailable = OverlayCallbackImpl.minusOneAvailable(LocalContext.current)
|
||||
val enableFeedAdapter = prefs2.enableFeed.getAdapter()
|
||||
|
||||
@@ -39,6 +39,7 @@ import android.content.pm.LauncherApps;
|
||||
import android.content.pm.LauncherApps.ArchiveCompatibilityParams;
|
||||
import android.os.UserHandle;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.os.BuildCompat;
|
||||
@@ -220,6 +221,19 @@ public class LauncherAppState implements SafeCloseable {
|
||||
refreshAndReloadLauncher();
|
||||
}
|
||||
|
||||
public void clearAllViewsFromHomeScreen() {
|
||||
final boolean isViewsRemoved =
|
||||
mLauncher.getModelWriter().clearAllHomeScreenViewsByType(
|
||||
LauncherSettings.Favorites.CONTAINER_DESKTOP);
|
||||
if (isViewsRemoved) {
|
||||
Toast.makeText(
|
||||
mLauncher,
|
||||
R.string.home_screen_all_views_removed_msg,
|
||||
Toast.LENGTH_SHORT
|
||||
).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshAndReloadLauncher() {
|
||||
LauncherIcons.clearPool(mContext);
|
||||
mIconCache.updateIconParams(
|
||||
|
||||
@@ -154,6 +154,35 @@ public class ModelWriter {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all views from the home screen.
|
||||
*/
|
||||
public boolean clearAllHomeScreenViewsByType(int type) {
|
||||
final ArrayList<ItemInfo> itemsToRemove = new ArrayList<>();
|
||||
|
||||
for (ItemInfo item : mBgDataModel.itemsIdMap) {
|
||||
if (item.container == type) {
|
||||
itemsToRemove.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
if (itemsToRemove.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
enqueueDeleteRunnable(newModelTask(() -> {
|
||||
final ModelDbController db = mModel.getModelDbController();
|
||||
|
||||
for (ItemInfo item : itemsToRemove) {
|
||||
db.delete(TABLE_NAME, itemIdMatch(item.id), null);
|
||||
mBgDataModel.removeItem(mContext, item);
|
||||
}
|
||||
}));
|
||||
|
||||
mModel.forceReload();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move an item in the DB to a new <container, screen, cellX, cellY>
|
||||
|
||||
Reference in New Issue
Block a user