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

Commit

Permalink
Add swipe to refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
M3DZIK committed Oct 14, 2023
1 parent 6342d23 commit 4fe5780
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ dependencies {
implementation(libs.androidx.ui)
implementation(libs.coil.compose)
implementation(libs.google.accompanist.drawablepainter)
implementation(libs.google.accompanist.swiperefresh)
implementation(libs.google.accompanist.systemuicontroller)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.librepass.client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.navigation.NavController
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import dev.medzik.android.components.navigate
import dev.medzik.android.components.rememberMutableBoolean
import dev.medzik.librepass.android.data.CipherTable
Expand Down Expand Up @@ -150,37 +152,44 @@ fun VaultScreen(navController: NavController) {
updateCiphers()
}

LazyColumn(
modifier = Modifier.fillMaxSize()
// Google has not yet added pull refresh to material3 for reasons unknown to me.
@Suppress("DEPRECATION")
SwipeRefresh(
state = rememberSwipeRefreshState(refreshing),
onRefresh = { updateCiphers() },
) {
items(ciphers.size) { index ->
CipherCard(
cipher = ciphers[index],
onClick = { cipher ->
navController.navigate(
screen = Screen.CipherView,
args = arrayOf(Argument.CipherId to cipher.id.toString())
)
},
onEdit = { cipher ->
navController.navigate(
screen = Screen.CipherEdit,
args = arrayOf(Argument.CipherId to cipher.id.toString())
)
},
onDelete = { cipher ->
scope.launch(Dispatchers.IO) {
try {
cipherClient.delete(cipher.id)
repository.cipher.delete(cipher.id)

ciphers = ciphers.filter { it.id != cipher.id }
} catch (e: Exception) {
e.showErrorToast(context)
LazyColumn(
modifier = Modifier.fillMaxSize()
) {
items(ciphers.size) { index ->
CipherCard(
cipher = ciphers[index],
onClick = { cipher ->
navController.navigate(
screen = Screen.CipherView,
args = arrayOf(Argument.CipherId to cipher.id.toString())
)
},
onEdit = { cipher ->
navController.navigate(
screen = Screen.CipherEdit,
args = arrayOf(Argument.CipherId to cipher.id.toString())
)
},
onDelete = { cipher ->
scope.launch(Dispatchers.IO) {
try {
cipherClient.delete(cipher.id)
repository.cipher.delete(cipher.id)

ciphers = ciphers.filter { it.id != cipher.id }
} catch (e: Exception) {
e.showErrorToast(context)
}
}
}
}
)
)
}
}
}
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-toolin
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil-compose" }
commons-codec = { module = "commons-codec:commons-codec", version.ref = "commons-codec" }
google-accompanist-drawablepainter = { module = "com.google.accompanist:accompanist-drawablepainter", version.ref = "google-accompanist" }
google-accompanist-swiperefresh = { module = "com.google.accompanist:accompanist-swiperefresh", version.ref = "google-accompanist" }
google-accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "google-accompanist" }
google-material = { module = "com.google.android.material:material", version.ref = "google-material" }
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinx-coroutines-android" }
Expand Down

0 comments on commit 4fe5780

Please sign in to comment.