From 716d79597050a24b315d5b384e744b4a3b47983b Mon Sep 17 00:00:00 2001 From: XiangRongLin <41164160+XiangRongLin@users.noreply.github.com> Date: Sat, 19 Dec 2020 16:54:42 +0100 Subject: [PATCH] cleanup --- .../settings/ContentSettingsManager.kt | 23 ++++++++++--------- .../newpipe/settings/NewPipeFileLocator.kt | 1 - .../settings/ContentSettingsManagerTest.kt | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsManager.kt b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsManager.kt index 49d35d984..1730a230e 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsManager.kt +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsManager.kt @@ -19,19 +19,19 @@ class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) { @Throws(Exception::class) fun exportDatabase(preferences: SharedPreferences, outputPath: String) { ZipOutputStream(BufferedOutputStream(FileOutputStream(outputPath))) - .use { outZip -> - ZipHelper.addFileToZip(outZip, fileLocator.db.path, "newpipe.db") + .use { outZip -> + ZipHelper.addFileToZip(outZip, fileLocator.db.path, "newpipe.db") - try { - ObjectOutputStream(FileOutputStream(fileLocator.settings)).use { output -> - output.writeObject(preferences.all) - output.flush() - } - } catch (e: IOException) { - e.printStackTrace() + try { + ObjectOutputStream(FileOutputStream(fileLocator.settings)).use { output -> + output.writeObject(preferences.all) + output.flush() } + } catch (e: IOException) { + e.printStackTrace() + } - ZipHelper.addFileToZip(outZip, fileLocator.settings.path, "newpipe.settings") + ZipHelper.addFileToZip(outZip, fileLocator.settings.path, "newpipe.settings") } } @@ -61,7 +61,7 @@ class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) { fun extractSettings(filePath: String): Boolean { return ZipHelper - .extractFileFromZip(filePath, fileLocator.settings.path, "newpipe.settings") + .extractFileFromZip(filePath, fileLocator.settings.path, "newpipe.settings") } fun loadSharedPreferences(preferences: SharedPreferences) { @@ -70,6 +70,7 @@ class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) { ObjectInputStream(FileInputStream(fileLocator.settings)).use { input -> preferenceEditor.clear() + @Suppress("UNCHECKED_CAST") val entries = input.readObject() as Map for ((key, value) in entries) { when (value) { diff --git a/app/src/main/java/org/schabi/newpipe/settings/NewPipeFileLocator.kt b/app/src/main/java/org/schabi/newpipe/settings/NewPipeFileLocator.kt index 1fe2fffa0..c2f93d15f 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/NewPipeFileLocator.kt +++ b/app/src/main/java/org/schabi/newpipe/settings/NewPipeFileLocator.kt @@ -18,5 +18,4 @@ class NewPipeFileLocator(private val homeDir: File) { val dbWal by lazy { File(homeDir, "/databases/newpipe.db-wal") } val settings by lazy { File(homeDir, "/databases/newpipe.settings") } - } diff --git a/app/src/test/java/org/schabi/newpipe/settings/ContentSettingsManagerTest.kt b/app/src/test/java/org/schabi/newpipe/settings/ContentSettingsManagerTest.kt index a21ad7cb1..3c59c29b3 100644 --- a/app/src/test/java/org/schabi/newpipe/settings/ContentSettingsManagerTest.kt +++ b/app/src/test/java/org/schabi/newpipe/settings/ContentSettingsManagerTest.kt @@ -10,9 +10,9 @@ import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mockito import org.mockito.Mockito.`when` -import org.mockito.Mockito.anyString import org.mockito.Mockito.anyBoolean import org.mockito.Mockito.anyInt +import org.mockito.Mockito.anyString import org.mockito.Mockito.atLeastOnce import org.mockito.Mockito.verify import org.mockito.Mockito.withSettings