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());
} }
lines.add(line.toString()); if (i != downloads.size()) {
stringBuilder.append("\n");
} }
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,23 +1,12 @@
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 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/.*";
private SyndTypeUtils() { private SyndTypeUtils() {
} }
@ -26,14 +15,18 @@ public class SyndTypeUtils {
if (type == null) { if (type == null) {
return false; return false;
} else { } else {
return type.matches(VALID_MEDIA_MIMETYPE); return type.startsWith("audio/")
|| type.startsWith("video/")
|| type.equals("application/ogg")
|| type.equals("application/octet-stream");
} }
} }
public static boolean imageTypeValid(String type) { public static boolean imageTypeValid(String type) {
if (type == null) { if (type == null) {
return false; return false;
} else { } else {
return type.matches(VALID_IMAGE_MIMETYPE); return type.startsWith("image/");
} }
} }
@ -46,10 +39,6 @@ public class SyndTypeUtils {
return null; return null;
} }
String extension = FilenameUtils.getExtension(url); String extension = FilenameUtils.getExtension(url);
if (extension == null) {
return null;
}
return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
} }
} }

View File

@ -23,6 +23,12 @@ public class 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));
} }