app/src/main/java/net/nashlegend/sourcewall/model/Article.java

(开头部分) 7KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

package net.nashlegend.sourcewall.model;

import android.os.Parcel;
import android.text.TextUtils;

import net.nashlegend.sourcewall.request.api.APIBase;

import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.ArrayList;

/**
 * Created by NashLegend on 2014/9/16 0016
 */
public class Article extends AceModel {

    private String id = "";
    private String title = "";
    private String url = "";
    private String imageUrl = "";
    private Author author;
    private String subjectName = "";
    private String subjectKey = "";
    private String date = "";
    private int commentNum = 0;
    private int likeNum = 0;
    private String summary = "";
    private String content = "";
    private ArrayList<UComment> hotComments = new ArrayList<UComment>();
    private ArrayList<UComment> comments = new ArrayList<UComment>();
    private boolean desc = false;

    public static Article fromJsonSimple(JSONObject jo) throws Exception {
        Article article = new Article();
        article.setId(jo.optString("id"));
        article.setCommentNum(jo.optInt("replies_count"));
        article.setAuthor(Author.fromJson(jo.optJSONObject("author")));
        article.setDate(APIBase.parseDate(jo.optString("date_published")));
        article.setSubjectName(jo.optJSONObject("subject").optString("name"));
        article.setSubjectKey(jo.optJSONObject("subject").optString("key"));
        article.setUrl(jo.optString("url"));
        article.setImageUrl(jo.optString("small_image"));
        article.setSummary(jo.optString("summary"));
        article.setTitle(jo.optString("title").trim());
        return article;
    }

    public static Article fromHtmlDetail(String id, String html) throws Exception {
        Article article = new Article();
        Document doc = Jsoup.parse(html);
        //replaceAll("line-height: normal;","");只是简单的处理,以防止Article样式不正确,字体过于紧凑
        //可能还有其他样式没有被我发现,所以加一个 TODO
        String articleContent = doc.getElementById("articleContent").outerHtml().replaceAll("line-height: normal;", "");
        String copyright = doc.getElementsByClass("copyright").outerHtml();
        article.setContent(articleContent + copyright);
        article.setId(id);
后面还有 208 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。