处理一部分activity的toolbar,已经处理完毕的标记为Deprecated,为了保持MTA数据上报兼容性,暂时未删除对应的Activity

This commit is contained in:
CsHeng
2017-12-14 17:56:54 +08:00
parent e0b70b26f3
commit bf7b0b0a82
67 changed files with 2251 additions and 2495 deletions

View File

@ -1,241 +1,25 @@
package com.gh.gamecenter;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import com.facebook.drawee.view.SimpleDraweeView;
import com.gh.base.BaseActivity;
import com.gh.common.util.CheckLoginUtils;
import com.gh.common.util.DialogUtils;
import com.gh.common.util.EntranceUtils;
import com.gh.common.util.ImageUtils;
import com.gh.common.util.LoginUtils;
import com.gh.common.util.PostCommentUtils;
import com.gh.gamecenter.adapter.CommentDetailAdapter;
import com.gh.gamecenter.adapter.OnCommentCallBackListener;
import com.gh.gamecenter.entity.CommentEntity;
import com.gh.gamecenter.entity.UserInfoEntity;
import com.lightgame.utils.Utils;
import org.json.JSONException;
import org.json.JSONObject;
import butterknife.BindView;
import butterknife.OnClick;
import butterknife.OnTouch;
import retrofit2.HttpException;
import com.halo.assistant.fragment.comment.CommentDetailFragment;
import com.halo.assistant.ui.IntentFactory;
/**
* Created by khy on 2017/3/22.
*/
@Deprecated
public class CommentDetailActivity extends CommonActivity {
// TODO: 16/11/17 时间比较紧 先暂时这么做 最好发表评论那块和评论详情整合
public class CommentDetailActivity extends BaseActivity implements OnCommentCallBackListener {
@BindView(R.id.comment_detail_rv)
RecyclerView mRecyclerView;
@BindView(R.id.comment_detail_close_comment)
View mCommentDetailCloseComment;
@BindView(R.id.comment_detail_comment_et)
EditText mCommentDetailCommentEt;
@BindView(R.id.comment_user_icon)
SimpleDraweeView mCommentUserIcon;
@BindView(R.id.comment_user_name)
TextView mCommentUserName;
@BindView(R.id.comment_send)
TextView mCommentSend;
@BindView(R.id.comment_detail_user_rl)
RelativeLayout mCommentDetailUserRl;
@BindView(R.id.comment_detail_comment_rl)
RelativeLayout mCommentDetailCommentRl;
@BindView(R.id.comment_detail_sv)
ScrollView mCommentDetailSv;
@BindView(R.id.reuse_none_data)
View mNoData;
private Dialog mSendingDialog;
private UserInfoEntity mUserInfo;
private CommentEntity mCommentEntity; // 回复评论的实体 用完马上清空
private CommentDetailAdapter mAdapter;
private LinearLayoutManager mLayoutManager;
public static Intent getCommentDetailIntent(Context context, String commentId) {
Intent intent = new Intent(context, CommentDetailActivity.class);
intent.putExtra(EntranceUtils.KEY_COMMENTID, commentId);
return intent;
}
@Override
protected int getLayoutId() {
return R.layout.activity_comment_detail;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setNavigationTitle(getString(R.string.title_comment_detail));
String commentId = getIntent().getStringExtra(EntranceUtils.KEY_COMMENTID);
mAdapter = new CommentDetailAdapter(this, commentId, this, mNoData, mRecyclerView);
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_IDLE && !mAdapter.isOver() && !mAdapter.isLoading()) {
mAdapter.loadData(mAdapter.getItemCount());
}
}
});
mUserInfo = LoginUtils.getUserInfo(this);
if (mUserInfo != null) {
ImageUtils.Companion.display(mCommentUserIcon, mUserInfo.getIcon());
mCommentUserName.setText(mUserInfo.getName());
}
}
@Override
public void onCommentCallback(CommentEntity entity) {
mCommentEntity = entity;
setSoftInput(true);
}
@OnTouch(R.id.comment_detail_close_comment)
public boolean OnRecyclerTouchListener() {
if (mCommentDetailCloseComment.getVisibility() == View.VISIBLE) {
setSoftInput(false);
}
return true;
}
@OnClick(R.id.comment_send)
public void OnSendCommentListener() {
final String content = mCommentDetailCommentEt.getText().toString();
if (content.length() == 0) {
Utils.toast(this, "评论内容不能为空!");
return;
}
mSendingDialog = DialogUtils.showWaitDialog(this, "正在提交");
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("content", content);
} catch (JSONException e) {
e.printStackTrace();
}
if (mCommentEntity != null && mCommentEntity.getId() == null) {
Utils.toast(this, "评论异常 id null");
mSendingDialog.cancel();
return;
}
PostCommentUtils.addCommentData(CommentDetailActivity.this, null, jsonObject.toString(), mCommentEntity,
new PostCommentUtils.PostCommentListener() {
@Override
public void postSuccess(JSONObject response) {
mSendingDialog.dismiss();
toast("发表成功");
mCommentDetailCommentEt.setText("");
setSoftInput(false);
}
@Override
public void postFailed(Throwable e) {
mSendingDialog.dismiss();
if (e instanceof HttpException) {
HttpException exception = (HttpException) e;
if (exception.code() == 403) {
try {
JSONObject errorJson = new JSONObject(exception.response().errorBody().string());
String detail = errorJson.getString("detail");
switch (detail) {
case "too frequent":
toast("别话痨哦~休息一会再来评论吧~");
break;
case "user blocked":
toast("账号状态异常,暂时无法发表评论");
break;
case "article blocked":
toast("文章异常,无法发表评论");
setSoftInput(false);
break;
case "illegal":
toast("评论内容可能包括敏感信息,请修改后再发表");
break;
default:
toast("评论失败,未知原因");
break;
}
} catch (Exception ex) {
ex.printStackTrace();
toast("评论异常");
}
return;
}
}
toast("提交失败,请检查网络设置");
}
});
}
//软键盘控制
private void setSoftInput(boolean isShow) {
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (isShow) {
CheckLoginUtils.checkLogin(this, new CheckLoginUtils.OnLoggenInListener() {
@Override
public void onLoggedIn() {
imm.showSoftInputFromInputMethod(mCommentDetailCommentEt.getWindowToken(), 0);
imm.toggleSoftInputFromWindow(mCommentDetailCommentEt.getWindowToken(), 0, InputMethodManager.HIDE_NOT_ALWAYS);
mCommentDetailCommentRl.setVisibility(View.VISIBLE);
mCommentDetailCommentEt.setFocusable(true);
mCommentDetailCommentEt.setFocusableInTouchMode(true);
mCommentDetailCommentEt.requestFocus();
mCommentDetailCloseComment.setVisibility(View.VISIBLE);
if (mCommentEntity != null && mCommentEntity.getUser() != null) {
mCommentDetailCommentEt.setHint("回复" + mCommentEntity.getUser().getName() + "");
} else {
mCommentDetailCommentEt.setHint("优质评论会被优先展示");
}
}
});
} else {
imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
mCommentDetailCloseComment.setVisibility(View.GONE);
mCommentDetailCommentRl.setVisibility(View.GONE);
if (mCommentEntity != null) {
mCommentEntity = null; // 清空当前评论实体
mCommentDetailCommentEt.setHint("优质评论会被优先展示");
mCommentDetailCommentEt.setText("");
}
}
public static Intent getIntent(Context context, String commentId) {
Bundle args = new Bundle();
args.putString(EntranceUtils.KEY_COMMENTID, commentId);
return new IntentFactory.Builder(context)
.setActivity(CommentDetailActivity.class)
.setFragment(CommentDetailFragment.class).setArgs(args).build();
}
}