Browse Source

Remove saveHandleState on current location

Carles Sentis 11 months ago
parent
commit
40be684c7f

+ 2 - 2
app/build.gradle.kts

@@ -14,8 +14,8 @@ android {
         applicationId = "com.arklan.weather"
         applicationId = "com.arklan.weather"
         minSdk = ConfigData.minSdk
         minSdk = ConfigData.minSdk
         targetSdk = ConfigData.targetSdk
         targetSdk = ConfigData.targetSdk
-        versionCode = 7
-        versionName = "1.6"
+        versionCode = 8
+        versionName = "1.7"
 
 
         testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
         testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
         vectorDrawables {
         vectorDrawables {

BIN
app/release/app-release.aab


BIN
buildSrc/build/kotlin/compileKotlin/cacheable/last-build.bin


BIN
buildSrc/build/kotlin/compileKotlin/local-state/build-history.bin


BIN
buildSrc/build/libs/buildSrc.jar


+ 7 - 0
feature/weather/src/main/java/com/trifork/feature/weather/presentation/WeatherViewModel.kt

@@ -66,6 +66,13 @@ class WeatherViewModel @Inject constructor(
         viewModelScope.launch(dispatcherProvider.io) {
         viewModelScope.launch(dispatcherProvider.io) {
             val location = if (geoLocation.lat == .0 || geoLocation.long == .0) {
             val location = if (geoLocation.lat == .0 || geoLocation.long == .0) {
                 locationTracker.getCurrentLocation()?.let {
                 locationTracker.getCurrentLocation()?.let {
+
+                    savedStateHandle.run {
+                        remove<String>("name")
+                        remove<String>("lat")
+                        remove<String>("long")
+                    }
+
                     WeatherLocation(
                     WeatherLocation(
                         localResource.getCurrentLocationString(),
                         localResource.getCurrentLocationString(),
                         it.latitude,
                         it.latitude,

+ 37 - 5
feature/weather/src/main/java/com/trifork/feature/weather/presentation/components/WeatherForecast.kt

@@ -1,6 +1,9 @@
 package com.trifork.feature.weather.presentation.components
 package com.trifork.feature.weather.presentation.components
 
 
+import androidx.compose.animation.core.FastOutSlowInEasing
+import androidx.compose.animation.core.tween
 import androidx.compose.foundation.clickable
 import androidx.compose.foundation.clickable
+import androidx.compose.foundation.gestures.animateScrollBy
 import androidx.compose.foundation.layout.Arrangement
 import androidx.compose.foundation.layout.Arrangement
 import androidx.compose.foundation.layout.Column
 import androidx.compose.foundation.layout.Column
 import androidx.compose.foundation.layout.Row
 import androidx.compose.foundation.layout.Row
@@ -11,23 +14,32 @@ import androidx.compose.foundation.layout.padding
 import androidx.compose.foundation.layout.width
 import androidx.compose.foundation.layout.width
 import androidx.compose.foundation.lazy.LazyRow
 import androidx.compose.foundation.lazy.LazyRow
 import androidx.compose.foundation.lazy.items
 import androidx.compose.foundation.lazy.items
+import androidx.compose.foundation.lazy.rememberLazyListState
 import androidx.compose.material3.MaterialTheme
 import androidx.compose.material3.MaterialTheme
 import androidx.compose.material3.Text
 import androidx.compose.material3.Text
 import androidx.compose.runtime.Composable
 import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableFloatStateOf
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+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.layout.onGloballyPositioned
+import androidx.compose.ui.platform.LocalConfiguration
 import androidx.compose.ui.platform.LocalContext
 import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.platform.LocalDensity
 import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
 import androidx.compose.ui.unit.sp
-import com.trifork.feature.common.util.MonthString
 import com.trifork.feature.common.util.WeekString
 import com.trifork.feature.common.util.WeekString
 import com.trifork.feature.weather.domain.model.WeatherData
 import com.trifork.feature.weather.domain.model.WeatherData
 import com.trifork.feature.weather.domain.model.WeatherInfo
 import com.trifork.feature.weather.domain.model.WeatherInfo
-import com.trifork.feature.weather.presentation.WeatherViewModel
 import com.trifork.feature.weather.presentation.mvi.WeatherEvent
 import com.trifork.feature.weather.presentation.mvi.WeatherEvent
 import kotlinx.collections.immutable.ImmutableList
 import kotlinx.collections.immutable.ImmutableList
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.launch
 import java.time.LocalDateTime
 import java.time.LocalDateTime
-import java.util.Locale
 
 
 @Composable
 @Composable
 fun WeatherForecast(
 fun WeatherForecast(
@@ -73,7 +85,13 @@ fun WeatherForecast(
             )
             )
         }
         }
         Spacer(modifier = Modifier.height(16.dp))
         Spacer(modifier = Modifier.height(16.dp))
-        LazyRow(content = {
+
+        val listState = rememberLazyListState()
+        val density = LocalDensity.current
+
+        LazyRow(
+            state = listState
+        ) {
             items(perDay.filter { it.time.plusHours(1) > LocalDateTime.now() }) { weatherData ->
             items(perDay.filter { it.time.plusHours(1) > LocalDateTime.now() }) { weatherData ->
                 HourlyWeatherDisplay(
                 HourlyWeatherDisplay(
                     weatherData = weatherData,
                     weatherData = weatherData,
@@ -93,6 +111,20 @@ fun WeatherForecast(
                         }
                         }
                 )
                 )
             }
             }
-        })
+        }
+
+        if (perDay[0].time.dayOfMonth != LocalDateTime.now().dayOfMonth) {
+            LaunchedEffect(key1 = perDay) {
+                launch {
+                    delay(500)
+                    val componentWidth = with(density) { (40.dp.roundToPx() + 32.dp.roundToPx()).toFloat() }
+                    listState.animateScrollBy(
+                        value = componentWidth * 11,
+                        animationSpec = tween(3000, easing = FastOutSlowInEasing)
+                    )
+                    listState.animateScrollToItem(10)
+                }
+            }
+        }
     }
     }
 }
 }