Move import export manager to separate folder
This commit is contained in:
parent
5e7ad6ffd1
commit
ea18b4ea1f
3 changed files with 19 additions and 16 deletions
|
@ -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<Intent> 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);
|
||||
|
|
|
@ -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"
|
||||
}
|
|
@ -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())
|
Loading…
Reference in a new issue