Commit 65e17298 authored by Geoffrey Métais's avatar Geoffrey Métais

Advanced option to dump media library

(cherry picked from commit a5cadec2)
parent 48ee9772
......@@ -415,6 +415,8 @@
<string name="save_video_always">Save speed across sessions</string>
<string name="auto_rescan">Auto rescan</string>
<string name="auto_rescan_summary">Automatically scan device for new or deleted media at application startup</string>
<string name="dump_media_db">Dump media database</string>
<string name="dump_media_db_summary">Copy database to internal storage root</string>
<string name="clear_media_db">Clear media database</string>
<string name="clear_media_db_summary">Access Android VLC info to clear data</string>
<string name="clear_history">Clear search history</string>
......
......@@ -16,6 +16,12 @@
android:summary="@string/network_caching_summary"
android:title="@string/network_caching" />
<Preference
android:enabled="true"
android:key="dump_media_db"
android:summary="@string/dump_media_db_summary"
android:title="@string/dump_media_db" />
<Preference
android:enabled="true"
android:key="clear_media_db"
......
......@@ -24,6 +24,7 @@
package org.videolan.vlc.gui.preferences;
import android.Manifest;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
......@@ -34,15 +35,22 @@ import android.support.v7.app.AlertDialog;
import android.support.v7.preference.EditTextPreference;
import android.support.v7.preference.Preference;
import android.text.TextUtils;
import android.widget.Toast;
import org.videolan.libvlc.util.AndroidUtil;
import org.videolan.medialibrary.Medialibrary;
import org.videolan.vlc.BuildConfig;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.DebugLogActivity;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.FileUtils;
import org.videolan.vlc.util.Permissions;
import org.videolan.vlc.util.VLCInstance;
import java.io.File;
public class PreferencesAdvanced extends BasePreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected int getXml() {
......@@ -104,7 +112,7 @@ public class PreferencesAdvanced extends BasePreferenceFragment implements Share
.setNegativeButton(android.R.string.cancel, null).show();
return true;
case "clear_media_db":
Intent i = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
final Intent i = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
i.addCategory(Intent.CATEGORY_DEFAULT);
i.setData(Uri.parse("package:" + VLCApplication.getAppContext().getPackageName()));
startActivity(i);
......@@ -112,6 +120,39 @@ public class PreferencesAdvanced extends BasePreferenceFragment implements Share
case "quit_app":
android.os.Process.killProcess(android.os.Process.myPid());
return true;
case "dump_media_db":
if (VLCApplication.getMLInstance().isWorking())
UiTools.snacker(getView(), getString(R.string.settings_ml_block_scan));
else {
VLCApplication.runBackground(new Runnable() {
@Override
public void run() {
final Runnable dump = new Runnable() {
@Override
public void run() {
final File db = new File(VLCApplication.getAppContext().getDir("db", Context.MODE_PRIVATE)+ Medialibrary.VLC_MEDIA_DB_NAME);
if (FileUtils.copyFile(db, new File(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + Medialibrary.VLC_MEDIA_DB_NAME)))
VLCApplication.runOnMainThread(new Runnable() {
@Override
public void run() {
Toast.makeText(VLCApplication.getAppContext(), "Database dumped on internal storage root", Toast.LENGTH_LONG).show();
}
});
else VLCApplication.runOnMainThread(new Runnable() {
@Override
public void run() {
Toast.makeText(VLCApplication.getAppContext(), "Failed to dumped database", Toast.LENGTH_LONG).show();
}
});
}
};
if (Permissions.canWriteStorage()) dump.run();
else Permissions.askWriteStoragePermission(getActivity(), false, dump);
}
});
}
return true;
}
return super.onPreferenceTreeClick(preference);
}
......
......@@ -180,7 +180,7 @@ public class FileUtils {
}
}
private static boolean copyFile(File src, File dst){
public static boolean copyFile(File src, File dst){
boolean ret = true;
if (src.isDirectory()) {
File[] filesList = src.listFiles();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment