Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import me.rhunk.snapenhance.ui.manager.Routes
import me.rhunk.snapenhance.ui.setup.Requirements
import me.rhunk.snapenhance.ui.util.ActivityLauncherHelper
import me.rhunk.snapenhance.ui.util.AlertDialogs
import me.rhunk.snapenhance.ui.util.openFile
import me.rhunk.snapenhance.ui.util.saveFile

class HomeSettings : Routes.Route() {
Expand Down Expand Up @@ -165,40 +166,79 @@ class HomeSettings : Routes.Route() {
var storedStoriesCount by rememberAsyncMutableState(defaultValue = 0) {
context.messageLogger.getStoredStoriesCount()
}
Text(
translation.format("message_logger_summary",
"messageCount" to storedMessagesCount.toString(),
"storyCount" to storedStoriesCount.toString()
), maxLines = 2, modifier = Modifier.padding(5.dp))
Row(
horizontalArrangement = Arrangement.spacedBy(10.dp),
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.padding(5.dp)
) {
Column(
modifier = Modifier.weight(1f),
verticalArrangement = Arrangement.spacedBy(2.dp),
Button(
onClick = {
runCatching {
activityLauncherHelper.saveFile("message_logger.db", "application/octet-stream") { uri ->
context.androidContext.contentResolver.openOutputStream(uri.toUri())?.use { outputStream ->
context.messageLogger.databaseFile.inputStream().use { inputStream ->
inputStream.copyTo(outputStream)
}
}
}
}.onFailure {
context.log.error("Failed to export database", it)
context.longToast("Failed to export database! ${it.localizedMessage}")
}
},
modifier = Modifier.weight(1f)
) {
Text(
translation.format("message_logger_summary",
"messageCount" to storedMessagesCount.toString(),
"storyCount" to storedStoriesCount.toString()
), maxLines = 2)
Text(text = translation["export_button"])
}
Button(onClick = {
runCatching {
activityLauncherHelper.saveFile("message_logger.db", "application/octet-stream") { uri ->
context.androidContext.contentResolver.openOutputStream(uri.toUri())?.use { outputStream ->
context.messageLogger.databaseFile.inputStream().use { inputStream ->
inputStream.copyTo(outputStream)
Button(
onClick = {
runCatching {
activityLauncherHelper.openFile("application/octet-stream") { uri ->
context.androidContext.contentResolver.openInputStream(uri.toUri())?.use { inputStream ->

val tempFile = context.androidContext.cacheDir.resolve("temp_import.db")
tempFile.outputStream().use { outputStream ->
inputStream.copyTo(outputStream)
}

context.messageLogger.closeDatabase()

tempFile.inputStream().use { tempInput ->
context.messageLogger.databaseFile.outputStream().use { dbOutput ->
tempInput.copyTo(dbOutput)
}
}

tempFile.delete()

context.messageLogger.init()

context.coroutineScope.launch {
storedMessagesCount = context.messageLogger.getStoredMessageCount()
storedStoriesCount = context.messageLogger.getStoredStoriesCount()
}

context.shortToast(translation["import_success_toast"])
}
}
}.onFailure {
context.log.error("Failed to import database", it)
context.longToast("Failed to import database! ${it.localizedMessage}")
}
}.onFailure {
context.log.error("Failed to export database", it)
context.longToast("Failed to export database! ${it.localizedMessage}")
}
}) {
Text(text = translation["export_button"])
},
modifier = Modifier.weight(1f)
) {
Text(text = translation["import_button"])
}
Button(onClick = {
}
Button(
onClick = {
runCatching {
context.messageLogger.purgeAll()
storedMessagesCount = 0
Expand All @@ -209,9 +249,12 @@ class HomeSettings : Routes.Route() {
}.onSuccess {
context.shortToast(translation["success_toast"])
}
}) {
Text(text = translation["clear_button"])
}
},
modifier = Modifier
.fillMaxWidth()
.padding(5.dp)
) {
Text(text = translation["clear_button"])
}
OutlinedButton(
modifier = Modifier
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/assets/lang/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
"message_logger_summary": "{messageCount} Nachrichten\n{storyCount} Stories",
"success_toast": "Erledigt!",
"export_button": "Exportieren",
"import_button": "Importieren",
"import_success_toast": "Datenbank erfolgreich importiert",
"clear_button": "Löschen",
"view_logger_history_button": "Historie des Nachrichtenaufzeichners ansehen"
},
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/assets/lang/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
"success_toast": "Done!",
"message_logger_summary": "{messageCount} messages\n{storyCount} stories",
"export_button": "Export",
"import_button": "Import",
"import_success_toast": "Database imported successfully",
"clear_button": "Clear",
"view_logger_history_button": "View Logger History"
},
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/assets/lang/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
"success_toast": "¡Hecho!",
"message_logger_summary": "{messageCount} mensajes\n{storyCount} historias",
"export_button": "Exportar",
"import_button": "Importar",
"import_success_toast": "Base de datos importada exitosamente",
"clear_button": "Borrar",
"view_logger_history_button": "Ver historial del registrador"
},
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/assets/lang/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@
"success_toast": "Succès !",
"message_logger_summary": "{messageCount} message(s)\n{storyCount} stories",
"export_button": "Exporter",
"import_button": "Importer",
"import_success_toast": "Base de données importée avec succès",
"clear_button": "Vider",
"view_logger_history_button": "Afficher l'historique de l'enregistreur"
},
Expand Down
4 changes: 3 additions & 1 deletion common/src/main/assets/lang/it_IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@
"clear_button": "Pulisci",
"debug_title": "Debug",
"actions_title": "Azioni",
"export_button": "Esporta"
"export_button": "Esporta",
"import_button": "Importa",
"import_success_toast": "Database importato con successo"
},
"home": {
"update_button": "Scarica",
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/assets/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
},
"home_settings": {
"export_button": "Экспорт",
"import_button": "Импорт",
"import_success_toast": "База данных успешно импортирована",
"clear_button": "Очистить",
"view_logger_history_button": "Посмотреть логгер историй",
"message_logger_title": "Логгер сообщений",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ class LoggerWrapper(

}

fun closeDatabase() {
synchronized(this) {
_database?.close()
_database = null
}
}

override fun getLoggedIds(conversationId: Array<String>, limit: Int): LongArray {
if (conversationId.any {
runCatching { UUID.fromString(it) }.isFailure
Expand Down