Commit a58c013d authored by feihuaduo's avatar feihuaduo

分享卡组时取消排序

分享卡组操作优化
卡组管理
parent 1cb1cf93
......@@ -104,8 +104,8 @@ dependencies {
//
implementation(name: 'paysdk-release-1.2.4', ext: 'aar')
implementation "com.pgyersdk:sdk:3.0.5"
//dialog库
implementation 'com.github.feihuaduo:DialogUtils:1.8.9'
//recyclerview的adapter库
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30'
}
......@@ -8,7 +8,7 @@ public class DeckType extends TextSelect {
this.name = name;
this.path = path;
super.setName(name);
super.setObject(this);
setObject(this);
}
public String getName() {
......
package cn.garymb.ygomobile.bean.events;
import androidx.annotation.Nullable;
import java.io.File;
import cn.garymb.ygomobile.bean.TextSelect;
......@@ -14,13 +16,15 @@ public class DeckFile extends TextSelect {
name=new File(path).getName();
name=name.substring(0,name.lastIndexOf("."));
super.setName(name);
super.setObject(this);
setObject(this);
}
public DeckFile(File file) {
path=file.getAbsolutePath();
name=file.getName();
name=name.substring(0,name.lastIndexOf("."));
super.setName(name);
setObject(this);
}
public String getName() {
......@@ -38,4 +42,5 @@ public class DeckFile extends TextSelect {
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 com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import java.util.ArrayList;
import java.util.List;
import cn.garymb.ygomobile.bean.TextSelect;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.utils.YGOUtil;
public class TextSelectAdapter extends RecyclerView.Adapter<TextSelectAdapter.ViewHolder> {
public class TextSelectAdapter<T extends TextSelect> extends BaseQuickAdapter<T, BaseViewHolder> {
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() {
private boolean isSelect;
private boolean isManySelect;
private List<T> selectList;
public TextSelectAdapter(List<T> data, int select) {
super(R.layout.text_select_item, data);
this.selectPosition = select;
if (select >= 0)
isSelect = true;
else
isSelect = false;
isManySelect = false;
selectList = new ArrayList<>();
setOnItemClickListener(new OnItemClickListener() {
@Override
public void onClick(View v) {
if (position==selectPosition)
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
if (isSelect && position == selectPosition)
return;
selectPosition = position;
notifyDataSetChanged();
if (onItemSelectListener != null)
onItemSelectListener.onItemSelect(position, data.get(position).getObject());
}
});
}
public void setOnItemSelectListener(OnItemSelectListener onItemSelectListener) {
this.onItemSelectListener = onItemSelectListener;
@Override
protected void convert(BaseViewHolder helper, T item) {
int position = helper.getAdapterPosition();
helper.setText(R.id.tv_name, item.getName());
if (isManySelect) {
if (selectList.contains(item))
helper.setBackgroundColor(R.id.ll_layout, YGOUtil.c(R.color.gray));
else
helper.setBackgroundRes(R.id.ll_layout, R.drawable.click_background);
} else if (isSelect) {
if (position == selectPosition) {
helper.setBackgroundColor(R.id.ll_layout, YGOUtil.c(R.color.gray));
} else {
helper.setBackgroundRes(R.id.ll_layout, R.drawable.click_background);
}
}else {
helper.setBackgroundRes(R.id.ll_layout, R.drawable.click_background);
}
@Override
public int getItemCount() {
return data.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
public void setSelectPosition(int selectPosition) {
this.selectPosition = selectPosition;
}
public boolean isSelect() {
return isSelect;
}
public boolean isManySelect() {
return isManySelect;
}
public void addManySelect(T t) {
if (selectList.contains(t))
selectList.remove(t);
else
selectList.add(t);
}
View view;
TextView tv_name;
public void setManySelect(boolean manySelect) {
isManySelect = manySelect;
if (!isManySelect) {
selectList.clear();
notifyDataSetChanged();
}
}
public List<T> getSelectList() {
return selectList;
}
public ViewHolder(View view) {
super(view);
this.view = view;
this.tv_name = view.findViewById(R.id.tv_name);
public int getSelectPosition() {
return selectPosition;
}
public void setOnItemSelectListener(OnItemSelectListener onItemSelectListener) {
this.onItemSelectListener = onItemSelectListener;
}
public interface OnItemSelectListener<T> {
......
......@@ -66,7 +66,7 @@ public class ChatAdapter extends RecyclerView.Adapter<ChatAdapter.ViewHolder> {
vh.ic_name.setText(cm.getName());
//vh.ic_time.setText(cm.getTime());
vh.ic_message.setText(cm.getMessage());
ImageUtil.tuxian(context, cm.getAvatar(), vh.ic_avatar);
ImageUtil.setAvatar(context, cm.getAvatar(), vh.ic_avatar);
if (position != 0) {
if (cm.getName().equals(data.get(position - 1).getName())) {
vh.ic_name.setVisibility(View.GONE);
......
package cn.garymb.ygomobile.ui.mycard.mcchat.util;
import android.content.Context;
import android.graphics.ColorFilter;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.net.Uri;
import android.util.Log;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import java.util.HashMap;
import java.util.Map;
import cn.garymb.ygomobile.lite.R;
public class ImageUtil {
public static void tuxian(Context context, String url, final ImageView im) {
public static void setAvatar(Context context, String url, final ImageView im) {
if (url != null) {
Glide.with(context)
.load(Uri.parse(url))
......@@ -21,4 +29,28 @@ public class ImageUtil {
}
}
public static void setImage(Context context, String url, final ImageView im) {
if (url != null) {
Glide.with(context)
.load(url)
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.placeholder(R.drawable.unknown)
.into(im);
}
}
public static void setGrayImage(int key, ImageView imageView) {
ColorMatrix matrix = new ColorMatrix();
matrix.setSaturation(0);
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
imageView.setColorFilter(filter);
}
public static void reImageColor(int key,ImageView imageView) {
imageView.setColorFilter(null);
}
}
......@@ -40,6 +40,7 @@ import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.ui.plus.ServiceDuelAssistant;
import cn.garymb.ygomobile.ui.plus.VUiKit;
import cn.garymb.ygomobile.ui.preference.PreferenceFragmentPlus;
import cn.garymb.ygomobile.utils.FileUtils;
import cn.garymb.ygomobile.utils.IOUtils;
import cn.garymb.ygomobile.utils.SystemUtils;
import ocgcore.ConfigManager;
......@@ -402,7 +403,7 @@ public class SettingFragment extends PreferenceFragmentPlus {
process.waitFor();
IOUtils.delete(soFile);
IOUtils.copyFile(file, soFile.getAbsolutePath(), true);
FileUtils.copyFile(file, soFile.getAbsolutePath(), true);
me.what = COPY_SO_OK;
} catch (Exception e) {
e.printStackTrace();
......
......@@ -3,6 +3,7 @@ package cn.garymb.ygomobile.utils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
......@@ -114,6 +115,54 @@ public class FileUtils {
}
}
public static void copyFile(String oldPath, String newPath, boolean isName) throws FileNotFoundException, 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;
while ((len = fis.read(buf)) != -1) {
fos.write(buf, 0, len);
}
fos.close();
fis.close();
}
public static void moveFile(String oldPath, String newPath, boolean isName) throws FileNotFoundException, 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;
while ((len = fis.read(buf)) != -1) {
fos.write(buf, 0, len);
}
fos.close();
fis.close();
//删除文件
File file=new File(oldPath);
if (file.exists() && file.isFile()) {
file.delete();
}
}
public static void copy(InputStream in, OutputStream out) throws IOException {
byte[] data = new byte[1024 * 8];
int len;
......
......@@ -225,26 +225,6 @@ public class IOUtils {
return false;
}
public static void copyFile(String oldPath, String newPath, boolean isname) throws FileNotFoundException, 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;
while ((len = fis.read(buf)) != -1) {
fos.write(buf, 0, len);
}
fos.close();
fis.close();
}
public static File asFile(InputStream is, String outPath) throws IOException {
OutputStream os = null;
......
......@@ -5,6 +5,7 @@ import android.widget.Toast;
import androidx.core.content.ContextCompat;
import cn.garymb.ygomobile.App;
import cn.garymb.ygomobile.lite.R;
public class YGOUtil {
......@@ -16,4 +17,7 @@ public class YGOUtil {
public static int c(int colorId){
return ContextCompat.getColor(App.get(),colorId);
}
public static String s(int stringId){
return App.get().getResources().getString(stringId);
}
}
package cn.garymb.ygomobile.utils.recyclerview;
import android.content.DialogInterface;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import cn.garymb.ygomobile.bean.DeckType;
import cn.garymb.ygomobile.bean.events.DeckFile;
import cn.garymb.ygomobile.ui.adapters.TextSelectAdapter;
import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.utils.IOUtils;
import cn.garymb.ygomobile.utils.YGODialogUtil;
import cn.garymb.ygomobile.utils.YGOUtil;
public class DeckTypeTouchHelperCallback extends ItemTouchHelper.Callback {
private int dragFlags;
private int swipeFlags;
private RecyclerView recyclerView;
private YGODialogUtil.OnDeckTypeListener onDeckTypeListener;
public DeckTypeTouchHelperCallback(YGODialogUtil.OnDeckTypeListener onDeckTypeListener) {
this.onDeckTypeListener = onDeckTypeListener;
}
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder p2) {
dragFlags = 0;
swipeFlags = 0;
this.recyclerView = recyclerView;
if (p2.getAdapterPosition() > 2)
swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
return makeMovementFlags(dragFlags, swipeFlags);
}
@Override
public boolean onMove(RecyclerView p1, RecyclerView.ViewHolder p2, RecyclerView.ViewHolder p3) {
return false;
}
@Override
public void onSwiped(RecyclerView.ViewHolder vh, int dire) {
int positon = vh.getAdapterPosition();
TextSelectAdapter textSelectAdapter = ((TextSelectAdapter) recyclerView.getAdapter());
DialogPlus dialogPlus = new DialogPlus(recyclerView.getContext());
dialogPlus.setMessage("确定删除该分类吗?分类下的卡组也将全部被删除");
dialogPlus.setLeftButtonText("删除");
dialogPlus.setRightButtonText("取消");
dialogPlus.setLeftButtonListener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialogPlus.dismiss();
onDeckTypeListener.onDeckTypeListener(positon);
}
});
dialogPlus.setRightButtonListener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
textSelectAdapter.notifyItemChanged(positon);
dialog.dismiss();
}
});
dialogPlus.show();
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:padding="10dp"
android:text="卡组管理"
android:textColor="@color/black"
android:textSize="15sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/ll_add"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/click_background"
android:gravity="center"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_add"
android:layout_width="30dp"
android:layout_height="30dp"
app:srcCompat="@drawable/ic_add" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="新建"
android:textColor="@color/black"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_move"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/click_background"
android:gravity="center"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_move"
android:layout_width="30dp"
android:layout_height="30dp"
app:srcCompat="@drawable/ic_move" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_move"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="移动"
android:textColor="@color/black"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_copy"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/click_background"
android:gravity="center"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_copy"
android:layout_width="30dp"
android:layout_height="30dp"
app:srcCompat="@drawable/ic_copy" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_copy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="复制"
android:textColor="@color/black"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_del"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/click_background"
android:gravity="center"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_del"
android:layout_width="30dp"
android:layout_height="30dp"
app:srcCompat="@drawable/ic_del" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_del"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="删除"
android:textColor="@color/black"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
......@@ -13,17 +133,26 @@
android:id="@+id/rv_type"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
android:layout_weight="1"
android:nestedScrollingEnabled="false" />
<View
android:background="@color/gray"
android:layout_width="1dp"
android:layout_height="match_parent"/>
android:layout_height="match_parent"
android:background="@color/gray" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_deck"
android:layout_width="0dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2" />
android:nestedScrollingEnabled="true" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/share_deck"
android:textColor="@color/black"
android:textSize="23sp"
android:textStyle="bold" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_image"
android:layout_width="140dp"
android:layout_height="280dp"
android:layout_marginTop="20dp"
android:scaleType="centerCrop" />
<Button
android:id="@+id/bt_image_share"
android:layout_marginTop="20dp"
android:textSize="15sp"
android:text="图片分享"
android:layout_width="140dp"
android:layout_height="50dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="20dp">
<androidx.appcompat.widget.AppCompatEditText
android:textColor="@color/black"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:id="@+id/et_code"
android:gravity="center"
android:textSize="16sp"
android:inputType="text"
android:background="@color/gray"
android:padding="10dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent" />
<Button
android:id="@+id/bt_code_share"
android:textSize="15sp"
android:text="卡组码分享"
android:layout_marginLeft="20dp"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:gravity="center"
android:background="@drawable/click_background"
......
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