From ea18b4ea1f853c90e84d27eb0a787fd061014449 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sun, 31 Dec 2023 16:28:21 +0100 Subject: [PATCH] Move import export manager to separate folder --- .../BackupRestoreSettingsFragment.java | 5 ++-- .../ImportExportManager.kt} | 5 ++-- ...agerTest.kt => ImportExportManagerTest.kt} | 25 ++++++++++--------- 3 files changed, 19 insertions(+), 16 deletions(-) rename app/src/main/java/org/schabi/newpipe/settings/{ContentSettingsManager.kt => export/ImportExportManager.kt} (96%) rename app/src/test/java/org/schabi/newpipe/settings/{ContentSettingsManagerTest.kt => ImportExportManagerTest.kt} (87%) diff --git a/app/src/main/java/org/schabi/newpipe/settings/BackupRestoreSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/BackupRestoreSettingsFragment.java index bc24fbe81..842023e50 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/BackupRestoreSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/BackupRestoreSettingsFragment.java @@ -24,6 +24,7 @@ import androidx.preference.PreferenceManager; import org.schabi.newpipe.NewPipeDatabase; import org.schabi.newpipe.R; import org.schabi.newpipe.error.ErrorUtil; +import org.schabi.newpipe.settings.export.ImportExportManager; import org.schabi.newpipe.streams.io.NoFileManagerSafeGuard; import org.schabi.newpipe.streams.io.StoredFileHelper; import org.schabi.newpipe.util.NavigationHelper; @@ -42,7 +43,7 @@ public class BackupRestoreSettingsFragment extends BasePreferenceFragment { private final SimpleDateFormat exportDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US); - private ContentSettingsManager manager; + private ImportExportManager manager; private String importExportDataPathKey; private final ActivityResultLauncher requestImportPathLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), @@ -57,7 +58,7 @@ public class BackupRestoreSettingsFragment extends BasePreferenceFragment { @Nullable final String rootKey) { final File homeDir = ContextCompat.getDataDir(requireContext()); Objects.requireNonNull(homeDir); - manager = new ContentSettingsManager(new NewPipeFileLocator(homeDir)); + manager = new ImportExportManager(new NewPipeFileLocator(homeDir)); manager.deleteSettingsFile(); importExportDataPathKey = getString(R.string.import_export_data_path); diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsManager.kt b/app/src/main/java/org/schabi/newpipe/settings/export/ImportExportManager.kt similarity index 96% rename from app/src/main/java/org/schabi/newpipe/settings/ContentSettingsManager.kt rename to app/src/main/java/org/schabi/newpipe/settings/export/ImportExportManager.kt index df56de516..9954a2b36 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsManager.kt +++ b/app/src/main/java/org/schabi/newpipe/settings/export/ImportExportManager.kt @@ -1,8 +1,9 @@ -package org.schabi.newpipe.settings +package org.schabi.newpipe.settings.export import android.content.SharedPreferences import android.util.Log import org.schabi.newpipe.MainActivity.DEBUG +import org.schabi.newpipe.settings.NewPipeFileLocator import org.schabi.newpipe.streams.io.SharpOutputStream import org.schabi.newpipe.streams.io.StoredFileHelper import org.schabi.newpipe.util.ZipHelper @@ -11,7 +12,7 @@ import java.io.ObjectInputStream import java.io.ObjectOutputStream import java.util.zip.ZipOutputStream -class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) { +class ImportExportManager(private val fileLocator: NewPipeFileLocator) { companion object { const val TAG = "ContentSetManager" } diff --git a/app/src/test/java/org/schabi/newpipe/settings/ContentSettingsManagerTest.kt b/app/src/test/java/org/schabi/newpipe/settings/ImportExportManagerTest.kt similarity index 87% rename from app/src/test/java/org/schabi/newpipe/settings/ContentSettingsManagerTest.kt rename to app/src/test/java/org/schabi/newpipe/settings/ImportExportManagerTest.kt index ec41a77f8..7b219df18 100644 --- a/app/src/test/java/org/schabi/newpipe/settings/ContentSettingsManagerTest.kt +++ b/app/src/test/java/org/schabi/newpipe/settings/ImportExportManagerTest.kt @@ -17,6 +17,7 @@ import org.mockito.Mockito.verify import org.mockito.Mockito.`when` import org.mockito.Mockito.withSettings import org.mockito.junit.MockitoJUnitRunner +import org.schabi.newpipe.settings.export.ImportExportManager import org.schabi.newpipe.streams.io.StoredFileHelper import us.shandian.giga.io.FileStream import java.io.File @@ -25,10 +26,10 @@ import java.nio.file.Files import java.util.zip.ZipFile @RunWith(MockitoJUnitRunner::class) -class ContentSettingsManagerTest { +class ImportExportManagerTest { companion object { - private val classloader = ContentSettingsManager::class.java.classLoader!! + private val classloader = ImportExportManager::class.java.classLoader!! } private lateinit var fileLocator: NewPipeFileLocator @@ -54,7 +55,7 @@ class ContentSettingsManagerTest { val output = File.createTempFile("newpipe_", "") `when`(storedFileHelper.stream).thenReturn(FileStream(output)) - ContentSettingsManager(fileLocator).exportDatabase(sharedPreferences, storedFileHelper) + ImportExportManager(fileLocator).exportDatabase(sharedPreferences, storedFileHelper) val zipFile = ZipFile(output) val entries = zipFile.entries().toList() @@ -77,7 +78,7 @@ class ContentSettingsManagerTest { val settings = File.createTempFile("newpipe_", "") `when`(fileLocator.settings).thenReturn(settings) - ContentSettingsManager(fileLocator).deleteSettingsFile() + ImportExportManager(fileLocator).deleteSettingsFile() assertFalse(settings.exists()) } @@ -87,7 +88,7 @@ class ContentSettingsManagerTest { val settings = File("non_existent") `when`(fileLocator.settings).thenReturn(settings) - ContentSettingsManager(fileLocator).deleteSettingsFile() + ImportExportManager(fileLocator).deleteSettingsFile() assertFalse(settings.exists()) } @@ -98,7 +99,7 @@ class ContentSettingsManagerTest { Assume.assumeTrue(dir.delete()) `when`(fileLocator.dbDir).thenReturn(dir) - ContentSettingsManager(fileLocator).ensureDbDirectoryExists() + ImportExportManager(fileLocator).ensureDbDirectoryExists() assertTrue(dir.exists()) } @@ -107,7 +108,7 @@ class ContentSettingsManagerTest { val dir = Files.createTempDirectory("newpipe_").toFile() `when`(fileLocator.dbDir).thenReturn(dir) - ContentSettingsManager(fileLocator).ensureDbDirectoryExists() + ImportExportManager(fileLocator).ensureDbDirectoryExists() assertTrue(dir.exists()) } @@ -124,7 +125,7 @@ class ContentSettingsManagerTest { val zip = File(classloader.getResource("settings/newpipe.zip")?.file!!) `when`(storedFileHelper.stream).thenReturn(FileStream(zip)) - val success = ContentSettingsManager(fileLocator).extractDb(storedFileHelper) + val success = ImportExportManager(fileLocator).extractDb(storedFileHelper) assertTrue(success) assertFalse(dbJournal.exists()) @@ -143,7 +144,7 @@ class ContentSettingsManagerTest { val emptyZip = File(classloader.getResource("settings/empty.zip")?.file!!) `when`(storedFileHelper.stream).thenReturn(FileStream(emptyZip)) - val success = ContentSettingsManager(fileLocator).extractDb(storedFileHelper) + val success = ImportExportManager(fileLocator).extractDb(storedFileHelper) assertFalse(success) assertTrue(dbJournal.exists()) @@ -159,7 +160,7 @@ class ContentSettingsManagerTest { val zip = File(classloader.getResource("settings/newpipe.zip")?.file!!) `when`(storedFileHelper.stream).thenReturn(FileStream(zip)) - val contains = ContentSettingsManager(fileLocator).extractSettings(storedFileHelper) + val contains = ImportExportManager(fileLocator).extractSettings(storedFileHelper) assertTrue(contains) } @@ -171,7 +172,7 @@ class ContentSettingsManagerTest { val emptyZip = File(classloader.getResource("settings/empty.zip")?.file!!) `when`(storedFileHelper.stream).thenReturn(FileStream(emptyZip)) - val contains = ContentSettingsManager(fileLocator).extractSettings(storedFileHelper) + val contains = ImportExportManager(fileLocator).extractSettings(storedFileHelper) assertFalse(contains) } @@ -185,7 +186,7 @@ class ContentSettingsManagerTest { val editor = Mockito.mock(SharedPreferences.Editor::class.java) `when`(preferences.edit()).thenReturn(editor) - ContentSettingsManager(fileLocator).loadSharedPreferences(preferences) + ImportExportManager(fileLocator).loadSharedPreferences(preferences) verify(editor, atLeastOnce()).putBoolean(anyString(), anyBoolean()) verify(editor, atLeastOnce()).putString(anyString(), anyString())