正在查看: 自健身 v3.3.4 应用的 ArticleDetailActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 自健身 v3.3.4 应用的 ArticleDetailActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.mu.gymtrain.Activity;
import android.content.res.Resources;
import android.os.Build;
import android.text.TextUtils;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
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.KeyboardUtils;
import com.blankj.utilcode.util.LogUtils;
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.ArticleCommentListAdapter;
import com.mu.gymtrain.Base.BaseActivity;
import com.mu.gymtrain.Bean.ArticleCommentListBean;
import com.mu.gymtrain.Bean.ArticleDetailBean;
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 java.util.List;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import okhttp3.Call;
public class ArticleDetailActivity extends BaseActivity implements BaseQuickAdapter.OnItemChildClickListener {
private ArticleCommentListAdapter adapter;
private int articleId;
private EditText etComment;
private int id;
private ImageView imgGood;
private String likeFlag;
private int likes;
private WebSettings mWebSettings;
private int page = 1;
private TextView tvSee;
private TextView tvZan;
private String userId;
private ArticleDetailViewModel viewModel;
private WebView webView;
public int getContentLayout() {
return R.layout.activity_article_detaiil_layout;
}
public void initView() {
String stringExtra = getIntent().getStringExtra("html");
this.id = getIntent().getIntExtra("id", 0);
this.likeFlag = getIntent().getStringExtra("likeFlag");
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);
ImageView imageView = (ImageView) findViewById(R.id.imgOneHead);
ImageView imageView2 = (ImageView) findViewById(R.id.imgGood);
this.imgGood = imageView2;
imageView2.setOnClickListener(this);
Glide.with(this).load(stringFromSP).apply(new RequestOptions().error(R.mipmap.ic_defalut_head).circleCrop()).into(imageView);
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));
ArticleCommentListAdapter articleCommentListAdapter = new ArticleCommentListAdapter();
this.adapter = articleCommentListAdapter;
findViewById2.setAdapter(articleCommentListAdapter);
findViewById.setOnClickListener(this);
ClickUtils.expandClickArea(findViewById, 50);
this.adapter.setOnItemChildClickListener(this);
initWebView();
LogUtils.i(new Object[]{"html " + stringExtra});
this.webView.loadUrl(stringExtra);
UiMessageUtils.getInstance().addListener(1, new UiMessageUtils.UiMessageCallback() {
public final void handleMessage(UiMessageUtils.UiMessage uiMessage) {
ArticleDetailActivity.this.lambda$initView$0$ArticleDetailActivity(uiMessage);
}
});
}
public void lambda$initView$0$ArticleDetailActivity(UiMessageUtils.UiMessage uiMessage) {
requestCommentList();
}
public void onClick(View v) {
super.onClick(v);
int id = v.getId();
if (id == 2131296609) {
finish();
return;
}
if (id == 2131296632) {
zan();
return;
}
if (id != 2131297411) {
return;
}
String obj = this.etComment.getText().toString();
if (TextUtils.isEmpty(obj)) {
showToast("请输入评论内容");
} else {
sendComment(obj);
}
}
private void zan() {
if (!TextUtils.isEmpty(this.likeFlag)) {
showToast("您已点过赞了");
} else {
showProgress();
this.viewModel.doLike(1, this.id, 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((AnonymousClass1) sendCommentBean);
}
@Override
public void onSucceed(SendCommentBean result) {
ArticleDetailActivity.this.dismissProgress();
ArticleDetailActivity.this.showToast("成功");
ArticleDetailActivity.this.imgGood.setBackgroundResource(R.drawable.icon_article_zan_check);
ArticleDetailActivity.this.tvZan.setText((ArticleDetailActivity.this.likes + 1) + "");
ArticleDetailActivity.this.likeFlag = "1";
}
@Override
public void onFail(Exception e) {
ArticleDetailActivity.this.dismissProgress();
ArticleDetailActivity.this.showToast(e.getMessage());
}
});
}
}
private void sendComment(String comment) {
KeyboardUtils.hideSoftInput(this.etComment);
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) {
ArticleDetailActivity.this.dismissProgress();
ArticleDetailActivity.this.etComment.setText("");
ArticleDetailActivity.this.requestCommentList();
}
@Override
public void onFail(Exception e) {
ArticleDetailActivity.this.dismissProgress();
ArticleDetailActivity.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((AnonymousClass3) dataBean);
}
@Override
public void onSucceed(ArticleDetailBean.DataBean result) {
ArticleDetailActivity.this.dismissProgress();
if (result == null) {
return;
}
ArticleDetailActivity.this.articleId = result.getId();
ArticleDetailActivity.this.tvSee.setText(result.getPageView() + "");
ArticleDetailActivity.this.likes = result.getLikes();
ArticleDetailActivity.this.tvZan.setText(ArticleDetailActivity.this.likes + "");
ArticleDetailActivity.this.likeFlag = result.getLikeFlag();
if (TextUtils.isEmpty(ArticleDetailActivity.this.likeFlag)) {
return;
}
ArticleDetailActivity.this.imgGood.setBackgroundResource(R.drawable.icon_article_zan_check);
ArticleDetailActivity.this.tvZan.setTextColor(ArticleDetailActivity.this.getResources().getColor(R.color.orange));
}
@Override
public void onFail(Exception e) {
ArticleDetailActivity.this.showToast(e.getMessage());
ArticleDetailActivity.this.dismissProgress();
}
});
requestCommentList();
}
public void requestCommentList() {
showProgress();
this.viewModel.articleCommentList(this.page, this.id, this.userId, new OnHttpListener<List<ArticleCommentListBean.ListBean>>() {
@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(List<ArticleCommentListBean.ListBean> list, boolean z) {
onSucceed((AnonymousClass4) list);
}
@Override
public void onSucceed(List<ArticleCommentListBean.ListBean> result) {
ArticleDetailActivity.this.adapter.setNewData(result);
ArticleDetailActivity.this.dismissProgress();
}
@Override
public void onFail(Exception e) {
ArticleDetailActivity.this.dismissProgress();
ArticleDetailActivity.this.showToast(e.getMessage());
}
});
}
private void initWebView() {
WebSettings settings = this.webView.getSettings();
this.mWebSettings = settings;
settings.setJavaScriptEnabled(true);
this.mWebSettings.setSupportZoom(true);
this.mWebSettings.setBuiltInZoomControls(false);
this.mWebSettings.setSavePassword(false);
this.mWebSettings.setCacheMode(2);
if (Build.VERSION.SDK_INT >= 21) {
this.mWebSettings.setMixedContentMode(0);
this.webView.setLayerType(2, null);
} else if (Build.VERSION.SDK_INT >= 19) {
this.webView.setLayerType(2, null);
} else if (Build.VERSION.SDK_INT < 19) {
this.webView.setLayerType(1, null);
}
this.mWebSettings.setDatabaseEnabled(true);
this.mWebSettings.setAppCacheEnabled(true);
this.mWebSettings.setLoadsImagesAutomatically(true);
this.mWebSettings.setSupportMultipleWindows(false);
this.mWebSettings.setBlockNetworkImage(false);
this.mWebSettings.setAllowFileAccess(true);
if (Build.VERSION.SDK_INT >= 16) {
this.mWebSettings.setAllowFileAccessFromFileURLs(false);
this.mWebSettings.setAllowUniversalAccessFromFileURLs(false);
}
this.mWebSettings.setJavaScriptCanOpenWindowsAutomatically(true);
if (Build.VERSION.SDK_INT >= 19) {
this.mWebSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
} else {
this.mWebSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
}
this.mWebSettings.setLoadWithOverviewMode(false);
this.mWebSettings.setUseWideViewPort(false);
this.mWebSettings.setDomStorageEnabled(true);
this.mWebSettings.setNeedInitialFocus(true);
this.mWebSettings.setDefaultTextEncodingName("utf-8");
this.mWebSettings.setGeolocationEnabled(true);
this.mWebSettings.setAppCacheMaxSize(Long.MAX_VALUE);
this.mWebSettings.setTextZoom(80);
}
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) {
ArticleDetailActivity.this.dismissProgress();
ArticleDetailActivity.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) {
ArticleDetailActivity.this.dismissProgress();
ArticleDetailActivity.this.showToast(e.getMessage());
}
});
} else if (view.getId() == 2131297399) {
new SendCommentDialog(this, new Function1<String, Unit>() {
public Unit invoke(String s) {
ArticleDetailActivity.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) {
ArticleDetailActivity.this.dismissProgress();
ArticleDetailActivity.this.requestCommentList();
}
@Override
public void onFail(Exception e) {
ArticleDetailActivity.this.dismissProgress();
ArticleDetailActivity.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) {
ArticleDetailActivity.this.dismissProgress();
ArticleDetailActivity.this.showToast("成功");
ArticleDetailActivity.this.requestCommentList();
}
@Override
public void onFail(Exception e) {
ArticleDetailActivity.this.dismissProgress();
ArticleDetailActivity.this.showToast(e.getMessage());
}
});
}
}