mirror of
https://github.com/PranshulGG/WeatherMaster.git
synced 2026-10-21 10:40:23 -05:00
refactor WidgetHourlyItem to use custom sizes and add WidgetReload class for widget updates
This commit is contained in:
1 parent
13747a633b
commit
08db096cdf
2 files changed
+42
-7
No files matched your search
+36
@@ -0,0 +1,36 @@
|
||||
package com.pranshulgg.weather_master_app.data.worker.widgets
|
||||
|
||||
import android.content.Context
|
||||
import com.pranshulgg.weather_master_app.core.model.weather.WeatherResult
|
||||
import com.pranshulgg.weather_master_app.data.provider.WeatherRepositoryProvider
|
||||
import com.pranshulgg.weather_master_app.data.repository.LocationsRepository
|
||||
import com.pranshulgg.weather_master_app.data.repository.WeatherUnitsRepository
|
||||
import jakarta.inject.Inject
|
||||
|
||||
class WidgetReload @Inject constructor(
|
||||
private val repositoryProvider: WeatherRepositoryProvider,
|
||||
private val locationsRepository: LocationsRepository,
|
||||
private val weatherUnitsRepository: WeatherUnitsRepository
|
||||
) {
|
||||
|
||||
suspend fun reload(context: Context) {
|
||||
val locations = locationsRepository.getLocationsOnce()
|
||||
val defaultLocation = locations.find { it.isDefault }
|
||||
val units = weatherUnitsRepository.getUnitsOnce()
|
||||
|
||||
if (defaultLocation == null || units == null) return
|
||||
|
||||
val repo = repositoryProvider.getRepository(defaultLocation.source)
|
||||
|
||||
val result = repo.getWeather(
|
||||
location = defaultLocation,
|
||||
isManualRefresh = false,
|
||||
isForceRefresh = false
|
||||
)
|
||||
|
||||
val weather = (result as? WeatherResult.Success)?.weather ?: return
|
||||
|
||||
val json = widgetWeatherMapper(weather, context, units)
|
||||
WeatherWidgetUpdater(context).update(json)
|
||||
}
|
||||
}
|
||||
+6
-7
@@ -1,6 +1,5 @@
|
||||
package com.pranshulgg.weather_master_app.widgets.weather.components
|
||||
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
@@ -8,11 +7,11 @@ import androidx.glance.GlanceModifier
|
||||
import androidx.glance.GlanceTheme
|
||||
import androidx.glance.Image
|
||||
import androidx.glance.ImageProvider
|
||||
import androidx.glance.background
|
||||
import androidx.glance.layout.Alignment
|
||||
import androidx.glance.layout.Column
|
||||
import androidx.glance.layout.Spacer
|
||||
import androidx.glance.layout.height
|
||||
import androidx.glance.layout.padding
|
||||
import androidx.glance.layout.size
|
||||
import androidx.glance.layout.width
|
||||
import androidx.glance.text.FontWeight
|
||||
@@ -20,32 +19,32 @@ import androidx.glance.text.Text
|
||||
import androidx.glance.text.TextStyle
|
||||
|
||||
@Composable
|
||||
fun WidgetHourlyItem(time: String, temp: String, icon: Int, isSmall: Boolean = false) {
|
||||
fun WidgetHourlyItem(time: String, temp: String, icon: Int, fontSize: Float, iconSize: Float) {
|
||||
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = GlanceModifier.width(48.dp).height(80.dp)
|
||||
modifier = GlanceModifier.padding(horizontal = 5.dp, vertical = 5.dp)
|
||||
) {
|
||||
Text(
|
||||
temp,
|
||||
style = TextStyle(
|
||||
color = GlanceTheme.colors.onSurface,
|
||||
fontWeight = FontWeight.Medium,
|
||||
fontSize = if (isSmall) 14.sp else 15.sp
|
||||
fontSize = fontSize.sp
|
||||
)
|
||||
)
|
||||
Spacer(GlanceModifier.height(3.dp))
|
||||
Image(
|
||||
provider = ImageProvider(icon),
|
||||
contentDescription = "",
|
||||
modifier = GlanceModifier.size(if (isSmall) 22.dp else 28.dp)
|
||||
modifier = GlanceModifier.size(iconSize.dp)
|
||||
)
|
||||
Spacer(GlanceModifier.height(3.dp))
|
||||
Text(
|
||||
time,
|
||||
style = TextStyle(
|
||||
color = GlanceTheme.colors.onSurfaceVariant,
|
||||
fontWeight = FontWeight.Medium, fontSize = if (isSmall) 14.sp else 15.sp
|
||||
fontWeight = FontWeight.Medium, fontSize = fontSize.sp
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user