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("网络错误");
}
});
}
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);
}
}
});
}
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;
}
Aggregations