Add media scan config
This commit is contained in:
1 parent
97c28c04c5
commit
a2a9dbcb02
9 files changed
+74
-9
No files matched your search
@@ -43,6 +43,7 @@ import com.hippo.network.StatusCodeException;
|
||||
import com.hippo.okhttp.CookieDB;
|
||||
import com.hippo.scene.SceneApplication;
|
||||
import com.hippo.text.Html;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.BitmapUtils;
|
||||
import com.hippo.util.ReadableTime;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
@@ -112,8 +113,18 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
Analytics.start(this);
|
||||
}
|
||||
|
||||
CommonOperations.ensureNoMediaFile(Settings.getDownloadLocation());
|
||||
// Check no media file
|
||||
UniFile downloadLocation = Settings.getDownloadLocation();
|
||||
if (Settings.getMediaScan()) {
|
||||
CommonOperations.removeNoMediaFile(downloadLocation);
|
||||
} else {
|
||||
CommonOperations.ensureNoMediaFile(downloadLocation);
|
||||
}
|
||||
|
||||
// Clear temp dir
|
||||
clearTempDir();
|
||||
|
||||
// Check app update
|
||||
update();
|
||||
|
||||
// Update version code
|
||||
|
||||
@@ -559,7 +559,18 @@ public class Settings {
|
||||
putString(KEY_DOWNLOAD_SAVE_QUERY, uri.getEncodedQuery());
|
||||
putString(KEY_DOWNLOAD_SAVE_FRAGMENT, uri.getEncodedFragment());
|
||||
|
||||
CommonOperations.ensureNoMediaFile(location);
|
||||
if (getMediaScan()) {
|
||||
CommonOperations.removeNoMediaFile(location);
|
||||
} else {
|
||||
CommonOperations.ensureNoMediaFile(location);
|
||||
}
|
||||
}
|
||||
|
||||
public static final String KEY_MEDIA_SCAN = "media_scan";
|
||||
private static final boolean DEFAULT_MEDIA_SCAN = false;
|
||||
|
||||
public static boolean getMediaScan() {
|
||||
return getBoolean(KEY_MEDIA_SCAN, DEFAULT_MEDIA_SCAN);
|
||||
}
|
||||
|
||||
private static final String KEY_RECENT_DOWNLOAD_LABEL = "recent_download_label";
|
||||
|
||||
@@ -309,4 +309,15 @@ public final class CommonOperations {
|
||||
IOUtils.closeQuietly(is);
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeNoMediaFile(UniFile file) {
|
||||
if (null == file) {
|
||||
return;
|
||||
}
|
||||
|
||||
UniFile noMedia = file.subFile(".nomedia");
|
||||
if (null != noMedia && noMedia.isFile()) {
|
||||
noMedia.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ import android.widget.Toast;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.ehviewer.ui.DirPickerActivity;
|
||||
import com.hippo.unifile.UniFile;
|
||||
|
||||
@@ -52,11 +53,13 @@ public class DownloadFragment extends PreferenceFragment implements
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.download_settings);
|
||||
|
||||
Preference mediaScan = findPreference(Settings.KEY_MEDIA_SCAN);
|
||||
Preference imageSize = findPreference(Settings.KEY_IMAGE_SIZE);
|
||||
mDownloadLocation = findPreference(KEY_DOWNLOAD_LOCATION);
|
||||
|
||||
onUpdateDownloadLocation();
|
||||
|
||||
mediaScan.setOnPreferenceChangeListener(this);
|
||||
imageSize.setOnPreferenceChangeListener(this);
|
||||
|
||||
if (mDownloadLocation != null) {
|
||||
@@ -190,7 +193,17 @@ public class DownloadFragment extends PreferenceFragment implements
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
String key = preference.getKey();
|
||||
if (Settings.KEY_IMAGE_SIZE.equals(key)) {
|
||||
if (Settings.KEY_MEDIA_SCAN.equals(key)) {
|
||||
if (newValue instanceof Boolean) {
|
||||
UniFile downloadLocation = Settings.getDownloadLocation();
|
||||
if ((Boolean) newValue) {
|
||||
CommonOperations.removeNoMediaFile(downloadLocation);
|
||||
} else {
|
||||
CommonOperations.ensureNoMediaFile(downloadLocation);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if (Settings.KEY_IMAGE_SIZE.equals(key)) {
|
||||
if (newValue instanceof String) {
|
||||
Settings.putImageSize((String) newValue);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user