Search in sources :

Example 1 with Forum

use of me.yluo.ruisiapp.model.Forum in project Ruisi by freedom10086.

the class EditActivity method start_edit.

private void start_edit() {
    String url = "forum.php?mod=post&action=edit&tid=" + tid + "&pid=" + pid + "&mobile=2";
    HttpUtil.get(url, new ResponseHandler() {

        @Override
        public void onSuccess(byte[] response) {
            Document document = Jsoup.parse(new String(response));
            params = RuisUtils.getForms(document, "postform");
            String title = params.get("subject");
            if (TextUtils.isEmpty(title)) {
                edTitle.setVisibility(View.GONE);
            } else {
                edTitle.setText(title);
            }
            if (TextUtils.isEmpty(params.get("message"))) {
                showToast("本贴不支持编辑!");
                finish();
            }
            edContent.setText(params.get("message"));
            Elements types = document.select("#typeid").select("option");
            for (Element e : types) {
                typeiddatas.add(new Forum(Integer.parseInt(e.attr("value")), e.text()));
            }
            if (typeiddatas.size() > 0) {
                typeIdContainer.setVisibility(View.VISIBLE);
                tvSelectType.setText(typeiddatas.get(0).name);
                typeId = typeiddatas.get(0).fid;
            } else {
                typeIdContainer.setVisibility(View.GONE);
            }
        }

        @Override
        public void onFailure(Throwable e) {
            super.onFailure(e);
            showToast("网络错误");
        }
    });
}
Also used : ResponseHandler(me.yluo.ruisiapp.myhttp.ResponseHandler) Element(org.jsoup.nodes.Element) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Forum(me.yluo.ruisiapp.model.Forum)

Example 2 with Forum

use of me.yluo.ruisiapp.model.Forum in project Ruisi by freedom10086.

the class NewPostActivity method switchFid.

private void switchFid(int fid) {
    typeiddatas.clear();
    typeId = 0;
    String url = "forum.php?mod=post&action=newthread&fid=" + fid + "&mobile=2";
    HttpUtil.get(url, new ResponseHandler() {

        @Override
        public void onSuccess(byte[] response) {
            Document document = Jsoup.parse(new String(response));
            Elements types = document.select("#typeid").select("option");
            for (Element e : types) {
                typeiddatas.add(new Forum(Integer.parseInt(e.attr("value")), e.text()));
            }
            if (typeiddatas.size() > 0) {
                typeIdContainer.setVisibility(View.VISIBLE);
                tvSelectType.setText(typeiddatas.get(0).name);
                typeId = typeiddatas.get(0).fid;
            } else {
                typeIdContainer.setVisibility(View.GONE);
            }
            // 检查是否能上传图片
            // uploadformdata:{uid:"252553", hash:"fe626ed21ff334263dfe552cd9a4c209"},
            String res = new String(response);
            int index = res.indexOf("uploadformdata:");
            if (index > 0) {
                int start = res.indexOf("hash", index) + 6;
                int end = res.indexOf("\"", start + 5);
                uploadHash = res.substring(start, end);
                Log.v("===", "uploadhash:" + uploadHash);
            }
        }
    });
}
Also used : ResponseHandler(me.yluo.ruisiapp.myhttp.ResponseHandler) UploadImageResponseHandler(me.yluo.ruisiapp.myhttp.UploadImageResponseHandler) Element(org.jsoup.nodes.Element) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Forum(me.yluo.ruisiapp.model.Forum)

Example 3 with Forum

use of me.yluo.ruisiapp.model.Forum in project Ruisi by freedom10086.

the class RuisUtils method getForums.

public static List<Category> getForums(Context context, boolean isLogin) {
    InputStream in = null;
    String s;
    try {
        in = context.getAssets().open("forums.json");
        int size = in.available();
        byte[] buffer = new byte[size];
        in.read(buffer);
        s = new String(buffer);
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    List<Category> cates = new ArrayList<>();
    JSONArray jsonArray = null;
    try {
        jsonArray = new JSONArray(s);
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject o = jsonArray.getJSONObject(i);
            boolean cateLogin = o.getBoolean("login");
            if (!isLogin && cateLogin) {
                // false true
                continue;
            }
            boolean cateCanPost = o.getBoolean("canPost");
            List<Forum> fs = new ArrayList<>();
            JSONArray forums = o.getJSONArray("forums");
            for (int j = 0; j < forums.length(); j++) {
                JSONObject oo = forums.getJSONObject(j);
                boolean forumLogin = oo.getBoolean("login");
                if (!isLogin && forumLogin) {
                    // false true
                    continue;
                }
                if (oo.has("manager") && !isManager(App.getGrade(context))) {
                    // 需要管理权限
                    continue;
                }
                fs.add(new Forum(oo.getString("name"), oo.getInt("fid"), forumLogin));
            }
            cates.add(new Category(o.getString("name"), o.getInt("gid"), cateLogin, cateCanPost, fs));
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return cates;
}
Also used : Category(me.yluo.ruisiapp.model.Category) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IOException(java.io.IOException) Forum(me.yluo.ruisiapp.model.Forum) JSONObject(org.json.JSONObject)

Aggregations

Forum (me.yluo.ruisiapp.model.Forum)3 ResponseHandler (me.yluo.ruisiapp.myhttp.ResponseHandler)2 Document (org.jsoup.nodes.Document)2 Element (org.jsoup.nodes.Element)2 Elements (org.jsoup.select.Elements)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Category (me.yluo.ruisiapp.model.Category)1 UploadImageResponseHandler (me.yluo.ruisiapp.myhttp.UploadImageResponseHandler)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1