Show toast after restoring the database
This commit is contained in:
parent
64bfe50dda
commit
b9880a3955
1 changed files with 14 additions and 11 deletions
|
@ -1,6 +1,7 @@
|
||||||
package it.vfsfitvnm.vimusic.ui.screens.settings
|
package it.vfsfitvnm.vimusic.ui.screens.settings
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.animation.ExperimentalAnimationApi
|
import androidx.compose.animation.ExperimentalAnimationApi
|
||||||
|
@ -55,12 +56,11 @@ fun DatabaseSettings() {
|
||||||
query {
|
query {
|
||||||
Database.internal.checkpoint()
|
Database.internal.checkpoint()
|
||||||
|
|
||||||
context.applicationContext.contentResolver.openOutputStream(uri)
|
context.applicationContext.contentResolver.openOutputStream(uri)?.use { output ->
|
||||||
?.use { outputStream ->
|
FileInputStream(Database.internal.path).use { input ->
|
||||||
FileInputStream(Database.internal.path).use { inputStream ->
|
input.copyTo(output)
|
||||||
inputStream.copyTo(outputStream)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,16 +68,19 @@ fun DatabaseSettings() {
|
||||||
rememberLauncherForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
|
rememberLauncherForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
|
||||||
if (uri == null) return@rememberLauncherForActivityResult
|
if (uri == null) return@rememberLauncherForActivityResult
|
||||||
|
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
"${context.applicationInfo.nonLocalizedLabel} is going to close itself after restoring the database",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
|
||||||
query {
|
query {
|
||||||
Database.internal.checkpoint()
|
Database.internal.checkpoint()
|
||||||
Database.internal.close()
|
Database.internal.close()
|
||||||
|
|
||||||
context.applicationContext.contentResolver.openInputStream(uri)
|
context.applicationContext.contentResolver.openInputStream(uri)?.use { input ->
|
||||||
?.use { inputStream ->
|
FileOutputStream(Database.internal.path).use(input::copyTo)
|
||||||
FileOutputStream(Database.internal.path).use { outputStream ->
|
}
|
||||||
inputStream.copyTo(outputStream)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
context.stopService(context.intent<PlayerService>())
|
context.stopService(context.intent<PlayerService>())
|
||||||
exitProcess(0)
|
exitProcess(0)
|
||||||
|
|
Loading…
Reference in a new issue