support article attachments, display image attachments inline (hello
lolcats)
This commit is contained in:
parent
36451d43b8
commit
845caf8252
@ -16,7 +16,8 @@ public class Article implements Parcelable {
|
||||
String title;
|
||||
String link;
|
||||
int feed_id;
|
||||
List<String> tags;
|
||||
List<String> tags;
|
||||
List<Attachment> attachments;
|
||||
String content;
|
||||
List<List<String>> labels;
|
||||
|
||||
@ -49,6 +50,7 @@ public class Article implements Parcelable {
|
||||
out.writeInt(feed_id);
|
||||
out.writeStringList(tags);
|
||||
out.writeString(content);
|
||||
out.writeList(attachments);
|
||||
}
|
||||
|
||||
public void readFromParcel(Parcel in) {
|
||||
@ -66,6 +68,9 @@ public class Article implements Parcelable {
|
||||
in.readStringList(tags);
|
||||
|
||||
content = in.readString();
|
||||
|
||||
attachments = new ArrayList<Attachment>();
|
||||
in.readList(attachments, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
|
@ -1,5 +1,8 @@
|
||||
package org.fox.ttrss;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
@ -142,11 +145,41 @@ public class ArticleFragment extends Fragment {
|
||||
//"<meta name=\"viewport\" content=\"target-densitydpi=device-dpi\" />" +
|
||||
"<style type=\"text/css\">" +
|
||||
cssOverride +
|
||||
"div.attachments { font-size : 70%; margin-top : 1em; }" +
|
||||
"img { max-width : 98%; height : auto; }" +
|
||||
"body { text-align : justify; }" +
|
||||
"</style>" +
|
||||
"</head>" +
|
||||
"<body>" + articleContent + "</body></html>";
|
||||
"<body>" + articleContent;
|
||||
|
||||
if (m_article.attachments.size() != 0) {
|
||||
String attachments = "<div class=\"attachments\">Attachments: ";
|
||||
|
||||
for (Attachment a : m_article.attachments) {
|
||||
if (a.content_type != null && a.content_url != null && a.content_type.indexOf("image") != -1) {
|
||||
|
||||
try {
|
||||
URL url = new URL(a.content_url.trim());
|
||||
|
||||
String atitle = (a.title != null && a.title.length() > 0) ? a.title : new File(url.getFile()).getName();
|
||||
|
||||
content += "<br/><img src=\"" + url.toString().replace("\"", "\\\"") + "\">";
|
||||
|
||||
attachments += "<a href=\""+url.toString().replace("\"", "\\\"") + "\">" + atitle + "</a>, ";
|
||||
|
||||
} catch (MalformedURLException e) {
|
||||
//
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
content += attachments.replaceAll(", $", "");
|
||||
content += "</div>";
|
||||
}
|
||||
|
||||
content += "</body></html>";
|
||||
|
||||
try {
|
||||
web.loadDataWithBaseURL(null, content, "text/html", "utf-8", null);
|
||||
|
54
src/org/fox/ttrss/Attachment.java
Normal file
54
src/org/fox/ttrss/Attachment.java
Normal file
@ -0,0 +1,54 @@
|
||||
package org.fox.ttrss;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
public class Attachment implements Parcelable {
|
||||
int id;
|
||||
String content_url;
|
||||
String content_type;
|
||||
String title;
|
||||
String duration;
|
||||
int post_id;
|
||||
|
||||
public Attachment(Parcel in) {
|
||||
readFromParcel(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeInt(id);
|
||||
out.writeString(content_url);
|
||||
out.writeString(content_type);
|
||||
out.writeString(title);
|
||||
out.writeString(duration);
|
||||
out.writeInt(post_id);
|
||||
}
|
||||
|
||||
public void readFromParcel(Parcel in) {
|
||||
id = in.readInt();
|
||||
content_url = in.readString();
|
||||
content_type = in.readString();
|
||||
title = in.readString();
|
||||
duration = in.readString();
|
||||
post_id = in.readInt();
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static final Parcelable.Creator CREATOR =
|
||||
new Parcelable.Creator() {
|
||||
public Attachment createFromParcel(Parcel in) {
|
||||
return new Attachment(in);
|
||||
}
|
||||
|
||||
public Attachment[] newArray(int size) {
|
||||
return new Attachment[size];
|
||||
}
|
||||
};
|
||||
|
||||
}
|
@ -197,6 +197,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
||||
put("sid", sessionId);
|
||||
put("feed_id", String.valueOf(m_feed.id));
|
||||
put("show_content", "true");
|
||||
put("include_attachments", "true");
|
||||
put("limit", String.valueOf(HEADLINES_REQUEST_SIZE));
|
||||
put("offset", String.valueOf(0));
|
||||
put("view_mode", showUnread ? "adaptive" : "all_articles");
|
||||
|
Loading…
Reference in New Issue
Block a user