Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Don't show toast with "Network error" after app launch
Browse files Browse the repository at this point in the history
closes #102
  • Loading branch information
M3DZIK committed Mar 2, 2024
1 parent 0e1fd79 commit 7d86228
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
android:required="false" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-permission android:name="android.permission.CAMERA" />

<application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import dev.medzik.librepass.android.ui.Screen
import dev.medzik.librepass.android.ui.components.CipherCard
import dev.medzik.librepass.android.utils.KeyAlias
import dev.medzik.librepass.android.utils.checkIfBiometricAvailable
import dev.medzik.librepass.android.utils.haveNetworkConnection
import dev.medzik.librepass.android.utils.showBiometricPromptForSetup
import dev.medzik.librepass.android.utils.showErrorToast
import dev.medzik.librepass.client.Server
Expand Down Expand Up @@ -169,7 +170,9 @@ fun VaultScreen(
ciphers = viewModel.vault.sortAlphabetically()

// sync remote ciphers
updateCiphers()
if (context.haveNetworkConnection()) {
updateCiphers()
}
}

val pullRefreshState = rememberPullRefreshState(refreshing, ::updateCiphers)
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/dev/medzik/librepass/android/utils/Network.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dev.medzik.librepass.android.utils

import android.content.Context
import android.net.ConnectivityManager

fun Context.haveNetworkConnection(): Boolean {
val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork = connectivityManager.activeNetwork
return activeNetwork != null
}

0 comments on commit 7d86228

Please sign in to comment.