Skip to content

Commit cd7d798

Browse files
Refactor widget and worker to use UserPreferencesRepository
Refactored DayAheadWidget and WidgetUpdateWorker to use UserPreferencesRepository instead of accessing SharedPreferences directly. This improves architectural consistency and centralizes data access logic. Changes: - Updated UserPreferencesRepository to expose summary flow and hasLocation method. - Updated DayAheadWidget to inject UserPreferencesRepository and collect summary flow. - Updated WidgetUpdateWorker to inject UserPreferencesRepository and use it for location check, preference retrieval, and summary saving. - Addressed code review feedback: Added try-catch block in MainViewModel.fetchWeather.
1 parent 087a507 commit cd7d798

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

app/src/main/java/com/example/theloop/MainViewModel.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,12 @@ class MainViewModel @Inject constructor(
140140
}
141141

142142
suspend fun fetchWeather(lat: Double, lon: Double) {
143-
fetchLocationName(lat, lon)
144-
weatherRepo.refresh(lat, lon, userPrefsRepo.tempUnit.first())
143+
try {
144+
fetchLocationName(lat, lon)
145+
weatherRepo.refresh(lat, lon, userPrefsRepo.tempUnit.first())
146+
} catch (e: Exception) {
147+
android.util.Log.e("MainViewModel", "Error fetching weather or location name", e)
148+
}
145149
}
146150

147151
suspend fun fetchNews() {

0 commit comments

Comments
 (0)