Commit da056f6b authored by noname's avatar noname

dialogDeckSelect

parent f77175cc
......@@ -167,22 +167,10 @@ public class FileUtils {
}
public static void copyFile(String oldPath, String newPath) throws IOException {
copyFile(oldPath, newPath, true);
}
public static void copyFile(String oldPath, String newPath, boolean isName) throws IOException {
//判断复制后的路径是否含有文件名,如果没有则加上
if (!isName) {
//由于newPath是路径加文件名,所以获取要复制的文件名与复制后的路径组成新的newPath
String abb[] = oldPath.split("/");
newPath = newPath + "/" + abb[abb.length - 1];
}
FileInputStream fis = new FileInputStream(oldPath);
FileOutputStream fos = new FileOutputStream(newPath);
byte[] buf = new byte[1024];
int len = 0;
int len;
while ((len = fis.read(buf)) != -1) {
fos.write(buf, 0, len);
}
......
......@@ -39,20 +39,27 @@ import cn.garymb.ygomobile.utils.recyclerview.DeckTypeTouchHelperCallback;
import static cn.garymb.ygomobile.lite.R.string.please_select_target_category;
public class YGODialogUtil {
private static final int IMAGE_MOVE = 0;
private static final int IMAGE_COPY = 1;
private static final int IMAGE_DEL = 2;
private static LinearLayout ll_move, ll_copy, ll_del, ll_add;
private static ImageView iv_move, iv_copy, iv_del;
private static TextView tv_move, tv_copy, tv_del;
private static TextSelectAdapter typeAdp, deckAdp;
private static Dialog ygoDialog;
public static void dialogDeckSelect(Context context, String selectDeckPath, OnDeckMenuListener onDeckMenuListener) {
DialogUtils du = DialogUtils.getdx(context);
View viewDialog = du.dialogBottomSheet(R.layout.dialog_deck_select, 0);
private static class ViewHolder{
private final int IMAGE_MOVE = 0;
private final int IMAGE_COPY = 1;
private final int IMAGE_DEL = 2;
private final LinearLayout ll_move;
private final LinearLayout ll_copy;
private final LinearLayout ll_del;
private final ImageView iv_move;
private final ImageView iv_copy;
private final ImageView iv_del;
private final TextView tv_move;
private final TextView tv_copy;
private final TextView tv_del;
private final TextSelectAdapter<DeckType> typeAdp;
private final TextSelectAdapter<DeckFile> deckAdp;
private final Dialog ygoDialog;
public ViewHolder(Context context, String selectDeckPath, OnDeckMenuListener onDeckMenuListener){
View viewDialog = DialogUtils.getdx(context).dialogBottomSheet(R.layout.dialog_deck_select, 0);
RecyclerView rv_type, rv_deck;
rv_deck = viewDialog.findViewById(R.id.rv_deck);
......@@ -60,7 +67,7 @@ public class YGODialogUtil {
ll_move = viewDialog.findViewById(R.id.ll_move);
ll_copy = viewDialog.findViewById(R.id.ll_copy);
ll_del = viewDialog.findViewById(R.id.ll_del);
ll_add = viewDialog.findViewById(R.id.ll_add);
LinearLayout ll_add = viewDialog.findViewById(R.id.ll_add);
iv_copy = viewDialog.findViewById(R.id.iv_copy);
iv_move = viewDialog.findViewById(R.id.iv_move);
iv_del = viewDialog.findViewById(R.id.iv_del);
......@@ -141,7 +148,7 @@ public class YGODialogUtil {
deckAdp.addManySelect(item);
deckAdp.notifyItemChanged(position);
} else {
dis();
dismiss();
onDeckMenuListener.onDeckSelect(item);
}
}
......@@ -167,12 +174,12 @@ public class YGODialogUtil {
ll_add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
du.dialogl(context.getString(R.string.new_deck),
DialogUtils.getdx(context).dialogl(context.getString(R.string.new_deck),
new String[]{context.getString(R.string.category_name),
context.getString(R.string.deck_name)}, R.drawable.radius).setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
du.dis();
DialogUtils.getdx(context).dis();
switch (position) {
case 0:
//if (deckList.size()>=8){
......@@ -185,9 +192,7 @@ public class YGODialogUtil {
editText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
editText.setSingleLine();
builder.setContentView(editText);
builder.setOnCloseLinster((dlg) -> {
dlg.dismiss();
});
builder.setOnCloseLinster(DialogInterface::dismiss);
builder.setLeftButtonListener((dlg, s) -> {
String name = editText.getText().toString().trim();
if (TextUtils.isEmpty(name)) {
......@@ -208,7 +213,7 @@ public class YGODialogUtil {
break;
case 1:
onDeckMenuListener.onDeckNew(typeList.get(typeAdp.getSelectPosition()));
dis();
dismiss();
break;
}
}
......@@ -221,12 +226,12 @@ public class YGODialogUtil {
public void onClick(View v) {
List<DeckType> otherType = getOtherTypeList();
du.dialogl(context.getString(please_select_target_category),
DialogUtils.getdx(context).dialogl(context.getString(please_select_target_category),
getStringType(otherType),
R.drawable.radius).setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
du.dis();
DialogUtils.getdx(context).dis();
DeckType toType = otherType.get(position);
IOUtils.createFolder(new File(toType.getPath()));
List<DeckFile> deckFileList = deckAdp.getSelectList();
......@@ -251,12 +256,12 @@ public class YGODialogUtil {
public void onClick(View v) {
List<DeckType> otherType = getOtherTypeList();
du.dialogl(context.getString(please_select_target_category),
DialogUtils.getdx(context).dialogl(context.getString(please_select_target_category),
getStringType(otherType),
R.drawable.radius).setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
du.dis();
DialogUtils.getdx(context).dis();
DeckType toType = otherType.get(position);
IOUtils.createFolder(new File(toType.getPath()));
List<DeckFile> deckFileList = deckAdp.getSelectList();
......@@ -310,7 +315,7 @@ public class YGODialogUtil {
}
});
ygoDialog = du.getDialog();
ygoDialog = DialogUtils.getdx(context).getDialog();
ygoDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
......@@ -358,7 +363,7 @@ public class YGODialogUtil {
itemTouchHelper.attachToRecyclerView(rv_type);
}
private static String[] getStringType(List<DeckType> deckTypeList) {
private String[] getStringType(List<DeckType> deckTypeList) {
String[] types = new String[deckTypeList.size()];
for (int i = 0; i < types.length; i++) {
types[i] = deckTypeList.get(i).getName();
......@@ -367,7 +372,7 @@ public class YGODialogUtil {
}
//获取可以移动的分类
private static List<DeckType> getOtherTypeList() {
private List<DeckType> getOtherTypeList() {
List<DeckType> typeList = typeAdp.getData();
List<DeckType> moveTypeList = new ArrayList<>();
DeckType selectType = typeList.get(typeAdp.getSelectPosition());
......@@ -380,7 +385,7 @@ public class YGODialogUtil {
return moveTypeList;
}
private static void showAllDeckUtil() {
private void showAllDeckUtil() {
ImageUtil.reImageColor(IMAGE_MOVE, iv_move);//可用时用原图标色
ImageUtil.reImageColor(IMAGE_DEL, iv_del);
ImageUtil.reImageColor(IMAGE_COPY, iv_copy);
......@@ -392,7 +397,7 @@ public class YGODialogUtil {
ll_move.setEnabled(true);
}
private static void hideAllDeckUtil() {
private void hideAllDeckUtil() {
ImageUtil.setGrayImage(IMAGE_MOVE, iv_move);
ImageUtil.setGrayImage(IMAGE_DEL, iv_del);
ImageUtil.setGrayImage(IMAGE_COPY, iv_copy);
......@@ -404,7 +409,7 @@ public class YGODialogUtil {
ll_move.setEnabled(false);
}
private static void showCopyDeckUtil() {
private void showCopyDeckUtil() {
ImageUtil.setGrayImage(IMAGE_MOVE, iv_move);
ImageUtil.setGrayImage(IMAGE_DEL, iv_del);
ImageUtil.reImageColor(IMAGE_COPY, iv_copy);
......@@ -416,16 +421,30 @@ public class YGODialogUtil {
ll_move.setEnabled(false);
}
private static void clearDeckSelect() {
private void clearDeckSelect() {
deckAdp.setManySelect(false);
hideAllDeckUtil();
}
public static void dis() {
if (ygoDialog != null)
public void show(){
if(ygoDialog != null && !ygoDialog.isShowing()) {
ygoDialog.show();
}
}
public void dismiss() {
if (ygoDialog != null && ygoDialog.isShowing())
ygoDialog.dismiss();
}
}
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);
......
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