【光环助手V5.6.0】前端优化汇总12月第5周(4,6) https://git.shanqu.cc/pm/halo-app-issues/-/issues/1672

This commit is contained in:
jack
2021-12-31 18:21:13 +08:00
parent dd8cc3c744
commit 213ccd86c0
44 changed files with 1699 additions and 733 deletions

View File

@ -1,19 +1,27 @@
package com.gh.gamecenter.collection;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import com.gh.base.OnListClickListener;
import com.gh.common.constant.ItemViewType;
import com.gh.common.syncpage.ISyncAdapterHandler;
import com.gh.common.util.CollectionUtils;
import com.gh.common.util.DialogHelper;
import com.gh.common.util.DisplayUtils;
import com.gh.common.util.ExtensionsKt;
import com.gh.gamecenter.R;
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
import com.gh.gamecenter.baselist.ListAdapter;
import com.gh.gamecenter.baselist.LoadType;
import com.gh.gamecenter.databinding.CommunityAnswerItemBinding;
import com.gh.gamecenter.databinding.PopupHistoryOptionBinding;
import com.gh.gamecenter.history.ManageOption;
import com.gh.gamecenter.qa.answer.CommunityAnswerItemViewHolder;
import com.gh.gamecenter.qa.entity.AnswerEntity;
import com.gh.gamecenter.qa.entity.Questions;
@ -22,8 +30,11 @@ import com.lightgame.utils.Utils;
import org.jetbrains.annotations.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import kotlin.Pair;
/**
@ -38,6 +49,11 @@ public class AnswerAdapter extends ListAdapter<AnswerEntity> implements ISyncAda
private String mEntrance;
private ManageOption mCurrentOption = ManageOption.OPTION_MANAGER;
private PopupWindow mPopWindow;
private PopupHistoryOptionBinding mPopupBinding;
private ArrayList<AnswerEntity> selectItems = new ArrayList<>();
public AnswerAdapter(Context context, AnswerViewModel viewModel, OnListClickListener listClickListener, String entrance) {
super(context);
mListViewModel = viewModel;
@ -66,6 +82,23 @@ public class AnswerAdapter extends ListAdapter<AnswerEntity> implements ISyncAda
}
}
public void changeOption(ManageOption option) {
mCurrentOption = option;
if (mCurrentOption == ManageOption.OPTION_MANAGER) {
if (mPopWindow != null) {
selectItems.clear();
mPopWindow.dismiss();
mPopWindow = null;
}
} else {
if (mPopWindow == null || mPopWindow.isShowing()) {
showOptionWindow();
}
}
notifyItemRangeChanged(0, mEntityList.size());
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
switch (getItemViewType(position)) {
@ -94,26 +127,40 @@ public class AnswerAdapter extends ListAdapter<AnswerEntity> implements ISyncAda
} else {
path = "插入回答-收藏回答列表";
}
viewHolder.getBinding().imageContainer.setOffset(mCurrentOption == ManageOption.OPTION_MANAGER ? 40f : 76f);
viewHolder.bindAnswerItem(entity, mEntrance, path);
holder.itemView.setOnClickListener(v -> {
if (entity.getActive()) {
// mContext.startActivity(AnswerDetailActivity.getIntent(mContext, entity.getId(), mEntrance, path));
mContext.startActivity(NewQuestionDetailActivity.getCommentIntent(mContext, entity.getQuestions().getId(), entity.getId(), mEntrance, path));
} else {
showDeleteDialog(entity.getId());
}
viewHolder.getBinding().selectIv.setVisibility(mCurrentOption == ManageOption.OPTION_MANAGER ? View.GONE : View.VISIBLE);
viewHolder.getBinding().selectIv.setChecked(selectItems.contains(entity));
if (!entity.getRead()) {
entity.setRead(true);
holder.itemView.setOnClickListener(v -> {
if (mCurrentOption == ManageOption.OPTION_MANAGER) {
if (entity.getActive()) {
mContext.startActivity(NewQuestionDetailActivity.getCommentIntent(mContext, entity.getQuestions().getId(), entity.getId(), mEntrance, path));
} else {
showDeleteDialog(entity.getId());
}
if (!entity.getRead()) {
entity.setRead(true);
notifyItemChanged(position);
mListViewModel.postCollectionAnswerRead(entity.getId());
}
} else {
if (selectItems.contains(entity)) {
selectItems.remove(entity);
} else {
selectItems.add(entity);
}
checkSelectItems();
notifyItemChanged(position);
mListViewModel.postCollectionAnswerRead(entity.getId());
}
});
viewHolder.getBinding().title.setOnClickListener(v -> {
Questions questions = entity.getQuestions();
// mContext.startActivity(QuestionsDetailActivity.getIntent(mContext, questions.getId(), mEntrance, path));
mContext.startActivity(NewQuestionDetailActivity.getIntent(mContext, questions.getId(), mEntrance, path));
if (mCurrentOption == ManageOption.OPTION_MANAGER) {
Questions questions = entity.getQuestions();
mContext.startActivity(NewQuestionDetailActivity.getIntent(mContext, questions.getId(), mEntrance, path));
}
});
break;
case ItemViewType.ITEM_FOOTER:
@ -157,4 +204,52 @@ public class AnswerAdapter extends ListAdapter<AnswerEntity> implements ISyncAda
AnswerEntity entity = mEntityList.get(position);
return new Pair(entity.getId(), entity);
}
private void showOptionWindow() {
mPopupBinding = PopupHistoryOptionBinding.inflate(LayoutInflater.from(mContext));
mPopupBinding.getRoot().setFocusable(true);
mPopupBinding.getRoot().setFocusableInTouchMode(true);
mPopWindow = new PopupWindow(mPopupBinding.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, DisplayUtils.dip2px(56f));
mPopWindow.showAtLocation(((AppCompatActivity) mContext).getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);
mPopupBinding.itemDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogHelper.showDialog(mContext,
"是否删除" + selectItems.size() + "条记录?",
"提示:删除记录将不可恢复",
"删除",
"取消",
() -> {
mListViewModel.removeHistories(selectItems);
selectItems.clear();
checkSelectItems();
},
() -> {
},
false, "", "");
}
});
mPopupBinding.checkAllCb.setOnClickListener(v -> {
if (mPopupBinding.checkAllCb.isChecked()) {
selectItems.clear();
selectItems.addAll(mEntityList);
} else {
selectItems.clear();
}
checkSelectItems();
notifyItemRangeChanged(0, mEntityList.size());
});
}
private void checkSelectItems() {
if (mPopupBinding == null) return;
mPopupBinding.selectNumTv.setText(selectItems.isEmpty() ? "" : "(" + selectItems.size() + ")");
mPopupBinding.itemDelete.setBackground(selectItems.isEmpty() ? ExtensionsKt.toDrawable(R.drawable.bg_shape_f5_radius_999) : ExtensionsKt.toDrawable(R.drawable.download_button_normal_style));
mPopupBinding.itemDelete.setTextColor(selectItems.isEmpty() ? ExtensionsKt.toColor(R.color.text_subtitle) : ExtensionsKt.toColor(R.color.white));
mPopupBinding.itemDelete.setEnabled(!selectItems.isEmpty());
mPopupBinding.checkAllCb.setChecked(selectItems.size() == mEntityList.size());
}
}