app/src/main/java/net/nashlegend/sourcewall/model/Question.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 Question extends AceModel {

    private String id = "";
    private String title = "";
    private String url = "";
    private Author author;
    private String tag = "";
    private String content = "";
    private String date = "";
    private String summary = "";
    private boolean answerable = true;
    private boolean featured = false;//热门、精彩
    private int commentNum = 0;
    private int recommendNum = 0;
    private int followNum = 0;
    private int answerNum = 0;

    private static final int maxImageWidth = 240;
    private static final String prefix = "<div class=\"ZoomBox\"><div class=\"content-zoom ZoomIn\">";
    private static final String suffix = "</div></div>";

    public static Question fromJson(JSONObject result) throws Exception {
        Question question = new Question();
        question.setAnswerable(result.optBoolean("is_answerable", true));//难道意味着已经回答了
        question.setAnswerNum(result.optInt("answers_count"));
        question.setCommentNum(result.optInt("replies_count"));
        question.setAuthor(Author.fromJson(result.optJSONObject("author")));
        question.setContent(result.optString("annotation_html").replaceAll("<img .*?/>", prefix + "$0" + suffix).replaceAll("style=\"max-width: \\d+px\"", "style=\"max-width: " + maxImageWidth + "px\""));
        question.setDate(APIBase.parseDate(result.optString("date_created")));
        question.setFollowNum(result.optInt("followers_count"));
        question.setId(result.getString("id"));
        question.setRecommendNum(result.optInt("recommends_count"));
        question.setTitle(result.optString("question").trim());
        question.setUrl(result.optString("url"));
        question.setSummary(result.optString("summary"));
        return question;
    }

    public static ArrayList<Question> fromHtmlList(String html) throws Exception {
        ArrayList<Question> questions = new ArrayList<>();
        Document doc = Jsoup.parse(html);
        Elements elements = doc.getElementsByClass("ask-list");
后面还有 205 行代码,解锁后查看完整代码

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

AI 解读

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

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