diff options
author | ByteHamster <info@bytehamster.com> | 2020-04-01 18:38:31 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2020-04-02 16:57:28 +0200 |
commit | 77ef2393365e0ff7621321f725a18ac858e50cbf (patch) | |
tree | 8d636834944e6bfdc5fcf88866e9a9f6124494c6 /core | |
parent | ea58748b22288ba8f4e372ed4801f242185e593c (diff) | |
download | AntennaPod-77ef2393365e0ff7621321f725a18ac858e50cbf.zip |
Performance improvements
Diffstat (limited to 'core')
4 files changed, 59 insertions, 66 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java index 59d0266df..f487193f3 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java @@ -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()); + } + 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) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java index d411e8ba8..6c7f69680 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java @@ -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; }); diff --git a/core/src/main/java/de/danoeh/antennapod/core/syndication/util/SyndTypeUtils.java b/core/src/main/java/de/danoeh/antennapod/core/syndication/util/SyndTypeUtils.java index 6c151d39b..155673296 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/syndication/util/SyndTypeUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/syndication/util/SyndTypeUtils.java @@ -1,55 +1,44 @@ 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() { - - } - - public static boolean enclosureTypeValid(String type) { - if (type == null) { - return false; - } else { - return type.matches(VALID_MEDIA_MIMETYPE); - } - } - public static boolean imageTypeValid(String type) { - 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); - } + private SyndTypeUtils() { + + } + + 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"); + } + } + + 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 + * 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); + return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); + } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java index 668f938a0..2454b6a00 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java @@ -20,9 +20,15 @@ public class 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 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)); } |