Search in sources :

Example 1 with Category

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();
}
Also used : LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) Date(java.util.Date) Uri(android.net.Uri) ImageView(android.widget.ImageView) ResponseHandler(me.yluo.ruisiapp.myhttp.ResponseHandler) Manifest(android.Manifest) UploadImageResponseHandler(me.yluo.ruisiapp.myhttp.UploadImageResponseHandler) MediaStore(android.provider.MediaStore) Element(org.jsoup.nodes.Element) Map(java.util.Map) View(android.view.View) RuisUtils(me.yluo.ruisiapp.utils.RuisUtils) AdapterView(android.widget.AdapterView) Log(android.util.Log) Category(me.yluo.ruisiapp.model.Category) AsyncTask(android.os.AsyncTask) ContextCompat(android.support.v4.content.ContextCompat) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ActivityCompat(android.support.v4.app.ActivityCompat) Forum(me.yluo.ruisiapp.model.Forum) R(me.yluo.ruisiapp.R) List(java.util.List) TextView(android.widget.TextView) Document(org.jsoup.nodes.Document) Jsoup(org.jsoup.Jsoup) Elements(org.jsoup.select.Elements) Nullable(android.support.annotation.Nullable) Context(android.content.Context) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UrlUtils(me.yluo.ruisiapp.utils.UrlUtils) EmotionInputHandler(me.yluo.ruisiapp.widget.emotioninput.EmotionInputHandler) SimpleDateFormat(java.text.SimpleDateFormat) Intent(android.content.Intent) HashMap(java.util.HashMap) MySmileyPicker(me.yluo.ruisiapp.widget.MySmileyPicker) Editable(android.text.Editable) ArrayList(java.util.ArrayList) MySpinner(me.yluo.ruisiapp.widget.MySpinner) MyColorPicker(me.yluo.ruisiapp.widget.MyColorPicker) Toast(android.widget.Toast) HttpUtil(me.yluo.ruisiapp.myhttp.HttpUtil) Parcelable(android.os.Parcelable) DimmenUtils(me.yluo.ruisiapp.utils.DimmenUtils) ComponentName(android.content.ComponentName) ProgressDialog(android.app.ProgressDialog) InputValidDialog(me.yluo.ruisiapp.widget.InputValidDialog) TextUtils(android.text.TextUtils) IOException(java.io.IOException) File(java.io.File) ResolveInfo(android.content.pm.ResolveInfo) Spinner(android.widget.Spinner) Bitmap(android.graphics.Bitmap) Activity(android.app.Activity) EditText(android.widget.EditText) App(me.yluo.ruisiapp.App) Category(me.yluo.ruisiapp.model.Category) MySpinner(me.yluo.ruisiapp.widget.MySpinner) Spinner(android.widget.Spinner) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) MySpinner(me.yluo.ruisiapp.widget.MySpinner) MyColorPicker(me.yluo.ruisiapp.widget.MyColorPicker) MySmileyPicker(me.yluo.ruisiapp.widget.MySmileyPicker) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView) EmotionInputHandler(me.yluo.ruisiapp.widget.emotioninput.EmotionInputHandler) LinearLayout(android.widget.LinearLayout)

Example 2 with Category

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;
}
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

IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Category (me.yluo.ruisiapp.model.Category)2 Forum (me.yluo.ruisiapp.model.Forum)2 Manifest (android.Manifest)1 Activity (android.app.Activity)1 ProgressDialog (android.app.ProgressDialog)1 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 Intent (android.content.Intent)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 Bitmap (android.graphics.Bitmap)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Uri (android.net.Uri)1 AsyncTask (android.os.AsyncTask)1 Bundle (android.os.Bundle)1 Parcelable (android.os.Parcelable)1 MediaStore (android.provider.MediaStore)1 Nullable (android.support.annotation.Nullable)1