diff options
Diffstat (limited to 'org.fox.ttrss/src/main/java')
3 files changed, 78 insertions, 47 deletions
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/tasker/TaskerReceiver.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/tasker/TaskerReceiver.java index 0bac722a..52c600bf 100644..100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/tasker/TaskerReceiver.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/tasker/TaskerReceiver.java @@ -4,6 +4,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; import android.util.Log; @@ -43,8 +44,12 @@ public class TaskerReceiver extends BroadcastReceiver { OfflineDownloadService.class); intent.putExtra("sessionId", sessionId); intent.putExtra("batchMode", true); - - fContext.startService(intent); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + fContext.startForegroundService(intent); + } else { + fContext.startService(intent); + } } break; case TaskerSettingsActivity.ACTION_UPLOAD: @@ -53,8 +58,13 @@ public class TaskerReceiver extends BroadcastReceiver { OfflineUploadService.class); intent.putExtra("sessionId", sessionId); intent.putExtra("batchMode", true); - - fContext.startService(intent); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + fContext.startForegroundService(intent); + } else { + fContext.startService(intent); + } + } break; default: diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/types/Article.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/types/Article.java index ae28bb1d..3b2f8e6f 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/types/Article.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/types/Article.java @@ -67,67 +67,85 @@ public class Article implements Parcelable { } public void collectMediaInfo() { - articleDoc = Jsoup.parse(content); - if (articleDoc != null) { - mediaList = articleDoc.select("img,video,iframe[src*=youtube.com/embed/]"); + // consider attachments first + if (attachments != null) { + for (Attachment a : attachments) { + if (a.content_type != null && a.content_type.contains("image/")) { + flavorImageUri = a.content_url; + + if (flavorImageUri != null && flavorImageUri.startsWith("//")) { + flavorImageUri = "https:" + flavorImageUri; + } - for (Element e : mediaList) { - if ("iframe".equals(e.tagName().toLowerCase())) { - flavorImage = e; - break; - } /*else if ("video".equals(e.tagName().toLowerCase())) { - flavorImage = e; break; - }*/ + } } + } + + // doing this the hard way then + if (flavorImageUri == null) { + articleDoc = Jsoup.parse(content); + + if (articleDoc != null) { + mediaList = articleDoc.select("img,video,iframe[src*=youtube.com/embed/]"); - if (flavorImage == null) { for (Element e : mediaList) { + if ("iframe".equals(e.tagName().toLowerCase())) { + flavorImage = e; + break; + } /*else if ("video".equals(e.tagName().toLowerCase())) { flavorImage = e; break; + }*/ } - } - if (flavorImage != null) { + if (flavorImage == null) { + for (Element e : mediaList) { + flavorImage = e; + break; + } + } - try { + if (flavorImage != null) { + try { - if ("video".equals(flavorImage.tagName().toLowerCase())) { - Element source = flavorImage.select("source").first(); - flavorStreamUri = source.attr("src"); + if ("video".equals(flavorImage.tagName().toLowerCase())) { + Element source = flavorImage.select("source").first(); + flavorStreamUri = source.attr("src"); - flavorImageUri = flavorImage.attr("poster"); - } else if ("iframe".equals(flavorImage.tagName().toLowerCase())) { + flavorImageUri = flavorImage.attr("poster"); + } else if ("iframe".equals(flavorImage.tagName().toLowerCase())) { - String srcEmbed = flavorImage.attr("src"); + String srcEmbed = flavorImage.attr("src"); - if (srcEmbed.length() > 0) { - Pattern pattern = Pattern.compile("/embed/([\\w-]+)"); - Matcher matcher = pattern.matcher(srcEmbed); + if (srcEmbed.length() > 0) { + Pattern pattern = Pattern.compile("/embed/([\\w-]+)"); + Matcher matcher = pattern.matcher(srcEmbed); - if (matcher.find()) { - youtubeVid = matcher.group(1); + if (matcher.find()) { + youtubeVid = matcher.group(1); - flavorImageUri = "https://img.youtube.com/vi/" + youtubeVid + "/hqdefault.jpg"; - flavorStreamUri = "https://youtu.be/" + youtubeVid; + flavorImageUri = "https://img.youtube.com/vi/" + youtubeVid + "/hqdefault.jpg"; + flavorStreamUri = "https://youtu.be/" + youtubeVid; + } + } + } else { + flavorImageUri = flavorImage.attr("src"); + + if (flavorImageUri != null && flavorImageUri.startsWith("//")) { + flavorImageUri = "https:" + flavorImageUri; } - } - } else { - flavorImageUri = flavorImage.attr("src"); - if (flavorImageUri != null && flavorImageUri.startsWith("//")) { - flavorImageUri = "https:" + flavorImageUri; + flavorStreamUri = null; } + } catch (Exception e) { + e.printStackTrace(); + flavorImage = null; + flavorImageUri = null; flavorStreamUri = null; } - } catch (Exception e) { - e.printStackTrace(); - - flavorImage = null; - flavorImageUri = null; - flavorStreamUri = null; } } } diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/widget/WidgetUpdateService.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/widget/WidgetUpdateService.java index efb0fcf1..d54d4422 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/widget/WidgetUpdateService.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/widget/WidgetUpdateService.java @@ -6,6 +6,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.net.ConnectivityManager; import android.net.NetworkInfo; +import android.os.Build; import android.os.Handler; import android.os.IBinder; import android.preference.PreferenceManager; @@ -43,10 +44,7 @@ public class WidgetUpdateService extends Service { // if no network is available networkInfo will be null // otherwise check if we are connected - if (networkInfo != null && networkInfo.isConnected()) { - return true; - } - return false; + return networkInfo != null && networkInfo.isConnected(); } @Override @@ -67,7 +65,12 @@ public class WidgetUpdateService extends Service { public void run() { Intent serviceIntent = new Intent(getApplicationContext(), WidgetUpdateService.class); serviceIntent.putExtra("retryCount", retryCount + 1); - startService(serviceIntent); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(serviceIntent); + } else { + startService(serviceIntent); + } } }, 3 * 1000); |