Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix theme issues in AlertActivity and PollenActivity #1147

Merged
merged 2 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,39 @@ class AlertActivity : GeoActivity() {
finish()
return@LaunchedEffect
}
location.value = locationC

val alerts = weatherRepository.getAlertListByLocationId(locationC.formattedId)
alertList.value = alerts
// Daily weather data is needed to check if the sun is still up or if it has set when
// day/night mode per location is enabled.
val weather = weatherRepository.getWeatherByLocationId(
locationC.formattedId,
withDaily = true,
withHourly = false,
withMinutely = false,
withAlerts = true
)

if (alerts.isNotEmpty()) {
val alertId = intent.getStringExtra(KEY_ALERT_ID)
if (!alertId.isNullOrEmpty()) {
val alertIndex = alerts.indexOfFirst { it.alertId == alertId }
if (alertIndex != -1) {
listState.scrollToItem(alertIndex)
location.value = locationC.copy(weather = weather)

if (weather != null) {
val alerts = weather.alertList
alertList.value = alerts

if (alerts.isNotEmpty()) {
val alertId = intent.getStringExtra(KEY_ALERT_ID)
if (!alertId.isNullOrEmpty()) {
val alertIndex = alerts.indexOfFirst { it.alertId == alertId }
if (alertIndex != -1) {
listState.scrollToItem(alertIndex)
} else {
listState.scrollToItem(0)
}
} else {
listState.scrollToItem(0)
}
} else {
listState.scrollToItem(0)
}
}
}

val scrollBehavior = generateCollapsedScrollBehavior()

val isLightTheme = MainThemeColorProvider.isLightTheme(context, location.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
Expand All @@ -56,6 +57,7 @@ import org.breezyweather.common.ui.widgets.insets.bottomInsetItem
import org.breezyweather.domain.weather.model.isIndexValid
import org.breezyweather.main.utils.MainThemeColorProvider
import org.breezyweather.sources.SourceManager
import org.breezyweather.theme.ThemeManager
import org.breezyweather.theme.compose.BreezyWeatherTheme
import org.breezyweather.theme.compose.DayNightTheme
import javax.inject.Inject
Expand Down Expand Up @@ -85,6 +87,7 @@ class PollenActivity : GeoActivity() {
private fun ContentView() {
val formattedId = intent.getStringExtra(KEY_POLLEN_ACTIVITY_LOCATION_FORMATTED_ID)
val location = remember { mutableStateOf<Location?>(null) }
val context = LocalContext.current

LaunchedEffect(formattedId) {
var locationC: Location? = null
Expand Down Expand Up @@ -116,7 +119,21 @@ class PollenActivity : GeoActivity() {

val scrollBehavior = generateCollapsedScrollBehavior()

BreezyWeatherTheme(lightTheme = MainThemeColorProvider.isLightTheme(this, location.value)) {
val isLightTheme = MainThemeColorProvider.isLightTheme(context, location.value)
BreezyWeatherTheme(lightTheme = isLightTheme) {
// re-setting the status bar color once the location is fetched above in the launched effect
ThemeManager
.getInstance(this)
.weatherThemeDelegate
.setSystemBarStyle(
context = this,
window = this.window,
statusShader = false,
lightStatus = isLightTheme,
navigationShader = true,
lightNavigation = false
)

Material3Scaffold(
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
Expand Down
Loading