mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-15 05:27:28 +01:00
Download manager rewrite (#535)
* Saving to SD working * Rename imagePath to uri * Handle android < 21 * Minor changes * Separate downloader from the manager. Optimize folder lookups * Persist downloads across restarts * Fix for #511 * Updated ReactiveNetwork. Add some documentation * More documentation and minor fixes * Handle persistent notifications. Other minor changes * Improve downloader and add documentation * Rename pageNumber to index in Page class * Remove unused methods * Use chop method * Make sure dest dir is created * Reset downloads dir preference * Use invalidate options menu in download fragment and fix wrong condition * Fix empty download queue after application restart * Use addAll method in download queue to avoid too many notifications * Inform download manager changes
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
package eu.kanade.tachiyomi.util
|
||||
|
||||
import android.app.AlarmManager
|
||||
import android.app.Notification
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.ConnectivityManager
|
||||
import android.os.PowerManager
|
||||
import android.support.annotation.StringRes
|
||||
import android.support.v4.app.NotificationCompat
|
||||
import android.support.v4.content.ContextCompat
|
||||
@@ -54,8 +55,13 @@ val Context.notificationManager: NotificationManager
|
||||
get() = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
|
||||
/**
|
||||
* Property to get the alarm manager from the context.
|
||||
* @return the alarm manager.
|
||||
* Property to get the connectivity manager from the context.
|
||||
*/
|
||||
val Context.alarmManager: AlarmManager
|
||||
get() = getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
val Context.connectivityManager: ConnectivityManager
|
||||
get() = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||
|
||||
/**
|
||||
* Property to get the power manager from the context.
|
||||
*/
|
||||
val Context.powerManager: PowerManager
|
||||
get() = getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||
@@ -5,10 +5,6 @@ import java.net.URISyntaxException;
|
||||
|
||||
public final class UrlUtil {
|
||||
|
||||
private static final String JPG = ".jpg";
|
||||
private static final String PNG = ".png";
|
||||
private static final String GIF = ".gif";
|
||||
|
||||
private UrlUtil() throws InstantiationException {
|
||||
throw new InstantiationException("This class is not for instantiation");
|
||||
}
|
||||
@@ -27,36 +23,4 @@ public final class UrlUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isJpg(String url) {
|
||||
return containsIgnoreCase(url, JPG);
|
||||
}
|
||||
|
||||
public static boolean isPng(String url) {
|
||||
return containsIgnoreCase(url, PNG);
|
||||
}
|
||||
|
||||
public static boolean isGif(String url) {
|
||||
return containsIgnoreCase(url, GIF);
|
||||
}
|
||||
|
||||
public static boolean containsIgnoreCase(String src, String what) {
|
||||
final int length = what.length();
|
||||
if (length == 0)
|
||||
return true; // Empty string is contained
|
||||
|
||||
final char firstLo = Character.toLowerCase(what.charAt(0));
|
||||
final char firstUp = Character.toUpperCase(what.charAt(0));
|
||||
|
||||
for (int i = src.length() - length; i >= 0; i--) {
|
||||
// Quick check before calling the more expensive regionMatches() method:
|
||||
final char ch = src.charAt(i);
|
||||
if (ch != firstLo && ch != firstUp)
|
||||
continue;
|
||||
|
||||
if (src.regionMatches(true, i, what, 0, length))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user