导航菜单

页面标题

页面副标题

自健身 v3.3.4 - ArticleDetailActivity2.java 源代码

正在查看: 自健身 v3.3.4 应用的 ArticleDetailActivity2.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.mu.gymtrain.Activity;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.text.TextUtils;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.blankj.utilcode.util.AdaptScreenUtils;
import com.blankj.utilcode.util.ClickUtils;
import com.blankj.utilcode.util.UiMessageUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.hjq.http.listener.OnHttpListener;
import com.mu.gymtrain.Adapter.ArticleCommentListAdapter2;
import com.mu.gymtrain.Base.BaseActivity;
import com.mu.gymtrain.Bean.ArticleCommentListBean;
import com.mu.gymtrain.Bean.ArticleDetailBean;
import com.mu.gymtrain.Bean.CommentBean;
import com.mu.gymtrain.Bean.SendCommentBean;
import com.mu.gymtrain.R;
import com.mu.gymtrain.Utils.FinalTools;
import com.mu.gymtrain.Utils.PreferenceUtils;
import com.mu.gymtrain.Utils.UrlConfig;
import com.mu.gymtrain.view.SendCommentDialog;
import com.mu.gymtrain.viewmodel.ArticleDetailViewModel;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import okhttp3.Call;

public class ArticleDetailActivity2 extends BaseActivity implements BaseQuickAdapter.OnItemChildClickListener {
    private ArticleCommentListAdapter2 adapter;
    private int articleId;
    private int commandId;
    private EditText etComment;
    private int id;
    private ImageView imgHead;
    private ImageView imgZan;
    private TextView tvOneContent;
    private TextView tvOneCount;
    private TextView tvOneName;
    private TextView tvSee;
    private TextView tvZan;
    private String userId;
    private ArticleDetailViewModel viewModel;
    private WebSettings webSettings;
    private WebView webView;

    public int getContentLayout() {
        return R.layout.activity_article_detaiil_layout2;
    }

    public void initView() {
        this.id = getIntent().getIntExtra("id", 0);
        this.commandId = getIntent().getIntExtra("commandId", 0);
        this.userId = PreferenceUtils.getInstance().getString(FinalTools.USER_ID, "");
        ((TextView) findViewById(R.id.tvTitle)).setText("文章详情");
        this.webView = (WebView) findViewById(R.id.webView);
        View findViewById = findViewById(R.id.imgBack);
        String stringFromSP = getStringFromSP(UrlConfig.Params.AVATAR);
        Glide.with(this).load(stringFromSP).apply(new RequestOptions().error(R.mipmap.ic_defalut_head).circleCrop()).into((ImageView) findViewById(R.id.imgOneHead));
        this.tvSee = (TextView) findViewById(R.id.tvSee);
        this.tvZan = (TextView) findViewById(R.id.tvZan);
        this.etComment = (EditText) findViewById(R.id.etComment);
        findViewById(R.id.tvSendComment).setOnClickListener(this);
        RecyclerView findViewById2 = findViewById(2131297022);
        findViewById2.setLayoutManager(new LinearLayoutManager(this));
        this.adapter = new ArticleCommentListAdapter2();
        this.imgHead = (ImageView) findViewById(R.id.imgHead);
        this.imgZan = (ImageView) findViewById(R.id.imgZan);
        this.tvOneName = (TextView) findViewById(R.id.tvOneName);
        this.tvOneCount = (TextView) findViewById(R.id.tvOneCount);
        this.tvOneContent = (TextView) findViewById(R.id.tvOneContent);
        findViewById2.setAdapter(this.adapter);
        findViewById.setOnClickListener(this);
        ClickUtils.expandClickArea(findViewById, 50);
        this.adapter.setOnItemChildClickListener(this);
        initWebView();
        UiMessageUtils.getInstance().addListener(1, new UiMessageUtils.UiMessageCallback() {
            public final void handleMessage(UiMessageUtils.UiMessage uiMessage) {
                ArticleDetailActivity2.this.lambda$initView$0$ArticleDetailActivity2(uiMessage);
            }
        });
    }

    public void lambda$initView$0$ArticleDetailActivity2(UiMessageUtils.UiMessage uiMessage) {
        requestCommentList();
    }

    public void onClick(View v) {
        super.onClick(v);
        int id = v.getId();
        if (id == 2131296609) {
            finish();
            return;
        }
        if (id != 2131297411) {
            return;
        }
        String obj = this.etComment.getText().toString();
        if (TextUtils.isEmpty(obj)) {
            showToast("请输入评论内容");
        } else {
            sendComment(obj);
        }
    }

    private void sendComment(String comment) {
        showProgress();
        this.viewModel.sendComment(comment, this.articleId, this.userId, new OnHttpListener() {
            @Override
            public void onEnd(Call call) {
                OnHttpListener.CC.$default$onEnd(this, call);
            }

            @Override
            public void onStart(Call call) {
                OnHttpListener.CC.$default$onStart(this, call);
            }

            @Override
            public void onSucceed(Object obj, boolean z) {
                onSucceed(obj);
            }

            @Override
            public void onSucceed(Object result) {
                ArticleDetailActivity2.this.dismissProgress();
                ArticleDetailActivity2.this.etComment.setText("");
                ArticleDetailActivity2.this.requestCommentList();
            }

            @Override
            public void onFail(Exception e) {
                ArticleDetailActivity2.this.dismissProgress();
                ArticleDetailActivity2.this.showToast(e.getMessage());
            }
        });
    }

    public void initData() {
        showProgress();
        ArticleDetailViewModel articleDetailViewModel = (ArticleDetailViewModel) new ViewModelProvider(this).get(ArticleDetailViewModel.class);
        this.viewModel = articleDetailViewModel;
        articleDetailViewModel.articleDetail(this.id, this.userId, new OnHttpListener<ArticleDetailBean.DataBean>() {
            @Override
            public void onEnd(Call call) {
                OnHttpListener.CC.$default$onEnd(this, call);
            }

            @Override
            public void onStart(Call call) {
                OnHttpListener.CC.$default$onStart(this, call);
            }

            @Override
            public void onSucceed(ArticleDetailBean.DataBean dataBean, boolean z) {
                onSucceed((AnonymousClass2) dataBean);
            }

            @Override
            public void onSucceed(ArticleDetailBean.DataBean result) {
                ArticleDetailActivity2.this.dismissProgress();
                ArticleDetailActivity2.this.articleId = result.getId();
                ArticleDetailActivity2.this.tvSee.setText(result.getPageView() + "");
                ArticleDetailActivity2.this.tvZan.setText(result.getLikes() + "");
                ArticleDetailActivity2.this.webView.loadData(result.getContent(), "text/html;charset=utf-8", "utf-8");
            }

            @Override
            public void onFail(Exception e) {
                ArticleDetailActivity2.this.showToast(e.getMessage());
                ArticleDetailActivity2.this.dismissProgress();
            }
        });
        requestCommentList();
    }

    public void requestCommentList() {
        showProgress();
        this.viewModel.articleCommentList2(this.commandId, this.userId, new OnHttpListener<CommentBean.DataBean>() {
            @Override
            public void onEnd(Call call) {
                OnHttpListener.CC.$default$onEnd(this, call);
            }

            @Override
            public void onStart(Call call) {
                OnHttpListener.CC.$default$onStart(this, call);
            }

            @Override
            public void onSucceed(CommentBean.DataBean dataBean, boolean z) {
                onSucceed((AnonymousClass3) dataBean);
            }

            @Override
            public void onSucceed(CommentBean.DataBean result) {
                Glide.with(ArticleDetailActivity2.this).load(result.getPublishAvatarUrl()).apply(new RequestOptions().circleCrop()).into(ArticleDetailActivity2.this.imgHead);
                ArticleDetailActivity2.this.tvOneName.setText(result.getPublishNickname());
                ArticleDetailActivity2.this.tvOneContent.setText(result.getContent());
                ArticleDetailActivity2.this.tvOneCount.setText(result.getLikes() + "");
                ArticleDetailActivity2.this.adapter.setNewData(result.getReplyList());
                if (TextUtils.isEmpty(result.getLikeFlag())) {
                    ArticleDetailActivity2.this.imgZan.setBackgroundResource(R.drawable.icon_dianzan);
                    ArticleDetailActivity2.this.tvOneCount.setTextColor(ArticleDetailActivity2.this.getColor(R.color.gray_99));
                } else {
                    ArticleDetailActivity2.this.imgZan.setBackgroundResource(R.drawable.icon_article_zan_check);
                    ArticleDetailActivity2.this.tvOneCount.setTextColor(ArticleDetailActivity2.this.getColor(R.color.orange));
                }
                ArticleDetailActivity2.this.dismissProgress();
            }

            @Override
            public void onFail(Exception e) {
                ArticleDetailActivity2.this.dismissProgress();
                ArticleDetailActivity2.this.showToast(e.getMessage());
            }
        });
    }

    private void initWebView() {
        WebSettings settings = this.webView.getSettings();
        this.webSettings = settings;
        settings.setAllowContentAccess(true);
        this.webSettings.setAppCacheEnabled(false);
        this.webSettings.setBuiltInZoomControls(false);
        this.webSettings.setUseWideViewPort(true);
        this.webSettings.setLoadWithOverviewMode(true);
        this.webSettings.setAppCacheEnabled(true);
        this.webSettings.setDomStorageEnabled(true);
        this.webSettings.setDatabaseEnabled(true);
        this.webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        this.webView.setSaveEnabled(true);
        this.webView.setKeepScreenOn(true);
        this.webSettings.setCacheMode(1);
        this.webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(final WebView view, final String url) {
                super.onPageFinished(view, url);
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }

            @Override
            public void onLoadResource(WebView webView, String s) {
                super.onLoadResource(webView, s);
            }
        });
    }

    public Resources getResources() {
        return AdaptScreenUtils.adaptWidth(super.getResources(), 750);
    }

    public void onItemChildClick(final BaseQuickAdapter adapter, View view, final int position) {
        final ArticleCommentListBean.ListBean listBean = (ArticleCommentListBean.ListBean) adapter.getItem(position);
        final String likeFlag = listBean.getLikeFlag();
        if (view.getId() == 2131296671) {
            showProgress();
            this.viewModel.doLike(2, listBean.getId(), this.userId, new OnHttpListener<SendCommentBean>() {
                @Override
                public void onEnd(Call call) {
                    OnHttpListener.CC.$default$onEnd(this, call);
                }

                @Override
                public void onStart(Call call) {
                    OnHttpListener.CC.$default$onStart(this, call);
                }

                @Override
                public void onSucceed(SendCommentBean sendCommentBean, boolean z) {
                    onSucceed((AnonymousClass5) sendCommentBean);
                }

                @Override
                public void onSucceed(SendCommentBean result) {
                    ArticleDetailActivity2.this.dismissProgress();
                    ArticleDetailActivity2.this.showToast("成功");
                    if (TextUtils.isEmpty(likeFlag)) {
                        listBean.setLikeFlag("1");
                        ArticleCommentListBean.ListBean listBean2 = listBean;
                        listBean2.setLikes(listBean2.getLikes() + 1);
                    }
                    adapter.notifyItemChanged(position);
                }

                @Override
                public void onFail(Exception e) {
                    ArticleDetailActivity2.this.dismissProgress();
                    ArticleDetailActivity2.this.showToast(e.getMessage());
                }
            });
        } else if (view.getId() == 2131297399) {
            new SendCommentDialog(this, new Function1<String, Unit>() {
                public Unit invoke(String s) {
                    ArticleDetailActivity2.this.replyComment(s, listBean.getId(), listBean);
                    return null;
                }
            }).show();
        } else if (view.getId() == 2131297327) {
            showProgress();
            this.viewModel.deleteComment(listBean.getId(), listBean.getPublishUserId(), new OnHttpListener<SendCommentBean>() {
                @Override
                public void onEnd(Call call) {
                    OnHttpListener.CC.$default$onEnd(this, call);
                }

                @Override
                public void onStart(Call call) {
                    OnHttpListener.CC.$default$onStart(this, call);
                }

                @Override
                public void onSucceed(SendCommentBean sendCommentBean, boolean z) {
                    onSucceed((AnonymousClass7) sendCommentBean);
                }

                @Override
                public void onSucceed(SendCommentBean result) {
                    ArticleDetailActivity2.this.dismissProgress();
                    ArticleDetailActivity2.this.requestCommentList();
                }

                @Override
                public void onFail(Exception e) {
                    ArticleDetailActivity2.this.dismissProgress();
                    ArticleDetailActivity2.this.showToast(e.getMessage());
                }
            });
        }
    }

    public void replyComment(String comment, int id, ArticleCommentListBean.ListBean item) {
        showProgress();
        this.viewModel.sendReply(comment, id, this.userId, new OnHttpListener() {
            @Override
            public void onEnd(Call call) {
                OnHttpListener.CC.$default$onEnd(this, call);
            }

            @Override
            public void onStart(Call call) {
                OnHttpListener.CC.$default$onStart(this, call);
            }

            @Override
            public void onSucceed(Object obj, boolean z) {
                onSucceed(obj);
            }

            @Override
            public void onSucceed(Object result) {
                ArticleDetailActivity2.this.dismissProgress();
                ArticleDetailActivity2.this.showToast("成功");
                ArticleDetailActivity2.this.requestCommentList();
            }

            @Override
            public void onFail(Exception e) {
                ArticleDetailActivity2.this.dismissProgress();
                ArticleDetailActivity2.this.showToast(e.getMessage());
            }
        });
    }
}