Commit 987d00f8 authored by fallenstardust's avatar fallenstardust

删除我的云卡组后禁用刷新按钮3秒

移除无用布局
parent 5f735674
package cn.garymb.ygomobile.deck_square; package cn.garymb.ygomobile.deck_square;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
...@@ -9,6 +12,8 @@ import androidx.annotation.NonNull; ...@@ -9,6 +12,8 @@ import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.GridLayoutManager;
import com.google.android.material.snackbar.Snackbar;
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.deck_square.api_response.LoginResponse; import cn.garymb.ygomobile.deck_square.api_response.LoginResponse;
...@@ -25,7 +30,7 @@ import cn.garymb.ygomobile.utils.YGOUtil; ...@@ -25,7 +30,7 @@ import cn.garymb.ygomobile.utils.YGOUtil;
//打开页面后,先扫描本地的卡组,读取其是否包含deckId,是的话代表平台上可能有 //打开页面后,先扫描本地的卡组,读取其是否包含deckId,是的话代表平台上可能有
//之后读取平台上的卡组,与本地卡组列表做比较。 //之后读取平台上的卡组,与本地卡组列表做比较。
public class DeckSquareMyDeckFragment extends Fragment { public class DeckSquareMyDeckFragment extends Fragment implements MyDeckListAdapter.OnDeckDeleteListener{
private static final String TAG = DeckSquareListAdapter.class.getSimpleName(); private static final String TAG = DeckSquareListAdapter.class.getSimpleName();
private FragmentDeckSquareMyDeckBinding binding; private FragmentDeckSquareMyDeckBinding binding;
private MyDeckListAdapter deckListAdapter; private MyDeckListAdapter deckListAdapter;
...@@ -92,7 +97,8 @@ public class DeckSquareMyDeckFragment extends Fragment { ...@@ -92,7 +97,8 @@ public class DeckSquareMyDeckFragment extends Fragment {
onDeckMenuListener.onDeckSelect(deckFile); onDeckMenuListener.onDeckSelect(deckFile);
} }
); );
// 设置删除监听器
deckListAdapter.setOnDeckDeleteListener(this);
return binding.getRoot(); return binding.getRoot();
} }
...@@ -148,4 +154,24 @@ public class DeckSquareMyDeckFragment extends Fragment { ...@@ -148,4 +154,24 @@ public class DeckSquareMyDeckFragment extends Fragment {
}); });
} }
@Override
public void onDeckDeleteStarted() {
binding.refreshData.setEnabled(false);
// 设置灰色滤镜
binding.refreshData.setColorFilter(Color.GRAY, PorterDuff.Mode.SRC_IN);
}
@Override
public void onDeckDeleteProgress(int secondsRemaining) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
binding.refreshData.setTooltipText(secondsRemaining+"s waiting");
}
}
@Override
public void onDeckDeleteFinished() {
binding.refreshData.setEnabled(true);
// 移除滤镜,恢复原颜色
binding.refreshData.clearColorFilter();
}
} }
package cn.garymb.ygomobile.deck_square; package cn.garymb.ygomobile.deck_square;
import android.os.CountDownTimer;
import android.util.Log; import android.util.Log;
import android.widget.ImageView; import android.widget.ImageView;
...@@ -13,16 +14,20 @@ import java.util.List; ...@@ -13,16 +14,20 @@ import java.util.List;
import cn.garymb.ygomobile.deck_square.api_response.LoginToken; import cn.garymb.ygomobile.deck_square.api_response.LoginToken;
import cn.garymb.ygomobile.deck_square.api_response.MyDeckResponse; import cn.garymb.ygomobile.deck_square.api_response.MyDeckResponse;
import cn.garymb.ygomobile.deck_square.api_response.MyOnlineDeckDetail; import cn.garymb.ygomobile.deck_square.api_response.MyOnlineDeckDetail;
import cn.garymb.ygomobile.deck_square.api_response.PushDeckResponse;
import cn.garymb.ygomobile.lite.R; import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.loader.ImageLoader; import cn.garymb.ygomobile.loader.ImageLoader;
import cn.garymb.ygomobile.ui.plus.DialogPlus; import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.ui.plus.VUiKit; import cn.garymb.ygomobile.ui.plus.VUiKit;
import cn.garymb.ygomobile.utils.LogUtil; import cn.garymb.ygomobile.utils.LogUtil;
import cn.garymb.ygomobile.utils.YGOUtil;
//提供“我的”卡组数据,打开后先从sharePreference查询,没有则从服务器查询,然后缓存到sharePreference //提供“我的”卡组数据,打开后先从sharePreference查询,没有则从服务器查询,然后缓存到sharePreference
public class MyDeckListAdapter extends BaseQuickAdapter<MyDeckItem, BaseViewHolder> { public class MyDeckListAdapter extends BaseQuickAdapter<MyDeckItem, BaseViewHolder> {
private static final String TAG = DeckSquareListAdapter.class.getSimpleName(); private static final String TAG = DeckSquareListAdapter.class.getSimpleName();
private ImageLoader imageLoader; private ImageLoader imageLoader;
// 添加监听器变量
private OnDeckDeleteListener deleteListener;
public MyDeckListAdapter(int layoutResId) { public MyDeckListAdapter(int layoutResId) {
super(layoutResId); super(layoutResId);
...@@ -30,10 +35,41 @@ public class MyDeckListAdapter extends BaseQuickAdapter<MyDeckItem, BaseViewHold ...@@ -30,10 +35,41 @@ public class MyDeckListAdapter extends BaseQuickAdapter<MyDeckItem, BaseViewHold
imageLoader = new ImageLoader(); imageLoader = new ImageLoader();
} }
public void loadData() { // 在MyDeckListAdapter中添加接口
List<MyDeckItem> myOnlieDecks = new ArrayList<>(); public interface OnDeckDeleteListener {
void onDeckDeleteStarted();
void onDeckDeleteProgress(int secondsRemaining);
void onDeckDeleteFinished();
}
// 添加设置监听器的方法
public void setOnDeckDeleteListener(OnDeckDeleteListener listener) {
this.deleteListener = listener;
}
private void startButtonCountdown() {
final int countdownSeconds = 3;
new CountDownTimer(countdownSeconds * 1000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
int secondsLeft = (int) (millisUntilFinished / 1000);
if (deleteListener != null) {
deleteListener.onDeckDeleteProgress(secondsLeft);
}
}
@Override
public void onFinish() {
if (deleteListener != null) {
deleteListener.onDeckDeleteFinished();
}
}
}.start();
}
public void loadData() {
List<MyDeckItem> myOnlineDecks = new ArrayList<>();
LoginToken loginToken = DeckSquareApiUtil.getLoginData(); LoginToken loginToken = DeckSquareApiUtil.getLoginData();
if (loginToken == null) { if (loginToken == null) {
return; return;
...@@ -70,13 +106,13 @@ public class MyDeckListAdapter extends BaseQuickAdapter<MyDeckItem, BaseViewHold ...@@ -70,13 +106,13 @@ public class MyDeckListAdapter extends BaseQuickAdapter<MyDeckItem, BaseViewHold
item.setDeckId(detail.getDeckId()); item.setDeckId(detail.getDeckId());
item.setUserId(detail.getUserId()); item.setUserId(detail.getUserId());
item.setUpdateDate(detail.getDeckUpdateDate()); item.setUpdateDate(detail.getDeckUpdateDate());
myOnlieDecks.add(item); myOnlineDecks.add(item);
} }
} }
LogUtil.i(TAG, "load mycard from server done"); LogUtil.i(TAG, "load mycard from server done");
getData().clear(); getData().clear();
addData(myOnlieDecks); addData(myOnlineDecks);
notifyDataSetChanged(); notifyDataSetChanged();
if (dialog_read_ex.isShowing()) { if (dialog_read_ex.isShowing()) {
...@@ -89,21 +125,50 @@ public class MyDeckListAdapter extends BaseQuickAdapter<MyDeckItem, BaseViewHold ...@@ -89,21 +125,50 @@ public class MyDeckListAdapter extends BaseQuickAdapter<MyDeckItem, BaseViewHold
} }
private static Boolean isMonster(List<String> list) { private void deleteMyDeckOnLine(MyDeckItem item) {
for (String data : list) { if (deleteListener != null) {
if (data.equals("怪兽")) { deleteListener.onDeckDeleteStarted();
return true; }
if (item != null) {
item.getDeckId();
LoginToken loginToken = DeckSquareApiUtil.getLoginData();
if (loginToken == null) {
return;
} }
VUiKit.defer().when(() -> {
PushDeckResponse result = DeckSquareApiUtil.deleteDeck(item.getDeckId(), loginToken);
return result;
}).fail(e -> {
if (deleteListener != null) {
deleteListener.onDeckDeleteFinished();
}
LogUtil.i(TAG, "square deck detail fail" + e.getMessage());
}).done(data -> {
if (data.isData()) {
/*
*服务器的api有问题:获取指定用户的卡组列表(无已删卡组)
*删除成功后,通过http://rarnu.xyz:38383/api/mdpro3/sync/795610/nodel接口查询用户卡组时
*要等待2~3秒api响应内容才会对应更新
*/
YGOUtil.showTextToast("删除成功,3秒后服务器将完成同步");
remove(item);
// 开始倒计时
startButtonCountdown();
} else {
if (deleteListener != null) {
deleteListener.onDeckDeleteFinished();
}
YGOUtil.showTextToast("delete fail " + data.getMessage());
}
});
} }
return false;
} }
@Override @Override
protected void convert(BaseViewHolder helper, MyDeckItem item) { protected void convert(BaseViewHolder helper, MyDeckItem item) {
helper.setText(R.id.my_deck_name, item.getDeckName()); helper.setText(R.id.my_deck_name, item.getDeckName());
//helper.setText(R.id.deck_upload_date, item.getDeckUploadDate());
//ImageView imageView = helper.getView(R.id.deck_upload_state_img);
helper.setText(R.id.deck_update_date, item.getUpdateDate()); helper.setText(R.id.deck_update_date, item.getUpdateDate());
ImageView cardImage = helper.getView(R.id.deck_info_image); ImageView cardImage = helper.getView(R.id.deck_info_image);
long code = item.getDeckCoverCard1(); long code = item.getDeckCoverCard1();
...@@ -114,6 +179,7 @@ public class MyDeckListAdapter extends BaseQuickAdapter<MyDeckItem, BaseViewHold ...@@ -114,6 +179,7 @@ public class MyDeckListAdapter extends BaseQuickAdapter<MyDeckItem, BaseViewHold
imageLoader.bindImage(cardImage, -1, null, ImageLoader.Type.small); imageLoader.bindImage(cardImage, -1, null, ImageLoader.Type.small);
} }
helper.getView(R.id.delete_my_online_deck_btn).setOnClickListener(view -> { deleteMyDeckOnLine(item); });
// else if (item.getDeckSouce() == 1) { // else if (item.getDeckSouce() == 1) {
// helper.setText(R.id.my_deck_id, item.getDeckId()); // helper.setText(R.id.my_deck_id, item.getDeckId());
// imageView.setImageResource(R.drawable.ic_server_download); // imageView.setImageResource(R.drawable.ic_server_download);
......
<?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:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/label_limitlist"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@color/blackLinght" />
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/sp_limit_list"
android:layout_width="match_parent"
android:layout_height="@dimen/item_height" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/deck_list"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@color/blackLinght" />
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/sp_ydk_list"
android:layout_width="match_parent"
android:layout_height="@dimen/item_height" />
</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="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:gravity="center"
android:text="Login"
android:textSize="20sp"
android:textStyle="bold" />
<EditText
android:id="@+id/et_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:hint="Username"
android:inputType="text" />
<EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:hint="Password"
android:inputType="textPassword" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<Button
android:id="@+id/btn_cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_weight="1"
android:text="Cancel" />
<Button
android:id="@+id/btn_login"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_weight="1"
android:backgroundTint="@color/colorPrimary"
android:text="Login" />
</LinearLayout>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_deck_cards"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="left"
android:orientation="vertical"
android:paddingLeft="4dp"
android:paddingTop="2dp"
android:paddingRight="5dp">
<Button
android:id="@+id/mc_login_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="登录" />
<Button
android:id="@+id/mc_logout_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="注销" />
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
</LinearLayout> </LinearLayout>
<ImageView <ImageView
android:id="@+id/delete_my_online_deck_btn"
android:layout_width="15dp" android:layout_width="15dp"
android:layout_height="15dp" android:layout_height="15dp"
android:layout_gravity="end" android:layout_gravity="end"
......
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