Optimise code, update copyright headers
This commit is contained in:
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -12,14 +28,10 @@ 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?): Boolean {
|
||||
if (!super.shouldShowApp(app, user)) {
|
||||
return false
|
||||
override fun shouldShowApp(app: ComponentName, user: UserHandle?) =
|
||||
when {
|
||||
!super.shouldShowApp(app, user) -> false
|
||||
customHideList.contains(ComponentKey(app, user).toString()) -> false
|
||||
else -> true
|
||||
}
|
||||
val key = ComponentKey(app, user)
|
||||
if (customHideList.contains(key.toString())) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,15 +21,12 @@ import androidx.compose.animation.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.navigation.NavGraphBuilder
|
||||
import app.lawnchair.ui.preferences.components.NavigationActionPreference
|
||||
import app.lawnchair.ui.preferences.components.NotificationDotsPreference
|
||||
import app.lawnchair.ui.preferences.components.PreferenceGroup
|
||||
import app.lawnchair.ui.preferences.components.PreferenceLayout
|
||||
import app.lawnchair.ui.preferences.components.SliderPreference
|
||||
import app.lawnchair.ui.preferences.components.SwitchPreference
|
||||
import app.lawnchair.ui.preferences.components.*
|
||||
import app.lawnchair.util.Meta
|
||||
import app.lawnchair.util.pageMeta
|
||||
import app.lawnchair.util.preferences.*
|
||||
import app.lawnchair.util.preferences.getAdapter
|
||||
import app.lawnchair.util.preferences.observeAsState
|
||||
import app.lawnchair.util.preferences.preferenceManager
|
||||
import com.android.launcher3.R
|
||||
|
||||
object GeneralRoutes {
|
||||
|
||||
@@ -1,10 +1,25 @@
|
||||
/*
|
||||
* 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.ui.preferences
|
||||
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.navigation.NavGraphBuilder
|
||||
import app.lawnchair.DefaultAppFilter
|
||||
@@ -29,7 +44,7 @@ fun NavGraphBuilder.hiddenAppsGraph(route: String) {
|
||||
@Composable
|
||||
fun HiddenAppsPreferences() {
|
||||
val pageTitle =
|
||||
with (hiddenAppsCount()) {
|
||||
with(hiddenAppsCount()) {
|
||||
if (this == 0) {
|
||||
stringResource(id = R.string.hidden_apps_label)
|
||||
} else {
|
||||
|
||||
@@ -23,7 +23,10 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import androidx.navigation.NavGraphBuilder
|
||||
import app.lawnchair.ui.preferences.components.*
|
||||
import app.lawnchair.ui.preferences.components.AnimatedCheck
|
||||
import app.lawnchair.ui.preferences.components.AppItem
|
||||
import app.lawnchair.ui.preferences.components.PreferenceLayoutLazyColumn
|
||||
import app.lawnchair.ui.preferences.components.preferenceGroupItems
|
||||
import app.lawnchair.util.Meta
|
||||
import app.lawnchair.util.pageMeta
|
||||
import app.lawnchair.util.preferences.getAdapter
|
||||
|
||||
@@ -1,7 +1,26 @@
|
||||
/*
|
||||
* 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.ui.preferences.components
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import androidx.compose.animation.*
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* 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.ui.preferences.components
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* 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.ui.preferences.components
|
||||
|
||||
import androidx.compose.animation.Crossfade
|
||||
|
||||
@@ -23,7 +23,6 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.compose.navigate
|
||||
import app.lawnchair.ui.preferences.LocalNavController
|
||||
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* 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.ui.preferences.components
|
||||
|
||||
import androidx.compose.runtime.*
|
||||
|
||||
@@ -29,7 +29,12 @@ import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
fun PreferenceCategoryListItem(label: String, description: String, @DrawableRes iconResource: Int, onClick: () -> Unit) {
|
||||
fun PreferenceCategoryListItem(
|
||||
label: String,
|
||||
description: String,
|
||||
@DrawableRes iconResource: Int,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.clickable(onClick = onClick)
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* 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.ui.preferences.components
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
|
||||
@@ -46,7 +46,11 @@ fun SliderPreference(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(text = label, style = MaterialTheme.typography.subtitle1, color = MaterialTheme.colors.onBackground)
|
||||
Text(
|
||||
text = label,
|
||||
style = MaterialTheme.typography.subtitle1,
|
||||
color = MaterialTheme.colors.onBackground
|
||||
)
|
||||
CompositionLocalProvider(
|
||||
LocalContentAlpha provides ContentAlpha.medium,
|
||||
LocalContentColor provides MaterialTheme.colors.onBackground
|
||||
|
||||
@@ -10,7 +10,7 @@ import androidx.navigation.compose.navigation
|
||||
inline fun NavGraphBuilder.preferenceGraph(
|
||||
route: String,
|
||||
crossinline root: @Composable () -> Unit,
|
||||
crossinline block: NavGraphBuilder.(subRoute: (String) -> String) -> Unit = { }
|
||||
crossinline block: NavGraphBuilder.(subRoute: (String) -> String) -> Unit = { }
|
||||
) {
|
||||
val subRoute: (String) -> String = { name -> "$route/$name" }
|
||||
val rootRoute = subRoute("root")
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.util.concurrent.ExecutionException
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
|
||||
fun <T, A>ensureOnMainThread(creator: (A) -> T): (A) -> T {
|
||||
fun <T, A> ensureOnMainThread(creator: (A) -> T): (A) -> T {
|
||||
return { it ->
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
creator(it)
|
||||
@@ -47,7 +47,7 @@ fun <T, A>ensureOnMainThread(creator: (A) -> T): (A) -> T {
|
||||
}
|
||||
}
|
||||
|
||||
fun <T>useApplicationContext(creator: (Context) -> T): (Context) -> T {
|
||||
fun <T> useApplicationContext(creator: (Context) -> T): (Context) -> T {
|
||||
return { it -> creator(it.applicationContext) }
|
||||
}
|
||||
|
||||
|
||||
@@ -202,14 +202,21 @@ fun Modifier.smartBorder(
|
||||
fun cutOutline(outline: Outline, height: Float, cutTop: Boolean, cutBottom: Boolean): Outline {
|
||||
if (!cutTop && !cutBottom) return outline
|
||||
return when (outline) {
|
||||
is Outline.Rectangle -> Outline.Rounded(RoundRect(cutRect(outline.rect, height, cutTop, cutBottom), CornerRadius.Zero))
|
||||
is Outline.Rounded -> Outline.Rounded(RoundRect(
|
||||
cutRect(outline.roundRect.boundingRect, height, cutTop, cutBottom),
|
||||
outline.roundRect.topLeftCornerRadius,
|
||||
outline.roundRect.topRightCornerRadius,
|
||||
outline.roundRect.bottomLeftCornerRadius,
|
||||
outline.roundRect.bottomRightCornerRadius,
|
||||
))
|
||||
is Outline.Rectangle -> Outline.Rounded(
|
||||
RoundRect(
|
||||
cutRect(outline.rect, height, cutTop, cutBottom),
|
||||
CornerRadius.Zero
|
||||
)
|
||||
)
|
||||
is Outline.Rounded -> Outline.Rounded(
|
||||
RoundRect(
|
||||
cutRect(outline.roundRect.boundingRect, height, cutTop, cutBottom),
|
||||
outline.roundRect.topLeftCornerRadius,
|
||||
outline.roundRect.topRightCornerRadius,
|
||||
outline.roundRect.bottomLeftCornerRadius,
|
||||
outline.roundRect.bottomRightCornerRadius,
|
||||
)
|
||||
)
|
||||
else -> outline
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* 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.util
|
||||
|
||||
import android.content.Context
|
||||
@@ -9,7 +25,6 @@ import android.graphics.drawable.Drawable
|
||||
import android.os.Handler
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import app.lawnchair.DefaultAppFilter
|
||||
import com.android.launcher3.AppFilter
|
||||
import com.android.launcher3.LauncherAppState
|
||||
import com.android.launcher3.Utilities
|
||||
@@ -23,7 +38,10 @@ import java.util.Comparator.comparing
|
||||
private val appFilter = AppFilter()
|
||||
|
||||
@Composable
|
||||
fun appsList(filter: AppFilter = appFilter, comparator: Comparator<App> = defaultComparator): State<Optional<List<App>>> {
|
||||
fun appsList(
|
||||
filter: AppFilter = appFilter,
|
||||
comparator: Comparator<App> = defaultComparator
|
||||
): State<Optional<List<App>>> {
|
||||
val context = LocalContext.current
|
||||
val appsState = remember { mutableStateOf(Optional.empty<List<App>>()) }
|
||||
DisposableEffect(Unit) {
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package app.lawnchair.util
|
||||
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
|
||||
class PropsContainer<P>(var props: P)
|
||||
|
||||
class SideEffect<S, P>(
|
||||
val consume: @Composable (@Composable (S) -> Unit) -> Unit,
|
||||
val provide: @Composable (P) -> Unit)
|
||||
val provide: @Composable (P) -> Unit
|
||||
)
|
||||
|
||||
inline fun <S, P> createSideEffect(crossinline reducePropsToState: (List<P>) -> S): SideEffect<S, P> {
|
||||
val mountedInstances = mutableListOf<PropsContainer<P>>()
|
||||
|
||||
@@ -1,14 +1,29 @@
|
||||
/*
|
||||
* 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.util
|
||||
|
||||
class MetaState(val title: String, val topBarFloating: Boolean)
|
||||
class Meta(val title: String? = null, val topBarFloating: Boolean? = null)
|
||||
|
||||
private fun <T> getFromPropsList(propsList: List<Meta>, defaultValue: T, extractor: (meta: Meta) -> T?): T {
|
||||
return propsList
|
||||
private fun <T> getFromPropsList(propsList: List<Meta>, defaultValue: T, extractor: (meta: Meta) -> T?): T =
|
||||
propsList
|
||||
.asSequence()
|
||||
.map(extractor)
|
||||
.lastOrNull { it != null } ?: defaultValue
|
||||
}
|
||||
|
||||
val pageMeta = createSideEffect<MetaState, Meta> { propsList ->
|
||||
MetaState(
|
||||
|
||||
@@ -1,10 +1,25 @@
|
||||
/*
|
||||
* 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.util.preferences
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import com.android.launcher3.InvariantDeviceProfile
|
||||
import com.android.launcher3.Utilities
|
||||
import java.lang.ClassCastException
|
||||
import java.util.*
|
||||
import kotlin.collections.HashMap
|
||||
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* 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.util.preferences
|
||||
|
||||
import androidx.compose.runtime.*
|
||||
|
||||
@@ -17,14 +17,12 @@
|
||||
package app.lawnchair.util.preferences
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import app.lawnchair.LawnchairLauncher
|
||||
import app.lawnchair.LawnchairLauncherQuickstep
|
||||
import com.android.launcher3.BuildConfig
|
||||
import com.android.launcher3.LauncherAppState
|
||||
import com.android.launcher3.Utilities
|
||||
import com.android.launcher3.pm.UserCache
|
||||
import com.android.launcher3.util.MainThreadInitializedObject
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
* 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.
|
||||
*
|
||||
* Modifications copyright 2021, Lawnchair
|
||||
*/
|
||||
|
||||
package com.android.launcher3.model;
|
||||
|
||||
Reference in New Issue
Block a user