Commit 66e262ec authored by fallenstardust's avatar fallenstardust

统一在cardsearcher初始化limitlistspinner设置触摸监听

parent 95d97598
...@@ -215,7 +215,7 @@ public class CardSearchFragment extends BaseFragemnt implements CardLoader.CallB ...@@ -215,7 +215,7 @@ public class CardSearchFragment extends BaseFragemnt implements CardLoader.CallB
mCardListAdapter.set(cardInfos); mCardListAdapter.set(cardInfos);
mResult_count.setText(String.valueOf(cardInfos.size())); mResult_count.setText(String.valueOf(cardInfos.size()));
mCardListAdapter.notifyDataSetChanged(); mCardListAdapter.notifyDataSetChanged();
if (cardInfos.size() > 0) { if (!cardInfos.isEmpty()) {
mListView.smoothScrollToPosition(0); mListView.smoothScrollToPosition(0);
} }
} }
......
...@@ -5,6 +5,7 @@ import android.content.Context; ...@@ -5,6 +5,7 @@ import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
...@@ -68,7 +69,7 @@ public class CardSearcher implements View.OnClickListener { ...@@ -68,7 +69,7 @@ public class CardSearcher implements View.OnClickListener {
private final Button resetButton; private final Button resetButton;
private final View view; private final View view;
private final View layout_monster; private final View layout_monster;
private final ICardSearcher mICardSearcher; private final ICardSearcher mICardSearcher;// ICardSearcher 即为CardLoader的接口;
private final Context mContext; private final Context mContext;
private final Button myFavButton; private final Button myFavButton;
protected StringManager mStringManager; protected StringManager mStringManager;
...@@ -218,6 +219,12 @@ public class CardSearcher implements View.OnClickListener { ...@@ -218,6 +219,12 @@ public class CardSearcher implements View.OnClickListener {
} }
}); });
limitListSpinner.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
refreshLimitListSpinnerItems(limitListSpinner);
}
return false; // 返回false以允许正常的spinner行为继续
});
typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
...@@ -294,9 +301,7 @@ public class CardSearcher implements View.OnClickListener { ...@@ -294,9 +301,7 @@ public class CardSearcher implements View.OnClickListener {
mCallBack.onSearchStart(); mCallBack.onSearchStart();
} }
if (reload) { if (reload) {
VUiKit.post(() -> { VUiKit.post(this::search);
search();
});
} else { } else {
if (mCallBack != null) { if (mCallBack != null) {
VUiKit.post(() -> { VUiKit.post(() -> {
...@@ -429,6 +434,52 @@ public class CardSearcher implements View.OnClickListener { ...@@ -429,6 +434,52 @@ public class CardSearcher implements View.OnClickListener {
} }
} }
private void refreshLimitListSpinnerItems(Spinner spinner) {
int index = 0;
int old_count = 0;
// 首先清除所有现有的item
if (spinner.getAdapter() != null && spinner.getAdapter() instanceof SimpleSpinnerAdapter) {
// 清除前先记录下当前选中项的索引
index = spinner.getSelectedItemPosition();
//清除前先记录下当前选项总数量
old_count = spinner.getCount();
//清空选项
((SimpleSpinnerAdapter) spinner.getAdapter()).clear();
//重新加载禁卡表,获取可能存在的变动后情况
mLimitManager.load();
}
List<SimpleSpinnerItem> items = new ArrayList<>();
List<String> limitLists = mLimitManager.getLimitNames();
int limit_count = mLimitManager.getCount();
// 添加默认选项
items.add(new SimpleSpinnerItem(0, getString(R.string.label_limitlist)));
// 遍历所有限制列表,构建下拉项
for (int i = 0; i < limit_count; i++) {
int j = i + 1;
String name = limitLists.get(i);
items.add(new SimpleSpinnerItem(j, name));
}
// 设置适配器
SimpleSpinnerAdapter adapter = new SimpleSpinnerAdapter(mContext);
adapter.setColor(Color.WHITE);
adapter.set(items);
spinner.setAdapter(adapter);
// 禁卡表变化时,相应调整index
index += spinner.getCount() - old_count;
if (index >= 0) {
spinner.setSelection(index);
}
// 不设置监听器,避免通知整个布局变化,降低性能占用,只在initLimitListSpinners执行后另行设置
}
private void initPscaleSpinners(Spinner spinner) { private void initPscaleSpinners(Spinner spinner) {
List<SimpleSpinnerItem> items = new ArrayList<>(); List<SimpleSpinnerItem> items = new ArrayList<>();
for (int i = -1; i <= 13; i++) { for (int i = -1; i <= 13; i++) {
......
...@@ -1620,16 +1620,6 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -1620,16 +1620,6 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
} }
}); });
spinner.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
// 刷新spinner
refreshLimitListSpinnerItems(spinner);
}
return false;
}
});
} }
/** /**
......
...@@ -89,7 +89,7 @@ public class LimitManager implements Closeable { ...@@ -89,7 +89,7 @@ public class LimitManager implements Closeable {
File[] files = AppsSettings.get().getExpansionsPath().listFiles(); File[] files = AppsSettings.get().getExpansionsPath().listFiles();
if (files != null) { if (files != null) {
for (File file : files) { for (File file : files) {
// 1.读取扩展卡压缩包中的lflist.conf文件 // 1.读取expansions文件夹中压缩包中的名字包含lflist、.conf文件
if (file.isFile() && (file.getName().endsWith(".zip") || file.getName().endsWith(Constants.YPK_FILE_EX))) { if (file.isFile() && (file.getName().endsWith(".zip") || file.getName().endsWith(Constants.YPK_FILE_EX))) {
Log.e("LimitManager", "读取压缩包"); Log.e("LimitManager", "读取压缩包");
try { try {
...@@ -109,6 +109,7 @@ public class LimitManager implements Closeable { ...@@ -109,6 +109,7 @@ public class LimitManager implements Closeable {
default_res3 = false; default_res3 = false;
} }
} }
// 2.读取扩展卡文件夹中的名字包含lflist、.conf文件
if (file.isFile() && file.getName().contains("lflist") && file.getName().endsWith(".conf")) { if (file.isFile() && file.getName().contains("lflist") && file.getName().endsWith(".conf")) {
expansion_rs2 = loadFile(file); expansion_rs2 = loadFile(file);
} }
...@@ -119,11 +120,12 @@ public class LimitManager implements Closeable { ...@@ -119,11 +120,12 @@ public class LimitManager implements Closeable {
// 3.加载主资源路径(ygocore文件夹)下的lflist.conf文件对象,这是内置默认文件 // 3.加载主资源路径(ygocore文件夹)下的lflist.conf文件对象,这是内置默认文件
File ygocore_lflist = new File(AppsSettings.get().getResourcePath(), Constants.CORE_LIMIT_PATH); File ygocore_lflist = new File(AppsSettings.get().getResourcePath(), Constants.CORE_LIMIT_PATH);
default_res3 = loadFile(ygocore_lflist); default_res3 = loadFile(ygocore_lflist);
LimitList blank_list = new LimitList("N/A");
mLimitLists.put("N/A", blank_list); // 4.添加一个空卡表N/A(为了和ygopro显示一致才这么写) 无禁限
mLimitLists.put("N/A", new LimitList("N/A"));
mLimitNames.add("N/A"); mLimitNames.add("N/A");
++mCount; ++mCount;
Log.e("LimitManager加载情况", "rs1=" + expansion_zip_rs1 + " rs2=" + expansion_rs2 + " res3=" + default_res3);
return expansion_zip_rs1 && expansion_rs2 && default_res3; return expansion_zip_rs1 && expansion_rs2 && default_res3;
} }
......
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