Java Code Examples for com.socks.jiandan.utils.TextUtil

The following examples show how to use com.socks.jiandan.utils.TextUtil. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
        case android.R.id.home:
            finish();
            return true;
        case R.id.action_more:
            new MaterialDialog.Builder(this)
                    .items(R.array.video_more)
                    .backgroundColor(getResources().getColor(JDApplication.COLOR_OF_DIALOG))
                    .contentColor(JDApplication.COLOR_OF_DIALOG_CONTENT)
                    .itemsCallback(new MaterialDialog.ListCallback() {
                        @Override
                        public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                            switch (which) {
                                //分享
                                case 0:
                                    ShareUtil.shareText(VideoDetailActivity.this, mToolbar.getTitle() + " " + url);
                                    break;
                                //复制
                                case 1:
                                    TextUtil.copy(VideoDetailActivity.this, url);
                                    break;
                                //浏览器打开
                                case 2:
                                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                                    break;
                            }
                        }
                    }).show();
            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 2
@Override
protected void initData() {
    parent_name = getIntent().getStringExtra("parent_name");
    tv_title.setText(TextUtil.isNull(parent_name) ? "回复:" : "回复:" + parent_name);
    /*新鲜事中 文章id=当前的thread_id=接口参数中的post_id*/
    thread_id = getIntent().getStringExtra("thread_id");
    parent_id = getIntent().getStringExtra("parent_id");
}
 
Example 3
Source Project: JianDan   Source File: VideoDetailActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
        case android.R.id.home:
            finish();
            return true;
        case R.id.action_more:
            new MaterialDialog.Builder(this)
                    .items(R.array.video_more)
                    .backgroundColor(getResources().getColor(JDApplication.COLOR_OF_DIALOG))
                    .contentColor(JDApplication.COLOR_OF_DIALOG_CONTENT)
                    .itemsCallback(new MaterialDialog.ListCallback() {
                        @Override
                        public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                            switch (which) {
                                //分享
                                case 0:
                                    ShareUtil.shareText(VideoDetailActivity.this, mToolbar.getTitle() + " " + url);
                                    break;
                                //复制
                                case 1:
                                    TextUtil.copy(VideoDetailActivity.this, url);
                                    break;
                                //浏览器打开
                                case 2:
                                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                                    break;
                            }
                        }
                    }).show();
            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 4
Source Project: JianDan   Source File: PushCommentActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void initData() {
    parent_name = getIntent().getStringExtra("parent_name");
    tv_title.setText(TextUtil.isNull(parent_name) ? "回复:" : "回复:" + parent_name);
    /*新鲜事中 文章id=当前的thread_id=接口参数中的post_id*/
    thread_id = getIntent().getStringExtra("thread_id");
    parent_id = getIntent().getStringExtra("parent_id");
}
 
Example 5
Source Project: JianDanRxJava   Source File: JokeAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(final JokeViewHolder holder, final int position) {

    final Joke joke = mJokes.get(position);
    holder.tv_content.setText(joke.getComment_content());
    holder.tv_author.setText(joke.getComment_author());
    holder.tv_time.setText(String2TimeUtil.dateString2GoodExperienceFormat(joke.getComment_date()));
    holder.tv_like.setText(joke.getVote_positive());
    holder.tv_comment_count.setText(joke.getComment_counts());
    holder.tv_unlike.setText(joke.getVote_negative());

    holder.img_share.setOnClickListener(v -> new MaterialDialog.Builder(mActivity)
            .items(R.array.joke_dialog)
            .backgroundColor(mActivity.getResources().getColor(JDApplication.COLOR_OF_DIALOG))
            .contentColor(JDApplication.COLOR_OF_DIALOG_CONTENT)
            .itemsCallback((dialog, view, which, text) -> {
                switch (which) {
                    case 0:
                        ShareUtil.shareText(mActivity, joke.getComment_content().trim());
                        break;
                    case 1:
                        TextUtil.copy(mActivity, joke.getComment_content());
                        break;
                }
            }).show());

    holder.ll_comment.setOnClickListener(v -> {
        Intent intent = new Intent(mActivity, CommentListActivity.class);
        intent.putExtra("thread_key", "comment-" + joke.getComment_ID());
        mActivity.startActivity(intent);
    });

    setAnimation(holder.card, position);

}
 
Example 6
Source Project: JianDanRxJava   Source File: FreshNewsDetailFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    loading.start();
    dismissLoading();

    JDApi.getFreshDetail(freshNews.id).subscribe(s -> {
        webView.loadDataWithBaseURL("", TextUtil.getHtml(freshNews, s), "text/html", "utf-8", "");
    }, e -> {
        loading.stop();
    });
}
 
Example 7
Source Project: JianDanRxJava   Source File: VideoDetailActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
        case android.R.id.home:
            finish();
            return true;
        case R.id.action_more:
            new MaterialDialog.Builder(this)
                    .items(R.array.video_more)
                    .backgroundColor(getResources().getColor(JDApplication.COLOR_OF_DIALOG))
                    .contentColor(JDApplication.COLOR_OF_DIALOG_CONTENT)
                    .itemsCallback((dialog, view, which, text) -> {
                        switch (which) {
                            //分享
                            case 0:
                                ShareUtil.shareText(VideoDetailActivity.this, mToolbar.getTitle() + " " + url);
                                break;
                            //复制
                            case 1:
                                TextUtil.copy(VideoDetailActivity.this, url);
                                break;
                            //浏览器打开
                            case 2:
                                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                                break;
                        }
                    }).show();
            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 8
Source Project: JianDanRxJava   Source File: PushCommentActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void loadData() {
    parent_name = getIntent().getStringExtra("parent_name");
    tv_title.setText(TextUtil.isNull(parent_name) ? getString(R.string.reply_colon) : getString(R.string.reply_colon) + parent_name);
    //新鲜事中 文章id=当前的thread_id=接口参数中的post_id
    thread_id = getIntent().getStringExtra("thread_id");
    parent_id = getIntent().getStringExtra("parent_id");
}
 
Example 9
Source Project: JianDan_OkHttp   Source File: VideoDetailActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
        case android.R.id.home:
            finish();
            return true;
        case R.id.action_more:
            new MaterialDialog.Builder(this)
                    .items(R.array.video_more)
                    .backgroundColor(getResources().getColor(JDApplication.COLOR_OF_DIALOG))
                    .contentColor(JDApplication.COLOR_OF_DIALOG_CONTENT)
                    .itemsCallback(new MaterialDialog.ListCallback() {
                        @Override
                        public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                            switch (which) {
                                //分享
                                case 0:
                                    ShareUtil.shareText(VideoDetailActivity.this, mToolbar.getTitle() + " " + url);
                                    break;
                                //复制
                                case 1:
                                    TextUtil.copy(VideoDetailActivity.this, url);
                                    break;
                                //浏览器打开
                                case 2:
                                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                                    break;
                            }
                        }
                    }).show();
            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 10
Source Project: JianDan_OkHttp   Source File: PushCommentActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void initData() {
    parent_name = getIntent().getStringExtra("parent_name");
    tv_title.setText(TextUtil.isNull(parent_name) ? "回复:" : "回复:" + parent_name);
    /*新鲜事中 文章id=当前的thread_id=接口参数中的post_id*/
    thread_id = getIntent().getStringExtra("thread_id");
    parent_id = getIntent().getStringExtra("parent_id");
}
 
Example 11
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
    positiveAction.setEnabled(TextUtil.isEmail(et_email.getText().toString().trim()
    ) && !TextUtil.isNull(et_name.getText().toString()));
}
 
Example 12
@Override
protected Response<ArrayList<Commentator>> parseNetworkResponse(NetworkResponse response) {

    try {
        //获取到所有的数据
        String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        JSONObject resultJson = new JSONObject(jsonStr);
        String allThreadId = resultJson.getString("response").replace("[", "").replace
                ("]", "").replace("\"", "");
        String[] threadIds = allThreadId.split("\\,");

        callBack.loadFinish(resultJson.optJSONObject("thread").optString("thread_id"));

        if (TextUtils.isEmpty(threadIds[0])) {
            return Response.success(new ArrayList<Commentator>(), HttpHeaderParser
                    .parseCacheHeaders(response));
        } else {

            //然后根据thread_id再去获得对应的评论和作者信息
            JSONObject parentPostsJson = resultJson.getJSONObject("parentPosts");
            //找出热门评论
            String hotPosts = resultJson.getString("hotPosts").replace("[", "").replace
                    ("]", "").replace("\"", "");
            String[] allHotPosts = hotPosts.split("\\,");

            ArrayList<Commentator> commentators = new ArrayList<>();
            List<String> allHotPostsArray = Arrays.asList(allHotPosts);

            for (String threadId : threadIds) {
                Commentator commentator = new Commentator();
                JSONObject threadObject = parentPostsJson.getJSONObject(threadId);

                //解析评论,打上TAG
                if (allHotPostsArray.contains(threadId)) {
                    commentator.setTag(Commentator.TAG_HOT);
                } else {
                    commentator.setTag(Commentator.TAG_NORMAL);
                }

                commentator.setPost_id(threadObject.optString("post_id"));
                commentator.setParent_id(threadObject.optString("parent_id"));

                String parentsString = threadObject.optString("parents").replace("[", "").replace
                        ("]", "").replace("\"", "");

                String[] parents = parentsString.split("\\,");
                commentator.setParents(parents);

                //如果第一个数据为空,则只有一层
                if (TextUtil.isNull(parents[0])) {
                    commentator.setFloorNum(1);
                } else {
                    commentator.setFloorNum(parents.length + 1);
                }

                commentator.setMessage(threadObject.optString("message"));
                commentator.setCreated_at(threadObject.optString("created_at"));
                JSONObject authorObject = threadObject.optJSONObject("author");
                commentator.setName(authorObject.optString("name"));
                commentator.setAvatar_url(authorObject.optString("avatar_url"));
                commentator.setType(Commentator.TYPE_NORMAL);
                commentators.add(commentator);
            }

            return Response.success(commentators, HttpHeaderParser.parseCacheHeaders(response));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new ParseError(e));
    }
}
 
Example 13
Source Project: JianDan   Source File: PushCommentActivity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
    positiveAction.setEnabled(TextUtil.isEmail(et_email.getText().toString().trim()
    ) && !TextUtil.isNull(et_name.getText().toString()));
}
 
Example 14
Source Project: JianDan   Source File: Request4CommentList.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Response<ArrayList<Commentator>> parseNetworkResponse(NetworkResponse response) {

    try {
        //获取到所有的数据
        String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        JSONObject resultJson = new JSONObject(jsonStr);
        String allThreadId = resultJson.getString("response").replace("[", "").replace
                ("]", "").replace("\"", "");
        String[] threadIds = allThreadId.split("\\,");

        callBack.loadFinish(resultJson.optJSONObject("thread").optString("thread_id"));

        if (TextUtils.isEmpty(threadIds[0])) {
            return Response.success(new ArrayList<Commentator>(), HttpHeaderParser
                    .parseCacheHeaders(response));
        } else {

            //然后根据thread_id再去获得对应的评论和作者信息
            JSONObject parentPostsJson = resultJson.getJSONObject("parentPosts");
            //找出热门评论
            String hotPosts = resultJson.getString("hotPosts").replace("[", "").replace
                    ("]", "").replace("\"", "");
            String[] allHotPosts = hotPosts.split("\\,");

            ArrayList<Commentator> commentators = new ArrayList<>();
            List<String> allHotPostsArray = Arrays.asList(allHotPosts);

            for (String threadId : threadIds) {
                Commentator commentator = new Commentator();
                JSONObject threadObject = parentPostsJson.getJSONObject(threadId);

                //解析评论,打上TAG
                if (allHotPostsArray.contains(threadId)) {
                    commentator.setTag(Commentator.TAG_HOT);
                } else {
                    commentator.setTag(Commentator.TAG_NORMAL);
                }

                commentator.setPost_id(threadObject.optString("post_id"));
                commentator.setParent_id(threadObject.optString("parent_id"));

                String parentsString = threadObject.optString("parents").replace("[", "").replace
                        ("]", "").replace("\"", "");

                String[] parents = parentsString.split("\\,");
                commentator.setParents(parents);

                //如果第一个数据为空,则只有一层
                if (TextUtil.isNull(parents[0])) {
                    commentator.setFloorNum(1);
                } else {
                    commentator.setFloorNum(parents.length + 1);
                }

                commentator.setMessage(threadObject.optString("message"));
                commentator.setCreated_at(threadObject.optString("created_at"));
                JSONObject authorObject = threadObject.optJSONObject("author");
                commentator.setName(authorObject.optString("name"));
                commentator.setAvatar_url(authorObject.optString("avatar_url"));
                commentator.setType(Commentator.TYPE_NORMAL);
                commentators.add(commentator);
            }

            return Response.success(commentators, HttpHeaderParser.parseCacheHeaders(response));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new ParseError(e));
    }
}
 
Example 15
Source Project: JianDanRxJava   Source File: InputWatcher.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
    buttonAction.setEnabled(TextUtil.isEmail(editEmail.getText().toString().trim()
    ) && !TextUtil.isNull(editName.getText().toString()));
}
 
Example 16
Source Project: JianDanRxJava   Source File: PictureAdapter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onBindViewHolder(final PictureViewHolder holder, final int position) {

    final Picture picture = mPictures.get(position);
    String picUrl = picture.getPics()[0];

    if (picUrl.endsWith(".gif")) {
        holder.img_gif.setVisibility(View.VISIBLE);
        //非WIFI网络情况下,GIF图只加载缩略图,详情页才加载真实图片
        if (!isWifiConnected) {
            picUrl = picUrl.replace("mw600", "small").replace("mw1200", "small").replace
                    ("large", "small");
        }
    } else {
        holder.img_gif.setVisibility(View.GONE);
    }

    holder.progress.setProgress(0);
    holder.progress.setVisibility(View.VISIBLE);

    ImageLoadProxy.displayImageList(picUrl, holder.img, R.drawable.ic_loading_large, new
                    SimpleImageLoadingListener() {
                        @Override
                        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                            super.onLoadingComplete(imageUri, view, loadedImage);
                            holder.progress.setVisibility(View.GONE);
                        }
                    },
            (imageUri, view, current, total) -> holder.progress.setProgress((int) (current * 100f / total)));

    if (TextUtil.isNull(picture.getText_content().trim())) {
        holder.tv_content.setVisibility(View.GONE);
    } else {
        holder.tv_content.setVisibility(View.VISIBLE);
        holder.tv_content.setText(picture.getText_content().trim());
    }

    holder.img.setOnClickListener(v -> IntentHelper.toImageDetailActivity(mActivity, picture));

    holder.tv_author.setText(picture.getComment_author());
    holder.tv_time.setText(String2TimeUtil.dateString2GoodExperienceFormat(picture.getComment_date()));
    holder.tv_like.setText(picture.getVote_positive());
    holder.tv_comment_count.setText(picture.getComment_counts());

    //用于恢复默认的文字
    holder.tv_like.setTypeface(Typeface.DEFAULT);
    holder.tv_like.setTextColor(mActivity.getResources().getColor(
            secondary_text_default_material_light));
    holder.tv_support_des.setTextColor(mActivity.getResources().getColor(
            secondary_text_default_material_light));

    holder.tv_unlike.setText(picture.getVote_negative());
    holder.tv_unlike.setTypeface(Typeface.DEFAULT);
    holder.tv_unlike.setTextColor(mActivity.getResources().getColor(
            secondary_text_default_material_light));
    holder.tv_un_support_des.setTextColor(mActivity.getResources().getColor(
            secondary_text_default_material_light));

    holder.img_share.setOnClickListener(v -> new MaterialDialog.Builder(mActivity)
            .items(R.array.picture_dialog)
            .backgroundColor(mActivity.getResources().getColor(JDApplication.COLOR_OF_DIALOG))
            .contentColor(JDApplication.COLOR_OF_DIALOG_CONTENT)
            .itemsCallback((dialog, view, which, text) -> {

                switch (which) {
                    case 0:
                        ShareUtil.sharePicture(mActivity, picture
                                .getPics()[0]);
                        break;
                    case 1:
                        FileUtil.savePicture(picture
                                .getPics()[0], mSaveFileCallBack);
                        break;
                }
            })
            .show());

    holder.ll_comment.setOnClickListener(v -> {
        Intent intent = new Intent(mActivity, CommentListActivity.class);
        intent.putExtra(BaseActivity.DATA_THREAD_KEY, "comment-" + picture.getComment_ID());
        mActivity.startActivity(intent);
    });

    setAnimation(holder.card, position);

}
 
Example 17
Source Project: JianDanRxJava   Source File: CommentListParser.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public ArrayList<Commentator> parse(Response response) {

    if (!response.isSuccessful())
        return null;


    try {
        //获取到所有的数据
        String jsonStr = response.body().string();
        JSONObject resultJson = new JSONObject(jsonStr);
        String allThreadId = resultJson.getString("response").replace("[", "").replace
                ("]", "").replace("\"", "");
        String[] threadIds = allThreadId.split("\\,");

        mCallBack.loadFinish(resultJson.optJSONObject("thread").optString("thread_id"));

        if (TextUtils.isEmpty(threadIds[0])) {
            return new ArrayList<>();
        } else {

            //然后根据thread_id再去获得对应的评论和作者信息
            JSONObject parentPostsJson = resultJson.getJSONObject("parentPosts");
            //找出热门评论
            String hotPosts = resultJson.getString("hotPosts").replace("[", "").replace
                    ("]", "").replace("\"", "");
            String[] allHotPosts = hotPosts.split("\\,");

            ArrayList<Commentator> commentators = new ArrayList<>();
            List<String> allHotPostsArray = Arrays.asList(allHotPosts);

            for (String threadId : threadIds) {
                Commentator commentator = new Commentator();
                JSONObject threadObject = parentPostsJson.getJSONObject(threadId);

                //解析评论,打上TAG
                if (allHotPostsArray.contains(threadId)) {
                    commentator.setTag(Commentator.TAG_HOT);
                } else {
                    commentator.setTag(Commentator.TAG_NORMAL);
                }

                commentator.setPost_id(threadObject.optString("post_id"));
                commentator.setParent_id(threadObject.optString("parent_id"));

                String parentsString = threadObject.optString("parents").replace("[", "").replace
                        ("]", "").replace("\"", "");

                String[] parents = parentsString.split("\\,");
                commentator.setParents(parents);

                //如果第一个数据为空,则只有一层
                if (TextUtil.isNull(parents[0])) {
                    commentator.setFloorNum(1);
                } else {
                    commentator.setFloorNum(parents.length + 1);
                }

                commentator.setMessage(threadObject.optString("message"));
                commentator.setCreated_at(threadObject.optString("created_at"));
                JSONObject authorObject = threadObject.optJSONObject("author");
                commentator.setName(authorObject.optString("name"));
                commentator.setAvatar_url(authorObject.optString("avatar_url"));
                commentator.setType(Commentator.TYPE_NORMAL);
                commentators.add(commentator);
            }

            return commentators;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 18
Source Project: JianDan_OkHttp   Source File: CommentListParser.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public ArrayList<Commentator> parse(Response response) {

    code = wrapperCode(response.code());
    if (!response.isSuccessful())
        return null;


    try {
        //获取到所有的数据
        String jsonStr = response.body().string();
        JSONObject resultJson = new JSONObject(jsonStr);
        String allThreadId = resultJson.getString("response").replace("[", "").replace
                ("]", "").replace("\"", "");
        String[] threadIds = allThreadId.split("\\,");

        callBack.loadFinish(resultJson.optJSONObject("thread").optString("thread_id"));

        if (TextUtils.isEmpty(threadIds[0])) {
            return new ArrayList<>();
        } else {

            //然后根据thread_id再去获得对应的评论和作者信息
            JSONObject parentPostsJson = resultJson.getJSONObject("parentPosts");
            //找出热门评论
            String hotPosts = resultJson.getString("hotPosts").replace("[", "").replace
                    ("]", "").replace("\"", "");
            String[] allHotPosts = hotPosts.split("\\,");

            ArrayList<Commentator> commentators = new ArrayList<>();
            List<String> allHotPostsArray = Arrays.asList(allHotPosts);

            for (String threadId : threadIds) {
                Commentator commentator = new Commentator();
                JSONObject threadObject = parentPostsJson.getJSONObject(threadId);

                //解析评论,打上TAG
                if (allHotPostsArray.contains(threadId)) {
                    commentator.setTag(Commentator.TAG_HOT);
                } else {
                    commentator.setTag(Commentator.TAG_NORMAL);
                }

                commentator.setPost_id(threadObject.optString("post_id"));
                commentator.setParent_id(threadObject.optString("parent_id"));

                String parentsString = threadObject.optString("parents").replace("[", "").replace
                        ("]", "").replace("\"", "");

                String[] parents = parentsString.split("\\,");
                commentator.setParents(parents);

                //如果第一个数据为空,则只有一层
                if (TextUtil.isNull(parents[0])) {
                    commentator.setFloorNum(1);
                } else {
                    commentator.setFloorNum(parents.length + 1);
                }

                commentator.setMessage(threadObject.optString("message"));
                commentator.setCreated_at(threadObject.optString("created_at"));
                JSONObject authorObject = threadObject.optJSONObject("author");
                commentator.setName(authorObject.optString("name"));
                commentator.setAvatar_url(authorObject.optString("avatar_url"));
                commentator.setType(Commentator.TYPE_NORMAL);
                commentators.add(commentator);
            }

            return commentators;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 19
Source Project: JianDan_OkHttp   Source File: PushCommentActivity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
    positiveAction.setEnabled(TextUtil.isEmail(et_email.getText().toString().trim()
    ) && !TextUtil.isNull(et_name.getText().toString()));
}
 
Example 20
Source Project: JianDan_OkHttp   Source File: Request4CommentList.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Response<ArrayList<Commentator>> parseNetworkResponse(NetworkResponse response) {

    try {
        //获取到所有的数据
        String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        JSONObject resultJson = new JSONObject(jsonStr);
        String allThreadId = resultJson.getString("response").replace("[", "").replace
                ("]", "").replace("\"", "");
        String[] threadIds = allThreadId.split("\\,");

        callBack.loadFinish(resultJson.optJSONObject("thread").optString("thread_id"));

        if (TextUtils.isEmpty(threadIds[0])) {
            return Response.success(new ArrayList<Commentator>(), HttpHeaderParser
                    .parseCacheHeaders(response));
        } else {

            //然后根据thread_id再去获得对应的评论和作者信息
            JSONObject parentPostsJson = resultJson.getJSONObject("parentPosts");
            //找出热门评论
            String hotPosts = resultJson.getString("hotPosts").replace("[", "").replace
                    ("]", "").replace("\"", "");
            String[] allHotPosts = hotPosts.split("\\,");

            ArrayList<Commentator> commentators = new ArrayList<>();
            List<String> allHotPostsArray = Arrays.asList(allHotPosts);

            for (String threadId : threadIds) {
                Commentator commentator = new Commentator();
                JSONObject threadObject = parentPostsJson.getJSONObject(threadId);

                //解析评论,打上TAG
                if (allHotPostsArray.contains(threadId)) {
                    commentator.setTag(Commentator.TAG_HOT);
                } else {
                    commentator.setTag(Commentator.TAG_NORMAL);
                }

                commentator.setPost_id(threadObject.optString("post_id"));
                commentator.setParent_id(threadObject.optString("parent_id"));

                String parentsString = threadObject.optString("parents").replace("[", "").replace
                        ("]", "").replace("\"", "");

                String[] parents = parentsString.split("\\,");
                commentator.setParents(parents);

                //如果第一个数据为空,则只有一层
                if (TextUtil.isNull(parents[0])) {
                    commentator.setFloorNum(1);
                } else {
                    commentator.setFloorNum(parents.length + 1);
                }

                commentator.setMessage(threadObject.optString("message"));
                commentator.setCreated_at(threadObject.optString("created_at"));
                JSONObject authorObject = threadObject.optJSONObject("author");
                commentator.setName(authorObject.optString("name"));
                commentator.setAvatar_url(authorObject.optString("avatar_url"));
                commentator.setType(Commentator.TYPE_NORMAL);
                commentators.add(commentator);
            }

            return Response.success(commentators, HttpHeaderParser.parseCacheHeaders(response));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new ParseError(e));
    }
}