diff --git a/app/src/main/java/com/pranshulgg/weather_master_app/core/model/domain/weather/Weather.kt b/app/src/main/java/com/pranshulgg/weather_master_app/core/model/domain/weather/Weather.kt index 91d306092..4ab2ba5a8 100644 --- a/app/src/main/java/com/pranshulgg/weather_master_app/core/model/domain/weather/Weather.kt +++ b/app/src/main/java/com/pranshulgg/weather_master_app/core/model/domain/weather/Weather.kt @@ -143,12 +143,12 @@ data class WeatherDaily( return pressureMsl != null && pressureMsl != -1.0 } - fun isMoonTimesValid(): Boolean { + fun isMoonValid(): Boolean { return moonrise != null && moonset != null } - fun isSunTimesValid(): Boolean { + fun isSunValid(): Boolean { return sunrise != null && sunset != null } } diff --git a/app/src/main/java/com/pranshulgg/weather_master_app/feature/shared/components/blocks/MoonBlock.kt b/app/src/main/java/com/pranshulgg/weather_master_app/feature/shared/components/blocks/MoonBlock.kt index d26da5750..9037764e5 100644 --- a/app/src/main/java/com/pranshulgg/weather_master_app/feature/shared/components/blocks/MoonBlock.kt +++ b/app/src/main/java/com/pranshulgg/weather_master_app/feature/shared/components/blocks/MoonBlock.kt @@ -38,6 +38,7 @@ import com.pranshulgg.weather_master_app.core.prefs.AppPrefsState import com.pranshulgg.weather_master_app.core.ui.components.Gap import com.pranshulgg.weather_master_app.core.ui.components.Symbol import com.pranshulgg.weather_master_app.core.ui.theme.ShadowElevation +import com.pranshulgg.weather_master_app.core.utils.formatters.getCurrentTimeFor import com.pranshulgg.weather_master_app.core.utils.formatters.to12HourTimeString import com.pranshulgg.weather_master_app.core.utils.formatters.to24HourTimeString import com.pranshulgg.weather_master_app.core.utils.weather.cache.isWeatherDailyDomainSafe @@ -76,9 +77,8 @@ fun MoonBlock(weather: Weather, dailyIndex: Int, prefs: AppPrefsState, onClickBl val moonrise = daily.moonrise val moonset = daily.moonset - val now = System.currentTimeMillis() - - val progress = ((now - moonrise).toFloat() / (moonset - moonrise)) + val now = getCurrentTimeFor(weather.location.timezone) + val progress = ((now - moonrise!!).toFloat() / (moonset!! - moonrise)) .coerceIn(0f, 1f) @@ -138,15 +138,15 @@ fun MoonBlock(weather: Weather, dailyIndex: Int, prefs: AppPrefsState, onClickBl moonrise, weather.location.timezone ) else to12HourTimeString( - moonrise, + moonrise!!, weather.location.timezone, "hh:mm a" ) val moonsetFormatted = if (is24hr) to24HourTimeString( - moonset, + moonset!!, weather.location.timezone ) else to12HourTimeString( - moonset, + moonset!!, weather.location.timezone, "hh:mm a" ) diff --git a/app/src/main/java/com/pranshulgg/weather_master_app/feature/shared/components/blocks/SunBlock.kt b/app/src/main/java/com/pranshulgg/weather_master_app/feature/shared/components/blocks/SunBlock.kt index 23a722927..9a6c866cf 100644 --- a/app/src/main/java/com/pranshulgg/weather_master_app/feature/shared/components/blocks/SunBlock.kt +++ b/app/src/main/java/com/pranshulgg/weather_master_app/feature/shared/components/blocks/SunBlock.kt @@ -80,8 +80,8 @@ fun SunBlock(weather: Weather, dailyIndex: Int, prefs: AppPrefsState, onClickBlo val now = getCurrentTimeFor(weather.location.timezone) - val progress = - if (now in daily.sunrise..daily.sunset) ((now - sunrise).toFloat() / (sunset - sunrise)) + val progress = if (now in daily.sunrise!!..daily.sunset!!) + ((now - sunrise).toFloat() / (sunset - sunrise)) .coerceIn(0f, 1f) else 1f diff --git a/app/src/main/java/com/pranshulgg/weather_master_app/feature/shared/components/blocks/WeatherBlocks.kt b/app/src/main/java/com/pranshulgg/weather_master_app/feature/shared/components/blocks/WeatherBlocks.kt index a000a19da..03bb0296d 100644 --- a/app/src/main/java/com/pranshulgg/weather_master_app/feature/shared/components/blocks/WeatherBlocks.kt +++ b/app/src/main/java/com/pranshulgg/weather_master_app/feature/shared/components/blocks/WeatherBlocks.kt @@ -39,8 +39,9 @@ private data class BlockRules( val isPressureValid: Boolean, val isVisibilityValid: Boolean, val isWindValid: Boolean, - val isHumidityDewPoint: Boolean - + val isHumidityDewPoint: Boolean, + val isSunValid: Boolean, + val isMoonValid: Boolean ) private fun shouldShow(block: WeatherBlock, rules: BlockRules): Boolean { @@ -55,6 +56,8 @@ private fun shouldShow(block: WeatherBlock, rules: BlockRules): Boolean { !rules.isVisibilityValid && block.type == WeatherBlockType.VISIBILITY_BLOCK -> false !rules.isWindValid && block.type == WeatherBlockType.WIND_BLOCK -> false !rules.isHumidityDewPoint && block.type == WeatherBlockType.HUMIDITY_BLOCK -> false + !rules.isSunValid && block.type == WeatherBlockType.SUN_BLOCK -> false + !rules.isMoonValid && block.type == WeatherBlockType.MOON_BLOCK -> false else -> true } } @@ -106,6 +109,9 @@ fun WeatherBlocks( weather.daily[dailyIndex].isHumidityValid() || weather.daily[dailyIndex].isDewPointValid() else weather.current.isHumidityValid() || weather.current.isDewPointValid() + val isSunValid = weather.daily[dailyIndex].isSunValid() + val isMoonValid = weather.daily[dailyIndex].isMoonValid() + val prefs = LocalAppPrefs.current val rules = BlockRules( @@ -117,7 +123,9 @@ fun WeatherBlocks( isPressureValid, isVisibilityValid, isWindValid, - isHumidityDewPoint + isHumidityDewPoint, + isSunValid, + isMoonValid )