Commit a8d84944 authored by fallenstardust's avatar fallenstardust

为mydecklistAdapter添加监听

parent 8336ab66
package cn.garymb.ygomobile.deck_square;
import android.util.Log;
import android.widget.Toast;
import com.google.gson.Gson;
......@@ -156,7 +155,7 @@ public class DeckSquareApiUtil {
* 阻塞方法,用于推送新卡组。首先从服务器请求一个新的卡组id,之后将卡组上传到服务器
* 先同步推送,之后异步推送。首先调用服务端api获取卡组id,之后将卡组id设置到ydk中,之后调用服务器api将卡组上传
*
* @param deckfile
* @param deckFile
* @param loginToken
*/
public static PushDeckResponse requestIdAndPushDeck(DeckFile deckFile, LoginToken loginToken) throws IOException {
......@@ -174,13 +173,13 @@ public class DeckSquareApiUtil {
Gson gson = new Gson();
DeckIdResponse deckIdResult = null;
{
Response response = OkhttpUtil.synchronousGet(getDeckIdUrl, null, headers);
String responseBodyString = response.body().string();
// Convert JSON to Java object using Gson
deckIdResult = gson.fromJson(responseBodyString, DeckIdResponse.class);
LogUtil.i(TAG, "deck id result:" + deckIdResult.toString());
}
Response response = OkhttpUtil.synchronousGet(getDeckIdUrl, null, headers);
String responseBodyString = response.body().string();
// Convert JSON to Java object using Gson
deckIdResult = gson.fromJson(responseBodyString, DeckIdResponse.class);
LogUtil.i(TAG, "deck id result:" + deckIdResult.toString());
if (deckIdResult == null) {
return null;
......
......@@ -58,7 +58,7 @@ public class DeckSquareMyDeckFragment extends Fragment {
}
binding.btnLogin.setOnClickListener(v -> attemptLogin());
binding.btnRegister.setOnClickListener(v -> WebActivity.open(getContext(), getString(R.string.register), MyCard.URL_MC_SIGN_UP));
deckListAdapter = new MyDeckListAdapter(R.layout.item_my_deck);
deckListAdapter = new MyDeckListAdapter(R.layout.item_my_deck, onDeckMenuListener, mDialogListener);
GridLayoutManager linearLayoutManager = new GridLayoutManager(getContext(), 3);
binding.listMyDeckInfo.setLayoutManager(linearLayoutManager);
binding.listMyDeckInfo.setAdapter(deckListAdapter);
......
......@@ -21,18 +21,23 @@ import cn.garymb.ygomobile.loader.ImageLoader;
import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.ui.plus.VUiKit;
import cn.garymb.ygomobile.utils.LogUtil;
import cn.garymb.ygomobile.utils.YGODeckDialogUtil;
import cn.garymb.ygomobile.utils.YGOUtil;
//提供“我的”卡组数据,打开后先从sharePreference查询,没有则从服务器查询,然后缓存到sharePreference
public class MyDeckListAdapter extends BaseQuickAdapter<MyDeckItem, BaseViewHolder> {
private static final String TAG = DeckSquareListAdapter.class.getSimpleName();
private YGODeckDialogUtil.OnDeckMenuListener onDeckMenuListener;//通知外部调用方,(如调用本fragment的activity)
private YGODeckDialogUtil.OnDeckDialogListener mDialogListener;
private ImageLoader imageLoader;
private List<MyDeckItem> originalData; // 保存原始数据
public MyDeckListAdapter(int layoutResId) {
public MyDeckListAdapter(int layoutResId, YGODeckDialogUtil.OnDeckMenuListener onDeckMenuListener, YGODeckDialogUtil.OnDeckDialogListener mDialogListener) {
super(layoutResId);
originalData = new ArrayList<>();
imageLoader = new ImageLoader();
this.onDeckMenuListener = onDeckMenuListener;
this.mDialogListener = mDialogListener;
}
public void loadData() {
......@@ -203,7 +208,8 @@ public class MyDeckListAdapter extends BaseQuickAdapter<MyDeckItem, BaseViewHold
//TODO
//点击“我的卡组”中的某个卡组后,弹出dialog,dialog根据卡组的同步情况自动显示对应的下载/上传按钮
DeckFile deckFile = new DeckFile(item.getDeckId(), DeckType.ServerType.MY_SQUARE);
mDialogListener.onDismiss();
onDeckMenuListener.onDeckSelect(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