Commit 5e136e20 authored by wangfugui's avatar wangfugui

修改卡组编辑功能,支持在线卡组

parent 7e3a7f78
package cn.garymb.ygomobile.bean;
public class DeckType extends TextSelect {
public enum ServerType {
LOCAL,
SQUARE,
MY_SQUARE,
}
private String name;
private String path;
private ServerType onServer;//true代表云端卡组,false代表本地卡组
public DeckType(String name, String path) {
this.name = name;
this.path = path;
onServer = ServerType.LOCAL;
super.setName(name);
setObject(this);
}
public DeckType(String name, String path, ServerType onServer) {
this.name = name;
this.path = path;
this.onServer = onServer;
setObject(this);
}
public String getName() {
return name;
}
......@@ -27,4 +42,16 @@ public class DeckType extends TextSelect {
this.path = path;
}
public ServerType getOnServer() {
return onServer;
}
public void setOnServer(ServerType onServer) {
this.onServer = onServer;
}
//true代表卡组位于本地
public boolean isLocal() {
return (this.onServer == ServerType.LOCAL);
}
}
......@@ -2,16 +2,35 @@ package cn.garymb.ygomobile.bean.events;
import java.io.File;
import cn.garymb.ygomobile.bean.DeckType;
import cn.garymb.ygomobile.bean.TextSelect;
import cn.garymb.ygomobile.utils.DeckUtil;
public class DeckFile extends TextSelect {
private final File path;
private final String fullName;
private File path;
private String fileFullName;//本地文件对应的名称,仅在onServer为false时有效
// private final File path;
// private final String fullName;
//分类
private String typeName;
private String typeName;//可取值包括cacheDeck,Pack
private int firstCode;
private DeckType.ServerType onServer;//true代表云端卡组,false代表本地卡组
private String deckId;//如果onServer为true,代表该卡组存储在云上,deckId是唯一id
// public DeckFile(boolean onServer) {
// this.onServer = onServer;
// }
public DeckFile(String name, String typeName, DeckType.ServerType onServer, String deckId) {
this.typeName = typeName;
this.onServer = onServer;
this.deckId = deckId;
this.setName(name);
this.fileFullName = null;
this.path = null;
this.firstCode = -1;
setObject(this);
}
public DeckFile(String path) {
this(new File(path));
......@@ -19,10 +38,10 @@ public class DeckFile extends TextSelect {
public DeckFile(File file) {
path = file;
fullName = file.getName();
String name = fullName;
fileFullName = file.getName();
String name = fileFullName;
int index = name.lastIndexOf(".");
if(index > 0) {
if (index > 0) {
name = name.substring(0, index);
}
typeName = DeckUtil.getDeckTypeName(path.getAbsolutePath());
......@@ -49,7 +68,7 @@ public class DeckFile extends TextSelect {
}
public String getFileName() {
return fullName;
return fileFullName;
}
public File getPathFile() {
......@@ -64,4 +83,26 @@ public class DeckFile extends TextSelect {
return path.lastModified();
}
public DeckType.ServerType getOnServer() {
return onServer;
}
public void setOnServer(DeckType.ServerType onServer) {
this.onServer = onServer;
}
//true代表卡组位于本地
public boolean isLocal() {
return (this.onServer == DeckType.ServerType.LOCAL);
}
public String getDeckId() {
return deckId;
}
public void setDeckId(String deckId) {
this.deckId = deckId;
}
}
......@@ -16,6 +16,7 @@ import cn.garymb.ygomobile.deck_square.api_response.LoginResponse;
import cn.garymb.ygomobile.deck_square.api_response.MyDeckResponse;
import cn.garymb.ygomobile.deck_square.api_response.PushCardJson;
import cn.garymb.ygomobile.deck_square.api_response.PushDeckResponse;
import cn.garymb.ygomobile.deck_square.api_response.SquareDeckResponse;
import cn.garymb.ygomobile.utils.LogUtil;
import cn.garymb.ygomobile.utils.OkhttpUtil;
import cn.garymb.ygomobile.utils.YGOUtil;
......@@ -29,9 +30,25 @@ public class DeckSquareApiUtil {
private static final String TAG = DeckSquareListAdapter.class.getSimpleName();
public static SquareDeckResponse getSquareDecks() throws IOException {
SquareDeckResponse result = null;
String url = "http://rarnu.xyz:38383/api/mdpro3/deck/list";
Map<String, String> headers = new HashMap<>();
headers.put("ReqSource", "MDPro3");
Response response = OkhttpUtil.synchronousGet(url, null, headers);
String responseBodyString = response.body().string();
// Type listType = new TypeToken<List<DeckInfo>>() {
// }.getType();
Gson gson = new Gson();
// Convert JSON to Java object using Gson
result = gson.fromJson(responseBodyString, SquareDeckResponse.class);
return result;
}
/**
* 阻塞方法
* 获取指定用户的卡组列表
* 获取指定用户的卡组列表(只能用于获取登录用户本人的卡组)
*
* @param serverUserId
* @param serverToken
......@@ -221,7 +238,6 @@ public class DeckSquareApiUtil {
}
return result;
}
......
......@@ -6,25 +6,19 @@ import android.widget.ImageView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.google.gson.Gson;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.garymb.ygomobile.deck_square.api_response.ApiDeckRecord;
import cn.garymb.ygomobile.deck_square.api_response.ApiResponse;
import cn.garymb.ygomobile.deck_square.api_response.OnlineDeckDetail;
import cn.garymb.ygomobile.deck_square.api_response.SquareDeckResponse;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.loader.ImageLoader;
import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.ui.plus.VUiKit;
import cn.garymb.ygomobile.utils.LogUtil;
import cn.garymb.ygomobile.utils.OkhttpUtil;
import okhttp3.Response;
//提供recyclerview的数据
public class DeckSquareListAdapter extends BaseQuickAdapter<ApiDeckRecord, BaseViewHolder> {
public class DeckSquareListAdapter extends BaseQuickAdapter<OnlineDeckDetail, BaseViewHolder> {
private static final String TAG = DeckSquareListAdapter.class.getSimpleName();
private ImageLoader imageLoader;
......@@ -37,27 +31,7 @@ public class DeckSquareListAdapter extends BaseQuickAdapter<ApiDeckRecord, BaseV
public void loadData() {
final DialogPlus dialog_read_ex = DialogPlus.show(getContext(), null, getContext().getString(R.string.fetch_ex_card));
VUiKit.defer().when(() -> {
LogUtil.d(TAG, "start fetch");
ApiResponse result = null;
try {
String url = "http://rarnu.xyz:38383/api/mdpro3/deck/list";
Map<String, String> headers = new HashMap<>();
headers.put("ReqSource", "MDPro3");
Response response = OkhttpUtil.synchronousGet(url, null, headers);
String responseBodyString = response.body().string();
// Type listType = new TypeToken<List<DeckInfo>>() {
// }.getType();
Gson gson = new Gson();
// Convert JSON to Java object using Gson
result = gson.fromJson(responseBodyString, ApiResponse.class);
LogUtil.i(TAG, responseBodyString);
int a = 0;
} catch (IOException e) {
Log.e(TAG, "Error occured when fetching data from pre-card server");
return null;
}
SquareDeckResponse result = DeckSquareApiUtil.getSquareDecks();
if (result == null) {
return null;
} else {
......@@ -73,11 +47,11 @@ public class DeckSquareListAdapter extends BaseQuickAdapter<ApiDeckRecord, BaseV
}
}
LogUtil.i(TAG, "webCrawler fail");
LogUtil.i(TAG, "Get square deck fail");
}).done((exCardDataList) -> {
if (exCardDataList != null) {
LogUtil.i(TAG, "webCrawler done");
LogUtil.i(TAG, "Get square deck success");
getData().clear();
addData(exCardDataList);
notifyDataSetChanged();
......@@ -102,7 +76,7 @@ public class DeckSquareListAdapter extends BaseQuickAdapter<ApiDeckRecord, BaseV
}
@Override
protected void convert(BaseViewHolder helper, ApiDeckRecord item) {
protected void convert(BaseViewHolder helper, OnlineDeckDetail item) {
helper.setText(R.id.deck_info_name, item.getDeckName());
helper.setText(R.id.deck_contributor, item.getDeckContributor());
helper.setText(R.id.deck_last_date, item.getLastDate());
......
......@@ -38,7 +38,7 @@ public class DeckListAdapter<T extends TextSelect> extends BaseQuickAdapter<T, D
private OnItemSelectListener onItemSelectListener;
private int selectPosition;
private final boolean isSelect;
private boolean isManySelect;
private boolean isManySelect;//标志位,是否选中多个卡组
private final List<T> selectList;
public DeckListAdapter(Context context, List<T> data, int select) {
......@@ -74,6 +74,19 @@ public class DeckListAdapter<T extends TextSelect> extends BaseQuickAdapter<T, D
int position = holder.getAdapterPosition();
//item是deckFile类型
this.deckFile = (DeckFile) item;
if (!deckFile.isLocal()) {
//卡组位于服务器上
holder.deckId.setVisibility(View.VISIBLE);
holder.deck_info.setVisibility(View.GONE);
holder.deckName.setText(item.getName());
holder.deckId.setText(((DeckFile) item).getDeckId());
} else {
//卡组位于本地
holder.deckId.setVisibility(View.GONE);
holder.deck_info.setVisibility(View.VISIBLE);
holder.deckName.setText(item.getName());
//预读卡组信息
this.deckInfo = DeckLoader.readDeck(mCardLoader, deckFile.getPathFile(), mLimitList);
......@@ -179,6 +192,7 @@ public class DeckListAdapter<T extends TextSelect> extends BaseQuickAdapter<T, D
holder.item_deck_list.setBackgroundResource(Color.TRANSPARENT);
}
}
}
public void setSelectPosition(int selectPosition) {
this.selectPosition = selectPosition;
......@@ -199,6 +213,12 @@ public class DeckListAdapter<T extends TextSelect> extends BaseQuickAdapter<T, D
selectList.add(t);
}
/**
* 内部维护了selectList,用于存储当前选中的卡组
* DeckListAdapter支持多选,传入false清除已选中的卡组,并更新adapter。传入true将标志位置1
*
* @param manySelect
*/
public void setManySelect(boolean manySelect) {
isManySelect = manySelect;
if (!isManySelect) {
......@@ -229,6 +249,7 @@ class DeckViewHolder extends com.chad.library.adapter.base.viewholder.BaseViewHo
ImageView prerelease_star;
ImageView banned_mark;
TextView deckName;
TextView deckId;
TextView main;
TextView extra;
TextView side;
......@@ -242,6 +263,7 @@ class DeckViewHolder extends com.chad.library.adapter.base.viewholder.BaseViewHo
item_deck_list = findView(R.id.item_deck_list);
cardImage = findView(R.id.card_image);
deckName = findView(R.id.deck_name);
deckId = findView(R.id.onlie_deck_id);
main = findView(R.id.count_main);
extra = findView(R.id.count_ex);
side = findView(R.id.count_side);
......
......@@ -37,7 +37,7 @@ public class TextSelectAdapter<T extends TextSelect> extends BaseQuickAdapter<T,
selectPosition = position;
notifyDataSetChanged();
if (onItemSelectListener != null)
onItemSelectListener.onItemSelect(position, data.get(position).getObject());
onItemSelectListener.onItemSelect(position, data.get(position));
}
});
}
......@@ -59,7 +59,7 @@ public class TextSelectAdapter<T extends TextSelect> extends BaseQuickAdapter<T,
} else {
helper.setBackgroundResource(R.id.ll_layout, Color.TRANSPARENT);
}
}else {
} else {
helper.setBackgroundResource(R.id.ll_layout, Color.TRANSPARENT);
}
......
......@@ -76,6 +76,9 @@ import cn.garymb.ygomobile.bean.events.CardInfoEvent;
import cn.garymb.ygomobile.bean.events.DeckFile;
import cn.garymb.ygomobile.core.IrrlichtBridge;
import cn.garymb.ygomobile.deck_square.DeckSquareActivity;
import cn.garymb.ygomobile.deck_square.DeckSquareApiUtil;
import cn.garymb.ygomobile.deck_square.DeckSquareFileUtil;
import cn.garymb.ygomobile.deck_square.api_response.DownloadDeckResponse;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.loader.CardLoader;
import cn.garymb.ygomobile.loader.CardSearchInfo;
......@@ -99,6 +102,7 @@ import cn.garymb.ygomobile.utils.BitmapUtil;
import cn.garymb.ygomobile.utils.DeckUtil;
import cn.garymb.ygomobile.utils.FileUtils;
import cn.garymb.ygomobile.utils.IOUtils;
import cn.garymb.ygomobile.utils.LogUtil;
import cn.garymb.ygomobile.utils.ShareUtil;
import cn.garymb.ygomobile.utils.YGODialogUtil;
import cn.garymb.ygomobile.utils.YGOUtil;
......@@ -207,6 +211,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
mContext = (BaseActivity) getActivity();
}
//通过本文件,外部调用fragment时,如果通过setArguments(mBundle)方法设置了ydk文件路径,则直接打开它
public void preLoadFile() {
String preLoadFile = "";
if (getArguments() != null) {
......@@ -382,6 +387,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
}
}
//region load deck
private void loadDeckFromFile(File file) {
if (!mCardLoader.isOpen() || file == null || !file.exists()) {
......@@ -397,7 +403,8 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
}
}).done((rs) -> {
dlg.dismiss();
setCurDeck(rs, file.getParent().equals(mSettings.getPackDeckDir()) || file.getParent().equals(mSettings.getCacheDeckDir()));
//setCurDeck(rs, file.getParent().equals(mSettings.getPackDeckDir()) || file.getParent().equals(mSettings.getCacheDeckDir()));
setCurDeck(rs, file.getParent().equals(mSettings.getPackDeckDir()));
});
}
......@@ -445,7 +452,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
}
/**
* 设置当前卡组
* 用户选中某个卡组后,更新当前界面,显示已选中的卡组。包括更新界面显示(tv_deck)、更新AppsSettings、通知DeckAdapter
*/
private void setCurDeck(DeckInfo deckInfo, boolean isPack) {
if (deckInfo == null) {
......@@ -1231,8 +1238,43 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
@Override
public void onDeckSelect(DeckFile deckFile) {
if (!deckFile.isLocal()) {//不在本地,在云上(卡组广场中或用户的云上)
VUiKit.defer().when(() -> {
DownloadDeckResponse response = DeckSquareApiUtil.getDeckById(deckFile.getDeckId());
if (response != null) {
return response.getData();
} else {
return null;
}
}).fail((e) -> {
LogUtil.i(TAG, "square deck detail fail" + e.getMessage());
}).done((deckData) -> {
if (deckData != null) {
deckData.getDeckYdk();
String fileFullName = deckData.getDeckName() + ".ydk";
String path = AppsSettings.get().getCacheDeckDir();
File dir = new File(getActivity().getApplicationInfo().dataDir, "cache");
boolean result = DeckSquareFileUtil.saveFileToPath(dir.getPath(), fileFullName, deckData.getDeckYdk());
if (result) {
LogUtil.i(TAG, "square deck detail done");
File file = new File(dir, fileFullName);
loadDeckFromFile(file);
}
}
});
} else {
loadDeckFromFile(deckFile.getPathFile());
}
}
@Override
public void onDeckDel(List<DeckFile> deckFileList) {
......
......@@ -68,11 +68,19 @@ public class DeckUtil {
}
};
/**
* 生成卡组类型的list
*
* @param context
* @return
*/
public static List<DeckType> getDeckTypeList(Context context) {
List<DeckType> deckTypeList = new ArrayList<>();
deckTypeList.add(new DeckType(YGOUtil.s(R.string.category_pack), AppsSettings.get().getPackDeckDir()));
deckTypeList.add(new DeckType(YGOUtil.s(R.string.category_windbot_deck), AppsSettings.get().getAiDeckDir()));
deckTypeList.add(new DeckType(YGOUtil.s(R.string.category_Uncategorized), AppsSettings.get().getDeckDir()));
deckTypeList.add(new DeckType(YGOUtil.s(R.string.category_pack), AppsSettings.get().getPackDeckDir(), DeckType.ServerType.LOCAL));
deckTypeList.add(new DeckType(YGOUtil.s(R.string.category_windbot_deck), AppsSettings.get().getAiDeckDir(), DeckType.ServerType.LOCAL));
deckTypeList.add(new DeckType(YGOUtil.s(R.string.category_Uncategorized), AppsSettings.get().getDeckDir(), DeckType.ServerType.LOCAL));
deckTypeList.add(new DeckType(YGOUtil.s(R.string.category_online_deck), "", DeckType.ServerType.SQUARE));
deckTypeList.add(new DeckType(YGOUtil.s(R.string.category_my_online_deck), "", DeckType.ServerType.MY_SQUARE));
File[] files = new File(AppsSettings.get().getDeckDir()).listFiles();
if (files != null) {
......@@ -138,6 +146,7 @@ public class DeckUtil {
/**
* 根据卡组绝对路径获取卡组分类名称
*
* @param deckPath
* @return
*/
......@@ -149,7 +158,7 @@ public class DeckUtil {
if (name.equals("pack") || name.equals("cacheDeck")) {
//卡包
return YGOUtil.s(R.string.category_pack);
} else if (name.equals("Decks")&&lastName.equals(Constants.WINDBOT_PATH)) {
} else if (name.equals("Decks") && lastName.equals(Constants.WINDBOT_PATH)) {
//ai卡组
return YGOUtil.s(R.string.category_windbot_deck);
} else if (name.equals("deck") && lastName.equals(Constants.PREF_DEF_GAME_DIR)) {
......@@ -162,6 +171,7 @@ public class DeckUtil {
return null;
}
//获取扩展卡的列表
public static List<DeckFile> getExpansionsDeckList() throws IOException {
AppsSettings appsSettings = AppsSettings.get();
List<DeckFile> deckList = new ArrayList<>();
......
......@@ -37,17 +37,63 @@ import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.bean.DeckType;
import cn.garymb.ygomobile.bean.events.DeckFile;
import cn.garymb.ygomobile.deck_square.DeckSquareApiUtil;
import cn.garymb.ygomobile.deck_square.api_response.MyDeckResponse;
import cn.garymb.ygomobile.deck_square.api_response.MyOnlineDeckDetail;
import cn.garymb.ygomobile.deck_square.api_response.OnlineDeckDetail;
import cn.garymb.ygomobile.deck_square.api_response.SquareDeckResponse;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.adapters.DeckListAdapter;
import cn.garymb.ygomobile.ui.adapters.SimpleListAdapter;
import cn.garymb.ygomobile.ui.adapters.TextSelectAdapter;
import cn.garymb.ygomobile.ui.mycard.mcchat.util.ImageUtil;
import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.ui.plus.VUiKit;
import cn.garymb.ygomobile.utils.recyclerview.DeckTypeTouchHelperCallback;
public class YGODialogUtil {
/* public enum DeckTypeEnum {
CARD_PACK(0, "PACK"),
WINDBOT(1, "WINDBOT"),
Uncategorized(2, "Uncategorized"),
ONLINE(3, "Online");
private final int code;
private final String description;
// Constructor
DeckTypeEnum(int code, String description) {
this.code = code;
this.description = description;
}
// Getter methods
public int getCode() {
return code;
}
public String getDescription() {
return description;
}
// Lookup by code
public static DeckTypeEnum fromCode(int code) {
for (DeckTypeEnum status : DeckTypeEnum.values()) {
if (status.code == code) {
return status;
}
}
throw new IllegalArgumentException("No DeckTypeEnum found for code: " + code);
}
}
*/
private static final String TAG = "YGODialogUtil";
/**
* @param context
* @param selectDeckPath 卡组路径。由调用方传入,本dialog根据selectDeckPath的值来确定“默认选中的卡组分类”。
* @param onDeckMenuListener
*/
public static void dialogDeckSelect(Context context, String selectDeckPath, OnDeckMenuListener onDeckMenuListener) {
ViewHolder viewHolder = new ViewHolder(context, selectDeckPath, onDeckMenuListener);
viewHolder.show();
......@@ -71,6 +117,9 @@ public class YGODialogUtil {
void onDeckTypeListener(int position);
}
/**
* 封装DialogPlus,在本类中调用DialogPlus.setContentView()
*/
private static class ViewHolder {
private final int IMAGE_MOVE = 0;
......@@ -89,15 +138,20 @@ public class YGODialogUtil {
private final TextView tv_move;
private final TextView tv_copy;
private final TextView tv_del;
private final TextSelectAdapter<DeckType> typeAdp;
private final DeckListAdapter<DeckFile> deckAdp;
private final TextSelectAdapter<DeckType> typeAdp;//卡组dialog中,左列的adapter
private final DeckListAdapter<DeckFile> deckAdp;//卡组dialog中,右列的adapter
private final DeckListAdapter<DeckFile> resultListAdapter;
private final List<DeckFile> allDeckList;
private final List<DeckFile> allDeckList;//存储所有卡组DeckFile,用于支持“根据关键词搜索卡组”功能
private final RecyclerView rv_type, rv_deck, rv_result_list;
private final List<DeckFile> resultList;
private final List<DeckFile> resultList;//存储卡组“根据关键词搜索”的结果
private final DialogPlus ygoDialog;
/**
* @param context
* @param selectDeckPath 外部传入当前选中的卡组路径
* @param onDeckMenuListener
*/
public ViewHolder(Context context, String selectDeckPath, OnDeckMenuListener onDeckMenuListener) {
ygoDialog = new DialogPlus(context);
ygoDialog.setContentView(R.layout.dialog_deck_select);
......@@ -131,9 +185,10 @@ public class YGODialogUtil {
List<DeckType> typeList = DeckUtil.getDeckTypeList(context);
int typeSelectPosition = 2;
int typeSelectPosition = 2;//卡组分类选择,默认值为2(未分类卡组)。0代表“卡包展示”,1代表“人机卡组”
int deckSelectPosition = -1;
List<DeckFile> deckList;
List<DeckFile> deckList; //存储当前卡组分类下的所有卡组
//根据卡组路径得到该卡组所属分类
if (!TextUtils.isEmpty(selectDeckPath)) {
File file = new File(selectDeckPath);
if (file.exists()) {
......@@ -147,6 +202,7 @@ public class YGODialogUtil {
typeSelectPosition = 1;
} else if (cateName.equals("deck") && parentName.equals(Constants.PREF_DEF_GAME_DIR)) {
//如果是deck并且上一个目录是ygocore的话,保证不会把名字为deck的卡包识别为未分类
typeSelectPosition = 2;
} else {
//其他卡包
for (int i = 3; i < typeList.size(); i++) {
......@@ -159,11 +215,14 @@ public class YGODialogUtil {
}
}
}
//根据卡组分类查出属于该分类下的所有卡组
deckList = DeckUtil.getDeckList(typeList.get(typeSelectPosition).getPath());
for (int i = 0; i < typeList.size(); i++) {
if (typeList.get(i).isLocal()) {
allDeckList.addAll(DeckUtil.getDeckList(typeList.get(i).getPath()));//把所有分类里的卡组全部纳入,用于关键词查询目标
}//在线卡组对应的项的path是空字符串
}
if (typeSelectPosition == 0) {
if (typeSelectPosition == 0) {//如果选中卡包,判断是否开启了先行卡,是的话加载先行卡
if (AppsSettings.get().isReadExpansions()) {
try {
deckList.addAll(0, DeckUtil.getExpansionsDeckList());//置顶ypk缓存的cacheDeck下的先行卡ydk
......@@ -181,6 +240,57 @@ public class YGODialogUtil {
public void onItemSelect(int position, DeckType item) {
clearDeckSelect();
deckList.clear();
if (item.getOnServer() == DeckType.ServerType.SQUARE) {
VUiKit.defer().when(() -> {
SquareDeckResponse result = DeckSquareApiUtil.getSquareDecks();
if (result == null) {
return null;
} else {
return result.getData().getRecords();
}
}).fail(e -> {
YGOUtil.showTextToast("Fetch square deck fail");
}).done(exCardDataList -> {
if (exCardDataList != null) {
LogUtil.i(TAG, "Get square deck success");
for (OnlineDeckDetail deckRecord : exCardDataList) {
DeckFile deckFile = new DeckFile(deckRecord.getDeckName(), "", DeckType.ServerType.SQUARE, deckRecord.getDeckId());
deckList.add(deckFile);
}
deckAdp.notifyDataSetChanged();
}
});
} else if (item.getOnServer() == DeckType.ServerType.MY_SQUARE) {
VUiKit.defer().when(() -> {
String serverToken = SharedPreferenceUtil.getServerToken();
Integer serverUserId = SharedPreferenceUtil.getServerUserId();
MyDeckResponse result = DeckSquareApiUtil.getUserDecks(serverUserId, serverToken);
if (result == null) {
return null;
} else {
return result.getData();
}
}).fail(e -> {
YGOUtil.showTextToast("Fetch square deck fail");
}).done(exCardDataList -> {
if (exCardDataList != null) {
LogUtil.i(TAG, "Get square deck success");
for (MyOnlineDeckDetail deckRecord : exCardDataList) {
DeckFile deckFile = new DeckFile(deckRecord.getDeckName(), "", DeckType.ServerType.MY_SQUARE, deckRecord.getDeckId());
deckList.add(deckFile);
}
deckAdp.notifyDataSetChanged();
}
});
} else {
deckList.addAll(DeckUtil.getDeckList(item.getPath()));
if (position == 0) {
if (AppsSettings.get().isReadExpansions()) {
......@@ -195,6 +305,7 @@ public class YGODialogUtil {
}
deckAdp.notifyDataSetChanged();
}
}
});
deckAdp.setOnItemSelectListener(new DeckListAdapter.OnItemSelectListener<DeckFile>() {
@Override
......@@ -503,6 +614,9 @@ public class YGODialogUtil {
}
}
/**
* 根据et_input_deck_name的当前值,在allDeckList中搜索卡组
*/
private void searchDeck() {
resultList.clear();
et_input_deck_name.clearFocus();
......@@ -526,6 +640,13 @@ public class YGODialogUtil {
return types;
}
/**
* 从deckList中检索包含keyword的卡组
*
* @param keyword
* @param deckList
* @return
*/
private List<DeckFile> getResultList(String keyword, List<DeckFile> deckList) {
List<DeckFile> resultList = new ArrayList<>();
for (int i = 0; i < deckList.size(); i++) {
......@@ -557,6 +678,7 @@ public class YGODialogUtil {
return moveTypeList;
}
//将界面上的iv_move、iv_del、iv_copy等图标颜色恢复,启用其点击事件
private void showAllDeckUtil() {
ImageUtil.reImageColor(IMAGE_MOVE, iv_move);//可用时用原图标色
ImageUtil.reImageColor(IMAGE_DEL, iv_del);
......@@ -569,6 +691,7 @@ public class YGODialogUtil {
ll_move.setEnabled(true);
}
//将界面上的iv_move、iv_del、iv_copy等图标颜色改为灰色,禁用其点击事件
private void hideAllDeckUtil() {
ImageUtil.setGrayImage(IMAGE_MOVE, iv_move);
ImageUtil.setGrayImage(IMAGE_DEL, iv_del);
......@@ -581,6 +704,7 @@ public class YGODialogUtil {
ll_move.setEnabled(false);
}
//将界面上的iv_copy图标颜色恢复,启用其点击事件
private void showCopyDeckUtil() {
ImageUtil.setGrayImage(IMAGE_MOVE, iv_move);
ImageUtil.setGrayImage(IMAGE_DEL, iv_del);
......@@ -593,6 +717,7 @@ public class YGODialogUtil {
ll_move.setEnabled(false);
}
//清除选中卡组的记录,隐藏对卡组进行复制、移动、删除的控件
private void clearDeckSelect() {
deckAdp.setManySelect(false);
hideAllDeckUtil();
......
......@@ -34,12 +34,19 @@
<cn.garymb.ygomobile.ui.widget.AlwaysMarqueeTextView
android:id="@+id/deck_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:maxLines="1"
android:singleLine="true"
android:textColor="@color/white"
tools:text="Deck Name" />
<TextView
android:id="@+id/onlie_deck_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/holo_blue_bright"
android:textSize="10sp"
tools:text="40" />
<LinearLayout
android:id="@+id/deck_info"
......@@ -53,16 +60,16 @@
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginRight="5dp"
android:visibility="visible"
android:background="@drawable/ic_expansions"/>
android:background="@drawable/ic_expansions"
android:visibility="visible" />
<ImageView
android:id="@+id/banned_mark"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginRight="@dimen/dp_10"
android:visibility="visible"
android:background="@drawable/ic_banned"/>
android:background="@drawable/ic_banned"
android:visibility="visible" />
<TextView
android:id="@+id/count_main"
......@@ -71,6 +78,7 @@
android:textColor="@color/holo_blue_bright"
android:textSize="10sp"
tools:text="40" />
<LinearLayout
android:id="@+id/ll_extra_n_side"
android:layout_width="match_parent"
......
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