use of me.yluo.ruisiapp.model.Category in project Ruisi by freedom10086.
the class NewPostActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_topic);
initToolBar(true, "发表新帖");
if (getIntent().getExtras() != null) {
fid = getIntent().getExtras().getInt("FID");
title = getIntent().getExtras().getString("TITLE");
}
addToolbarMenu(R.drawable.ic_send_white_24dp).setOnClickListener(this);
myColorPicker = new MyColorPicker(this);
smileyPicker = new MySmileyPicker(this);
forumSpinner = new MySpinner(this);
typeidSpinner = new MySpinner(this);
typeIdContainer = findViewById(R.id.type_id_container);
typeIdContainer.setVisibility(View.GONE);
tvSelectForum = findViewById(R.id.tv_select_forum);
tvSelectType = findViewById(R.id.tv_select_type);
tvSelectForum.setOnClickListener(this);
tvSelectType.setOnClickListener(this);
edTitle = findViewById(R.id.ed_title);
edContent = findViewById(R.id.ed_content);
List<Category> categories = RuisUtils.getForums(this, true);
if (categories == null) {
showLongToast("读取板块列表出错,请确保assets目录有forums.json文件");
finish();
return;
}
for (Category c : categories) {
if (c.canPost) {
datas.addAll(c.forums);
}
}
if (TextUtils.isEmpty(title) || fid <= 0) {
title = datas.get(0).name;
fid = datas.get(0).fid;
}
tvSelectForum.setText(title);
forumSpinner.setData(datas);
forumSpinner.setListener((pos, v) -> {
fid = datas.get(pos).fid;
tvSelectForum.setText(datas.get(pos).name);
switchFid(fid);
});
typeidSpinner.setListener((pos, v) -> {
typeId = typeiddatas.get(pos).fid;
tvSelectType.setText(typeiddatas.get(pos).name);
});
final LinearLayout edit_bar = findViewById(R.id.edit_bar);
for (int i = 0; i < edit_bar.getChildCount(); i++) {
View c = edit_bar.getChildAt(i);
if (c instanceof ImageView) {
c.setOnClickListener(this);
}
}
Spinner setSize = findViewById(R.id.action_text_size);
setSize.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
// [size=7][/size]
if (edContent == null || (edContent.getText().length() <= 0 && i == 0)) {
return;
}
handleInsert("[size=" + (i + 1) + "][/size]");
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
myColorPicker.setListener((pos, v, color) -> handleInsert("[color=" + color + "][/color]"));
handler = new EmotionInputHandler(edContent, (enable, s) -> {
});
smileyPicker.setListener((str, a) -> {
handler.insertSmiley(str, a);
});
findViewById(R.id.action_backspace).setOnLongClickListener(v -> {
int start = edContent.getSelectionStart();
int end = edContent.getSelectionEnd();
if (start == 0) {
return false;
}
if ((start == end) && start > 0) {
start = start - 5;
}
if (start < 0) {
start = 0;
}
edContent.getText().delete(start, end);
return true;
});
switchFid(fid);
checkValid();
}
use of me.yluo.ruisiapp.model.Category 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