Skip to content

Commit

Permalink
Merge branch 'LawnchairLauncher:14-dev' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler authored Jul 27, 2024
2 parents 755c0a0 + fb92d55 commit 4c4c5f9
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 74 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ dependencies {
implementation "androidx.compose.material:material-icons-extended"
implementation "androidx.compose.material:material"
implementation "androidx.compose.runtime:runtime-livedata"
implementation 'androidx.compose.material3:material3:1.3.0-beta04'
implementation 'androidx.compose.material3:material3:1.3.0-beta05'
implementation 'androidx.compose.material3:material3-window-size-class:1.3.0-beta05'
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
implementation "androidx.activity:activity-compose:1.9.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SearchTargetFactory(
val user = appInfo.user
return SearchTargetCompat.Builder(
SearchTargetCompat.RESULT_TYPE_APPLICATION,
if (asRow) LayoutType.ICON_HORIZONTAL_TEXT else LayoutType.ICON_SINGLE_VERTICAL_TEXT,
if (asRow) LayoutType.SMALL_ICON_HORIZONTAL_TEXT else LayoutType.ICON_SINGLE_VERTICAL_TEXT,
generateHashKey(ComponentKey(componentName, user).toString()),
).apply {
setPackageName(componentName.packageName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,17 @@ class LawnchairAppSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm(c
val searchTargets = mutableListOf<SearchTargetCompat>()

if (appResults.isNotEmpty()) {
if (appResults.size == 1) {
appResults.mapTo(searchTargets, searchTargetFactory::createAppSearchTarget)

if (appResults.size == 1 && context.isDefaultLauncher()) {
val singleAppResult = appResults.firstOrNull()
singleAppResult?.let { searchTargets.add(searchTargetFactory.createAppSearchTarget(it, true)) }
if (context.isDefaultLauncher()) {
val shortcuts = singleAppResult?.let { searchUtils.getShortcuts(it, context) }
if (shortcuts != null) {
if (shortcuts.isNotEmpty()) {
searchTargets.addAll(shortcuts.map(searchTargetFactory::createShortcutTarget))
}
val shortcuts = singleAppResult?.let { searchUtils.getShortcuts(it, context) }
if (shortcuts != null) {
singleAppResult.let { searchTargets.add(searchTargetFactory.createAppSearchTarget(it, true)) }
if (shortcuts.isNotEmpty()) {
searchTargets.addAll(shortcuts.map(searchTargetFactory::createShortcutTarget))
}
}
} else {
appResults.mapTo(searchTargets, searchTargetFactory::createAppSearchTarget)
}
searchTargets.add(searchTargetFactory.createHeaderTarget(SPACE))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,17 @@ class LawnchairLocalSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm
searchTargets: MutableList<SearchTargetCompat>,
) {
if (appResults.isNotEmpty()) {
if (appResults.size == 1) {
appResults.mapTo(searchTargets, searchTargetFactory::createAppSearchTarget)

if (appResults.size == 1 && context.isDefaultLauncher()) {
val singleAppResult = appResults.firstOrNull()
singleAppResult?.let { searchTargets.add(searchTargetFactory.createAppSearchTarget(it, true)) }
if (context.isDefaultLauncher()) {
val shortcuts = singleAppResult?.let { searchUtils.getShortcuts(it, context) }
if (shortcuts != null) {
if (shortcuts.isNotEmpty()) {
searchTargets.addAll(shortcuts.map(searchTargetFactory::createShortcutTarget))
}
val shortcuts = singleAppResult?.let { searchUtils.getShortcuts(it, context) }
if (shortcuts != null) {
singleAppResult.let { searchTargets.add(searchTargetFactory.createAppSearchTarget(it, true)) }
if (shortcuts.isNotEmpty()) {
searchTargets.addAll(shortcuts.map(searchTargetFactory::createShortcutTarget))
}
}
} else {
appResults.mapTo(searchTargets, searchTargetFactory::createAppSearchTarget)
}
searchTargets.add(searchTargetFactory.createHeaderTarget(SPACE))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ sealed class LawnchairSearchAlgorithm(

// todo make quick launch work on non-app results
if (
(target.isApp && target.layoutType == ICON_HORIZONTAL_TEXT && target.extras.getBoolean(EXTRA_QUICK_LAUNCH, false)) ||
(target.isApp && target.layoutType == SMALL_ICON_HORIZONTAL_TEXT) ||
target.isShortcut
) {
SearchAdapterItem.createAdapterItem(target, getAppBackground(index, appAndShortcutIndices))
SearchAdapterItem.createAdapterItem(target, getGroupedBackground(index, appAndShortcutIndices))
} else if (target.layoutType == ICON_SINGLE_VERTICAL_TEXT && target.extras.getBoolean(EXTRA_QUICK_LAUNCH, false)) {
SearchAdapterItem.createAdapterItem(target, normalBackground)
} else {
Expand Down Expand Up @@ -169,13 +169,6 @@ sealed class LawnchairSearchAlgorithm(
else -> centerBackground
}

private fun getAppBackground(index: Int, indices: List<Int>): SearchItemBackground = when {
indices.size == 1 -> normalBackground
index == indices.first() -> topBackground
index == indices.last() -> bottomBackground
else -> centerBackground
}

private fun getGroupedBackground(index: Int, indices: List<Int>): SearchItemBackground = when {
indices.size == 1 -> normalBackground
index == indices.first() -> topBackground
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package app.lawnchair.ui.preferences

import android.app.Activity
import android.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
Expand Down Expand Up @@ -73,12 +71,6 @@ class PreferenceActivity : AppCompatActivity() {
}
}

fun Context.findActivity(): Activity? = when (this) {
is Activity -> this
is ContextWrapper -> baseContext.findActivity()
else -> null
}

/**
* The default light scrim, as defined by androidx and the platform:
* https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:activity/activity/src/main/java/androidx/activity/EdgeToEdge.kt;l=35-38;drc=27e7d52e8604a080133e8b842db10c89b4482598
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,32 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.rounded.Launch
import androidx.compose.material.icons.rounded.Close
import androidx.compose.material.icons.rounded.NewReleases
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.SwipeToDismissBox
import androidx.compose.material3.SwipeToDismissBoxValue
import androidx.compose.material3.Text
import androidx.compose.material3.rememberSwipeToDismissBoxState
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand All @@ -40,6 +43,7 @@ import app.lawnchair.ui.preferences.data.liveinfo.liveInformationManager
import app.lawnchair.ui.preferences.data.liveinfo.model.Announcement
import app.lawnchair.ui.util.addIf
import com.android.launcher3.BuildConfig
import com.android.launcher3.R
import kotlinx.collections.immutable.ImmutableList

@Composable
Expand All @@ -66,7 +70,7 @@ fun AnnouncementPreference(
modifier = modifier,
) {
announcements.forEachIndexed { index, announcement ->
var show by remember { mutableStateOf(true) }
var show by rememberSaveable { mutableStateOf(true) }
AnnouncementItem(show, announcement) { show = false }
if (index != announcements.lastIndex && show && (!announcement.test || BuildConfig.DEBUG)) {
Spacer(modifier = Modifier.height(16.dp))
Expand Down Expand Up @@ -103,13 +107,60 @@ private fun AnnouncementItemContent(
modifier: Modifier = Modifier,
onClose: () -> Unit,
) {
Surface(
modifier = modifier
.padding(16.dp, 0.dp, 16.dp, 0.dp),
shape = MaterialTheme.shapes.large,
color = MaterialTheme.colorScheme.surfaceVariant,
val state = rememberSwipeToDismissBoxState(
confirmValueChange = {
when (it) {
SwipeToDismissBoxValue.StartToEnd -> {
onClose()
}
SwipeToDismissBoxValue.EndToStart -> return@rememberSwipeToDismissBoxState false
SwipeToDismissBoxValue.Settled -> return@rememberSwipeToDismissBoxState false
}
return@rememberSwipeToDismissBoxState true
},
)

SwipeToDismissBox(
state = state,
enableDismissFromEndToStart = false,
backgroundContent = {
Surface(
modifier = modifier
.alpha(
if (state.dismissDirection != SwipeToDismissBoxValue.StartToEnd) 1f else calculateAlpha(state.progress),
)
.fillMaxSize()
.padding(16.dp, 0.dp, 16.dp, 0.dp),
shape = MaterialTheme.shapes.large,
color = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp),
) {
PreferenceTemplate(
{},
description = {
Text(stringResource(R.string.accessibility_close))
},
)
}
},
) {
AnnouncementPreferenceItemContent(text = text, url = url, onClose = onClose)
Surface(
modifier = modifier
.alpha(
if (state.dismissDirection != SwipeToDismissBoxValue.StartToEnd) 1f else calculateAlpha(state.progress),
)
.padding(16.dp, 0.dp, 16.dp, 0.dp),
shape = MaterialTheme.shapes.large,
color = MaterialTheme.colorScheme.surfaceVariant,
) {
AnnouncementPreferenceItemContent(text = text, url = url)
}
}
}

private fun calculateAlpha(progress: Float): Float {
return when {
progress < 0.5f -> 1f // Fully opaque until halfway
else -> 1f - (progress - 0.5f) * 2 // Fade out linearly from halfway to the end
}
}

Expand All @@ -118,7 +169,6 @@ private fun AnnouncementPreferenceItemContent(
text: String,
url: String?,
modifier: Modifier = Modifier,
onClose: (() -> Unit)?,
) {
val context = LocalContext.current
val hasLink = !url.isNullOrBlank()
Expand Down Expand Up @@ -165,19 +215,6 @@ private fun AnnouncementPreferenceItemContent(
}

Spacer(modifier = Modifier.width(8.dp))

if (onClose != null) {
IconButton(
onClick = onClose,
modifier = Modifier.size(16.dp).offset(x = (8).dp, y = (-16).dp),
) {
Icon(
imageVector = Icons.Rounded.Close,
tint = MaterialTheme.colorScheme.surfaceTint,
contentDescription = null,
)
}
}
}
},
)
Expand All @@ -189,7 +226,6 @@ private fun InfoPreferenceWithoutLinkPreview() {
AnnouncementPreferenceItemContent(
text = "Very important announcement ",
url = "",
onClose = null,
)
}

Expand All @@ -199,6 +235,5 @@ private fun InfoPreferenceWithLinkPreview() {
AnnouncementPreferenceItemContent(
text = "Very important announcement with a very important link",
url = "https://lawnchair.app/",
onClose = null,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kotlinx.serialization.Serializable

@Serializable
data class LiveInformation(
private val version: Int,
private val announcements: List<Announcement>,
) {

Expand All @@ -14,6 +15,7 @@ data class LiveInformation(

companion object {
val default = LiveInformation(
version = 1,
announcements = emptyList(),
)
}
Expand Down
Loading

0 comments on commit 4c4c5f9

Please sign in to comment.