Fix permissions formatting logging 9989925042154523083#110
Fix permissions formatting logging 9989925042154523083#110harrydbarnes wants to merge 8 commits intomainfrom
Conversation
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
- Implemented permission result handling in MainActivity to refresh data or show feedback. - Replaced hardcoded SimpleDateFormat with DateUtils in CalendarCard to respect user time format preference. - Added TODO in MainViewModel regarding hardcoded news category. - Replaced e.printStackTrace() with Log.e() in repositories for better error tracking. - Added TAG constants to repositories.
Summary of ChangesHello @harrydbarnes, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request represents a substantial architectural overhaul of the application, transitioning from a Java-based Android Views setup to a modern Kotlin-first stack utilizing Jetpack Compose for the UI, Dagger Hilt for dependency injection, and Room for persistent local data caching. The changes aim to improve maintainability, scalability, and developer experience by adopting contemporary Android development best practices. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request successfully migrates the application to a modern Android development stack, leveraging Kotlin, Jetpack Compose, Hilt for dependency injection, and Room for local data persistence. This is a significant improvement for code maintainability and scalability. The modularization into repositories and DAOs is well-structured. However, there are a few areas that need attention to ensure full functionality and robustness, particularly regarding data loading state management, news category selection, widget update resilience, and UI functionality regressions.
| val isLoading: Boolean = false, | ||
| val userGreeting: String = "", | ||
| val tempUnit: String = "celsius" |
| private val _userName = MutableStateFlow(prefs.getString(AppConstants.KEY_USER_NAME, "User") ?: "User") | ||
|
|
||
| val weather = weatherRepo.weatherData | ||
| // TODO: Re-implement category selection (regression). Hardcoded to "US" for now. |
There was a problem hiding this comment.
The news articles are currently hardcoded to fetch only "US" category news. The previous Java implementation allowed for dynamic news category selection. This functionality should be re-implemented to restore the full feature set.
| // TODO: Re-implement category selection (regression). Hardcoded to "US" for now. | |
| val news = newsRepo.getArticles(selectedNewsCategory) // Re-implement category selection |
| private val newsRepo: NewsRepository, | ||
| private val calendarRepo: CalendarRepository, | ||
| private val funFactRepo: FunFactRepository, | ||
| @ApplicationContext private val context: Context |
There was a problem hiding this comment.
The context parameter is injected into the MainViewModel. While Hilt allows this, it's generally recommended to avoid injecting Context directly into ViewModels to prevent potential memory leaks and to promote testability. Consider passing only the necessary application-level context (e.g., Application context) or specific dependencies that require context, or refactor logic that needs context into a separate repository or use AndroidViewModel if application context is truly needed.
| try { newsRepo.refreshNews() } catch (e: Exception) { android.util.Log.e("WidgetUpdateWorker", "Failed to refresh news", e) } | ||
| try { calendarRepo.refreshEvents() } catch (e: Exception) { android.util.Log.e("WidgetUpdateWorker", "Failed to refresh calendar", e) } |
There was a problem hiding this comment.
The try-catch blocks around newsRepo.refreshNews() and calendarRepo.refreshEvents() only log errors but do not affect the worker's Result. If these refreshes fail, the widget might display stale or incomplete data, yet the worker reports Result.success(). Consider returning Result.retry() or Result.failure() if these critical data fetches fail to ensure data consistency.
| news.world?.let { allArticles.addAll(it.map { a -> a.toEntity("World") }) } | ||
|
|
||
| if (allArticles.isNotEmpty()) { | ||
| dao.clearAll() |
There was a problem hiding this comment.
Calling dao.clearAll() before inserting new articles means that if the API call for news fails (e.g., network error), the database will be left empty, resulting in no news being displayed. It's safer to only clear the database if the new data is successfully fetched and is not empty, or to use a transaction to ensure atomicity.
| weather = state.weather, | ||
| locationName = state.locationName, | ||
| tempUnit = state.tempUnit, | ||
| onClick = { /* TODO: Implement navigation to settings */ } |
| text = state.summary ?: "", | ||
| style = MaterialTheme.typography.bodyLarge | ||
| ) | ||
| } |
There was a problem hiding this comment.
The Text composable for state.summary is rendered even if state.summary is null, resulting in an empty text view. It's generally better practice to conditionally render the Text composable only when state.summary is not null to avoid unnecessary UI elements.
if (state.summary != null) {
item {
Text(
text = state.summary,
style = MaterialTheme.typography.bodyLarge
)
}
}
No description provided.