Commit 44ce1006 authored by feihuaduo's avatar feihuaduo

修复卡组保存后卡组码无法刷新的问题

dialogUtils使用云端1.8.9.20
gradle版本升级至7.2.0
parent fe4863cf
...@@ -10,7 +10,7 @@ buildscript { ...@@ -10,7 +10,7 @@ buildscript {
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:7.1.2' classpath 'com.android.tools.build:gradle:7.2.0'
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'
} }
......
...@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME ...@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
...@@ -115,7 +115,7 @@ dependencies { ...@@ -115,7 +115,7 @@ dependencies {
implementation 'com.nightonke:boommenu:2.1.0' implementation 'com.nightonke:boommenu:2.1.0'
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
//dialog库 //dialog库
implementation(name: 'dialogutils2-release', ext: 'aar') implementation 'com.github.feihuaduo:DialogUtils:1.8.9.20'
//recyclerview的adapter库 //recyclerview的adapter库
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4'
implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.appcompat:appcompat:1.2.0'
......
package cn.garymb.ygomobile.adapter;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.core.content.ContextCompat;
import cn.garymb.ygomobile.lite.R;
/**
* Create By feihua On 2022/5/18
*/
public class TextBaseAdapter extends BaseAdapter {
private Context context;
private String[] data;
private int leftPadding;
private int rightPadding;
private int topPadding;
private int bottomPadding;
private int textColor = 0;
public TextBaseAdapter(Context context, String[] data, int textColor, int leftPadding, int topPadding, int rightPadding, int bottomPadding) {
this.context = context;
this.data = data;
this.textColor = textColor;
this.leftPadding = leftPadding;
this.rightPadding = rightPadding;
this.topPadding = topPadding;
this.bottomPadding = bottomPadding;
}
@Override
public int getCount() {
return data.length;//设置此数据适配起有几个item
}
@Override
public Object getItem(int p1)//未知,好像无用
{
return data[p1];
}
@Override
public long getItemId(int p1)//未知,好像无用
{
return p1;
}
@Override
public View getView(int p1, View p2, ViewGroup p3) {
AppCompatTextView t = new AppCompatTextView(context);
if (textColor == 0)
t.setTextColor(ContextCompat.getColor(context, R.color.colorAccent));
else
t.setTextColor(textColor);
t.setText(data[p1]);//p1为对应的数组下标
t.setTextSize(20);
t.setGravity(Gravity.CENTER);
t.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
t.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.MATCH_PARENT));
return t;//返回设置好的view组件,也可以是布局,也可以是控件
}
}
...@@ -134,7 +134,7 @@ public class CardLoader implements ICardSearcher { ...@@ -134,7 +134,7 @@ public class CardLoader implements ICardSearcher {
if (searchInfo != null && card.Name.equals(searchInfo.getKeyWord().getValue())) { if (searchInfo != null && card.Name.equals(searchInfo.getKeyWord().getValue())) {
cards.remove(i); cards.remove(i);
keywordtmp.add(card); keywordtmp.add(card);
continue;//ظ continue;//避免重复
} }
if (searchInfo == null || searchInfo.isValid(card)) { if (searchInfo == null || searchInfo.isValid(card)) {
list.add(card); list.add(card);
......
...@@ -774,11 +774,18 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi ...@@ -774,11 +774,18 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
// if (file != null) { // if (file != null) {
// loadDeckFromFile(file); // loadDeckFromFile(file);
// } // }
Deck deck = mDeckAdapater.toDeck(mDeckAdapater.getYdkFile());
if (deck.getDeckCount()==0){
builderShareLoading.dismiss();
YGOUtil.show("卡组中没有卡片");
return;
}
//延时半秒,使整体看起来更流畅 //延时半秒,使整体看起来更流畅
new Handler().postDelayed(this::shareDeck1, 500); new Handler().postDelayed(() -> shareDeck1(deck), 500);
} }
private void shareDeck1() { private void shareDeck1(Deck deck) {
//开启绘图缓存 //开启绘图缓存
mRecyclerView.setDrawingCacheEnabled(true); mRecyclerView.setDrawingCacheEnabled(true);
//这个方法可调可不调,因为在getDrawingCache()里会自动判断有没有缓存有没有准备好, //这个方法可调可不调,因为在getDrawingCache()里会自动判断有没有缓存有没有准备好,
...@@ -793,7 +800,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi ...@@ -793,7 +800,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
mRecyclerView.destroyDrawingCache(); mRecyclerView.destroyDrawingCache();
// shotRecyclerView(mRecyclerView) // shotRecyclerView(mRecyclerView)
Deck deck = mDeckAdapater.toDeck(mDeckAdapater.getYdkFile());
String deckName = deck.getName(); String deckName = deck.getName();
int end = deckName.lastIndexOf("."); int end = deckName.lastIndexOf(".");
if (end != -1) { if (end != -1) {
...@@ -803,13 +810,13 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi ...@@ -803,13 +810,13 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
BitmapUtil.saveBitmap(bitmap, savePath, 50); BitmapUtil.saveBitmap(bitmap, savePath, 50);
builderShareLoading.dismiss(); builderShareLoading.dismiss();
DialogUtils du = DialogUtils.getdx(this); DialogUtils du = DialogUtils.getdx(this);
View viewDialog = du.dialogBottomSheet(R.layout.dialog_deck_share,0); View viewDialog = du.dialogBottomSheet(R.layout.dialog_deck_share,true);
ImageView iv_image = viewDialog.findViewById(R.id.iv_image); ImageView iv_image = viewDialog.findViewById(R.id.iv_image);
Button bt_image_share = viewDialog.findViewById(R.id.bt_image_share); Button bt_image_share = viewDialog.findViewById(R.id.bt_image_share);
Button bt_code_share = viewDialog.findViewById(R.id.bt_code_share); Button bt_code_share = viewDialog.findViewById(R.id.bt_code_share);
TextView tv_code = viewDialog.findViewById(R.id.et_code); TextView tv_code = viewDialog.findViewById(R.id.et_code);
tv_code.setText(mDeckAdapater.getDeckInfo().toDeck().toAppUri().toString()); tv_code.setText(deck.toAppUri().toString());
ImageUtil.setImage(this, savePath, iv_image); ImageUtil.show(this, savePath, iv_image,System.currentTimeMillis()+"");
bt_code_share.setOnClickListener(v -> { bt_code_share.setOnClickListener(v -> {
du.dis(); du.dis();
......
...@@ -4,15 +4,24 @@ import android.content.Context; ...@@ -4,15 +4,24 @@ import android.content.Context;
import android.graphics.ColorMatrix; import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter; import android.graphics.ColorMatrixColorFilter;
import android.net.Uri; import android.net.Uri;
import android.text.TextUtils;
import android.widget.ImageView; import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.signature.ObjectKey;
import com.ourygo.assistant.util.Util;
import cn.garymb.ygomobile.lite.R; import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.utils.glide.GlideCompat; import cn.garymb.ygomobile.utils.glide.GlideCompat;
public class ImageUtil { public class ImageUtil {
public static final RequestOptions imageOption = RequestOptions
.diskCacheStrategyOf(DiskCacheStrategy.DATA)
.placeholder(R.drawable.unknown);
public static void setAvatar(Context context, String url, final ImageView im) { public static void setAvatar(Context context, String url, final ImageView im) {
if (url != null) { if (url != null) {
GlideCompat.with(context) GlideCompat.with(context)
...@@ -25,13 +34,14 @@ public class ImageUtil { ...@@ -25,13 +34,14 @@ public class ImageUtil {
public static void setImage(Context context, String url, final ImageView im) { public static void setImage(Context context, String url, final ImageView im) {
if (url != null) { // if (url != null) {
GlideCompat.with(context) // GlideCompat.with(context)
.load(url) // .load(url)
.diskCacheStrategy(DiskCacheStrategy.DATA) // .diskCacheStrategy(DiskCacheStrategy.DATA)
.placeholder(R.drawable.unknown) // .placeholder(R.drawable.unknown)
.into(im); // .into(im);
} // }
show(context, url, im, null);
} }
public static void setGrayImage(int key, ImageView imageView) { public static void setGrayImage(int key, ImageView imageView) {
...@@ -41,9 +51,29 @@ public class ImageUtil { ...@@ -41,9 +51,29 @@ public class ImageUtil {
imageView.setColorFilter(filter); imageView.setColorFilter(filter);
} }
public static void reImageColor(int key,ImageView imageView) { public static void reImageColor(int key, ImageView imageView) {
imageView.setColorFilter(null); imageView.setColorFilter(null);
} }
public static void show(Context context, String uri, final ImageView im, String objectKey) {
if (!Util.isContextExisted(context))
return;
if (TextUtils.isEmpty(uri))
return;
if (TextUtils.isEmpty(objectKey)) {
setImage(context, uri, im);
Glide.with(context)
.load(uri)
.apply(imageOption)
.into(im);
} else {
Glide.with(context)
.load(uri)
.signature(new ObjectKey(objectKey))
.apply(imageOption)
.into(im);
}
}
} }
package cn.garymb.ygomobile.utils; package cn.garymb.ygomobile.utils;
import static cn.garymb.ygomobile.lite.R.string.please_select_target_category;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.text.InputType; import android.text.InputType;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
...@@ -31,6 +32,7 @@ import java.util.List; ...@@ -31,6 +32,7 @@ import java.util.List;
import cn.garymb.ygomobile.AppsSettings; import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.Constants; import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.adapter.TextBaseAdapter;
import cn.garymb.ygomobile.bean.DeckType; import cn.garymb.ygomobile.bean.DeckType;
import cn.garymb.ygomobile.bean.events.DeckFile; import cn.garymb.ygomobile.bean.events.DeckFile;
import cn.garymb.ygomobile.lite.R; import cn.garymb.ygomobile.lite.R;
...@@ -39,10 +41,40 @@ import cn.garymb.ygomobile.ui.mycard.mcchat.util.ImageUtil; ...@@ -39,10 +41,40 @@ import cn.garymb.ygomobile.ui.mycard.mcchat.util.ImageUtil;
import cn.garymb.ygomobile.ui.plus.DialogPlus; import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.utils.recyclerview.DeckTypeTouchHelperCallback; import cn.garymb.ygomobile.utils.recyclerview.DeckTypeTouchHelperCallback;
import static cn.garymb.ygomobile.lite.R.string.please_select_target_category;
public class YGODialogUtil { public class YGODialogUtil {
private static class ViewHolder{ public static void dialogDeckSelect(Context context, String selectDeckPath, OnDeckMenuListener onDeckMenuListener) {
ViewHolder viewHolder = new ViewHolder(context, selectDeckPath, onDeckMenuListener);
viewHolder.show();
}
public static ListView dialogl(Context context, String title, String[] list) {
DialogUtils dialogUtils = DialogUtils.getInstance(context);
ListView listView = dialogUtils.dialogl1(title
, new TextBaseAdapter(context, list, YGOUtil.c(R.color.white)
, 16, 16, 16, 16));
dialogUtils.setDialogBackgroundResource(R.drawable.radius);
dialogUtils.setTitleColor(YGOUtil.c(R.color.holo_blue_light));
return listView;
}
public interface OnDeckMenuListener {
void onDeckSelect(DeckFile deckFile);
void onDeckDel(List<DeckFile> deckFileList);
void onDeckMove(List<DeckFile> deckFileList, DeckType toDeckType);
void onDeckCopy(List<DeckFile> deckFileList, DeckType toDeckType);
void onDeckNew(DeckType currentDeckType);
}
public interface OnDeckTypeListener {
void onDeckTypeListener(int position);
}
private static class ViewHolder {
private final int IMAGE_MOVE = 0; private final int IMAGE_MOVE = 0;
private final int IMAGE_COPY = 1; private final int IMAGE_COPY = 1;
...@@ -61,9 +93,9 @@ public class YGODialogUtil { ...@@ -61,9 +93,9 @@ public class YGODialogUtil {
private final TextSelectAdapter<DeckFile> deckAdp; private final TextSelectAdapter<DeckFile> deckAdp;
private final Dialog ygoDialog; private final Dialog ygoDialog;
public ViewHolder(Context context, String selectDeckPath, OnDeckMenuListener onDeckMenuListener){ public ViewHolder(Context context, String selectDeckPath, OnDeckMenuListener onDeckMenuListener) {
DialogUtils du = DialogUtils.getdx(context); DialogUtils du = DialogUtils.getdx(context);
View viewDialog = du.dialogBottomSheet(R.layout.dialog_deck_select, 0); View viewDialog = du.dialogBottomSheet(R.layout.dialog_deck_select, false);
RecyclerView rv_type, rv_deck; RecyclerView rv_type, rv_deck;
rv_deck = viewDialog.findViewById(R.id.rv_deck); rv_deck = viewDialog.findViewById(R.id.rv_deck);
...@@ -178,48 +210,45 @@ public class YGODialogUtil { ...@@ -178,48 +210,45 @@ public class YGODialogUtil {
ll_add.setOnClickListener(new View.OnClickListener() { ll_add.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
du.dialogl(context.getString(R.string.new_deck), dialogl(context, context.getString(R.string.new_deck),
new String[]{context.getString(R.string.category_name), new String[]{context.getString(R.string.category_name),
context.getString(R.string.deck_name)}, R.drawable.radius).setOnItemClickListener(new AdapterView.OnItemClickListener() { context.getString(R.string.deck_name)}).setOnItemClickListener((parent, view, position, id) -> {
@Override du.dis();
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (position) {
du.dis(); case 0:
switch (position) { //if (deckList.size()>=8){
case 0: // YGOUtil.show("最多只能有5个自定义分类");
//if (deckList.size()>=8){ //}
// YGOUtil.show("最多只能有5个自定义分类"); DialogPlus builder = new DialogPlus(context);
//} builder.setTitle(R.string.please_input_category_name);
DialogPlus builder = new DialogPlus(context); EditText editText = new EditText(context);
builder.setTitle(R.string.please_input_category_name); editText.setGravity(Gravity.TOP | Gravity.LEFT);
EditText editText = new EditText(context); editText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
editText.setGravity(Gravity.TOP | Gravity.LEFT); editText.setSingleLine();
editText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); builder.setContentView(editText);
editText.setSingleLine(); builder.setOnCloseLinster(DialogInterface::dismiss);
builder.setContentView(editText); builder.setLeftButtonListener((dlg, s) -> {
builder.setOnCloseLinster(DialogInterface::dismiss); String name = editText.getText().toString().trim();
builder.setLeftButtonListener((dlg, s) -> { if (TextUtils.isEmpty(name)) {
String name = editText.getText().toString().trim(); YGOUtil.show(context.getString(R.string.invalid_category_name));
if (TextUtils.isEmpty(name)) { return;
YGOUtil.show(context.getString(R.string.invalid_category_name)); }
return; File file = new File(AppsSettings.get().getDeckDir(), name);
} if (IOUtils.createFolder(file)) {
File file = new File(AppsSettings.get().getDeckDir(), name); typeList.add(new DeckType(name, file.getAbsolutePath()));
if (IOUtils.createFolder(file)) { typeAdp.notifyItemInserted(typeList.size() - 1);
typeList.add(new DeckType(name, file.getAbsolutePath())); dlg.dismiss();
typeAdp.notifyItemInserted(typeList.size() - 1); } else {
dlg.dismiss(); YGOUtil.show(context.getString(R.string.create_new_failed));
} else { }
YGOUtil.show(context.getString(R.string.create_new_failed));
} });
builder.show();
}); break;
builder.show(); case 1:
break; onDeckMenuListener.onDeckNew(typeList.get(typeAdp.getSelectPosition()));
case 1: dismiss();
onDeckMenuListener.onDeckNew(typeList.get(typeAdp.getSelectPosition())); break;
dismiss();
break;
}
} }
}); });
} }
...@@ -228,48 +257,46 @@ public class YGODialogUtil { ...@@ -228,48 +257,46 @@ public class YGODialogUtil {
ll_move.setOnClickListener(v -> { ll_move.setOnClickListener(v -> {
List<DeckType> otherType = getOtherTypeList(); List<DeckType> otherType = getOtherTypeList();
du.dialogl(context.getString(please_select_target_category), dialogl(context, context.getString(please_select_target_category),
getStringType(otherType), getStringType(otherType)).setOnItemClickListener((parent, view, position, id) -> {
R.drawable.radius).setOnItemClickListener((parent, view, position, id) -> { du.dis();
du.dis(); DeckType toType = otherType.get(position);
DeckType toType = otherType.get(position); IOUtils.createFolder(new File(toType.getPath()));
IOUtils.createFolder(new File(toType.getPath())); List<DeckFile> deckFileList = deckAdp.getSelectList();
List<DeckFile> deckFileList = deckAdp.getSelectList(); for (DeckFile deckFile : deckFileList) {
for (DeckFile deckFile : deckFileList) { try {
try {
FileUtils.moveFile(deckFile.getPath(), new File(toType.getPath(), deckFile.getFileName()).getPath()); FileUtils.moveFile(deckFile.getPath(), new File(toType.getPath(), deckFile.getFileName()).getPath());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
}
deckList.remove(deckFile);
} }
YGOUtil.show(context.getString(R.string.done)); deckList.remove(deckFile);
onDeckMenuListener.onDeckMove(deckAdp.getSelectList(), toType); }
clearDeckSelect(); YGOUtil.show(context.getString(R.string.done));
onDeckMenuListener.onDeckMove(deckAdp.getSelectList(), toType);
clearDeckSelect();
}); });
}); });
ll_copy.setOnClickListener(v -> { ll_copy.setOnClickListener(v -> {
List<DeckType> otherType = getOtherTypeList(); List<DeckType> otherType = getOtherTypeList();
du.dialogl(context.getString(please_select_target_category), dialogl(context, context.getString(please_select_target_category),
getStringType(otherType), getStringType(otherType)).setOnItemClickListener((parent, view, position, id) -> {
R.drawable.radius).setOnItemClickListener((parent, view, position, id) -> { du.dis();
du.dis(); DeckType toType = otherType.get(position);
DeckType toType = otherType.get(position); IOUtils.createFolder(new File(toType.getPath()));
IOUtils.createFolder(new File(toType.getPath())); List<DeckFile> deckFileList = deckAdp.getSelectList();
List<DeckFile> deckFileList = deckAdp.getSelectList(); for (DeckFile deckFile : deckFileList) {
for (DeckFile deckFile : deckFileList) { try {
try { FileUtils.copyFile(deckFile.getPath(), new File(toType.getPath(), deckFile.getFileName()).getPath());
FileUtils.copyFile(deckFile.getPath(), new File(toType.getPath(), deckFile.getFileName()).getPath()); } catch (IOException e) {
} catch (IOException e) { e.printStackTrace();
e.printStackTrace(); }
} }
} YGOUtil.show(context.getString(R.string.done));
YGOUtil.show(context.getString(R.string.done)); onDeckMenuListener.onDeckCopy(deckAdp.getSelectList(), toType);
onDeckMenuListener.onDeckCopy(deckAdp.getSelectList(), toType); clearDeckSelect();
clearDeckSelect(); });
});
}); });
ll_del.setOnClickListener(new View.OnClickListener() { ll_del.setOnClickListener(new View.OnClickListener() {
...@@ -418,8 +445,8 @@ public class YGODialogUtil { ...@@ -418,8 +445,8 @@ public class YGODialogUtil {
hideAllDeckUtil(); hideAllDeckUtil();
} }
public void show(){ public void show() {
if(ygoDialog != null && !ygoDialog.isShowing()) { if (ygoDialog != null && !ygoDialog.isShowing()) {
ygoDialog.show(); ygoDialog.show();
} }
} }
...@@ -431,27 +458,4 @@ public class YGODialogUtil { ...@@ -431,27 +458,4 @@ public class YGODialogUtil {
} }
public static void dialogDeckSelect(Context context, String selectDeckPath, OnDeckMenuListener onDeckMenuListener) {
ViewHolder viewHolder = new ViewHolder(context, selectDeckPath, onDeckMenuListener);
viewHolder.show();
}
public interface OnDeckMenuListener {
void onDeckSelect(DeckFile deckFile);
void onDeckDel(List<DeckFile> deckFileList);
void onDeckMove(List<DeckFile> deckFileList, DeckType toDeckType);
void onDeckCopy(List<DeckFile> deckFileList, DeckType toDeckType);
void onDeckNew(DeckType currentDeckType);
}
public interface OnDeckTypeListener {
void onDeckTypeListener(int position);
}
} }
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