Refactor clock widget
This commit is contained in:
parent
41b9cecb95
commit
63e5c1337c
@ -72,7 +72,7 @@ fun WidgetColumn(
|
||||
.verticalScroll(scrollState)
|
||||
.navigationBarsPadding()
|
||||
) {
|
||||
ClockWidget(transparentBackground = background > 0.75f)
|
||||
ClockWidget()
|
||||
|
||||
AnimatedVisibility(visible = scrollState.value == 0) {
|
||||
NavBarSpacer()
|
||||
|
||||
@ -29,26 +29,20 @@ import kotlinx.coroutines.flow.map
|
||||
|
||||
@Composable
|
||||
fun ClockWidget(
|
||||
modifier: Modifier = Modifier,
|
||||
transparentBackground: Boolean
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val windowHeight = LocalWindowSize.current.height
|
||||
val insets = LocalWindowInsets.current
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth(),
|
||||
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(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier.height(IntrinsicSize.Min)
|
||||
) {
|
||||
Clock(transparentBackground)
|
||||
Clock()
|
||||
|
||||
DynamicZone()
|
||||
}
|
||||
@ -58,7 +52,7 @@ fun ClockWidget(
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Clock(transparentBackground: Boolean) {
|
||||
fun Clock() {
|
||||
var time by remember { mutableStateOf(System.currentTimeMillis()) }
|
||||
val context = LocalContext.current
|
||||
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()
|
||||
} else binding.searchBar.drop()
|
||||
if (scrollY == 0) {
|
||||
binding.clockWidget.transparentBackground = true
|
||||
if (!searchVisibility) {
|
||||
binding.searchBar.hide()
|
||||
windowBackgroundBlur = false
|
||||
}
|
||||
} else {
|
||||
binding.clockWidget.transparentBackground = false
|
||||
binding.searchBar.show()
|
||||
if (!searchVisibility) {
|
||||
windowBackgroundBlur = true
|
||||
|
||||
@ -1,33 +1,12 @@
|
||||
package de.mm20.launcher2.ui.legacy.widget
|
||||
|
||||
import android.animation.AnimatorSet
|
||||
import android.animation.LayoutTransition
|
||||
import android.animation.ObjectAnimator
|
||||
import android.content.ContentUris
|
||||
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.TypedValue
|
||||
import android.view.animation.AccelerateInterpolator
|
||||
import android.view.animation.DecelerateInterpolator
|
||||
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.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.LegacyLauncherTheme
|
||||
import de.mm20.launcher2.ui.R
|
||||
import de.mm20.launcher2.ui.legacy.view.LauncherCardView
|
||||
import java.util.*
|
||||
|
||||
class ClockWidget : FrameLayout {
|
||||
|
||||
@ -55,15 +34,10 @@ class ClockWidget : FrameLayout {
|
||||
|
||||
|
||||
composeView.setContent {
|
||||
val transparentBg by transparentBackgroundState.observeAsState(true)
|
||||
LegacyLauncherTheme {
|
||||
ClockWidget(transparentBackground = transparentBg)
|
||||
ClockWidget()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val transparentBackgroundState = MutableLiveData<Boolean>()
|
||||
|
||||
var transparentBackground: Boolean = true
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user