Commit cea6a555 authored by feihuaduo's avatar feihuaduo

使用BaseQuickAdapter

gradle版本更新至7.0.3
修复决斗助手房间检查无法识别多行文字的问题
parent 7559c10c
...@@ -9,7 +9,7 @@ buildscript { ...@@ -9,7 +9,7 @@ buildscript {
google() google()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:7.0.2' classpath 'com.android.tools.build:gradle:7.0.3'
classpath 'com.android.tools.build:gradle-experimental:0.11.1' classpath 'com.android.tools.build:gradle-experimental:0.11.1'
//classpath 'me.tatarka:gradle-retrolambda:3.2.5' //classpath 'me.tatarka:gradle-retrolambda:3.2.5'
} }
......
...@@ -117,7 +117,7 @@ dependencies { ...@@ -117,7 +117,7 @@ dependencies {
//dialog库 //dialog库
implementation(name: 'dialogutils2-release', ext: 'aar') implementation(name: 'dialogutils2-release', ext: 'aar')
//recyclerview的adapter库 //recyclerview的adapter库
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4'
implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0' implementation 'com.google.android.material:material:1.3.0'
//图片选择 //图片选择
......
...@@ -7,21 +7,24 @@ import android.view.ViewGroup; ...@@ -7,21 +7,24 @@ import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
public abstract class BaseRecyclerAdapterPlus<T, V extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<V> { public abstract class BaseRecyclerAdapterPlus<T, V extends BaseViewHolder> extends BaseQuickAdapter<T,V> {
protected Context context; protected Context context;
private LayoutInflater mLayoutInflater; private LayoutInflater mLayoutInflater;
protected final List<T> mItems = new ArrayList<T>(); // protected final List<T> mItems = new ArrayList<T>();
public BaseRecyclerAdapterPlus(Context context) { public BaseRecyclerAdapterPlus(Context context,int layout) {
super(); super(layout,new ArrayList<>());
this.context = context; this.context = context;
mLayoutInflater = LayoutInflater.from(context); mLayoutInflater = LayoutInflater.from(context);
} }
public Context getContext() { public Context getAdapterContext() {
return context; return context;
} }
...@@ -37,23 +40,21 @@ public abstract class BaseRecyclerAdapterPlus<T, V extends RecyclerView.ViewHold ...@@ -37,23 +40,21 @@ public abstract class BaseRecyclerAdapterPlus<T, V extends RecyclerView.ViewHold
} }
} }
if (pos >= 0) { if (pos >= 0) {
mItems.add(pos, item); addData(pos, item);
} else { } else {
mItems.add(item); addData(item);
} }
return true; return true;
} }
return true; return true;
} }
public T remove(int pos) {
return mItems.remove(pos);
}
public void removeItem(T item) { public void removeItem(T item) {
mItems.remove(item); remove(item);
} }
public List<T> getItems() { public List<T> getItems() {
return mItems; return getData();
} }
protected <VW extends View> VW inflate(int resource, ViewGroup root) { protected <VW extends View> VW inflate(int resource, ViewGroup root) {
...@@ -65,7 +66,7 @@ public abstract class BaseRecyclerAdapterPlus<T, V extends RecyclerView.ViewHold ...@@ -65,7 +66,7 @@ public abstract class BaseRecyclerAdapterPlus<T, V extends RecyclerView.ViewHold
} }
public void clear() { public void clear() {
mItems.clear(); getData().clear();
} }
public void set(Collection<T> items) { public void set(Collection<T> items) {
...@@ -75,36 +76,36 @@ public abstract class BaseRecyclerAdapterPlus<T, V extends RecyclerView.ViewHold ...@@ -75,36 +76,36 @@ public abstract class BaseRecyclerAdapterPlus<T, V extends RecyclerView.ViewHold
public void addAll(Collection<T> items) { public void addAll(Collection<T> items) {
if (items != null) { if (items != null) {
mItems.addAll(items); addData(items);
} }
} }
public int findItem(T item) { public int findItem(T item) {
return mItems.indexOf(item); return getItems().indexOf(item);
} }
public boolean exist(T item) { public boolean exist(T item) {
if (item == null) return false; if (item == null) return false;
return mItems.contains(item); return getItems().contains(item);
} }
@Override // @Override
public abstract V onCreateViewHolder(ViewGroup parent, int viewType); // public abstract V onCreateViewHolder(ViewGroup parent, int viewType);
@Override // @Override
public abstract void onBindViewHolder(V holder, int position); // public abstract void onBindViewHolder(V holder, int position);
public final T getItem(int position) { // public final T getItem(int position) {
if (position >= 0 && position < getItemCount()) { // if (position >= 0 && position < getItemCount()) {
return mItems.get(position); // return getItems().get(position);
} // }
return null; // return null;
} // }
@Override // @Override
public int getItemCount() { // public int getItemCount() {
return mItems.size(); // return mItems.size();
} // }
public final T getItemById(long id) { public final T getItemById(long id) {
return getItem((int) id); return getItem((int) id);
......
...@@ -5,7 +5,15 @@ import android.content.Intent; ...@@ -5,7 +5,15 @@ import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.provider.Settings; import android.provider.Settings;
import android.view.ViewGroup; import android.util.Log;
import android.view.View;
import androidx.annotation.NonNull;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.tubb.smrv.SwipeHorizontalMenuLayout;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
...@@ -15,72 +23,107 @@ import cn.garymb.ygomobile.lite.R; ...@@ -15,72 +23,107 @@ import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.home.ServerInfoViewHolder; import cn.garymb.ygomobile.ui.home.ServerInfoViewHolder;
import cn.garymb.ygomobile.ui.plus.DialogPlus; import cn.garymb.ygomobile.ui.plus.DialogPlus;
public class ServerListAdapter extends BaseRecyclerAdapterPlus<ServerInfo, ServerInfoViewHolder> { public class ServerListAdapter extends BaseRecyclerAdapterPlus<ServerInfo, BaseViewHolder> {
public ServerListAdapter(Context context) { public ServerListAdapter(Context context) {
super(context); super(context, R.layout.item_server_info_swipe);
bindMenu();
} }
@Override // @Override
public ServerInfoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // public ServerInfoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new ServerInfoViewHolder(inflate(R.layout.item_server_info_swipe, parent, false)); // return new ServerInfoViewHolder(inflate(R.layout.item_server_info_swipe, parent, false));
} // }
@Override // @Override
public void onBindViewHolder(ServerInfoViewHolder holder, int position) { // public void onBindViewHolder(ServerInfoViewHolder holder, int position) {
ServerInfo item = getItem(position); // ServerInfo item = getItem(position);
holder.serverName.setText(item.getName()); // holder.serverName.setText(item.getName());
holder.serverIp.setText(item.getServerAddr()); // holder.serverIp.setText(item.getServerAddr());
holder.userName.setText(item.getPlayerName()); // holder.userName.setText(item.getPlayerName());
holder.serverPort.setText(String.valueOf(item.getPort())); // holder.serverPort.setText(String.valueOf(item.getPort()));
holder.iv_fond.setOnClickListener((v) -> { // holder.iv_fond.setOnClickListener((v) -> {
DialogPlus builder = new DialogPlus(getContext()); // DialogPlus builder = new DialogPlus(getContext());
builder.setTitle(R.string.OpenTIP); // builder.setTitle(R.string.OpenTIP);
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { // if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
builder.setMessage(context.getString(R.string.join_helper_tip1) + context.getString(R.string.join_helper_tip2)); // builder.setMessage(context.getString(R.string.join_helper_tip1) + context.getString(R.string.join_helper_tip2));
builder.setLeftButtonText(R.string.Open_Alert_Window); // builder.setLeftButtonText(R.string.Open_Alert_Window);
builder.setLeftButtonListener((dlg, s) -> { // builder.setLeftButtonListener((dlg, s) -> {
getContext().startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + context.getPackageName()))); // getContext().startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + context.getPackageName())));
dlg.dismiss(); // dlg.dismiss();
}); // });
} else { // } else {
builder.setMessage(R.string.join_helper_tip1); // builder.setMessage(R.string.join_helper_tip1);
// }
// builder.show();
// });
// if (position == 0) {
// holder.iv_fond.setBackgroundResource(R.drawable.cube);
// } else {
// holder.iv_fond.setBackgroundResource(R.drawable.cube2);
// }
// bindMenu(holder, position);
// }
public void bindMenu() {
addChildClickViewIds(R.id.smContentView,R.id.btn_edit_delete,R.id.btn_delete,R.id.iv_fond);
setOnItemChildClickListener((adapter, view, position) -> {
switch (view.getId()){
case R.id.smContentView:
ServerInfoEvent event = new ServerInfoEvent(position, false);
event.join = true;
EventBus.getDefault().post(event);
SwipeHorizontalMenuLayout menuLayout= (SwipeHorizontalMenuLayout) adapter.getViewByPosition(position,R.id.swipe_layout);
if (menuLayout.isMenuOpen()) {
menuLayout.smoothCloseMenu();
}
break;
case R.id.btn_edit_delete:
EventBus.getDefault().post(new ServerInfoEvent(position, false));
SwipeHorizontalMenuLayout menuLayout1= (SwipeHorizontalMenuLayout) adapter.getViewByPosition(position,R.id.swipe_layout);
if (menuLayout1.isMenuOpen()) {
menuLayout1.smoothCloseMenu();
}
break;
case R.id.btn_delete:
EventBus.getDefault().post(new ServerInfoEvent(position, true));
SwipeHorizontalMenuLayout menuLayout2= (SwipeHorizontalMenuLayout) adapter.getViewByPosition(position,R.id.swipe_layout);
if (menuLayout2.isMenuOpen()) {
menuLayout2.smoothCloseMenu();
}
break;
case R.id.iv_fond:
DialogPlus builder = new DialogPlus(getContext());
builder.setTitle(R.string.OpenTIP);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
builder.setMessage(context.getString(R.string.join_helper_tip1) + context.getString(R.string.join_helper_tip2));
builder.setLeftButtonText(R.string.Open_Alert_Window);
builder.setLeftButtonListener((dlg, s) -> {
getContext().startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + context.getPackageName())));
dlg.dismiss();
});
} else {
builder.setMessage(R.string.join_helper_tip1);
}
builder.show();
break;
} }
builder.show();
}); });
if (position == 0) {
holder.iv_fond.setBackgroundResource(R.drawable.cube);
} else {
holder.iv_fond.setBackgroundResource(R.drawable.cube2);
}
bindMenu(holder, position);
} }
public void bindMenu(ServerInfoViewHolder holder, int position) { @Override
if (holder.contentView != null) { protected void convert(@NonNull com.chad.library.adapter.base.viewholder.BaseViewHolder baseViewHolder, ServerInfo serverInfo) {
holder.contentView.setOnClickListener((v) -> { int position = baseViewHolder.getAdapterPosition()
ServerInfoEvent event = new ServerInfoEvent(position, false); - getHeaderLayoutCount();
event.join = true; baseViewHolder.setText(R.id.server_name, serverInfo.getName());
EventBus.getDefault().post(event); baseViewHolder.setText(R.id.text_ip, serverInfo.getServerAddr());
if (holder.mMenuLayout.isMenuOpen()) { baseViewHolder.setText(R.id.text_player, serverInfo.getPlayerName());
holder.mMenuLayout.smoothCloseMenu(); baseViewHolder.setText(R.id.text_port, String.valueOf(serverInfo.getPort()));
}
}); if (position == 0) {
} baseViewHolder.setBackgroundResource(R.id.iv_fond, R.drawable.cube);
if (holder.btnEdit != null) { } else {
holder.btnEdit.setOnClickListener((v) -> { baseViewHolder.setBackgroundResource(R.id.iv_fond, R.drawable.cube2);
EventBus.getDefault().post(new ServerInfoEvent(position, false));
if (holder.mMenuLayout.isMenuOpen()) {
holder.mMenuLayout.smoothCloseMenu();
}
});
}
if (holder.btnDelete != null) {
holder.btnDelete.setOnClickListener((v) -> {
EventBus.getDefault().post(new ServerInfoEvent(position, true));
if (holder.mMenuLayout.isMenuOpen()) {
holder.mMenuLayout.smoothCloseMenu();
}
});
} }
} }
} }
......
...@@ -5,7 +5,8 @@ import android.graphics.Color; ...@@ -5,7 +5,8 @@ import android.graphics.Color;
import android.view.View; import android.view.View;
import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder; import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -54,15 +55,15 @@ public class TextSelectAdapter<T extends TextSelect> extends BaseQuickAdapter<T, ...@@ -54,15 +55,15 @@ public class TextSelectAdapter<T extends TextSelect> extends BaseQuickAdapter<T,
if (selectList.contains(item)) if (selectList.contains(item))
helper.setBackgroundColor(R.id.ll_layout, YGOUtil.c(R.color.colorMain)); helper.setBackgroundColor(R.id.ll_layout, YGOUtil.c(R.color.colorMain));
else else
helper.setBackgroundRes(R.id.ll_layout, Color.TRANSPARENT); helper.setBackgroundResource(R.id.ll_layout, Color.TRANSPARENT);
} else if (isSelect) { } else if (isSelect) {
if (position == selectPosition) { if (position == selectPosition) {
helper.setBackgroundColor(R.id.ll_layout, YGOUtil.c(R.color.colorMain)); helper.setBackgroundColor(R.id.ll_layout, YGOUtil.c(R.color.colorMain));
} else { } else {
helper.setBackgroundRes(R.id.ll_layout, Color.TRANSPARENT); helper.setBackgroundResource(R.id.ll_layout, Color.TRANSPARENT);
} }
}else { }else {
helper.setBackgroundRes(R.id.ll_layout, Color.TRANSPARENT); helper.setBackgroundResource(R.id.ll_layout, Color.TRANSPARENT);
} }
} }
......
...@@ -176,8 +176,8 @@ public class ServerListManager { ...@@ -176,8 +176,8 @@ public class ServerListManager {
mChanged = true; mChanged = true;
mAdapter.notifyItemMoved(left, right); mAdapter.notifyItemMoved(left, right);
Collections.swap(mAdapter.getItems(), left, right); Collections.swap(mAdapter.getItems(), left, right);
mAdapter.bindMenu((ServerInfoViewHolder) viewHolder, right); // mAdapter.bindMenu((ServerInfoViewHolder) viewHolder, right);
mAdapter.bindMenu((ServerInfoViewHolder) target, left); // mAdapter.bindMenu((ServerInfoViewHolder) target, left);
return true; return true;
} }
return true; return true;
......
...@@ -15,11 +15,13 @@ import android.widget.ImageView; ...@@ -15,11 +15,13 @@ import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemLongClickListener;
import com.feihua.dialogutils.util.DialogUtils; import com.feihua.dialogutils.util.DialogUtils;
import java.io.File; import java.io.File;
...@@ -155,9 +157,9 @@ public class YGODialogUtil { ...@@ -155,9 +157,9 @@ public class YGODialogUtil {
} }
} }
}); });
deckAdp.setOnItemLongClickListener(new BaseQuickAdapter.OnItemLongClickListener() { deckAdp.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override @Override
public boolean onItemLongClick(BaseQuickAdapter adapter, View view, int position) { public boolean onItemLongClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
if (deckAdp.isSelect() || typeAdp.getSelectPosition() == 0) if (deckAdp.isSelect() || typeAdp.getSelectPosition() == 0)
return true; return true;
......
...@@ -76,7 +76,6 @@ public class DuelAssistantManagement implements OnClipChangedListener { ...@@ -76,7 +76,6 @@ public class DuelAssistantManagement implements OnClipChangedListener {
return true; return true;
} }
} }
return true;
} }
//如果是卡组url //如果是卡组url
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment