Skip to content

Commit

Permalink
no internet messages
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed Jan 6, 2024
1 parent c4abb0c commit 4ac6345
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
8 changes: 7 additions & 1 deletion app/src/main/java/com/geode/launcher/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import com.geode.launcher.ui.theme.Typography
import com.geode.launcher.utils.LaunchUtils
import com.geode.launcher.utils.PreferenceUtils
import com.geode.launcher.utils.useCountdownTimer
import java.net.ConnectException
import java.net.UnknownHostException


class MainActivity : ComponentActivity() {
Expand Down Expand Up @@ -137,7 +139,11 @@ fun UpdateCard(releaseViewModel: ReleaseViewModel, modifier: Modifier = Modifier

when (val state = releaseState) {
is ReleaseViewModel.ReleaseUIState.Failure -> {
val message = state.exception.message
val message = when (state.exception) {
is UnknownHostException, is ConnectException ->
stringResource(R.string.release_fetch_no_internet)
else -> state.exception.message
}

UpdateMessageIndicator(
stringResource(R.string.release_fetch_failed, message ?: ""),
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/java/com/geode/launcher/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import com.geode.launcher.api.ReleaseViewModel
import com.geode.launcher.ui.theme.GeodeLauncherTheme
import com.geode.launcher.ui.theme.Typography
import com.geode.launcher.utils.PreferenceUtils
import java.net.ConnectException
import java.net.UnknownHostException

class SettingsActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -118,9 +120,13 @@ fun UpdateIndicator(

when (updateStatus) {
is ReleaseViewModel.ReleaseUIState.Failure -> {
snackbarHostState.showSnackbar(
context.getString(R.string.preference_check_for_updates_failed),
)
val message = when (updateStatus.exception) {
is UnknownHostException, is ConnectException ->
context.getString(R.string.release_fetch_no_internet)
else -> context.getString(R.string.preference_check_for_updates_failed)
}

snackbarHostState.showSnackbar(message)
}
is ReleaseViewModel.ReleaseUIState.Finished -> {
if (updateStatus.hasUpdated) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<string name="release_fetch_success">Geode updated!</string>
<string name="release_fetch_downloading">Downloading update… (%1$s/%2$s)</string>
<string name="release_fetch_cancelling">Cancelling update…</string>
<string name="release_fetch_no_internet">No internet found.</string>
<string name="release_fetch_cancelled">Update cancelled.</string>
<string name="release_fetch_button_retry">Retry</string>
<string name="release_fetch_button_cancel">Cancel</string>
Expand Down Expand Up @@ -54,5 +55,6 @@
<string name="preference_check_for_updates_none_found">No updates found.</string>
<string name="preference_check_for_updates_success">Geode has been updated!</string>
<string name="preference_check_for_updates_downloading">Downloading update…</string>
<string name="preference_check_for_updates_no_internet">No internet found.</string>
<string name="preference_check_for_updates_already_updating">An update is already in progress!</string>
</resources>

0 comments on commit 4ac6345

Please sign in to comment.