Show message if there are no shownotes
This commit is contained in:
parent
734b19e906
commit
73069817f8
|
@ -2,7 +2,10 @@ package de.danoeh.antennapod.core.util.playback;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.support.annotation.ColorInt;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
|
|
||||||
|
@ -14,6 +17,7 @@ import org.jsoup.select.Elements;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import de.danoeh.antennapod.core.R;
|
||||||
import de.danoeh.antennapod.core.util.Converter;
|
import de.danoeh.antennapod.core.util.Converter;
|
||||||
import de.danoeh.antennapod.core.util.ShownotesProvider;
|
import de.danoeh.antennapod.core.util.ShownotesProvider;
|
||||||
|
|
||||||
|
@ -32,21 +36,28 @@ public class Timeline {
|
||||||
|
|
||||||
private ShownotesProvider shownotesProvider;
|
private ShownotesProvider shownotesProvider;
|
||||||
|
|
||||||
|
private final String noShownotesLabel;
|
||||||
private final String colorString;
|
private final String colorPrimaryString;
|
||||||
|
private final String colorSecondaryString;
|
||||||
private final int pageMargin;
|
private final int pageMargin;
|
||||||
|
|
||||||
public Timeline(Context context, ShownotesProvider shownotesProvider) {
|
public Timeline(Context context, ShownotesProvider shownotesProvider) {
|
||||||
if (shownotesProvider == null) throw new IllegalArgumentException("shownotesProvider = null");
|
if (shownotesProvider == null) throw new IllegalArgumentException("shownotesProvider = null");
|
||||||
this.shownotesProvider = shownotesProvider;
|
this.shownotesProvider = shownotesProvider;
|
||||||
|
|
||||||
TypedArray res = context
|
noShownotesLabel = context.getString(R.string.no_shownotes_label);
|
||||||
.getTheme()
|
|
||||||
.obtainStyledAttributes(
|
TypedArray res = context.getTheme().obtainStyledAttributes(
|
||||||
new int[]{android.R.attr.textColorPrimary});
|
new int[]{ android.R.attr.textColorPrimary});
|
||||||
int colorResource = res.getColor(0, 0);
|
@ColorInt int col = res.getColor(0, 0);
|
||||||
colorString = String.format("#%06X",
|
colorPrimaryString = "rgba(" + Color.red(col) + "," + Color.green(col) + "," +
|
||||||
0xFFFFFF & colorResource);
|
Color.blue(col) + "," + (Color.alpha(col)/256.0) + ")";
|
||||||
|
res.recycle();
|
||||||
|
res = context.getTheme().obtainStyledAttributes(
|
||||||
|
new int[]{android.R.attr.textColorSecondary});
|
||||||
|
col = res.getColor(0, 0);
|
||||||
|
colorSecondaryString = "rgba(" + Color.red(col) + "," + Color.green(col) + "," +
|
||||||
|
Color.blue(col) + "," + (Color.alpha(col)/256.0) + ")";
|
||||||
res.recycle();
|
res.recycle();
|
||||||
|
|
||||||
pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
|
pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
|
||||||
|
@ -81,9 +92,24 @@ public class Timeline {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (shownotes == null) {
|
|
||||||
Log.d(TAG, "shownotesProvider contained no shownotes. Returning empty string");
|
if(TextUtils.isEmpty(shownotes)) {
|
||||||
return "";
|
Log.d(TAG, "shownotesProvider contained no shownotes. Returning 'no shownotes' message");
|
||||||
|
shownotes ="<html>" +
|
||||||
|
"<head>" +
|
||||||
|
"<style type='text/css'>" +
|
||||||
|
"html, body { margin: 0; padding: 0; width: 100%; height: 100%; } " +
|
||||||
|
"html { display: table; }" +
|
||||||
|
"body { display: table-cell; vertical-align: middle; text-align:center;" +
|
||||||
|
"-webkit-text-size-adjust: none; font-size: 87%; color: " + colorSecondaryString + ";} " +
|
||||||
|
"</style>" +
|
||||||
|
"</head>" +
|
||||||
|
"<body>" +
|
||||||
|
"<p>" + noShownotesLabel + "</p>" +
|
||||||
|
"</body>" +
|
||||||
|
"</html>";
|
||||||
|
Log.d(TAG, "shownotes: " + shownotes);
|
||||||
|
return shownotes;
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace ASCII line breaks with HTML ones if shownotes don't contain HTML line breaks already
|
// replace ASCII line breaks with HTML ones if shownotes don't contain HTML line breaks already
|
||||||
|
@ -94,7 +120,7 @@ public class Timeline {
|
||||||
Document document = Jsoup.parse(shownotes);
|
Document document = Jsoup.parse(shownotes);
|
||||||
|
|
||||||
// apply style
|
// apply style
|
||||||
String styleStr = String.format(WEBVIEW_STYLE, colorString, "100%", pageMargin,
|
String styleStr = String.format(WEBVIEW_STYLE, colorPrimaryString, "100%", pageMargin,
|
||||||
pageMargin, pageMargin, pageMargin);
|
pageMargin, pageMargin, pageMargin);
|
||||||
document.head().appendElement("style").attr("type", "text/css").text(styleStr);
|
document.head().appendElement("style").attr("type", "text/css").text(styleStr);
|
||||||
|
|
||||||
|
|
|
@ -278,6 +278,8 @@
|
||||||
<string name="no_items_label">There are no items in this list.</string>
|
<string name="no_items_label">There are no items in this list.</string>
|
||||||
<string name="no_feeds_label">You haven\'t subscribed to any feeds yet.</string>
|
<string name="no_feeds_label">You haven\'t subscribed to any feeds yet.</string>
|
||||||
<string name="no_chapters_label">This episode has no chapters.</string>
|
<string name="no_chapters_label">This episode has no chapters.</string>
|
||||||
|
<string name="no_shownotes_label">This episode has no shownotes.</string>
|
||||||
|
|
||||||
|
|
||||||
<!-- Preferences -->
|
<!-- Preferences -->
|
||||||
<string name="other_pref">Other</string>
|
<string name="other_pref">Other</string>
|
||||||
|
|
Loading…
Reference in New Issue