Changes:
- Declare RxJava as dependency - Add a folder chooser for downloads - Fix a force close when updating library - Enable ACRA and add a setting to send crash reports - Manga class now uses the default get resolver - Other minor changes
This commit is contained in:
@@ -1,95 +1,20 @@
|
||||
package eu.kanade.mangafeed.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import okio.BufferedSink;
|
||||
import okio.BufferedSource;
|
||||
import okio.Okio;
|
||||
|
||||
public final class DiskUtils {
|
||||
private static final Pattern DIR_SEPARATOR = Pattern.compile("/");
|
||||
|
||||
private DiskUtils() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
// http://stackoverflow.com/questions/13976982/removable-storage-external-sdcard-path-by-manufacturers
|
||||
// http://stackoverflow.com/questions/11281010/how-can-i-get-external-sd-card-path-for-android-4-0
|
||||
public static String[] getStorageDirectories(Context context) {
|
||||
final Set<String> storageDirectories = new HashSet<String>();
|
||||
|
||||
storageDirectories.add(context.getFilesDir().getAbsolutePath());
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
File[] directories = context.getExternalFilesDirs(null);
|
||||
if (directories != null) {
|
||||
for (File storage : directories) {
|
||||
if (storage != null) {
|
||||
storageDirectories.add(storage.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final String rawExternalStorage = System.getenv("EXTERNAL_STORAGE");
|
||||
final String rawSecondaryStoragesStr = System.getenv("SECONDARY_STORAGE");
|
||||
final String rawEmulatedStorageTarget = System.getenv("EMULATED_STORAGE_TARGET");
|
||||
|
||||
if (TextUtils.isEmpty(rawEmulatedStorageTarget)) {
|
||||
if (TextUtils.isEmpty(rawExternalStorage)) {
|
||||
storageDirectories.add("/storage/sdcard0" + File.separator + context.getPackageName());
|
||||
} else {
|
||||
storageDirectories.add(rawExternalStorage + File.separator + context.getPackageName());
|
||||
}
|
||||
} else {
|
||||
final String rawUserId;
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
rawUserId = "";
|
||||
} else {
|
||||
final String path = Environment.getExternalStorageDirectory().getAbsolutePath();
|
||||
final String[] folders = DIR_SEPARATOR.split(path);
|
||||
final String lastFolder = folders[folders.length - 1];
|
||||
boolean isDigit = false;
|
||||
|
||||
try {
|
||||
Integer.valueOf(lastFolder);
|
||||
isDigit = true;
|
||||
} catch (NumberFormatException e) {
|
||||
// Do Nothing.
|
||||
}
|
||||
|
||||
rawUserId = isDigit ? lastFolder : "";
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(rawUserId)) {
|
||||
storageDirectories.add(rawEmulatedStorageTarget + File.separator + context.getPackageName());
|
||||
} else {
|
||||
storageDirectories.add(rawEmulatedStorageTarget + File.separator + rawUserId + File.separator + context.getPackageName());
|
||||
}
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(rawSecondaryStoragesStr)) {
|
||||
String[] rawSecondaryStorages = rawSecondaryStoragesStr.split(File.pathSeparator);
|
||||
for (int index = 0; index < rawSecondaryStorages.length; index++) {
|
||||
storageDirectories.add(rawSecondaryStorages[index] + File.separator + context.getPackageName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return storageDirectories.toArray(new String[storageDirectories.size()]);
|
||||
}
|
||||
|
||||
public static String hashKeyForDisk(String key) {
|
||||
String cacheKey;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user