Rename HomeTransition and related classes to EnterHomeTransition

This commit is contained in:
MM20 2023-03-03 17:13:21 +01:00
parent f534458680
commit ea08584656
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
8 changed files with 32 additions and 47 deletions

View File

@ -9,7 +9,7 @@ class LauncherActivity: SharedLauncherActivity(LauncherActivityMode.Launcher) {
super.onNewIntent(intent) super.onNewIntent(intent)
val navContract = intent?.let { GestureNavContract.fromIntent(it) } val navContract = intent?.let { GestureNavContract.fromIntent(it) }
if (navContract != null) { if (navContract != null) {
homeTransitionManager.resolve(navContract, window) enterHomeTransitionManager.resolve(navContract, window)
} else { } else {
onBackPressed() onBackPressed()
} }
@ -17,7 +17,7 @@ class LauncherActivity: SharedLauncherActivity(LauncherActivityMode.Launcher) {
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
homeTransitionManager.clear() enterHomeTransitionManager.clear()
} }
override fun onBackPressed() { override fun onBackPressed() {

View File

@ -5,11 +5,9 @@ import android.content.pm.ActivityInfo
import android.content.res.Configuration import android.content.res.Configuration
import android.content.res.Resources import android.content.res.Resources
import android.os.Bundle import android.os.Bundle
import android.util.Log
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.imePadding import androidx.compose.foundation.layout.imePadding
@ -32,15 +30,11 @@ import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.TransformOrigin import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.unit.dp
import androidx.core.view.WindowCompat import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsControllerCompat import androidx.core.view.WindowInsetsControllerCompat
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import androidx.lifecycle.Observer
import androidx.lifecycle.flowWithLifecycle import androidx.lifecycle.flowWithLifecycle
import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.google.accompanist.systemuicontroller.rememberSystemUiController
import de.mm20.launcher2.globalactions.GlobalActionsService
import de.mm20.launcher2.preferences.Settings import de.mm20.launcher2.preferences.Settings
import de.mm20.launcher2.preferences.Settings.SystemBarsSettings.SystemBarColors import de.mm20.launcher2.preferences.Settings.SystemBarsSettings.SystemBarColors
import de.mm20.launcher2.ui.assistant.AssistantScaffold import de.mm20.launcher2.ui.assistant.AssistantScaffold
@ -48,29 +42,23 @@ import de.mm20.launcher2.ui.base.BaseActivity
import de.mm20.launcher2.ui.base.ProvideCurrentTime import de.mm20.launcher2.ui.base.ProvideCurrentTime
import de.mm20.launcher2.ui.base.ProvideSettings import de.mm20.launcher2.ui.base.ProvideSettings
import de.mm20.launcher2.ui.component.NavBarEffects import de.mm20.launcher2.ui.component.NavBarEffects
import de.mm20.launcher2.ui.gestures.Gesture
import de.mm20.launcher2.ui.gestures.GestureDetector import de.mm20.launcher2.ui.gestures.GestureDetector
import de.mm20.launcher2.ui.gestures.GestureHandler
import de.mm20.launcher2.ui.gestures.LocalGestureDetector import de.mm20.launcher2.ui.gestures.LocalGestureDetector
import de.mm20.launcher2.ui.ktx.animateTo import de.mm20.launcher2.ui.ktx.animateTo
import de.mm20.launcher2.ui.ktx.toPixels
import de.mm20.launcher2.ui.launcher.gestures.LauncherGestureHandler import de.mm20.launcher2.ui.launcher.gestures.LauncherGestureHandler
import de.mm20.launcher2.ui.launcher.search.SearchVM import de.mm20.launcher2.ui.launcher.search.SearchVM
import de.mm20.launcher2.ui.launcher.sheets.FailedGestureSheet
import de.mm20.launcher2.ui.launcher.sheets.LauncherBottomSheets import de.mm20.launcher2.ui.launcher.sheets.LauncherBottomSheets
import de.mm20.launcher2.ui.launcher.sheets.LauncherBottomSheetManager import de.mm20.launcher2.ui.launcher.sheets.LauncherBottomSheetManager
import de.mm20.launcher2.ui.launcher.sheets.LocalBottomSheetManager import de.mm20.launcher2.ui.launcher.sheets.LocalBottomSheetManager
import de.mm20.launcher2.ui.launcher.transitions.HomeTransition import de.mm20.launcher2.ui.launcher.transitions.EnterHomeTransition
import de.mm20.launcher2.ui.launcher.transitions.HomeTransitionManager import de.mm20.launcher2.ui.launcher.transitions.EnterHomeTransitionManager
import de.mm20.launcher2.ui.launcher.transitions.LocalHomeTransitionManager import de.mm20.launcher2.ui.launcher.transitions.LocalEnterHomeTransitionManager
import de.mm20.launcher2.ui.locals.LocalPreferDarkContentOverWallpaper import de.mm20.launcher2.ui.locals.LocalPreferDarkContentOverWallpaper
import de.mm20.launcher2.ui.locals.LocalSnackbarHostState import de.mm20.launcher2.ui.locals.LocalSnackbarHostState
import de.mm20.launcher2.ui.locals.LocalWallpaperColors import de.mm20.launcher2.ui.locals.LocalWallpaperColors
import de.mm20.launcher2.ui.locals.LocalWindowSize import de.mm20.launcher2.ui.locals.LocalWindowSize
import de.mm20.launcher2.ui.theme.LauncherTheme import de.mm20.launcher2.ui.theme.LauncherTheme
import de.mm20.launcher2.ui.theme.wallpaperColorsAsState import de.mm20.launcher2.ui.theme.wallpaperColorsAsState
import org.koin.android.ext.android.inject
import kotlin.math.absoluteValue
import kotlin.math.pow import kotlin.math.pow
@ -81,7 +69,7 @@ abstract class SharedLauncherActivity(
private val viewModel: LauncherScaffoldVM by viewModels() private val viewModel: LauncherScaffoldVM by viewModels()
private val searchVM: SearchVM by viewModels() private val searchVM: SearchVM by viewModels()
internal val homeTransitionManager = HomeTransitionManager() internal val enterHomeTransitionManager = EnterHomeTransitionManager()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -104,7 +92,7 @@ abstract class SharedLauncherActivity(
val wallpaperColors by wallpaperColorsAsState() val wallpaperColors by wallpaperColorsAsState()
val dimBackground by viewModel.dimBackground.observeAsState(false) val dimBackground by viewModel.dimBackground.observeAsState(false)
CompositionLocalProvider( CompositionLocalProvider(
LocalHomeTransitionManager provides homeTransitionManager, LocalEnterHomeTransitionManager provides enterHomeTransitionManager,
LocalWindowSize provides windowSize, LocalWindowSize provides windowSize,
LocalSnackbarHostState provides snackbarHostState, LocalSnackbarHostState provides snackbarHostState,
LocalWallpaperColors provides wallpaperColors, LocalWallpaperColors provides wallpaperColors,
@ -145,13 +133,13 @@ abstract class SharedLauncherActivity(
val enterTransitionProgress = remember { mutableStateOf(1f) } val enterTransitionProgress = remember { mutableStateOf(1f) }
var enterTransition by remember { var enterTransition by remember {
mutableStateOf<HomeTransition?>( mutableStateOf<EnterHomeTransition?>(
null null
) )
} }
LaunchedEffect(null) { LaunchedEffect(null) {
homeTransitionManager enterHomeTransitionManager
.currentTransition .currentTransition
.flowWithLifecycle(lifecycle, Lifecycle.State.RESUMED) .flowWithLifecycle(lifecycle, Lifecycle.State.RESUMED)
.collect { .collect {

View File

@ -4,7 +4,6 @@ import android.content.ComponentName
import androidx.activity.compose.BackHandler import androidx.activity.compose.BackHandler
import androidx.compose.animation.core.animateFloatAsState import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.border import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
@ -25,7 +24,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Rect import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.hapticfeedback.HapticFeedbackType import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.layout.boundsInWindow import androidx.compose.ui.layout.boundsInWindow
import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.layout.onGloballyPositioned
@ -33,7 +31,6 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalHapticFeedback import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Popup import androidx.compose.ui.window.Popup
@ -59,8 +56,8 @@ import de.mm20.launcher2.ui.launcher.search.files.FileItemGridPopup
import de.mm20.launcher2.ui.launcher.search.shortcut.ShortcutItemGridPopup import de.mm20.launcher2.ui.launcher.search.shortcut.ShortcutItemGridPopup
import de.mm20.launcher2.ui.launcher.search.website.WebsiteItemGridPopup import de.mm20.launcher2.ui.launcher.search.website.WebsiteItemGridPopup
import de.mm20.launcher2.ui.launcher.search.wikipedia.WikipediaItemGridPopup import de.mm20.launcher2.ui.launcher.search.wikipedia.WikipediaItemGridPopup
import de.mm20.launcher2.ui.launcher.transitions.HandleHomeTransition import de.mm20.launcher2.ui.launcher.transitions.HandleEnterHomeTransition
import de.mm20.launcher2.ui.launcher.transitions.HomeTransitionParams import de.mm20.launcher2.ui.launcher.transitions.EnterHomeTransitionParams
import de.mm20.launcher2.ui.locals.LocalGridSettings import de.mm20.launcher2.ui.locals.LocalGridSettings
import de.mm20.launcher2.ui.locals.LocalWindowPosition import de.mm20.launcher2.ui.locals.LocalWindowPosition
import de.mm20.launcher2.ui.locals.LocalWindowSize import de.mm20.launcher2.ui.locals.LocalWindowSize
@ -91,14 +88,14 @@ fun GridItem(
val windowSize = LocalWindowSize.current val windowSize = LocalWindowSize.current
if (item is LauncherApp) { if (item is LauncherApp) {
HandleHomeTransition { HandleEnterHomeTransition {
val cn = ComponentName(item.`package`, item.activity) val cn = ComponentName(item.`package`, item.activity)
if ( if (
it.componentName == cn && it.componentName == cn &&
bounds.right > 0f && bounds.left < windowSize.width && bounds.right > 0f && bounds.left < windowSize.width &&
bounds.bottom > 0f && bounds.top < windowSize.height bounds.bottom > 0f && bounds.top < windowSize.height
) { ) {
return@HandleHomeTransition HomeTransitionParams( return@HandleEnterHomeTransition EnterHomeTransitionParams(
bounds bounds
) { _, _ -> ) { _, _ ->
ShapedLauncherIcon( ShapedLauncherIcon(
@ -106,7 +103,7 @@ fun GridItem(
icon = { icon }) icon = { icon })
} }
} }
return@HandleHomeTransition null return@HandleEnterHomeTransition null
} }
} }

View File

@ -4,7 +4,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect import androidx.compose.ui.geometry.Rect
data class HomeTransition( data class EnterHomeTransition(
val startBounds: Rect, val startBounds: Rect,
val targetBounds: Rect, val targetBounds: Rect,
val icon: (@Composable (animVector: Offset, progress: () -> Float) -> Unit)? = null val icon: (@Composable (animVector: Offset, progress: () -> Float) -> Unit)? = null

View File

@ -4,13 +4,13 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.DisposableEffect
import com.android.launcher3.GestureNavContract import com.android.launcher3.GestureNavContract
fun interface HomeTransitionHandler { fun interface EnterHomeTransitionHandler {
fun handle(gestureNavContract: GestureNavContract): HomeTransitionParams? fun handle(gestureNavContract: GestureNavContract): EnterHomeTransitionParams?
} }
@Composable @Composable
fun HandleHomeTransition(handler: HomeTransitionHandler) { fun HandleEnterHomeTransition(handler: EnterHomeTransitionHandler) {
val transitionManager = LocalHomeTransitionManager.current val transitionManager = LocalEnterHomeTransitionManager.current
DisposableEffect(null) { DisposableEffect(null) {
transitionManager?.registerHandler(handler) transitionManager?.registerHandler(handler)

View File

@ -9,11 +9,11 @@ import androidx.compose.ui.graphics.toAndroidRectF
import com.android.launcher3.GestureNavContract import com.android.launcher3.GestureNavContract
import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableSharedFlow
class HomeTransitionManager { class EnterHomeTransitionManager {
val currentTransition = MutableSharedFlow<HomeTransition?>(1) val currentTransition = MutableSharedFlow<EnterHomeTransition?>(1)
private val handlers = mutableSetOf<HomeTransitionHandler>() private val handlers = mutableSetOf<EnterHomeTransitionHandler>()
fun resolve(gestureNavContract: GestureNavContract, window: Window) { fun resolve(gestureNavContract: GestureNavContract, window: Window) {
for (handler in handlers) { for (handler in handlers) {
@ -22,7 +22,7 @@ class HomeTransitionManager {
val startRect = Rect(Offset(0f, 0f), Size(window.decorView.width.toFloat(), window.decorView.height.toFloat())) val startRect = Rect(Offset(0f, 0f), Size(window.decorView.width.toFloat(), window.decorView.height.toFloat()))
val targetBounds = result.targetBounds val targetBounds = result.targetBounds
gestureNavContract.sendEndPosition(targetBounds.toAndroidRectF()) gestureNavContract.sendEndPosition(targetBounds.toAndroidRectF())
currentTransition.tryEmit(HomeTransition( currentTransition.tryEmit(EnterHomeTransition(
startBounds = startRect, startBounds = startRect,
icon = result.icon, icon = result.icon,
targetBounds = targetBounds, targetBounds = targetBounds,
@ -37,13 +37,13 @@ class HomeTransitionManager {
currentTransition.tryEmit(null) currentTransition.tryEmit(null)
} }
fun registerHandler(handler: HomeTransitionHandler) { fun registerHandler(handler: EnterHomeTransitionHandler) {
handlers.add(handler) handlers.add(handler)
} }
fun unregisterHandler(handler: HomeTransitionHandler) { fun unregisterHandler(handler: EnterHomeTransitionHandler) {
handlers.remove(handler) handlers.remove(handler)
} }
} }
val LocalHomeTransitionManager = compositionLocalOf<HomeTransitionManager?> { null } val LocalEnterHomeTransitionManager = compositionLocalOf<EnterHomeTransitionManager?> { null }

View File

@ -6,7 +6,7 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect import androidx.compose.ui.geometry.Rect
@Stable @Stable
data class HomeTransitionParams( data class EnterHomeTransitionParams(
val targetBounds: Rect, val targetBounds: Rect,
val icon: (@Composable (animVector: Offset, progress: () -> Float) -> Unit)? = null val icon: (@Composable (animVector: Offset, progress: () -> Float) -> Unit)? = null
) )

View File

@ -72,8 +72,8 @@ import de.mm20.launcher2.music.SupportedActions
import de.mm20.launcher2.ui.R import de.mm20.launcher2.ui.R
import de.mm20.launcher2.ui.component.MissingPermissionBanner import de.mm20.launcher2.ui.component.MissingPermissionBanner
import de.mm20.launcher2.ui.ktx.conditional import de.mm20.launcher2.ui.ktx.conditional
import de.mm20.launcher2.ui.launcher.transitions.HandleHomeTransition import de.mm20.launcher2.ui.launcher.transitions.HandleEnterHomeTransition
import de.mm20.launcher2.ui.launcher.transitions.HomeTransitionParams import de.mm20.launcher2.ui.launcher.transitions.EnterHomeTransitionParams
import de.mm20.launcher2.ui.locals.LocalCardStyle import de.mm20.launcher2.ui.locals.LocalCardStyle
import de.mm20.launcher2.ui.locals.LocalWindowSize import de.mm20.launcher2.ui.locals.LocalWindowSize
import kotlin.math.min import kotlin.math.min
@ -250,13 +250,13 @@ fun MusicWidget() {
contentDescription = null, contentDescription = null,
contentScale = ContentScale.Crop contentScale = ContentScale.Crop
) )
HandleHomeTransition { HandleEnterHomeTransition {
if ( if (
it.componentName.packageName == viewModel.currentPlayerPackage && it.componentName.packageName == viewModel.currentPlayerPackage &&
bounds.right > 0f && bounds.left < windowSize.width && bounds.right > 0f && bounds.left < windowSize.width &&
bounds.bottom > 0f && bounds.top < windowSize.height bounds.bottom > 0f && bounds.top < windowSize.height
) { ) {
return@HandleHomeTransition HomeTransitionParams( return@HandleEnterHomeTransition EnterHomeTransitionParams(
bounds bounds
) { _, _ -> ) { _, _ ->
val shape = MaterialTheme.shapes.small val shape = MaterialTheme.shapes.small
@ -270,7 +270,7 @@ fun MusicWidget() {
) )
} }
} }
return@HandleHomeTransition null return@HandleEnterHomeTransition null
} }
} }
} else { } else {