Performance improvements

This commit is contained in:
ByteHamster 2020-04-01 18:38:31 +02:00
parent ea58748b22
commit 77ef239336
5 changed files with 56 additions and 63 deletions

View File

@ -186,7 +186,7 @@ public class QueueFragment extends Fragment {
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN) @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEventMainThread(DownloadEvent event) { public void onEventMainThread(DownloadEvent event) {
Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); Log.d(TAG, "onEventMainThread() called with DownloadEvent");
DownloaderUpdate update = event.update; DownloaderUpdate update = event.update;
if (event.hasChangedFeedUpdateStatus(isUpdatingFeeds)) { if (event.hasChangedFeedUpdateStatus(isUpdatingFeeds)) {
getActivity().invalidateOptionsMenu(); getActivity().invalidateOptionsMenu();

View File

@ -5,7 +5,6 @@ import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.os.Build; import android.os.Build;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import de.danoeh.antennapod.core.ClientConfig; import de.danoeh.antennapod.core.ClientConfig;
@ -14,7 +13,6 @@ import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.util.gui.NotificationUtils; import de.danoeh.antennapod.core.util.gui.NotificationUtils;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class DownloadServiceNotification { public class DownloadServiceNotification {
@ -64,33 +62,36 @@ public class DownloadServiceNotification {
} }
private static String compileNotificationString(List<Downloader> downloads) { private static String compileNotificationString(List<Downloader> downloads) {
List<String> lines = new ArrayList<>(downloads.size()); StringBuilder stringBuilder = new StringBuilder();
for (Downloader downloader : downloads) { for (int i = 0; i < downloads.size(); i++) {
Downloader downloader = downloads.get(i);
if (downloader.cancelled) { if (downloader.cancelled) {
continue; continue;
} }
StringBuilder line = new StringBuilder(""); stringBuilder.append("");
DownloadRequest request = downloader.getDownloadRequest(); DownloadRequest request = downloader.getDownloadRequest();
switch (request.getFeedfileType()) { switch (request.getFeedfileType()) {
case Feed.FEEDFILETYPE_FEED: case Feed.FEEDFILETYPE_FEED:
if (request.getTitle() != null) { if (request.getTitle() != null) {
line.append(request.getTitle()); stringBuilder.append(request.getTitle());
} }
break; break;
case FeedMedia.FEEDFILETYPE_FEEDMEDIA: case FeedMedia.FEEDFILETYPE_FEEDMEDIA:
if (request.getTitle() != null) { if (request.getTitle() != null) {
line.append(request.getTitle()) stringBuilder.append(request.getTitle())
.append(" (") .append(" (")
.append(request.getProgressPercent()) .append(request.getProgressPercent())
.append("%)"); .append("%)");
} }
break; break;
default: default:
line.append("Unknown: ").append(request.getFeedfileType()); stringBuilder.append("Unknown: ").append(request.getFeedfileType());
}
if (i != downloads.size()) {
stringBuilder.append("\n");
} }
lines.add(line.toString());
} }
return TextUtils.join("\n", lines); return stringBuilder.toString();
} }
private static String createAutoDownloadNotificationContent(List<DownloadStatus> statuses) { private static String createAutoDownloadNotificationContent(List<DownloadStatus> statuses) {

View File

@ -63,6 +63,7 @@ public class DBWriter {
static { static {
dbExec = Executors.newSingleThreadExecutor(r -> { dbExec = Executors.newSingleThreadExecutor(r -> {
Thread t = new Thread(r); Thread t = new Thread(r);
t.setName("DatabaseExecutor");
t.setPriority(Thread.MIN_PRIORITY); t.setPriority(Thread.MIN_PRIORITY);
return t; return t;
}); });

View File

@ -1,55 +1,44 @@
package de.danoeh.antennapod.core.syndication.util; package de.danoeh.antennapod.core.syndication.util;
import android.text.TextUtils;
import android.webkit.MimeTypeMap; import android.webkit.MimeTypeMap;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import java.util.Arrays; /**
* Utility class for handling MIME-Types of enclosures.
/** Utility class for handling MIME-Types of enclosures */ * */
public class SyndTypeUtils { public class SyndTypeUtils {
private SyndTypeUtils() {
private static final String VALID_MEDIA_MIMETYPE = TextUtils.join("|", Arrays.asList( }
"audio/.*",
"video/.*",
"application/ogg",
"application/octet-stream"));
private static final String VALID_IMAGE_MIMETYPE = "image/.*"; public static boolean enclosureTypeValid(String type) {
if (type == null) {
return false;
} else {
return type.startsWith("audio/")
|| type.startsWith("video/")
|| type.equals("application/ogg")
|| type.equals("application/octet-stream");
}
}
private SyndTypeUtils() { public static boolean imageTypeValid(String type) {
if (type == null) {
return false;
} else {
return type.startsWith("image/");
}
}
} /**
* Should be used if mime-type of enclosure tag is not supported. This
public static boolean enclosureTypeValid(String type) { * method will return the mime-type of the file extension.
if (type == null) { */
return false; public static String getMimeTypeFromUrl(String url) {
} else { if (url == null) {
return type.matches(VALID_MEDIA_MIMETYPE); return null;
} }
} String extension = FilenameUtils.getExtension(url);
public static boolean imageTypeValid(String type) { return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
if (type == null) { }
return false;
} else {
return type.matches(VALID_IMAGE_MIMETYPE);
}
}
/**
* Should be used if mime-type of enclosure tag is not supported. This
* method will return the mime-type of the file extension.
*/
public static String getMimeTypeFromUrl(String url) {
if (url == null) {
return null;
}
String extension = FilenameUtils.getExtension(url);
if (extension == null) {
return null;
}
return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
}
} }

View File

@ -20,9 +20,15 @@ public class DateUtils {
private DateUtils(){} private DateUtils(){}
private static final String TAG = "DateUtils"; private static final String TAG = "DateUtils";
private static final TimeZone defaultTimezone = TimeZone.getTimeZone("GMT"); private static final TimeZone defaultTimezone = TimeZone.getTimeZone("GMT");
private static final SimpleDateFormat dateFormatParser = new SimpleDateFormat("", Locale.US);
static {
dateFormatParser.setLenient(false);
dateFormatParser.setTimeZone(defaultTimezone);
}
public static Date parse(final String input) { public static Date parse(final String input) {
if (input == null) { if (input == null) {
@ -92,16 +98,12 @@ public class DateUtils {
"EEE d MMM yyyy HH:mm:ss 'GMT'Z (z)" "EEE d MMM yyyy HH:mm:ss 'GMT'Z (z)"
}; };
SimpleDateFormat parser = new SimpleDateFormat("", Locale.US);
parser.setLenient(false);
parser.setTimeZone(defaultTimezone);
ParsePosition pos = new ParsePosition(0); ParsePosition pos = new ParsePosition(0);
for (String pattern : patterns) { for (String pattern : patterns) {
parser.applyPattern(pattern); dateFormatParser.applyPattern(pattern);
pos.setIndex(0); pos.setIndex(0);
try { try {
Date result = parser.parse(date, pos); Date result = dateFormatParser.parse(date, pos);
if (result != null && pos.getIndex() == date.length()) { if (result != null && pos.getIndex() == date.length()) {
return result; return result;
} }
@ -111,7 +113,7 @@ public class DateUtils {
} }
// if date string starts with a weekday, try parsing date string without it // if date string starts with a weekday, try parsing date string without it
if(date.matches("^\\w+, .*$")) { if (date.matches("^\\w+, .*$")) {
return parse(date.substring(date.indexOf(',') + 1)); return parse(date.substring(date.indexOf(',') + 1));
} }