Fix crashes

pull/543/head
Koitharu 3 years ago
parent f87db4e6d3
commit 1af1f071ad
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -82,7 +82,7 @@ afterEvaluate {
} }
dependencies { dependencies {
//noinspection GradleDependency //noinspection GradleDependency
implementation('com.github.KotatsuApp:kotatsu-parsers:e9d473711d') { implementation('com.github.KotatsuApp:kotatsu-parsers:c892a38c52') {
exclude group: 'org.json', module: 'json' exclude group: 'org.json', module: 'json'
} }

@ -26,7 +26,7 @@ class CompositeMutex<T : Any> : Set<T> {
} }
override fun isEmpty(): Boolean { override fun isEmpty(): Boolean {
return state.isEmpty return state.isEmpty()
} }
override fun iterator(): Iterator<T> { override fun iterator(): Iterator<T> {

@ -19,7 +19,7 @@ class CompositeMutex2<T : Any> : Set<T> {
} }
override fun isEmpty(): Boolean { override fun isEmpty(): Boolean {
return delegates.isEmpty return delegates.isEmpty()
} }
override fun iterator(): Iterator<T> { override fun iterator(): Iterator<T> {

@ -139,6 +139,7 @@ class AppearanceSettingsFragment :
private val deviceLocales = LocaleManagerCompat.getSystemLocales(context) private val deviceLocales = LocaleManagerCompat.getSystemLocales(context)
.map { it.language } .map { it.language }
.distinct()
override fun compare(a: Locale, b: Locale): Int { override fun compare(a: Locale, b: Locale): Int {
return if (a === b) { return if (a === b) {

@ -16,6 +16,7 @@ import org.koitharu.kotatsu.core.ui.AlertDialogFragment
import org.koitharu.kotatsu.core.util.ext.getDisplayMessage import org.koitharu.kotatsu.core.util.ext.getDisplayMessage
import org.koitharu.kotatsu.core.util.ext.observe import org.koitharu.kotatsu.core.util.ext.observe
import org.koitharu.kotatsu.core.util.ext.observeEvent import org.koitharu.kotatsu.core.util.ext.observeEvent
import org.koitharu.kotatsu.core.util.ext.tryLaunch
import org.koitharu.kotatsu.databinding.DialogProgressBinding import org.koitharu.kotatsu.databinding.DialogProgressBinding
import java.io.File import java.io.File
import java.io.FileOutputStream import java.io.FileOutputStream
@ -81,7 +82,10 @@ class BackupDialogFragment : AlertDialogFragment<DialogProgressBinding>() {
private fun onBackupDone(file: File) { private fun onBackupDone(file: File) {
this.backup = file this.backup = file
saveFileContract.launch(file.name) if (!saveFileContract.tryLaunch(file.name)) {
Toast.makeText(requireContext(), R.string.operation_not_supported, Toast.LENGTH_SHORT).show()
dismiss()
}
} }
private fun saveBackup(file: File, output: Uri) { private fun saveBackup(file: File, output: Uri) {
@ -91,7 +95,7 @@ class BackupDialogFragment : AlertDialogFragment<DialogProgressBinding>() {
it.write(file.readBytes()) it.write(file.readBytes())
} }
} }
Toast.makeText(requireContext(), R.string.backup_saved, Toast.LENGTH_LONG).show() Toast.makeText(requireContext(), R.string.backup_saved, Toast.LENGTH_SHORT).show()
dismiss() dismiss()
} catch (e: InterruptedException) { } catch (e: InterruptedException) {
throw e throw e

@ -52,9 +52,9 @@ class PeriodicalBackupWorker @AssistedInject constructor(
} }
val dirUri = settings.periodicalBackupOutput ?: return Result.success(resultData) val dirUri = settings.periodicalBackupOutput ?: return Result.success(resultData)
val target = DocumentFile.fromTreeUri(applicationContext, dirUri) val target = DocumentFile.fromTreeUri(applicationContext, dirUri)
?.createFile("application/zip", file.name) ?.createFile("application/zip", file.nameWithoutExtension)
?.uri ?: return Result.failure() ?.uri ?: return Result.failure()
applicationContext.contentResolver.openOutputStream(target)?.use { output -> applicationContext.contentResolver.openOutputStream(target, "wt")?.use { output ->
file.source().use { input -> file.source().use { input ->
output.sink().buffer().writeAllCancellable(input) output.sink().buffer().writeAllCancellable(input)
} }

Loading…
Cancel
Save