Skip to content

Fix/network check on article#2111

Open
santi-pine03 wants to merge 2 commits into
android:mainfrom
santi-pine03:fix/network-check-on-article
Open

Fix/network check on article#2111
santi-pine03 wants to merge 2 commits into
android:mainfrom
santi-pine03:fix/network-check-on-article

Conversation

@santi-pine03
Copy link
Copy Markdown

@santi-pine03 santi-pine03 commented May 17, 2026

What I have done and why

Added a network connectivity check before launching a Chrome Custom Tab when a user taps on a news article card.

Previously, tapping an article while offline would launch Chrome Custom Tab unconditionally, resulting in Chrome displaying its own network error page and taking the user outside of the app with no app feedback.

The changes add a LocalIsOffline CompositionLocal in core/ui and provides it from NiaApp.kt, where isOffline is already collected. Both NewsFeed.kt and NewsResourceCardList.kt now check this value before launching the Chrome Custom Tab. If the device is offline, a Toast is shown with the message "Can't open, no internet connection".

Additionally, LocalSnackbarHostState was moved from feature/bookmarks/impl to core/ui so that it can be accessed from lower level UI modules without creating an invalid dependency.

This Fixes the issue #2110

@santi-pine03 santi-pine03 requested a review from dturner as a code owner May 17, 2026 01:16
Copy link
Copy Markdown

@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 centralizes UI-related composition locals by moving LocalSnackbarHostState and introducing LocalIsOffline within the core:ui module. It also implements an offline check in NewsFeed and NewsResourceCardList to prevent opening news resources without a connection. Feedback suggests consolidating the duplicated offline notification logic into a reusable helper and switching from Toast to Snackbar to ensure consistency with the app's existing notification patterns.

Comment on lines +72 to +78
if (isOffline) {
Toast.makeText(
context,
context.getString(R.string.core_ui_not_connected),
Toast.LENGTH_SHORT,
).show()
} else {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The logic for checking the offline state and displaying a Toast is duplicated here and in NewsResourceCardList.kt. Consider abstracting this into a reusable helper function (e.g., an extension on Context) within the core:ui module. This would improve maintainability and ensure that any future changes to the offline notification logic only need to be made in one place. Additionally, using a Toast is inconsistent with the Snackbar-based notification pattern used elsewhere in the app; since LocalSnackbarHostState is now available in this module, it should be preferred for a more consistent user experience.

Comment on lines +59 to +65
if (isOffline) {
Toast.makeText(
context,
context.getString(R.string.core_ui_not_connected),
Toast.LENGTH_SHORT,
).show()
} else {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This offline check and Toast notification logic is identical to the implementation in NewsFeed.kt. To adhere to DRY (Don't Repeat Yourself) principles and simplify future updates to the user feedback mechanism, it is recommended to consolidate this logic into a shared utility function within this module.

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