Commit 70fb40fa authored by fallenstardust's avatar fallenstardust

添加undo与redo功能

对挪动,删除,添加都存一份历史deckinfo数组
parent 94c7fd18
...@@ -20,9 +20,9 @@ public class DeckInfo { ...@@ -20,9 +20,9 @@ public class DeckInfo {
Side, Side,
} }
private final List<Card> mainCards; public List<Card> mainCards;
private final List<Card> extraCards; public List<Card> extraCards;
private final List<Card> sideCards; public List<Card> sideCards;
private final List<Card> allCards; private final List<Card> allCards;
public File source;//当前打开的ydk文件的file public File source;//当前打开的ydk文件的file
......
...@@ -4,7 +4,6 @@ import static android.content.Context.CLIPBOARD_SERVICE; ...@@ -4,7 +4,6 @@ import static android.content.Context.CLIPBOARD_SERVICE;
import static cn.garymb.ygomobile.Constants.ORI_DECK; import static cn.garymb.ygomobile.Constants.ORI_DECK;
import static cn.garymb.ygomobile.Constants.YDK_FILE_EX; import static cn.garymb.ygomobile.Constants.YDK_FILE_EX;
import static cn.garymb.ygomobile.core.IrrlichtBridge.ACTION_SHARE_FILE; import static cn.garymb.ygomobile.core.IrrlichtBridge.ACTION_SHARE_FILE;
import static cn.garymb.ygomobile.ui.cards.deck_square.DeckSquareFileUtil.convertToUnixTimestamp;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
...@@ -33,6 +32,7 @@ import android.view.animation.AnimationUtils; ...@@ -33,6 +32,7 @@ import android.view.animation.AnimationUtils;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.Spinner; import android.widget.Spinner;
...@@ -127,6 +127,9 @@ import ocgcore.enums.LimitType; ...@@ -127,6 +127,9 @@ import ocgcore.enums.LimitType;
*/ */
public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewItemListener.OnItemListener, OnItemDragListener, YGODeckDialogUtil.OnDeckMenuListener, CardLoader.CallBack, CardSearcher.CallBack { public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewItemListener.OnItemListener, OnItemDragListener, YGODeckDialogUtil.OnDeckMenuListener, CardLoader.CallBack, CardSearcher.CallBack {
private static final String TAG = "DeckManagerFragment"; private static final String TAG = "DeckManagerFragment";
public static List<MyOnlineDeckDetail> originalData; // 保存原始数据
private final AppsSettings mSettings = AppsSettings.get();
public DeckAdapater mDeckAdapater;
protected DrawerLayout mDrawerLayout; protected DrawerLayout mDrawerLayout;
protected RecyclerView mListView; protected RecyclerView mListView;
protected CardLoader mCardLoader; protected CardLoader mCardLoader;
...@@ -135,19 +138,19 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -135,19 +138,19 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
protected PackManager mPackManager; protected PackManager mPackManager;
protected CardListAdapter mCardListAdapter; protected CardListAdapter mCardListAdapter;
protected boolean isLoad = false; protected boolean isLoad = false;
protected int screenWidth;
long exitLasttime = 0;
private HomeActivity activity; private HomeActivity activity;
private String mDeckId; private String mDeckId;
private LinearLayout ll_click_like; private LinearLayout ll_click_like;
private TextView tv_add_1; private TextView tv_add_1;
public static List<MyOnlineDeckDetail> originalData; // 保存原始数据
protected int screenWidth;
//region ui onCreate/onDestroy //region ui onCreate/onDestroy
private RecyclerView mRecyclerView; private RecyclerView mRecyclerView;
public DeckAdapater mDeckAdapater;
private final AppsSettings mSettings = AppsSettings.get();
private BaseActivity mContext; private BaseActivity mContext;
long exitLasttime = 0; // 历史记录列表,用于存储卡组状态
private List<DeckInfo> deckHistory = new ArrayList<>();
// 当前历史记录索引
private int historyIndex = -1;
private File mPreLoadFile;//预加载卡组,用于外部打开ydk文件或通过卡组广场预览卡组时,值为file。当未通过预加载打开ydk(打开卡组时),值为null private File mPreLoadFile;//预加载卡组,用于外部打开ydk文件或通过卡组广场预览卡组时,值为file。当未通过预加载打开ydk(打开卡组时),值为null
private DeckItemTouchHelper mDeckItemTouchHelper; private DeckItemTouchHelper mDeckItemTouchHelper;
...@@ -158,13 +161,21 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -158,13 +161,21 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
private DialogPlus mDialog; private DialogPlus mDialog;
private DialogPlus builderShareLoading; private DialogPlus builderShareLoading;
private ImageButton btnUndo;
private ImageButton btnRedo;
private View layoutView; private View layoutView;
public static List<MyOnlineDeckDetail> getOriginalData() {
return originalData;
}
/** /**
* 创建并返回Fragment的视图层次结构 * 创建并返回Fragment的视图层次结构
* *
* @param inflater 用于将XML布局文件转换为View对象的LayoutInflater实例,不可为空 * @param inflater 用于将XML布局文件转换为View对象的LayoutInflater实例,不可为空
* @param container 父容器ViewGroup,可为空 * @param container 父容器ViewGroup,可为空
* @param savedInstanceState 保存Fragment状态的Bundle对象,可为空 * @param savedInstanceState 保存Fragment状态的Bundle对象,可为空
* @return 返回创建的View对象,如果创建失败则返回null * @return 返回创建的View对象,如果创建失败则返回null
*/ */
...@@ -295,6 +306,16 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -295,6 +306,16 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
getActivity().getSupportFragmentManager(), "pagerDialog"); getActivity().getSupportFragmentManager(), "pagerDialog");
}); });
// 初始化撤销/重做按钮
btnUndo = layoutView.findViewById(R.id.btn_undo);
btnRedo = layoutView.findViewById(R.id.btn_redo);
btnUndo.setOnClickListener(v -> undo());
btnRedo.setOnClickListener(v -> redo());
// 初始化按钮状态
updateUndoRedoButtons();
mContext = (BaseActivity) getActivity(); mContext = (BaseActivity) getActivity();
/** /**
...@@ -367,7 +388,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -367,7 +388,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
/** /**
* 设置列表项点击监听器和滚动监听器 * 设置列表项点击监听器和滚动监听器
* * <p>
* 该方法主要完成以下功能: * 该方法主要完成以下功能:
* 1. 为卡片列表适配器设置点击和长按事件监听器 * 1. 为卡片列表适配器设置点击和长按事件监听器
* 2. 为列表视图添加滚动监听器,用于控制图片加载框架的暂停和恢复 * 2. 为列表视图添加滚动监听器,用于控制图片加载框架的暂停和恢复
...@@ -452,12 +473,6 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -452,12 +473,6 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
} }
/**
* 处理卡组中卡片的长按删除操作
* 当用户长按卡片时,根据设置决定是否显示删除确认对话框或直接删除
*
* @param pos 被长按的卡片在列表中的位置索引
*/
@Override @Override
public void onDragLongPress(int pos) { public void onDragLongPress(int pos) {
// 检查位置索引有效性 // 检查位置索引有效性
...@@ -481,6 +496,8 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -481,6 +496,8 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
dialogPlus.setLeftButtonListener((dlg, v) -> { dialogPlus.setLeftButtonListener((dlg, v) -> {
dlg.dismiss(); dlg.dismiss();
mDeckItemTouchHelper.remove(pos); mDeckItemTouchHelper.remove(pos);
// 添加到历史记录
addDeckToHistory(mDeckAdapater.getCurrentState());
}); });
dialogPlus.show(); dialogPlus.show();
} else { } else {
...@@ -493,7 +510,6 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -493,7 +510,6 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
public void onDragLongPressEnd() { public void onDragLongPressEnd() {
mDeckAdapater.hideHeadView(); mDeckAdapater.hideHeadView();
} }
//endregion
public void AnimationShake2(View view) { public void AnimationShake2(View view) {
Animation shake = AnimationUtils.loadAnimation(getContext(), R.anim.shake);//加载动画资源文件 Animation shake = AnimationUtils.loadAnimation(getContext(), R.anim.shake);//加载动画资源文件
...@@ -502,7 +518,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -502,7 +518,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
/** /**
* 隐藏所有打开的抽屉菜单 * 隐藏所有打开的抽屉菜单
* * <p>
* 该方法会检查左右两侧的抽屉是否处于打开状态,如果打开则将其关闭。 * 该方法会检查左右两侧的抽屉是否处于打开状态,如果打开则将其关闭。
* 主要用于在特定场景下统一关闭所有抽屉菜单,确保界面的一致性。 * 主要用于在特定场景下统一关闭所有抽屉菜单,确保界面的一致性。
*/ */
...@@ -528,6 +544,8 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -528,6 +544,8 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
} }
} }
//region load deck
protected void showResult(boolean autoClose) { protected void showResult(boolean autoClose) {
if (mDrawerLayout.isDrawerOpen(Constants.CARD_SEARCH_GRAVITY)) { if (mDrawerLayout.isDrawerOpen(Constants.CARD_SEARCH_GRAVITY)) {
mDrawerLayout.closeDrawer(Constants.CARD_SEARCH_GRAVITY); mDrawerLayout.closeDrawer(Constants.CARD_SEARCH_GRAVITY);
...@@ -540,7 +558,8 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -540,7 +558,8 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
} }
} }
//region load deck //region init
/** /**
* 从指定文件中加载卡牌包数据 * 从指定文件中加载卡牌包数据
* *
...@@ -572,7 +591,6 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -572,7 +591,6 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
}); });
} }
//region init
/** /**
* 初始化函数,用于加载卡组数据和相关配置 * 初始化函数,用于加载卡组数据和相关配置
* *
...@@ -635,8 +653,9 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -635,8 +653,9 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
/** /**
* 设置当前选中的卡组并更新界面显示 * 设置当前选中的卡组并更新界面显示
*
* @param deckInfo 选中的卡组信息,如果为null则创建新的空卡组信息对象 * @param deckInfo 选中的卡组信息,如果为null则创建新的空卡组信息对象
* @param isPack 是否为卡包模式 * @param isPack 是否为卡包模式
*/ */
private void setCurDeck(DeckInfo deckInfo, boolean isPack) { private void setCurDeck(DeckInfo deckInfo, boolean isPack) {
// 处理空卡组信息情况 // 处理空卡组信息情况
...@@ -653,8 +672,118 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -653,8 +672,118 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
// 通知适配器更新卡组数据和界面 // 通知适配器更新卡组数据和界面
mDeckAdapater.setDeck(deckInfo, isPack); mDeckAdapater.setDeck(deckInfo, isPack);
mDeckAdapater.notifyDataSetChanged(); mDeckAdapater.notifyDataSetChanged();
// 清空历史记录并添加初始状态
clearDeckHistory();
addDeckToHistory(deckInfo);
// 更新按钮状态
updateUndoRedoButtons();
}
/**
* 清空卡组历史记录
*/
private void clearDeckHistory() {
deckHistory.clear();
historyIndex = -1;
}
/**
* 将当前卡组状态添加到历史记录中
*
* @param deckInfo 当前卡组状态
*/
private void addDeckToHistory(DeckInfo deckInfo) {
// 如果当前不在历史记录的最新位置,需要删除之后的历史记录
if (historyIndex < deckHistory.size() - 1) {
deckHistory.subList(historyIndex + 1, deckHistory.size()).clear();
}
// 添加新的历史记录
deckHistory.add(deckInfo); // 使用clone确保是深拷贝
historyIndex = deckHistory.size() - 1;
// 更新按钮状态
updateUndoRedoButtons();
} }
/**
* 撤销操作
*/
private void undo() {
if (canUndo()) {
historyIndex--;
DeckInfo previousState = deckHistory.get(historyIndex);
mDeckAdapater.setDeck(previousState, false);
mDeckAdapater.notifyDataSetChanged();
// 更新按钮状态
updateUndoRedoButtons();
}
}
/**
* 重做操作
*/
private void redo() {
if (canRedo()) {
historyIndex++;
DeckInfo nextState = deckHistory.get(historyIndex);
mDeckAdapater.setDeck(nextState, false);
mDeckAdapater.notifyDataSetChanged();
// 更新按钮状态
updateUndoRedoButtons();
}
}
/**
* 检查是否可以撤销
*
* @return 如果可以撤销返回true,否则返回false
*/
private boolean canUndo() {
return historyIndex > 0;
}
/**
* 检查是否可以重做
*
* @return 如果可以重做返回true,否则返回false
*/
private boolean canRedo() {
return historyIndex < deckHistory.size() - 1;
}
/**
* 更新撤销/重做按钮的状态和可见性
*/
private void updateUndoRedoButtons() {
if (btnUndo != null && btnRedo != null) {
// 只有历史记录大于1时才显示按钮
if (deckHistory.size() > 1) {
btnUndo.setVisibility(View.VISIBLE);
btnRedo.setVisibility(View.VISIBLE);
// 根据是否可以撤销/重做来启用/禁用按钮
btnUndo.setEnabled(canUndo());
btnRedo.setEnabled(canRedo());
// 当无法撤销或重做时隐藏对应按钮
if (!canUndo()) {
btnUndo.setVisibility(View.GONE);
}
if (!canRedo()) {
btnRedo.setVisibility(View.GONE);
}
} else {
// 历史记录小于等于1时隐藏按钮
btnUndo.setVisibility(View.GONE);
btnRedo.setVisibility(View.GONE);
}
}
}
/** /**
* 判断指定文件是否位于卡牌目录中 * 判断指定文件是否位于卡牌目录中
* *
...@@ -755,12 +884,12 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -755,12 +884,12 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
return mDialog != null && mDialog.isShowing(); return mDialog != null && mDialog.isShowing();
} }
/** /**
* 显示卡片详情对话框 * 显示卡片详情对话框
* *
* @param provider 卡片列表提供者,用于获取当前卡片的上下文数据 * @param provider 卡片列表提供者,用于获取当前卡片的上下文数据
* @param cardInfo 要显示的卡片信息,如果为null则不执行任何操作 * @param cardInfo 要显示的卡片信息,如果为null则不执行任何操作
* @param pos 当前卡片在列表中的位置 * @param pos 当前卡片在列表中的位置
*/ */
protected void showCardDialog(CardListProvider provider, Card cardInfo, int pos) { protected void showCardDialog(CardListProvider provider, Card cardInfo, int pos) {
// 如果卡片信息为空,则不进行任何操作 // 如果卡片信息为空,则不进行任何操作
...@@ -855,7 +984,6 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -855,7 +984,6 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
} }
} }
private void showSearchKeyWord(String keyword) {//使用此方法,可以适用关键词查询逻辑,让完全符合关键词的卡名置顶显示,并同时搜索字段和效果文本 private void showSearchKeyWord(String keyword) {//使用此方法,可以适用关键词查询逻辑,让完全符合关键词的卡名置顶显示,并同时搜索字段和效果文本
CardSearchInfo searchInfo = new CardSearchInfo.Builder().keyword(keyword).types(new long[]{}).build();//构建CardSearchInfo时type不能为null CardSearchInfo searchInfo = new CardSearchInfo.Builder().keyword(keyword).types(new long[]{}).build();//构建CardSearchInfo时type不能为null
mCardLoader.search(searchInfo); mCardLoader.search(searchInfo);
...@@ -869,11 +997,21 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -869,11 +997,21 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
} }
} }
/**
* 添加到副卡组
*
* @param cardInfo 要添加的卡片信息
* @return 添加成功返回true,添加失败返回false
*/
private boolean addSideCard(Card cardInfo) { private boolean addSideCard(Card cardInfo) {
// 检查卡片添加限制
if (checkLimit(cardInfo)) { if (checkLimit(cardInfo)) {
// 执行添加卡片操作
boolean rs = mDeckAdapater.AddCard(cardInfo, DeckItemType.SideCard); boolean rs = mDeckAdapater.AddCard(cardInfo, DeckItemType.SideCard);
if (rs) { if (rs) {
YGOUtil.showTextToast(R.string.add_card_tip_ok); YGOUtil.showTextToast(R.string.add_card_tip_ok);
// 添加到历史记录
addDeckToHistory(mDeckAdapater.getCurrentState());
} else { } else {
YGOUtil.showTextToast(R.string.add_card_tip_fail); YGOUtil.showTextToast(R.string.add_card_tip_fail);
} }
...@@ -882,16 +1020,27 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -882,16 +1020,27 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
return false; return false;
} }
/**
* 添加主卡组卡片
*
* @param cardInfo 要添加的卡片信息
* @return 添加成功返回true,否则返回false
*/
private boolean addMainCard(Card cardInfo) { private boolean addMainCard(Card cardInfo) {
// 检查卡片添加限制
if (checkLimit(cardInfo)) { if (checkLimit(cardInfo)) {
boolean rs; boolean rs;
// 根据卡片类型选择添加位置
if (cardInfo.isExtraCard()) { if (cardInfo.isExtraCard()) {
rs = mDeckAdapater.AddCard(cardInfo, DeckItemType.ExtraCard); rs = mDeckAdapater.AddCard(cardInfo, DeckItemType.ExtraCard);
} else { } else {
rs = mDeckAdapater.AddCard(cardInfo, DeckItemType.MainCard); rs = mDeckAdapater.AddCard(cardInfo, DeckItemType.MainCard);
} }
// 处理添加结果
if (rs) { if (rs) {
YGOUtil.showTextToast(R.string.add_card_tip_ok); YGOUtil.showTextToast(R.string.add_card_tip_ok);
// 添加到历史记录
addDeckToHistory(mDeckAdapater.getCurrentState());
} else { } else {
YGOUtil.showTextToast(R.string.add_card_tip_fail); YGOUtil.showTextToast(R.string.add_card_tip_fail);
} }
...@@ -1116,6 +1265,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -1116,6 +1265,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
/** /**
* 创建新的卡组文件 * 创建新的卡组文件
*
* @param savePath 新卡组文件的保存路径 * @param savePath 新卡组文件的保存路径
*/ */
private void createDeck(String savePath) { private void createDeck(String savePath) {
...@@ -1260,7 +1410,6 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -1260,7 +1410,6 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
// shareUrl(uriString, label); // shareUrl(uriString, label);
} }
private void shareUrl(String uri, String label) { private void shareUrl(String uri, String label) {
String url = getString(R.string.deck_share_head) + " " + uri; String url = getString(R.string.deck_share_head) + " " + uri;
ShareUtil.shareText(getContext(), getString(R.string.share_deck), url, null); ShareUtil.shareText(getContext(), getString(R.string.share_deck), url, null);
...@@ -1283,6 +1432,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -1283,6 +1432,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
/** /**
* 从存储卡组的文件夹中获取所有名字以.ydk结尾的文件,并将mPreLoadFile也加入到返回结果中 * 从存储卡组的文件夹中获取所有名字以.ydk结尾的文件,并将mPreLoadFile也加入到返回结果中
*
* @return 包含所有.ydk文件的文件列表,如果目录不存在或无法访问则返回null * @return 包含所有.ydk文件的文件列表,如果目录不存在或无法访问则返回null
*/ */
private List<File> getYdkFiles() { private List<File> getYdkFiles() {
...@@ -1311,8 +1461,9 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -1311,8 +1461,9 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
/** /**
* 初始化限制列表下拉框 * 初始化限制列表下拉框
*
* @param spinner 要初始化的Spinner控件 * @param spinner 要初始化的Spinner控件
* @param cur 当前选中的限制列表对象,用于设置默认选中项 * @param cur 当前选中的限制列表对象,用于设置默认选中项
*/ */
private void initLimitListSpinners(Spinner spinner, LimitList cur) { private void initLimitListSpinners(Spinner spinner, LimitList cur) {
List<SimpleSpinnerItem> items = new ArrayList<>(); List<SimpleSpinnerItem> items = new ArrayList<>();
...@@ -1360,6 +1511,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -1360,6 +1511,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
/** /**
* 设置限制列表并更新相关适配器 * 设置限制列表并更新相关适配器
*
* @param limitList 限制列表对象,如果为null则直接返回 * @param limitList 限制列表对象,如果为null则直接返回
*/ */
private void setLimitList(LimitList limitList) { private void setLimitList(LimitList limitList) {
...@@ -1444,7 +1596,6 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -1444,7 +1596,6 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
} }
} }
private void initBoomMenuButton(BoomMenuButton menu) { private void initBoomMenuButton(BoomMenuButton menu) {
final SparseArray<Integer> mMenuIds = new SparseArray<>(); final SparseArray<Integer> mMenuIds = new SparseArray<>();
addMenuButton(mMenuIds, menu, R.id.action_share_deck, R.string.share_deck, R.drawable.shareicon); addMenuButton(mMenuIds, menu, R.id.action_share_deck, R.string.share_deck, R.drawable.shareicon);
...@@ -1511,10 +1662,6 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -1511,10 +1662,6 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
YGOUtil.showTextToast(R.string.done); YGOUtil.showTextToast(R.string.done);
} }
public static List<MyOnlineDeckDetail> getOriginalData() {
return originalData;
}
//在卡组选择的dialog中点击某个卡组(来自本地或服务器)后,dialog通过本回调函数通知本页面。 //在卡组选择的dialog中点击某个卡组(来自本地或服务器)后,dialog通过本回调函数通知本页面。
//在本页面中根据卡组来源(本地或服务器)显示卡组内容 //在本页面中根据卡组来源(本地或服务器)显示卡组内容
@Override @Override
...@@ -1532,7 +1679,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -1532,7 +1679,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
}).done((deckData) -> { }).done((deckData) -> {
if (deckData != null) { if (deckData != null) {
mDeckId = deckData.getDeckId(); mDeckId = deckData.getDeckId();
LogUtil.i(TAG,deckData.toString()); LogUtil.i(TAG, deckData.toString());
String fileFullName = deckData.getDeckName() + YDK_FILE_EX; String fileFullName = deckData.getDeckName() + YDK_FILE_EX;
File dir = new File(getActivity().getApplicationInfo().dataDir, "cache"); File dir = new File(getActivity().getApplicationInfo().dataDir, "cache");
//将卡组存到cache缓存目录中 //将卡组存到cache缓存目录中
...@@ -1559,7 +1706,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -1559,7 +1706,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
return; return;
String currentDeckPath = deck.getAbsolutePath(); String currentDeckPath = deck.getAbsolutePath();
for (DeckFile deckFile : deckFileList) { for (DeckFile deckFile : deckFileList) {
LogUtil.w(TAG, "要删除的卡组:"+"\n卡组分类"+deckFile.getTypeName()+ "\n卡组名称:"+deckFile.getFileName()+"\n卡组id"+deckFile.getDeckId()); LogUtil.w(TAG, "要删除的卡组:" + "\n卡组分类" + deckFile.getTypeName() + "\n卡组名称:" + deckFile.getFileName() + "\n卡组id" + deckFile.getDeckId());
if (TextUtils.equals(deckFile.getPath(), currentDeckPath)) { if (TextUtils.equals(deckFile.getPath(), currentDeckPath)) {
List<File> files = getYdkFiles(); List<File> files = getYdkFiles();
File file = null; File file = null;
...@@ -1627,6 +1774,8 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -1627,6 +1774,8 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
@Override @Override
public void onDragEnd() { public void onDragEnd() {
// 在拖拽结束后添加当前状态到历史记录中
addDeckToHistory(mDeckAdapater.getCurrentState());
} }
//https://www.jianshu.com/p/99649af3b191 //https://www.jianshu.com/p/99649af3b191
......
...@@ -40,12 +40,14 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement ...@@ -40,12 +40,14 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
private final SparseArray<Integer> mCount = new SparseArray<>(); private final SparseArray<Integer> mCount = new SparseArray<>();
private final Context context; private final Context context;
private final LayoutInflater mLayoutInflater; private final LayoutInflater mLayoutInflater;
private final int Padding = 1;
private final RecyclerView recyclerView;
private final Random mRandom;
private final ImageLoader imageLoader;
private ImageTop mImageTop; private ImageTop mImageTop;
private int mMainCount; private int mMainCount;
private int mExtraCount; private int mExtraCount;
private int mSideCount; private int mSideCount;
private int mMainMonsterCount; private int mMainMonsterCount;
private int mMainSpellCount; private int mMainSpellCount;
private int mMainTrapCount; private int mMainTrapCount;
...@@ -56,18 +58,13 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement ...@@ -56,18 +58,13 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
private int mSideMonsterCount; private int mSideMonsterCount;
private int mSideSpellCount; private int mSideSpellCount;
private int mSideTrapCount; private int mSideTrapCount;
private int mFullWidth; private int mFullWidth;
private int mWidth; private int mWidth;
private int mHeight; private int mHeight;
private final int Padding = 1;
private final RecyclerView recyclerView;
private final Random mRandom;
private DeckViewHolder mHeadHolder; private DeckViewHolder mHeadHolder;
private DeckItem mRemoveItem; private DeckItem mRemoveItem;
private int mRemoveIndex; private int mRemoveIndex;
private LimitList mLimitList; private LimitList mLimitList;
private final ImageLoader imageLoader;
private boolean showHead = false; private boolean showHead = false;
private String mDeckMd5; private String mDeckMd5;
private DeckInfo mDeckInfo; private DeckInfo mDeckInfo;
...@@ -98,6 +95,46 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement ...@@ -98,6 +95,46 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
return mCount; return mCount;
} }
/**
* 获取当前卡组状态的副本
*
* @return 当前卡组状态的副本
*/
public DeckInfo getCurrentState() {
// 创建当前状态的深拷贝
DeckInfo currentState = new DeckInfo();
// 从 mItems 中提取不同类型的卡片
List<Card> mainCards = new ArrayList<>();
List<Card> extraCards = new ArrayList<>();
List<Card> sideCards = new ArrayList<>();
for (DeckItem item : mItems) {
if (item != null && item.getCardInfo() != null) {
switch (item.getType()) {
case MainCard:
mainCards.add(item.getCardInfo());
break;
case ExtraCard:
extraCards.add(item.getCardInfo());
break;
case SideCard:
sideCards.add(item.getCardInfo());
break;
}
}
}
currentState.mainCards = mainCards;
currentState.extraCards = extraCards;
currentState.sideCards = sideCards;
// 通过 mDeckInfo 获取 source
if (mDeckInfo != null) {
currentState.source = mDeckInfo.source;
}
return currentState;
}
public boolean AddCard(Card cardInfo, DeckItemType type) { public boolean AddCard(Card cardInfo, DeckItemType type) {
if (cardInfo == null) return false; if (cardInfo == null) return false;
if (cardInfo.isType(CardType.Token)) { if (cardInfo.isType(CardType.Token)) {
...@@ -151,10 +188,6 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement ...@@ -151,10 +188,6 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
notifyItemRangeChanged(DeckItem.MainStart, DeckItem.MainStart + getMainCount()); notifyItemRangeChanged(DeckItem.MainStart, DeckItem.MainStart + getMainCount());
} }
public void setLimitList(LimitList limitList) {
mLimitList = limitList;
}
private boolean comp(DeckItem d1, DeckItem d2) { private boolean comp(DeckItem d1, DeckItem d2) {
if (d1.getType() == d2.getType()) { if (d1.getType() == d2.getType()) {
Card c1 = d1.getCardInfo(); Card c1 = d1.getCardInfo();
...@@ -386,6 +419,10 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement ...@@ -386,6 +419,10 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
return mLimitList; return mLimitList;
} }
public void setLimitList(LimitList limitList) {
mLimitList = limitList;
}
public @Nullable public @Nullable
File getYdkFile() { File getYdkFile() {
if (mDeckInfo != null) { if (mDeckInfo != null) {
......
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#91BF03" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
<path android:fillColor="@android:color/white" android:pathData="M18.4,10.6C16.55,8.99 14.15,8 11.5,8c-4.65,0 -8.58,3.03 -9.96,7.22L3.9,16c1.05,-3.19 4.05,-5.5 7.6,-5.5 1.95,0 3.73,0.72 5.12,1.88L13,16h9V7l-3.6,3.6z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#91BF03" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
<path android:fillColor="@android:color/white" android:pathData="M12.5,8c-2.65,0 -5.05,0.99 -6.9,2.6L2,7v9h9l-3.62,-3.62c1.39,-1.16 3.16,-1.88 5.12,-1.88 3.54,0 6.55,2.31 7.6,5.5l2.37,-0.78C21.08,11.03 17.15,8 12.5,8z"/>
</vector>
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="100dp" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:orientation="horizontal"> android:orientation="horizontal">
...@@ -41,8 +41,8 @@ ...@@ -41,8 +41,8 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:layout_weight="1"
android:orientation="horizontal"> android:orientation="horizontal">
<TextView <TextView
...@@ -81,17 +81,16 @@ ...@@ -81,17 +81,16 @@
android:layout_marginStart="5dp" android:layout_marginStart="5dp"
android:layout_marginEnd="5dp" android:layout_marginEnd="5dp"
android:layout_weight="1" android:layout_weight="1"
android:textSize="10sp"
android:maxLines="1"
android:gravity="center" android:gravity="center"
android:maxLines="1"
android:shadowColor="@color/black" android:shadowColor="@color/black"
android:shadowDx="1" android:shadowDx="1"
android:shadowDy="1" android:shadowDy="1"
android:shadowRadius="2" android:shadowRadius="2"
android:text="@string/like_deck_thumb" android:text="@string/like_deck_thumb"
android:textColor="@color/white" /> android:textColor="@color/white"
android:textSize="10sp" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
...@@ -99,8 +98,8 @@ ...@@ -99,8 +98,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:layout_weight="1"
android:layout_marginTop="2dp" android:layout_marginTop="2dp"
android:layout_weight="1"
android:background="@drawable/button_radius_black_transparents" android:background="@drawable/button_radius_black_transparents"
android:ellipsize="end" android:ellipsize="end"
android:gravity="center|left" android:gravity="center|left"
...@@ -126,102 +125,142 @@ ...@@ -126,102 +125,142 @@
android:visibility="gone" /> android:visibility="gone" />
<LinearLayout <LinearLayout
android:id="@+id/nav_list" android:layout_width="wrap_content"
android:layout_width="60dp" android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical"> android:orientation="vertical">
<!-- 撤销/重做按钮 -->
<ImageView <LinearLayout
android:id="@+id/btn_nav_list" android:layout_width="wrap_content"
android:layout_width="48dp" android:layout_height="wrap_content"
android:layout_height="48dp"
android:layout_gravity="center" android:layout_gravity="center"
android:src="@drawable/listicon" /> android:layout_marginBottom="10dp"
android:orientation="horizontal">
<TextView <ImageButton
android:layout_width="match_parent" android:id="@+id/btn_undo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:gravity="center"
android:enabled="false"
android:background="@drawable/ic_radius_bg"
android:src="@drawable/ic_undo" />
<ImageButton
android:id="@+id/btn_redo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="@drawable/ic_radius_bg"
android:gravity="center"
android:enabled="false"
android:src="@drawable/ic_redo" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="bottom|center_horizontal" android:orientation="horizontal">
android:shadowColor="@color/black"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="2"
android:text="@string/searchresult"
android:textColor="@color/white"
android:textSize="10sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/nav_search" android:id="@+id/nav_list"
android:layout_width="60dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:orientation="vertical"> android:orientation="vertical">
<ImageView <ImageView
android:id="@+id/btn_nav_search" android:id="@+id/btn_nav_list"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_gravity="center" android:layout_gravity="center"
android:src="@drawable/search" /> android:src="@drawable/listicon" />
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:gravity="bottom|center_horizontal" android:gravity="bottom|center_horizontal"
android:shadowColor="@color/black" android:shadowColor="@color/black"
android:shadowDx="1" android:shadowDx="1"
android:shadowDy="1" android:shadowDy="1"
android:shadowRadius="2" android:shadowRadius="2"
android:text="@string/card_search" android:text="@string/searchresult"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="10sp" android:textSize="10sp"
android:textStyle="bold" /> android:textStyle="bold" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/deck_menu" android:id="@+id/nav_search"
android:layout_width="60dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:layout_marginLeft="2dp" android:orientation="vertical">
android:layout_marginRight="2dp"
android:orientation="vertical">
<com.nightonke.boommenu.BoomMenuButton <ImageView
android:id="@+id/bmb" android:id="@+id/btn_nav_search"
android:layout_width="wrap_content" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_gravity="center_vertical" android:layout_gravity="center"
android:background="@drawable/buttonfunction" android:src="@drawable/search" />
app:bmb_buttonEnum="textOutsideCircle"
app:bmb_buttonPlaceEnum="buttonPlace_sc_9_1" <TextView
app:bmb_dimColor="#80000000" android:layout_width="match_parent"
app:bmb_normalColor="@android:color/transparent" android:layout_height="match_parent"
app:bmb_piecePlaceEnum="piecePlace_dot_9_1"> android:gravity="bottom|center_horizontal"
android:shadowColor="@color/black"
<ImageView android:shadowDx="1"
android:id="@+id/cube2" android:shadowDy="1"
android:layout_width="35dp" android:shadowRadius="2"
android:layout_height="35dp" android:text="@string/card_search"
android:layout_gravity="center" android:textColor="@color/white"
app:srcCompat="@drawable/cube" /> android:textSize="10sp"
</com.nightonke.boommenu.BoomMenuButton> android:textStyle="bold" />
</LinearLayout>
<TextView
android:layout_width="match_parent" <LinearLayout
android:layout_height="wrap_content" android:id="@+id/deck_menu"
android:gravity="bottom|center_horizontal" android:layout_width="wrap_content"
android:shadowColor="@color/black" android:layout_height="match_parent"
android:shadowDx="1" android:layout_gravity="bottom"
android:shadowDy="1" android:layout_marginLeft="2dp"
android:shadowRadius="2" android:layout_marginRight="2dp"
android:text="@string/Function_Menu" android:orientation="vertical">
android:textColor="@color/white"
android:textSize="10sp" <com.nightonke.boommenu.BoomMenuButton
android:textStyle="bold" /> android:id="@+id/bmb"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_gravity="center_vertical"
android:background="@drawable/buttonfunction"
app:bmb_buttonEnum="textOutsideCircle"
app:bmb_buttonPlaceEnum="buttonPlace_sc_9_1"
app:bmb_dimColor="#80000000"
app:bmb_normalColor="@android:color/transparent"
app:bmb_piecePlaceEnum="piecePlace_dot_9_1">
<ImageView
android:id="@+id/cube2"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center"
app:srcCompat="@drawable/cube" />
</com.nightonke.boommenu.BoomMenuButton>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom|center_horizontal"
android:shadowColor="@color/black"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="2"
android:text="@string/Function_Menu"
android:textColor="@color/white"
android:textSize="10sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</FrameLayout> </FrameLayout>
......
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