Refactor clock widget
This commit is contained in:
parent
41b9cecb95
commit
63e5c1337c
@ -72,7 +72,7 @@ fun WidgetColumn(
|
|||||||
.verticalScroll(scrollState)
|
.verticalScroll(scrollState)
|
||||||
.navigationBarsPadding()
|
.navigationBarsPadding()
|
||||||
) {
|
) {
|
||||||
ClockWidget(transparentBackground = background > 0.75f)
|
ClockWidget()
|
||||||
|
|
||||||
AnimatedVisibility(visible = scrollState.value == 0) {
|
AnimatedVisibility(visible = scrollState.value == 0) {
|
||||||
NavBarSpacer()
|
NavBarSpacer()
|
||||||
|
|||||||
@ -29,26 +29,20 @@ import kotlinx.coroutines.flow.map
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ClockWidget(
|
fun ClockWidget(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier
|
||||||
transparentBackground: Boolean
|
|
||||||
) {
|
) {
|
||||||
val windowHeight = LocalWindowSize.current.height
|
|
||||||
val insets = LocalWindowInsets.current
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth(),
|
.fillMaxWidth(),
|
||||||
contentAlignment = Alignment.BottomCenter
|
contentAlignment = Alignment.BottomCenter
|
||||||
) {
|
) {
|
||||||
val contentColor by animateColorAsState(
|
|
||||||
if (transparentBackground) Color.White else MaterialTheme.colorScheme.onSurface
|
|
||||||
)
|
|
||||||
|
|
||||||
CompositionLocalProvider(LocalContentColor provides contentColor) {
|
CompositionLocalProvider(LocalContentColor provides Color.White) {
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
modifier = Modifier.height(IntrinsicSize.Min)
|
modifier = Modifier.height(IntrinsicSize.Min)
|
||||||
) {
|
) {
|
||||||
Clock(transparentBackground)
|
Clock()
|
||||||
|
|
||||||
DynamicZone()
|
DynamicZone()
|
||||||
}
|
}
|
||||||
@ -58,7 +52,7 @@ fun ClockWidget(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun Clock(transparentBackground: Boolean) {
|
fun Clock() {
|
||||||
var time by remember { mutableStateOf(System.currentTimeMillis()) }
|
var time by remember { mutableStateOf(System.currentTimeMillis()) }
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val dataStore = context.dataStore
|
val dataStore = context.dataStore
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
package de.mm20.launcher2.ui.launcher.widgets.clock
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
|
||||||
|
class ClockWidgetVM: ViewModel() {
|
||||||
|
}
|
||||||
@ -274,13 +274,11 @@ class LauncherActivity : AppCompatActivity() {
|
|||||||
binding.searchBar.raise()
|
binding.searchBar.raise()
|
||||||
} else binding.searchBar.drop()
|
} else binding.searchBar.drop()
|
||||||
if (scrollY == 0) {
|
if (scrollY == 0) {
|
||||||
binding.clockWidget.transparentBackground = true
|
|
||||||
if (!searchVisibility) {
|
if (!searchVisibility) {
|
||||||
binding.searchBar.hide()
|
binding.searchBar.hide()
|
||||||
windowBackgroundBlur = false
|
windowBackgroundBlur = false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
binding.clockWidget.transparentBackground = false
|
|
||||||
binding.searchBar.show()
|
binding.searchBar.show()
|
||||||
if (!searchVisibility) {
|
if (!searchVisibility) {
|
||||||
windowBackgroundBlur = true
|
windowBackgroundBlur = true
|
||||||
|
|||||||
@ -1,33 +1,12 @@
|
|||||||
package de.mm20.launcher2.ui.legacy.widget
|
package de.mm20.launcher2.ui.legacy.widget
|
||||||
|
|
||||||
import android.animation.AnimatorSet
|
|
||||||
import android.animation.LayoutTransition
|
import android.animation.LayoutTransition
|
||||||
import android.animation.ObjectAnimator
|
|
||||||
import android.content.ContentUris
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
|
||||||
import android.graphics.Color
|
|
||||||
import android.provider.CalendarContract
|
|
||||||
import android.text.format.DateFormat
|
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.util.TypedValue
|
|
||||||
import android.view.animation.AccelerateInterpolator
|
|
||||||
import android.view.animation.DecelerateInterpolator
|
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import android.widget.TextClock
|
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.livedata.observeAsState
|
|
||||||
import androidx.compose.ui.platform.ComposeView
|
import androidx.compose.ui.platform.ComposeView
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
|
||||||
import de.mm20.launcher2.ktx.dp
|
|
||||||
import de.mm20.launcher2.legacy.helper.ActivityStarter
|
|
||||||
import de.mm20.launcher2.preferences.LauncherPreferences
|
|
||||||
import de.mm20.launcher2.ui.ClockWidget
|
import de.mm20.launcher2.ui.ClockWidget
|
||||||
import de.mm20.launcher2.ui.LegacyLauncherTheme
|
import de.mm20.launcher2.ui.LegacyLauncherTheme
|
||||||
import de.mm20.launcher2.ui.R
|
|
||||||
import de.mm20.launcher2.ui.legacy.view.LauncherCardView
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class ClockWidget : FrameLayout {
|
class ClockWidget : FrameLayout {
|
||||||
|
|
||||||
@ -55,15 +34,10 @@ class ClockWidget : FrameLayout {
|
|||||||
|
|
||||||
|
|
||||||
composeView.setContent {
|
composeView.setContent {
|
||||||
val transparentBg by transparentBackgroundState.observeAsState(true)
|
|
||||||
LegacyLauncherTheme {
|
LegacyLauncherTheme {
|
||||||
ClockWidget(transparentBackground = transparentBg)
|
ClockWidget()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val transparentBackgroundState = MutableLiveData<Boolean>()
|
|
||||||
|
|
||||||
var transparentBackground: Boolean = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user