mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-01-27 17:09:22 +01:00
Moved css to readable file instead of variable
This commit is contained in:
parent
c524d20cc9
commit
6a0542ca1f
37
core/src/main/assets/shownotes-style.css
Normal file
37
core/src/main/assets/shownotes-style.css
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
@font-face {
|
||||||
|
font-family: 'Roboto-Light';
|
||||||
|
src: url('file:///android_asset/Roboto-Light.ttf');
|
||||||
|
}
|
||||||
|
* {
|
||||||
|
color: %s;
|
||||||
|
font-family: roboto-Light;
|
||||||
|
font-size: 13pt;
|
||||||
|
overflow-wrap: break-word;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
font-style: normal;
|
||||||
|
text-decoration: none;
|
||||||
|
font-weight: normal;
|
||||||
|
color: #00A8DF;
|
||||||
|
}
|
||||||
|
a.timecode {
|
||||||
|
color: #669900;
|
||||||
|
}
|
||||||
|
img, iframe {
|
||||||
|
display: block;
|
||||||
|
margin: 10 auto;
|
||||||
|
max-width: 100%%;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
margin: %dpx %dpx %dpx %dpx;
|
||||||
|
}
|
||||||
|
p#apNoShownotes {
|
||||||
|
position: fixed;
|
||||||
|
top: 50%%;
|
||||||
|
left: 50%%;
|
||||||
|
transform: translate(-50%%, -50%%);
|
||||||
|
text-align: center;
|
||||||
|
-webkit-text-size-adjust: none;
|
||||||
|
font-size: 80%%;
|
||||||
|
}
|
@ -10,11 +10,14 @@ import android.util.Log;
|
|||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -34,43 +37,14 @@ import de.danoeh.antennapod.core.util.ShownotesProvider;
|
|||||||
public class Timeline {
|
public class Timeline {
|
||||||
private static final String TAG = "Timeline";
|
private static final String TAG = "Timeline";
|
||||||
|
|
||||||
private static final String WEBVIEW_STYLE =
|
private static final Pattern TIMECODE_LINK_REGEX = Pattern.compile("antennapod://timecode/((\\d+))");
|
||||||
"@font-face {"
|
private static final String TIMECODE_LINK = "<a class=\"timecode\" href=\"antennapod://timecode/%d\">%s</a>";
|
||||||
+ "font-family: 'Roboto-Light';"
|
private static final Pattern TIMECODE_REGEX = Pattern.compile("\\b((\\d+):)?(\\d+):(\\d{2})\\b");
|
||||||
+ "src: url('file:///android_asset/Roboto-Light.ttf');"
|
private static final Pattern LINE_BREAK_REGEX = Pattern.compile("<br */?>");
|
||||||
+ "}"
|
|
||||||
+ "* {"
|
|
||||||
+ "color: %s;"
|
|
||||||
+ "font-family: roboto-Light;"
|
|
||||||
+ "font-size: 13pt;"
|
|
||||||
+ "overflow-wrap: break-word;"
|
|
||||||
+ "}"
|
|
||||||
+ "a {"
|
|
||||||
+ "font-style: normal;"
|
|
||||||
+ "text-decoration: none;"
|
|
||||||
+ "font-weight: normal;"
|
|
||||||
+ "color: #00A8DF;"
|
|
||||||
+ "}"
|
|
||||||
+ "a.timecode {"
|
|
||||||
+ "color: #669900;"
|
|
||||||
+ "}"
|
|
||||||
+ "img, iframe {"
|
|
||||||
+ "display: block;"
|
|
||||||
+ "margin: 10 auto;"
|
|
||||||
+ "max-width: %s;"
|
|
||||||
+ "height: auto;"
|
|
||||||
+ "}"
|
|
||||||
+ "body {"
|
|
||||||
+ "margin: %dpx %dpx %dpx %dpx;"
|
|
||||||
+ "}";
|
|
||||||
|
|
||||||
|
|
||||||
private ShownotesProvider shownotesProvider;
|
|
||||||
|
|
||||||
|
private final ShownotesProvider shownotesProvider;
|
||||||
private final String noShownotesLabel;
|
private final String noShownotesLabel;
|
||||||
private final String colorPrimaryString;
|
private final String webviewStyle;
|
||||||
private final String colorSecondaryString;
|
|
||||||
private final int pageMargin;
|
|
||||||
|
|
||||||
public Timeline(Context context, ShownotesProvider shownotesProvider) {
|
public Timeline(Context context, ShownotesProvider shownotesProvider) {
|
||||||
if (shownotesProvider == null) {
|
if (shownotesProvider == null) {
|
||||||
@ -82,25 +56,20 @@ public class Timeline {
|
|||||||
|
|
||||||
TypedArray res = context.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
|
TypedArray res = context.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
|
||||||
@ColorInt int col = res.getColor(0, 0);
|
@ColorInt int col = res.getColor(0, 0);
|
||||||
colorPrimaryString = "rgba(" + Color.red(col) + "," + Color.green(col) + "," +
|
final String colorPrimary = "rgba(" + Color.red(col) + "," + Color.green(col) + ","
|
||||||
Color.blue(col) + "," + (Color.alpha(col) / 255.0) + ")";
|
+ Color.blue(col) + "," + (Color.alpha(col) / 255.0) + ")";
|
||||||
res.recycle();
|
res.recycle();
|
||||||
res = context.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorSecondary});
|
final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
|
||||||
col = res.getColor(0, 0);
|
context.getResources().getDisplayMetrics());
|
||||||
colorSecondaryString = "rgba(" + Color.red(col) + "," + Color.green(col) + "," +
|
String styleString = "";
|
||||||
Color.blue(col) + "," + (Color.alpha(col) / 255.0) + ")";
|
try {
|
||||||
res.recycle();
|
InputStream templateStream = context.getAssets().open("shownotes-style.css");
|
||||||
|
styleString = IOUtils.toString(templateStream, "UTF-8");
|
||||||
pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
|
} catch (IOException e) {
|
||||||
context.getResources().getDisplayMetrics()
|
e.printStackTrace();
|
||||||
);
|
}
|
||||||
|
webviewStyle = String.format(Locale.getDefault(), styleString, colorPrimary, margin, margin, margin, margin);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Pattern TIMECODE_LINK_REGEX = Pattern.compile("antennapod://timecode/((\\d+))");
|
|
||||||
private static final String TIMECODE_LINK = "<a class=\"timecode\" href=\"antennapod://timecode/%d\">%s</a>";
|
|
||||||
private static final Pattern TIMECODE_REGEX = Pattern.compile("\\b((\\d+):)?(\\d+):(\\d{2})\\b");
|
|
||||||
private static final Pattern LINE_BREAK_REGEX = Pattern.compile("<br */?>");
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies an app-specific CSS stylesheet and adds timecode links (optional).
|
* Applies an app-specific CSS stylesheet and adds timecode links (optional).
|
||||||
@ -112,8 +81,6 @@ public class Timeline {
|
|||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public String processShownotes() {
|
public String processShownotes() {
|
||||||
// load shownotes
|
|
||||||
|
|
||||||
String shownotes;
|
String shownotes;
|
||||||
try {
|
try {
|
||||||
shownotes = shownotesProvider.loadShownotes().call();
|
shownotes = shownotesProvider.loadShownotes().call();
|
||||||
@ -124,21 +91,7 @@ public class Timeline {
|
|||||||
|
|
||||||
if (TextUtils.isEmpty(shownotes)) {
|
if (TextUtils.isEmpty(shownotes)) {
|
||||||
Log.d(TAG, "shownotesProvider contained no shownotes. Returning 'no shownotes' message");
|
Log.d(TAG, "shownotesProvider contained no shownotes. Returning 'no shownotes' message");
|
||||||
shownotes = "<html>" +
|
shownotes = "<html><head></head><body><p id='apNoShownotes'>" + noShownotesLabel + "</p></body></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
|
||||||
@ -147,11 +100,7 @@ public class Timeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Document document = Jsoup.parse(shownotes);
|
Document document = Jsoup.parse(shownotes);
|
||||||
|
document.head().appendElement("style").attr("type", "text/css").text(webviewStyle);
|
||||||
// apply style
|
|
||||||
String styleStr = String.format(Locale.getDefault(), WEBVIEW_STYLE, colorPrimaryString, "100%",
|
|
||||||
pageMargin, pageMargin, pageMargin, pageMargin);
|
|
||||||
document.head().appendElement("style").attr("type", "text/css").text(styleStr);
|
|
||||||
|
|
||||||
// apply timecode links
|
// apply timecode links
|
||||||
addTimecodes(document);
|
addTimecodes(document);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user