-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Fix/network check on article #2111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright 2026 The Android Open Source Project | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.samples.apps.nowinandroid.core.ui | ||
|
|
||
| import androidx.compose.runtime.compositionLocalOf | ||
|
|
||
| val LocalIsOffline = compositionLocalOf { false } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * Copyright 2022 The Android Open Source Project | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.samples.apps.nowinandroid.core.ui | ||
|
|
||
| import androidx.compose.material3.SnackbarHostState | ||
| import androidx.compose.runtime.compositionLocalOf | ||
|
|
||
| val LocalSnackbarHostState = compositionLocalOf<SnackbarHostState> { | ||
| error("SnackbarHostState should be initialized at runtime") | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| package com.google.samples.apps.nowinandroid.core.ui | ||
|
|
||
| import android.net.Uri | ||
| import android.widget.Toast | ||
| import androidx.compose.foundation.lazy.LazyListScope | ||
| import androidx.compose.foundation.lazy.items | ||
| import androidx.compose.material3.MaterialTheme | ||
|
|
@@ -47,18 +48,27 @@ fun LazyListScope.userNewsResourceCardItems( | |
| val backgroundColor = MaterialTheme.colorScheme.background.toArgb() | ||
| val context = LocalContext.current | ||
| val analyticsHelper = LocalAnalyticsHelper.current | ||
| val isOffline = LocalIsOffline.current | ||
|
|
||
| NewsResourceCardExpanded( | ||
| userNewsResource = userNewsResource, | ||
| isBookmarked = userNewsResource.isSaved, | ||
| hasBeenViewed = userNewsResource.hasBeenViewed, | ||
| onToggleBookmark = { onToggleBookmark(userNewsResource) }, | ||
| onClick = { | ||
| analyticsHelper.logNewsResourceOpened( | ||
| newsResourceId = userNewsResource.id, | ||
| ) | ||
| launchCustomChromeTab(context, resourceUrl, backgroundColor) | ||
| onNewsResourceViewed(userNewsResource.id) | ||
| if (isOffline) { | ||
| Toast.makeText( | ||
| context, | ||
| context.getString(R.string.core_ui_not_connected), | ||
| Toast.LENGTH_SHORT, | ||
| ).show() | ||
| } else { | ||
|
Comment on lines
+59
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This offline check and |
||
| analyticsHelper.logNewsResourceOpened( | ||
| newsResourceId = userNewsResource.id, | ||
| ) | ||
| launchCustomChromeTab(context, resourceUrl, backgroundColor) | ||
| onNewsResourceViewed(userNewsResource.id) | ||
| } | ||
| }, | ||
| onTopicClick = onTopicClick, | ||
| modifier = itemModifier, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for checking the offline state and displaying a
Toastis duplicated here and inNewsResourceCardList.kt. Consider abstracting this into a reusable helper function (e.g., an extension onContext) within thecore:uimodule. 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 aToastis inconsistent with theSnackbar-based notification pattern used elsewhere in the app; sinceLocalSnackbarHostStateis now available in this module, it should be preferred for a more consistent user experience.