diff --git a/lawnchair/res/values/config.xml b/lawnchair/res/values/config.xml
index 0d72e17ba7..ef9b1572be 100644
--- a/lawnchair/res/values/config.xml
+++ b/lawnchair/res/values/config.xml
@@ -17,5 +17,5 @@
com.lawnchair.settings.ui.SettingsActivity$LauncherSettingsFragment
- app.lawnchair.LawnchairAppFilter
+ app.lawnchair.DefaultAppFilter
diff --git a/lawnchair/src/app/lawnchair/DefaultAppFilter.kt b/lawnchair/src/app/lawnchair/DefaultAppFilter.kt
index 0c255de040..3ddfa87543 100644
--- a/lawnchair/src/app/lawnchair/DefaultAppFilter.kt
+++ b/lawnchair/src/app/lawnchair/DefaultAppFilter.kt
@@ -18,9 +18,11 @@ package app.lawnchair
import android.content.ComponentName
import android.os.UserHandle
+import androidx.annotation.Keep
import com.android.launcher3.AppFilter
import com.android.launcher3.BuildConfig
+@Keep
open class DefaultAppFilter : AppFilter() {
private val defaultHideList = setOf(
// Voice search
diff --git a/lawnchair/src/app/lawnchair/LawnchairAppFilter.kt b/lawnchair/src/app/lawnchair/LawnchairAppFilter.kt
deleted file mode 100644
index 3594820fa1..0000000000
--- a/lawnchair/src/app/lawnchair/LawnchairAppFilter.kt
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2021, Lawnchair
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package app.lawnchair
-
-import android.content.ComponentName
-import android.content.Context
-import android.os.UserHandle
-import androidx.annotation.Keep
-import app.lawnchair.util.preferences.PreferenceManager
-import com.android.launcher3.util.ComponentKey
-
-@Keep
-class LawnchairAppFilter(context: Context) : DefaultAppFilter() {
- private val prefs = PreferenceManager.getInstance(context)
- private val customHideList get() = prefs.hiddenAppSet.get()
-
- override fun shouldShowApp(app: ComponentName, user: UserHandle?) =
- when {
- !super.shouldShowApp(app, user) -> false
- customHideList.contains(ComponentKey(app, user).toString()) -> false
- else -> true
- }
-}
diff --git a/lawnchair/src/app/lawnchair/LawnchairLauncherQuickstep.kt b/lawnchair/src/app/lawnchair/LawnchairLauncherQuickstep.kt
index 98d938f2ea..9f622ebde6 100644
--- a/lawnchair/src/app/lawnchair/LawnchairLauncherQuickstep.kt
+++ b/lawnchair/src/app/lawnchair/LawnchairLauncherQuickstep.kt
@@ -18,31 +18,57 @@ package app.lawnchair
import android.content.Context
import android.content.ContextWrapper
+import android.os.Bundle
+import androidx.lifecycle.Lifecycle
+import androidx.lifecycle.LifecycleOwner
+import androidx.lifecycle.LifecycleRegistry
import com.android.launcher3.uioverrides.QuickstepLauncher
import com.android.systemui.plugins.shared.LauncherOverlayManager
import app.lawnchair.nexuslauncher.OverlayCallbackImpl
import app.lawnchair.util.restartLauncher
+import com.android.launcher3.BaseActivity
import com.android.launcher3.LauncherAppState
-open class LawnchairLauncherQuickstep : QuickstepLauncher() {
- private var paused = false
+open class LawnchairLauncherQuickstep : QuickstepLauncher(), LifecycleOwner {
+ private val lifecycleRegistry = LifecycleRegistry(this)
- override fun getDefaultOverlay(): LauncherOverlayManager {
- return OverlayCallbackImpl(this)
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
+ }
+
+ override fun onStart() {
+ super.onStart()
+ lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
}
override fun onResume() {
super.onResume()
-
+ lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_RESUME)
restartIfPending()
-
- paused = false
}
override fun onPause() {
super.onPause()
+ lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE)
+ }
- paused = true
+ override fun onStop() {
+ super.onStop()
+ lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
+ }
+
+ override fun getLifecycle(): Lifecycle {
+ return lifecycleRegistry
+ }
+
+ override fun getDefaultOverlay(): LauncherOverlayManager {
+ return OverlayCallbackImpl(this)
}
open fun restartIfPending() {
@@ -52,7 +78,7 @@ open class LawnchairLauncherQuickstep : QuickstepLauncher() {
}
fun scheduleRestart() {
- if (paused) {
+ if (lifecycle.currentState !== Lifecycle.State.RESUMED) {
sRestart = true
} else {
restartLauncher(this)
@@ -61,11 +87,9 @@ open class LawnchairLauncherQuickstep : QuickstepLauncher() {
companion object {
var sRestart = false
- @JvmStatic
- fun getLauncher(context: Context): LawnchairLauncherQuickstep {
- return context as? LawnchairLauncherQuickstep
- ?: (context as ContextWrapper).baseContext as? LawnchairLauncherQuickstep
- ?: LauncherAppState.getInstance(context).launcher as LawnchairLauncherQuickstep
- }
}
-}
\ No newline at end of file
+}
+
+val Context.launcher: LawnchairLauncherQuickstep get() {
+ return BaseActivity.fromContext(this)
+}
diff --git a/lawnchair/src/app/lawnchair/allapps/LawnchairAlphabeticalAppsList.kt b/lawnchair/src/app/lawnchair/allapps/LawnchairAlphabeticalAppsList.kt
new file mode 100644
index 0000000000..0caf304aaa
--- /dev/null
+++ b/lawnchair/src/app/lawnchair/allapps/LawnchairAlphabeticalAppsList.kt
@@ -0,0 +1,37 @@
+package app.lawnchair.allapps
+
+import android.content.Context
+import app.lawnchair.launcher
+import app.lawnchair.util.preferences.PreferenceManager
+import app.lawnchair.util.preferences.subscribe
+import com.android.launcher3.allapps.AllAppsStore
+import com.android.launcher3.allapps.AlphabeticalAppsList
+import com.android.launcher3.model.data.AppInfo
+import com.android.launcher3.util.ItemInfoMatcher
+import java.lang.IllegalArgumentException
+
+class LawnchairAlphabeticalAppsList(context: Context, appsStore: AllAppsStore, isWork: Boolean) :
+ AlphabeticalAppsList(context, appsStore, isWork) {
+
+ private val hiddenApps = PreferenceManager.getInstance(context).hiddenAppSet
+ private var itemFilter: ItemInfoMatcher? = null
+
+ init {
+ super.updateItemFilter { info, cn ->
+ if (info !is AppInfo) {
+ throw IllegalArgumentException("info must be an AppInfo")
+ }
+ when {
+ itemFilter?.matches(info, cn) == false -> false
+ hiddenApps.get().contains(info.toComponentKey().toString()) -> false
+ else -> true
+ }
+ }
+ hiddenApps.subscribe(context.launcher, this::onAppsUpdated)
+ }
+
+ override fun updateItemFilter(itemFilter: ItemInfoMatcher?) {
+ this.itemFilter = itemFilter
+ onAppsUpdated()
+ }
+}
diff --git a/lawnchair/src/app/lawnchair/util/preferences/PrefLifecycleObserver.kt b/lawnchair/src/app/lawnchair/util/preferences/PrefLifecycleObserver.kt
new file mode 100644
index 0000000000..ef9a38d0a0
--- /dev/null
+++ b/lawnchair/src/app/lawnchair/util/preferences/PrefLifecycleObserver.kt
@@ -0,0 +1,30 @@
+package app.lawnchair.util.preferences
+
+import androidx.lifecycle.Lifecycle
+import androidx.lifecycle.LifecycleObserver
+import androidx.lifecycle.LifecycleOwner
+import androidx.lifecycle.OnLifecycleEvent
+
+class PrefLifecycleObserver(
+ private val prefEntry: PrefEntry,
+ private val onChange: () -> Unit
+ ) : LifecycleObserver, PreferenceChangeListener {
+
+ @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
+ fun connectListener() {
+ prefEntry.addListener(this)
+ }
+
+ @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
+ fun disconnectListener() {
+ prefEntry.removeListener(this)
+ }
+
+ override fun onPreferenceChange() {
+ onChange()
+ }
+}
+
+fun PrefEntry.subscribe(lifecycleOwner: LifecycleOwner, onChange: () -> Unit) {
+ lifecycleOwner.lifecycle.addObserver(PrefLifecycleObserver(this, onChange))
+}
diff --git a/lawnchair/src/app/lawnchair/util/preferences/PreferenceManager.kt b/lawnchair/src/app/lawnchair/util/preferences/PreferenceManager.kt
index 6a09003850..0866f60e31 100644
--- a/lawnchair/src/app/lawnchair/util/preferences/PreferenceManager.kt
+++ b/lawnchair/src/app/lawnchair/util/preferences/PreferenceManager.kt
@@ -21,16 +21,13 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import app.lawnchair.LawnchairLauncher
import app.lawnchair.LawnchairLauncherQuickstep
+import app.lawnchair.launcher
import com.android.launcher3.BuildConfig
import com.android.launcher3.LauncherAppState
import com.android.launcher3.pm.UserCache
import com.android.launcher3.util.MainThreadInitializedObject
class PreferenceManager private constructor(context: Context) : BasePreferenceManager(context) {
- private val reloadApps = {
- val launcher = LauncherAppState.getInstance(context).launcher
- UserCache.INSTANCE.get(context).userProfiles.forEach { launcher.model.onPackagesReload(it) }
- }
private val reloadIcons = {
val model = LauncherAppState.getInstance(context).model
model.clearIconCache()
@@ -38,14 +35,14 @@ class PreferenceManager private constructor(context: Context) : BasePreferenceMa
}
private val scheduleRestart = {
if (BuildConfig.FLAVOR_recents == "withQuickstep") {
- LawnchairLauncherQuickstep.getLauncher(context).scheduleRestart()
+ context.launcher.scheduleRestart()
} else {
LawnchairLauncher.getLauncher(context).scheduleRestart()
}
}
private val reloadGrid = scheduleRestart
- val hiddenAppSet = StringSetPref("hidden-app-set", setOf(), reloadApps)
+ val hiddenAppSet = StringSetPref("hidden-app-set", setOf())
val iconPackPackage = StringPref("pref_iconPackPackage", "", reloadIcons)
val allowRotation = BoolPref("pref_allowRotation", true)
val wrapAdaptiveIcons = BoolPref("prefs_wrapAdaptive", false, reloadIcons)
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index cbe2e11209..dd869ee13f 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -71,6 +71,8 @@ import com.android.launcher3.views.SpringRelativeLayout;
import java.util.ArrayList;
+import app.lawnchair.allapps.LawnchairAlphabeticalAppsList;
+
/**
* The all apps view container.
*/
@@ -632,7 +634,7 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
AdapterHolder(boolean isWork) {
mIsWork = isWork;
- appsList = new AlphabeticalAppsList(mLauncher, mAllAppsStore, isWork);
+ appsList = new LawnchairAlphabeticalAppsList(mLauncher, mAllAppsStore, isWork);
adapter = new AllAppsGridAdapter(mLauncher, getLayoutInflater(), appsList);
appsList.setAdapter(adapter);
layoutManager = adapter.getLayoutManager();