Extract settings file deletion
This commit is contained in:
parent
122e80fae9
commit
af119db1d7
|
@ -44,13 +44,6 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||||
|
|
||||||
private ContentSettingsManager manager;
|
private ContentSettingsManager manager;
|
||||||
|
|
||||||
private File databasesDir;
|
|
||||||
private File newpipeDb;
|
|
||||||
private File newpipeDbJournal;
|
|
||||||
private File newpipeDbShm;
|
|
||||||
private File newpipeDbWal;
|
|
||||||
private File newpipeSettings;
|
|
||||||
|
|
||||||
private String thumbnailLoadToggleKey;
|
private String thumbnailLoadToggleKey;
|
||||||
private String youtubeRestrictedModeEnabledKey;
|
private String youtubeRestrictedModeEnabledKey;
|
||||||
|
|
||||||
|
@ -115,16 +108,8 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
|
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
|
||||||
final File homeDir = ContextCompat.getDataDir(requireContext());
|
final File homeDir = ContextCompat.getDataDir(requireContext());
|
||||||
databasesDir = new File(homeDir, "/databases");
|
|
||||||
newpipeDb = new File(homeDir, "/databases/newpipe.db");
|
|
||||||
newpipeDbJournal = new File(homeDir, "/databases/newpipe.db-journal");
|
|
||||||
newpipeDbShm = new File(homeDir, "/databases/newpipe.db-shm");
|
|
||||||
newpipeDbWal = new File(homeDir, "/databases/newpipe.db-wal");
|
|
||||||
|
|
||||||
newpipeSettings = new File(homeDir, "/databases/newpipe.settings");
|
|
||||||
newpipeSettings.delete();
|
|
||||||
|
|
||||||
manager = new ContentSettingsManager(new NewPipeFileLocator(homeDir));
|
manager = new ContentSettingsManager(new NewPipeFileLocator(homeDir));
|
||||||
|
manager.deleteSettingsFile();
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.content_settings);
|
addPreferencesFromResource(R.xml.content_settings);
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ import java.io.FileOutputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.ObjectInputStream
|
import java.io.ObjectInputStream
|
||||||
import java.io.ObjectOutputStream
|
import java.io.ObjectOutputStream
|
||||||
import java.util.zip.ZipFile
|
|
||||||
import java.util.zip.ZipOutputStream
|
import java.util.zip.ZipOutputStream
|
||||||
|
|
||||||
class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) {
|
class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) {
|
||||||
|
@ -36,6 +35,10 @@ class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun deleteSettingsFile() {
|
||||||
|
fileLocator.settings.delete()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to create database directory if it does not exist.
|
* Tries to create database directory if it does not exist.
|
||||||
*
|
*
|
||||||
|
|
|
@ -65,6 +65,26 @@ class ContentSettingsManagerTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Settings file must be deleted`() {
|
||||||
|
val settings = File.createTempFile("newpipe_", "")
|
||||||
|
`when`(fileLocator.settings).thenReturn(settings)
|
||||||
|
|
||||||
|
ContentSettingsManager(fileLocator).deleteSettingsFile()
|
||||||
|
|
||||||
|
assertFalse(settings.exists())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Deleting settings file must do nothing if none exist`() {
|
||||||
|
val settings = File("non_existent")
|
||||||
|
`when`(fileLocator.settings).thenReturn(settings)
|
||||||
|
|
||||||
|
ContentSettingsManager(fileLocator).deleteSettingsFile()
|
||||||
|
|
||||||
|
assertFalse(settings.exists())
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `The database must be extracted from the zip file`() {
|
fun `The database must be extracted from the zip file`() {
|
||||||
val db = File.createTempFile("newpipe_", "")
|
val db = File.createTempFile("newpipe_", "")
|
||||||
|
|
Loading…
Reference in New Issue