Skip to content

Fix permissions formatting logging 9989925042154523083#114

Closed
harrydbarnes wants to merge 14 commits intomainfrom
fix-permissions-formatting-logging-9989925042154523083
Closed

Fix permissions formatting logging 9989925042154523083#114
harrydbarnes wants to merge 14 commits intomainfrom
fix-permissions-formatting-logging-9989925042154523083

Conversation

@harrydbarnes
Copy link
Owner

No description provided.

google-labs-jules bot and others added 14 commits January 20, 2026 07:02
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.
- Implemented permission result handling in MainActivity.
- Replaced hardcoded date format with DateUtils in CalendarCard.
- Re-implemented dynamic news category selection in MainViewModel.
- Added isLoading state to MainViewModel.
- Replaced e.printStackTrace() with Log.e() in repositories.
- Updated repositories to return Boolean success/failure status.
- Implemented transactional replaceAll in ArticleDao/NewsRepository to prevent data loss.
- Implemented retry logic in WidgetUpdateWorker based on refresh success.
- Created missing colors.xml to fix build failure.
- Implemented settings navigation in HomeScreen.
- Implemented permission result handling in MainActivity.
- Replaced hardcoded date format with DateUtils in CalendarCard.
- Re-implemented dynamic news category selection in MainViewModel.
- Added isLoading state to MainViewModel.
- Fixed combine function signature in MainViewModel to handle 8 flows.
- Replaced e.printStackTrace() with Log.e() in repositories.
- Updated repositories to return Boolean success/failure status.
- Implemented transactional replaceAll in ArticleDao/NewsRepository to prevent data loss.
- Implemented retry logic in WidgetUpdateWorker based on refresh success.
- Created missing colors.xml to fix build failure.
- Implemented settings navigation in HomeScreen.
…Repository.kt

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.
- Replaced hardcoded date format with DateUtils in CalendarCard.
- Re-implemented dynamic news category selection in MainViewModel.
- Added isLoading state to MainViewModel.
- Fixed combine function signature in MainViewModel to handle 8 flows.
- Replaced e.printStackTrace() with Log.e() in repositories.
- Updated repositories to return Boolean success/failure status.
- Implemented transactional replaceAll in ArticleDao/NewsRepository to prevent data loss.
- Implemented retry logic in WidgetUpdateWorker based on refresh success.
- Created missing colors.xml to fix build failure.
- Implemented settings navigation in HomeScreen.
- Fixed syntax error in CalendarRepository.
- Implemented permission result handling in MainActivity.
- Replaced hardcoded date format with DateUtils in CalendarCard.
- Re-implemented dynamic news category selection in MainViewModel.
- Added isLoading state to MainViewModel.
- Refactored MainViewModel combine logic to use chained calls for type safety.
- Replaced e.printStackTrace() with Log.e() in repositories and DayAheadWidget.
- Updated repositories to return Boolean success/failure status.
- Implemented transactional replaceAll in ArticleDao/NewsRepository.
- Implemented retry logic in WidgetUpdateWorker.
- Created missing colors.xml to fix build failure.
- Implemented settings navigation in HomeScreen.
- Fixed CalendarRepository syntax error and extracted magic number.
- Added @JvmStatic to AppUtils for Java interop.
- Extracted Hilt versions in build.gradle.
- Added null/blank title filtering in NewsRepository.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 significant architectural overhaul and modernization of the application. The entire codebase has been migrated from Java to Kotlin, and the user interface has been completely rewritten using Jetpack Compose, replacing the traditional Android View system. This refactoring introduces a robust data layer with Room Persistence Library for local caching and a new repository pattern, alongside Hilt for streamlined dependency injection. These changes aim to improve code maintainability, scalability, and developer experience, while also bringing the UI up to modern Android standards.

Highlights

  • Language Migration: The entire application codebase has been migrated from Java to Kotlin, embracing modern language features and paradigms.
  • UI Modernization with Jetpack Compose: The user interface has been completely rewritten using Jetpack Compose, replacing the traditional Android View system and associated XML layouts. This includes new Composable functions for the HomeScreen, WeatherCard, NewsCard, and CalendarCard.
  • Dependency Injection with Hilt: Hilt (built on Dagger 2) has been integrated for dependency injection, streamlining the management of dependencies across the application, including ViewModels, Workers, and Repositories.
  • Local Data Persistence with Room: The Room Persistence Library has been introduced for robust local data caching of weather, news articles, and calendar events, improving offline capabilities and data access efficiency.
  • Architectural Refactoring with Repository Pattern and Kotlin Flow: A new repository layer has been implemented for data management, abstracting data sources and improving testability. The MainViewModel has been modernized to leverage Kotlin Flow for reactive data streams, enhancing data observation and state management.
  • Widget and Worker Updates: The DayAheadWidget and WidgetUpdateWorker have been converted to Kotlin and integrated with Hilt and Room for consistent data access and background processing.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request represents a significant and well-executed migration of the application from a legacy Java and XML-based architecture to a modern Kotlin stack utilizing Jetpack Compose, Hilt, Room, and Coroutines. The adoption of a repository pattern, reactive UI with StateFlow, and dependency injection greatly improves the codebase's maintainability, testability, and scalability.

My review highlights a critical regression in location fetching that needs to be addressed to restore core weather functionality. I've also provided a few suggestions to further improve code clarity, adhere to current API best practices, and reduce code duplication. Overall, this is an excellent modernization effort.

Comment on lines +120 to +124
val latStr = prefs.getString(AppConstants.KEY_LATITUDE, AppConstants.DEFAULT_LATITUDE.toString())
val lonStr = prefs.getString(AppConstants.KEY_LONGITUDE, AppConstants.DEFAULT_LONGITUDE.toString())

val lat = try { latStr?.toDouble() ?: AppConstants.DEFAULT_LATITUDE } catch (e: Exception) { AppConstants.DEFAULT_LATITUDE }
val lon = try { lonStr?.toDouble() ?: AppConstants.DEFAULT_LONGITUDE } catch (e: Exception) { AppConstants.DEFAULT_LONGITUDE }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The application's location fetching logic appears to have been lost in the refactoring. The ViewModel now reads latitude and longitude from SharedPreferences, but there's no mechanism to update these values with the device's current location. This will cause the app to show weather for a stale or default location, which is a critical issue.

You should re-implement location fetching, for example, by using the FusedLocationProviderClient in the MainActivity and passing the location to the ViewModel, or preferably by creating a LocationRepository that provides location updates as a Flow for the ViewModel to consume.

Comment on lines +168 to +169
@Suppress("DEPRECATION")
val addresses = geocoder.getFromLocation(lat, lon, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The getFromLocation method with latitude and longitude is deprecated on API 33 and above. While you've suppressed the warning, it's recommended to migrate to the new asynchronous version which takes a GeocodeListener. This avoids potential IOExceptions and aligns with modern Android practices. You can wrap the callback-based API using suspendCancellableCoroutine to make it fit nicely within your suspend function.

android.Manifest.permission.READ_CALENDAR
) != android.content.pm.PackageManager.PERMISSION_GRANTED
) {
return@withContext true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The refreshEvents function returns true when READ_CALENDAR permission is not granted. This can be misleading to the caller, as it implies the operation was successful when in fact no events were fetched. You should return false to indicate that the operation could not be completed due to missing permissions. This allows the caller to handle this state more explicitly.

Suggested change
return@withContext true
return@withContext false

Comment on lines +33 to +40
news.business?.filter { !it.title.isNullOrBlank() }?.let { allArticles.addAll(it.map { a -> a.toEntity("Business") }) }
news.entertainment?.filter { !it.title.isNullOrBlank() }?.let { allArticles.addAll(it.map { a -> a.toEntity("Entertainment") }) }
news.health?.filter { !it.title.isNullOrBlank() }?.let { allArticles.addAll(it.map { a -> a.toEntity("Health") }) }
news.science?.filter { !it.title.isNullOrBlank() }?.let { allArticles.addAll(it.map { a -> a.toEntity("Science") }) }
news.sports?.filter { !it.title.isNullOrBlank() }?.let { allArticles.addAll(it.map { a -> a.toEntity("Sports") }) }
news.technology?.filter { !it.title.isNullOrBlank() }?.let { allArticles.addAll(it.map { a -> a.toEntity("Technology") }) }
news.us?.filter { !it.title.isNullOrBlank() }?.let { allArticles.addAll(it.map { a -> a.toEntity("US") }) }
news.world?.filter { !it.title.isNullOrBlank() }?.let { allArticles.addAll(it.map { a -> a.toEntity("World") }) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for filtering and mapping articles for each category is duplicated. This can be extracted into a private helper function to improve readability and maintainability.

                        fun addArticles(category: String, articles: List<Article>?) {
                            articles?.filter { !it.title.isNullOrBlank() }
                                ?.map { it.toEntity(category) }
                                ?.let { allArticles.addAll(it) }
                        }

                        addArticles("Business", news.business)
                        addArticles("Entertainment", news.entertainment)
                        addArticles("Health", news.health)
                        addArticles("Science", news.science)
                        addArticles("Sports", news.sports)
                        addArticles("Technology", news.technology)
                        addArticles("US", news.us)
                        addArticles("World", news.world)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant