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)
public void onEventMainThread(DownloadEvent event) {
Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]");
Log.d(TAG, "onEventMainThread() called with DownloadEvent");
DownloaderUpdate update = event.update;
if (event.hasChangedFeedUpdateStatus(isUpdatingFeeds)) {
getActivity().invalidateOptionsMenu();

View File

@ -5,7 +5,6 @@ import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import androidx.core.app.NotificationCompat;
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.util.gui.NotificationUtils;
import java.util.ArrayList;
import java.util.List;
public class DownloadServiceNotification {
@ -64,33 +62,36 @@ public class DownloadServiceNotification {
}
private static String compileNotificationString(List<Downloader> downloads) {
List<String> lines = new ArrayList<>(downloads.size());
for (Downloader downloader : downloads) {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < downloads.size(); i++) {
Downloader downloader = downloads.get(i);
if (downloader.cancelled) {
continue;
}
StringBuilder line = new StringBuilder("");
stringBuilder.append("");
DownloadRequest request = downloader.getDownloadRequest();
switch (request.getFeedfileType()) {
case Feed.FEEDFILETYPE_FEED:
if (request.getTitle() != null) {
line.append(request.getTitle());
stringBuilder.append(request.getTitle());
}
break;
case FeedMedia.FEEDFILETYPE_FEEDMEDIA:
if (request.getTitle() != null) {
line.append(request.getTitle())
stringBuilder.append(request.getTitle())
.append(" (")
.append(request.getProgressPercent())
.append("%)");
}
break;
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) {

View File

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

View File

@ -1,23 +1,12 @@
package de.danoeh.antennapod.core.syndication.util;
import android.text.TextUtils;
import android.webkit.MimeTypeMap;
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 {
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() {
}
@ -26,14 +15,18 @@ public class SyndTypeUtils {
if (type == null) {
return false;
} 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) {
if (type == null) {
return false;
} else {
return type.matches(VALID_IMAGE_MIMETYPE);
return type.startsWith("image/");
}
}
@ -46,10 +39,6 @@ public class SyndTypeUtils {
return null;
}
String extension = FilenameUtils.getExtension(url);
if (extension == null) {
return null;
}
return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
}
}

View File

@ -23,6 +23,12 @@ public class DateUtils {
private static final String TAG = "DateUtils";
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) {
if (input == null) {
@ -92,16 +98,12 @@ public class DateUtils {
"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);
for (String pattern : patterns) {
parser.applyPattern(pattern);
dateFormatParser.applyPattern(pattern);
pos.setIndex(0);
try {
Date result = parser.parse(date, pos);
Date result = dateFormatParser.parse(date, pos);
if (result != null && pos.getIndex() == date.length()) {
return result;
}
@ -111,7 +113,7 @@ public class DateUtils {
}
// 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));
}