Commit cd25c603 authored by feihuaduo's avatar feihuaduo

卡组分类dialog

parent 40ea24c9
......@@ -161,6 +161,9 @@ public class AppsSettings {
return mSharedPreferences.getBoolean(PREF_ONLY_GAME, DEF_PREF_ONLY_GAME);
}
/***
* 是否使用额外卡库
*/
public boolean isReadExpansions() {
return mSharedPreferences.getBoolean(PREF_READ_EX, DEF_PREF_READ_EX);
}
......@@ -398,14 +401,14 @@ public class AppsSettings {
}
/***
* 是否使用额外卡库
* 是否优先使用外置数据
*/
public boolean isUseExtraCards() {
return mSharedPreferences.getBoolean(Constants.PREF_USE_EXTRA_CARD_CARDS, Constants.PREF_DEF_USE_EXTRA_CARD_CARDS);
}
/***
* 设置是否使用额外卡库
* 设置是否优先使用外置数据
*/
public void setUseExtraCards(boolean useExtraCards) {
mSharedPreferences.putBoolean(Constants.PREF_USE_EXTRA_CARD_CARDS, useExtraCards);
......@@ -466,6 +469,21 @@ public class AppsSettings {
return new File(getResourcePath(), Constants.CORE_DECK_PATH).getAbsolutePath();
}
//获取ai卡组文件夹
public String getAiDeckDir() {
return new File(getResourcePath(), Constants.CORE_DECK_PATH+"/Decks").getAbsolutePath();
}
//获取新卡卡包文件夹
public String getPackDeckDir() {
return new File(getResourcePath(), "pack").getAbsolutePath();
}
//获取临时存放卡组的目录
public String getCacheDeckDir(){
return context.getExternalFilesDir("cacheDeck").getAbsolutePath();
}
//获取残局文件夹
public String getSingleDir() {
return new File(getResourcePath(), Constants.CORE_SINGLE_PATH).getAbsolutePath();
......
package cn.garymb.ygomobile.bean;
public class DeckType extends TextSelect {
private String name;
private String path;
public DeckType(String name, String path) {
this.name = name;
this.path = path;
super.setName(name);
super.setObject(this);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
}
package cn.garymb.ygomobile.bean;
public class TextSelect {
private String name;
private Object object;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Object getObject() {
return object;
}
public void setObject(Object object) {
this.object = object;
}
public static TextSelect toTextSelect(String name,Object object){
TextSelect textSelect=new TextSelect();
textSelect.setName(name);
textSelect.setObject(object);
return textSelect;
}
}
package cn.garymb.ygomobile.bean.events;
import java.io.File;
import cn.garymb.ygomobile.bean.TextSelect;
public class DeckFile extends TextSelect {
private String name;
private String path;
public DeckFile(String path) {
this.path = path;
name=new File(path).getName();
name=name.substring(0,name.lastIndexOf("."));
super.setName(name);
super.setObject(this);
}
public DeckFile(File file) {
path=file.getAbsolutePath();
name=file.getName();
name=name.substring(0,name.lastIndexOf("."));
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
}
package cn.garymb.ygomobile.ui.adapters;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import cn.garymb.ygomobile.bean.TextSelect;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.mycard.mcchat.util.Util;
import cn.garymb.ygomobile.utils.YGOUtil;
public class TextSelectAdapter extends RecyclerView.Adapter<TextSelectAdapter.ViewHolder> {
private OnItemSelectListener onItemSelectListener;
private List<? extends TextSelect> data;
private int selectPosition;
public TextSelectAdapter(List<? extends TextSelect> data, int selectPosition) {
this.data = data;
this.selectPosition = selectPosition;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.text_select_item, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.tv_name.setText(data.get(position).getName());
if (position==selectPosition){
holder.view.setBackgroundColor(YGOUtil.c(R.color.gray));
}else {
holder.view.setBackgroundColor(YGOUtil.c(R.color.white));
}
holder.view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (position==selectPosition)
return;
selectPosition = position;
notifyDataSetChanged();
onItemSelectListener.onItemSelect(position, data.get(position).getObject());
}
});
}
public void setOnItemSelectListener(OnItemSelectListener onItemSelectListener) {
this.onItemSelectListener = onItemSelectListener;
}
@Override
public int getItemCount() {
return data.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
View view;
TextView tv_name;
public ViewHolder(View view) {
super(view);
this.view = view;
this.tv_name = view.findViewById(R.id.tv_name);
}
}
public interface OnItemSelectListener<T> {
void onItemSelect(int position, T item);
}
}
......@@ -26,8 +26,10 @@ import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.feihua.dialogutils.util.DialogUtils;
import com.nightonke.boommenu.BoomButtons.BoomButton;
import com.nightonke.boommenu.BoomButtons.TextOutsideCircleButton;
import com.nightonke.boommenu.BoomMenuButton;
......@@ -69,6 +71,7 @@ import cn.garymb.ygomobile.utils.BitmapUtil;
import cn.garymb.ygomobile.utils.FileUtils;
import cn.garymb.ygomobile.utils.IOUtils;
import cn.garymb.ygomobile.utils.ShareUtil;
import cn.garymb.ygomobile.utils.YGODialogUtil;
import ocgcore.DataManager;
import ocgcore.data.Card;
import ocgcore.data.LimitList;
......@@ -86,15 +89,20 @@ class DeckManagerActivityImpl extends BaseCardsAcitivity implements RecyclerView
private File mPreLoadFile;
private DeckItemTouchHelper mDeckItemTouchHelper;
private AppCompatSpinner mDeckSpinner;
private TextView tv_deck;
private SimpleSpinnerAdapter mSimpleSpinnerAdapter;
private AppCompatSpinner mLimitSpinner;
private CardDetail mCardDetail;
private DialogPlus mDialog;
private DialogPlus builderShareLoading;
private DialogUtils du;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
du=DialogUtils.getdx(this);
tv_deck=$(R.id.tv_deck);
mDeckSpinner = $(R.id.toolbar_list);
mDeckSpinner.setPopupBackgroundResource(R.color.colorNavy);
mLimitSpinner = $(R.id.sp_limit_list);
......@@ -147,6 +155,12 @@ class DeckManagerActivityImpl extends BaseCardsAcitivity implements RecyclerView
}
init(_file);
EventBus.getDefault().register(this);
tv_deck.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
YGODialogUtil.dialogDeckSelect(DeckManagerActivityImpl.this,null);
}
});
}
@Override
......
package cn.garymb.ygomobile.utils;
import android.os.Build;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import cn.garymb.ygomobile.App;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.bean.DeckType;
import cn.garymb.ygomobile.bean.events.DeckFile;
public class DeckUtil {
public static List<DeckType> getDeckTypeList() {
List<DeckType> deckTypeList = new ArrayList<>();
deckTypeList.add(new DeckType("卡包展示", AppsSettings.get().getPackDeckDir()));
deckTypeList.add(new DeckType("人机卡组", AppsSettings.get().getAiDeckDir()));
deckTypeList.add(new DeckType("未分类", AppsSettings.get().getDeckDir()));
File[] files = new File(AppsSettings.get().getDeckDir()).listFiles();
if (files != null) {
for (File f : files) {
if (f.isDirectory()) {
deckTypeList.add(new DeckType(f.getName(), f.getAbsolutePath()));
}
}
}
return deckTypeList;
}
public static List<DeckFile> getDeckList(String path) {
List<DeckFile> deckList = new ArrayList<>();
File[] files = new File(path).listFiles();
if (files != null){
for (File file : files) {
if (file.isFile() && file.getName().endsWith(".ydk")) {
deckList.add(new DeckFile(file));
}
}
}
return deckList;
}
public static List<DeckFile> getExpansionsDeckList() throws IOException {
AppsSettings appsSettings= AppsSettings.get();
List<DeckFile> deckList = new ArrayList<>();
File[] files = new File(appsSettings.getExpansionsPath(), Constants.CORE_DECK_PATH).listFiles();
if(files!=null) {
for (File file : files) {
if (file.isFile() && file.getName().endsWith(".ydk")) {
deckList.add(new DeckFile(file));
}
}
}
files = appsSettings.getExpansionsPath().listFiles();
for (File file : files) {
if (file.isFile() && file.getName().endsWith(".zip")) {
ZipFile zipFile = new ZipFile(file.getAbsoluteFile());
Enumeration entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
if (entry.getName().endsWith(".ydk")){
String name=entry.getName();
name=name.substring(name.lastIndexOf("/"),name.length());
InputStream inputStream = zipFile.getInputStream(entry);
deckList.add(new DeckFile(
IOUtils.asFile(inputStream,
appsSettings.getCacheDeckDir()+"/"+name)));
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
IOUtils.close(zipFile);
}
}
}
return deckList;
}
}
......@@ -246,4 +246,24 @@ public class IOUtils {
}
public static File asFile(InputStream is, String outPath) throws IOException {
OutputStream os = null;
try {
os = new FileOutputStream(outPath);
int len = 0;
byte[] buffer = new byte[8192];
while ((len = is.read(buffer)) != -1) {
os.write(buffer, 0, len);
}
} finally {
if (os!=null)
os.close();
is.close();
}
return new File(outPath);
}
}
package cn.garymb.ygomobile.utils;
import android.content.Context;
import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.feihua.dialogutils.util.DialogUtils;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
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.lite.R;
import cn.garymb.ygomobile.ui.adapters.TextSelectAdapter;
public class YGODialogUtil {
public static void dialogDeckSelect(Context context, String selectDeckPath) {
View viewDialog = DialogUtils.getdx(context).dialogBottomSheet(R.layout.dialog_deck_select);
RecyclerView rv_type, rv_deck;
rv_deck = viewDialog.findViewById(R.id.rv_deck);
rv_type = viewDialog.findViewById(R.id.rv_type);
rv_deck.setLayoutManager(new LinearLayoutManager(context));
rv_type.setLayoutManager(new LinearLayoutManager(context));
TextSelectAdapter typeAdp, deckAdp;
List<DeckType> typeList = DeckUtil.getDeckTypeList();
int typeSelectPosition=2;
int deckSelectPosition=-1;
List<DeckFile> deckList ;
if (selectDeckPath != null) {
String name = new File(selectDeckPath).getParentFile().getName();
if (name.equals("pack") || name.equals("cacheDeck")) {
//卡包
typeSelectPosition=0;
} else if (name.equals("Decks")) {
//ai卡组
typeSelectPosition=1;
} else if (name.equals("deck") && new File(selectDeckPath).getParentFile().getParentFile().getName().equals(Constants.PREF_DEF_GAME_DIR)) {
//如果是deck并且上一个目录是ygocore的话,保证不会把名字为deck的卡包识别为未分类
typeSelectPosition=2;
} else {
//其他卡包
for (int i=3;i<typeList.size();i++){
DeckType deckType=typeList.get(i);
if(deckType.getName().equals(name)){
typeSelectPosition=i;
break;
}
}
}
}
deckList = DeckUtil.getDeckList(typeList.get(typeSelectPosition).getPath());
typeAdp = new TextSelectAdapter(typeList, typeSelectPosition);
deckAdp = new TextSelectAdapter(deckList, deckSelectPosition);
rv_type.setAdapter(typeAdp);
rv_deck.setAdapter(deckAdp);
typeAdp.setOnItemSelectListener(new TextSelectAdapter.OnItemSelectListener<DeckType>() {
@Override
public void onItemSelect(int position, DeckType item) {
deckList.clear();
deckList.addAll(DeckUtil.getDeckList(item.getPath()));
if (position == 0) {
if (AppsSettings.get().isReadExpansions()) {
try {
deckList.addAll(DeckUtil.getExpansionsDeckList());
} catch (IOException e) {
YGOUtil.show("额外卡库加载失败,愿意为" + e);
}
}
}
deckAdp.notifyDataSetChanged();
}
});
deckAdp.setOnItemSelectListener(new TextSelectAdapter.OnItemSelectListener<DeckFile>() {
@Override
public void onItemSelect(int position, DeckFile item) {
DialogUtils.getdx(context).dis();
}
});
// rv_deck.setAdapter();
}
}
package cn.garymb.ygomobile.utils;
import android.content.Context;
import android.widget.Toast;
import androidx.core.content.ContextCompat;
import cn.garymb.ygomobile.App;
public class YGOUtil {
//提示
public static void show(String message) {
Toast.makeText(App.get(), message, Toast.LENGTH_SHORT).show();
}
public static int c(int colorId){
return ContextCompat.getColor(App.get(),colorId);
}
}
......@@ -36,16 +36,39 @@
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:padding="5dp"
android:gravity="center_vertical"
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="@dimen/item_and_text_height">
<TextView
android:textSize="12sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/deck_name"
android:textColor="@color/holo_blue_light" />
<androidx.appcompat.widget.AppCompatTextView
android:maxLines="1"
android:ellipsize="end"
android:layout_marginTop="2dp"
android:textColor="@color/white"
android:textStyle="bold"
android:text="假装这是一个卡组.ydk"
android:textSize="18sp"
android:id="@+id/tv_deck"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/toolbar_list"
android:layout_width="0dp"
android:layout_height="@dimen/item_height"
android:visibility="gone"
android:layout_weight="1" />
<LinearLayout
......
......@@ -6,19 +6,24 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="horizontal">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_type"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<View
android:background="@color/gray"
android:layout_width="1dp"
android:layout_height="match_parent"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_deck"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
android:layout_weight="2" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:gravity="center"
android:background="@drawable/click_background"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatTextView
android:gravity="center"
android:textColor="@color/black"
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
\ No newline at end of file
......@@ -13,6 +13,7 @@
<dimen name="title_height">55dp</dimen>
<dimen name="item_height2">70dp</dimen>
<dimen name="item_height">48dp</dimen>
<dimen name="item_and_text_height">68dp</dimen>
<dimen name="button_width_small">40dp</dimen>
<dimen name="button_width">80dp</dimen>
<dimen name="card_small_width">66dp</dimen>
......
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