Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Date picker and time picker color by theme (#3558)
Browse files Browse the repository at this point in the history
* Fix legacy and m3 theme arrangement for pickers

* Add new color for pickers with the theme

* Fix condition of theme value

* Fix theme wrapper

* Fix issue of edge to edge

* Fix scrolling down color line
  • Loading branch information
oguzsout authored Sep 25, 2024
1 parent f65fde2 commit 4aec53f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 37 deletions.
55 changes: 34 additions & 21 deletions app/src/main/java/com/ivy/wallet/RootActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ import com.google.android.material.timepicker.MaterialTimePicker
import com.google.android.material.timepicker.TimeFormat
import com.google.android.play.core.review.ReviewManagerFactory
import com.ivy.IvyNavGraph
import com.ivy.base.legacy.Theme
import com.ivy.base.time.TimeConverter
import com.ivy.base.time.TimeProvider
import com.ivy.design.api.IvyDesign
import com.ivy.design.api.IvyUI
import com.ivy.design.system.IvyMaterial3Theme
import com.ivy.domain.RootScreen
import com.ivy.home.customerjourney.CustomerJourneyCardsProvider
import com.ivy.legacy.Constants
Expand Down Expand Up @@ -88,26 +91,11 @@ class RootActivity : AppCompatActivity(), RootScreen {

private val viewModel: RootViewModel by viewModels()

@OptIn(
ExperimentalAnimationApi::class,
ExperimentalFoundationApi::class
)
@OptIn(ExperimentalFoundationApi::class, ExperimentalAnimationApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)

setupActivityForResultLaunchers()

// Make the app drawing area fullscreen (draw behind status and nav bars)
WindowCompat.setDecorFitsSystemWindows(window, false)

setupDatePicker()
setupTimePicker()

AddTransactionWidget.updateBroadcast(this)
AddTransactionWidgetCompact.updateBroadcast(this)
WalletBalanceWidgetReceiver.updateBroadcast(this)

setupApp()
setContent {
val viewModel: RootViewModel = viewModel()
val isSystemInDarkTheme = isSystemInDarkTheme()
Expand All @@ -118,10 +106,8 @@ class RootActivity : AppCompatActivity(), RootScreen {

val appLocked by viewModel.appLocked.collectAsState()
when (appLocked) {
null -> {
// display nothing
null -> { // display nothing
}

true -> {
IvyUI(
design = appDesign(ivyContext),
Expand Down Expand Up @@ -157,10 +143,28 @@ class RootActivity : AppCompatActivity(), RootScreen {
}
}

dateTimePicker.Content()
IvyMaterial3Theme(
dark = isDarkThemeEnabled(
ivyDesign = appDesign(ivyContext),
systemDarkTheme = isSystemInDarkTheme
),
isTrueBlack = appDesign(ivyContext).context().theme == Theme.AMOLED_DARK
) {
dateTimePicker.Content()
}
}
}

private fun setupApp() {
setupActivityForResultLaunchers()
WindowCompat.setDecorFitsSystemWindows(window, false)
setupDatePicker()
setupTimePicker()
AddTransactionWidget.updateBroadcast(this)
AddTransactionWidgetCompact.updateBroadcast(this)
WalletBalanceWidgetReceiver.updateBroadcast(this)
}

private companion object {
private const val MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000
}
Expand Down Expand Up @@ -227,6 +231,15 @@ class RootActivity : AppCompatActivity(), RootScreen {
}
}

private fun isDarkThemeEnabled(ivyDesign: IvyDesign, systemDarkTheme: Boolean): Boolean {
return when (ivyDesign.context().theme) {
Theme.LIGHT -> false
Theme.DARK -> true
Theme.AMOLED_DARK -> true
else -> systemDarkTheme
}
}

private fun setupActivityForResultLaunchers() {
createFileLauncher()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.ivy.design.system

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import com.ivy.design.system.colors.IvyColors

@Composable
fun IvyMaterial3Theme(
dark: Boolean,
isTrueBlack: Boolean,
dark: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit
) {
MaterialTheme(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package com.ivy.ui.time.impl
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.DatePicker
import androidx.compose.material3.DatePickerDefaults
import androidx.compose.material3.DatePickerDialog
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TimePicker
import androidx.compose.material3.TimePickerDefaults
import androidx.compose.material3.rememberDatePickerState
import androidx.compose.material3.rememberTimePickerState
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -53,19 +56,28 @@ class AndroidDateTimePicker @Inject constructor(
modifier = modifier,
onDismissRequest = { datePickerViewState = null },
confirmButton = {
ConfirmButton(
onClick = {
datePickerViewState = null
pickerState.selectedDateMillis
?.let(Instant::ofEpochMilli)
?.let {
with(timeConverter) { it.toLocalDate() }
}?.let(viewState.onDatePicked)
}
)
}
ConfirmButton(onClick = {
datePickerViewState = null
pickerState.selectedDateMillis?.let(Instant::ofEpochMilli)
?.let {
with(timeConverter) { it.toLocalDate() }
}?.let(viewState.onDatePicked)
})
},
colors = DatePickerDefaults.colors(
containerColor = MaterialTheme.colorScheme.surfaceVariant,
)
) {
DatePicker(state = pickerState)
DatePicker(
state = pickerState,
colors = DatePickerDefaults.colors(
titleContentColor = MaterialTheme.colorScheme.onBackground,
selectedDayContainerColor = MaterialTheme.colorScheme.primary,
todayContentColor = MaterialTheme.colorScheme.onBackground,
todayDateBorderColor = MaterialTheme.colorScheme.onBackground,
dayContentColor = MaterialTheme.colorScheme.onBackground
)
)
}
}

Expand All @@ -92,11 +104,18 @@ class AndroidDateTimePicker @Inject constructor(
)
}
)
}
},
colors = DatePickerDefaults.colors(
containerColor = MaterialTheme.colorScheme.surfaceVariant,
)
) {
TimePicker(
modifier = Modifier.padding(16.dp),
state = pickerState
state = pickerState,
colors = TimePickerDefaults.colors(
selectorColor = MaterialTheme.colorScheme.primary,
timeSelectorSelectedContainerColor = MaterialTheme.colorScheme.primary
)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ object UI {
fun IvyTheme(
theme: Theme,
design: IvyDesign,
isDarkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit
) {
val colors = design.colors(theme, isSystemInDarkTheme())
val colors = design.colors(theme, isDarkTheme)
val typography = design.typography()
val shapes = design.shapes()

Expand Down

0 comments on commit 4aec53f

Please sign in to comment.