Commit dd5440b9 authored by fallenstardust's avatar fallenstardust Committed by GitHub

Merge pull request #52 from 247321453/master

修复bug,改进游戏
parents e6f5ed58 25d39a8f
......@@ -131,20 +131,17 @@ bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) {
ILogger* logger = device->getLogger();
// logger->setLogLevel(ELL_WARNING);
isPSEnabled = options->isPendulumScaleEnabled();
dataManager.FileSystem = device->getFileSystem();
((CIrrDeviceAndroid*)device)->onAppCmd = onHandleAndroidCommand;
xScale = android::getXScale(app);
yScale = android::getYScale(app);
char log_scale[256] = {0};
sprintf(log_scale, "xScale = %f, yScale = %f", xScale, yScale);
Printer::log(log_scale);
ALOGD("xScale = %f, yScale = %f", xScale, yScale);
//io::path databaseDir = options->getDBDir();
io::path workingDir = options->getWorkDir();
char log_working[256] = {0};
sprintf(log_working, "workingDir= %s", workingDir.c_str());
Printer::log(log_working);
ALOGD("workingDir= %s", workingDir.c_str());
dataManager.FileSystem->changeWorkingDirectoryTo(workingDir);
/* Your media must be somewhere inside the assets folder. The assets folder is the root for the file system.
......@@ -201,9 +198,7 @@ bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) {
} else {
isNPOTSupported = ((COGLES1Driver *) driver)->queryOpenGLFeature(COGLES1ExtensionHandler::IRR_OES_texture_npot);
}
char log_npot[256];
sprintf(log_npot, "isNPOTSupported = %d", isNPOTSupported);
Printer::log(log_npot);
ALOGD("isNPOTSupported = %d", isNPOTSupported);
if (isNPOTSupported) {
if (quality == 1) {
driver->setTextureCreationFlag(irr::video::ETCF_CREATE_MIP_MAPS, false);
......@@ -1301,14 +1296,14 @@ void Game::MainLoop() {
if (!driver->queryFeature(video::EVDF_PIXEL_SHADER_1_1) &&
!driver->queryFeature(video::EVDF_ARB_FRAGMENT_PROGRAM_1))
{
Printer::log("WARNING: Pixel shaders disabled "
ALOGD("WARNING: Pixel shaders disabled "
"because of missing driver/hardware support.");
psFileName = "";
}
if (!driver->queryFeature(video::EVDF_VERTEX_SHADER_1_1) &&
!driver->queryFeature(video::EVDF_ARB_VERTEX_PROGRAM_1))
{
Printer::log("WARNING: Vertex shaders disabled "
ALOGD("WARNING: Vertex shaders disabled "
"because of missing driver/hardware support.");
solidvsFileName = "";
TACvsFileName = "";
......@@ -1316,7 +1311,6 @@ void Game::MainLoop() {
}
video::IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices();
if (gpu) {
char log_custom_shader[1024];
const video::E_GPU_SHADING_LANGUAGE shadingLanguage = video::EGSL_DEFAULT;
ogles2Solid = gpu->addHighLevelShaderMaterialFromFiles(
psFileName, "vertexMain", video::EVST_VS_1_1,
......@@ -1330,12 +1324,9 @@ void Game::MainLoop() {
psFileName, "vertexMain", video::EVST_VS_1_1,
blendvsFileName, "pixelMain", video::EPST_PS_1_1,
&customShadersCallback, video::EMT_ONETEXTURE_BLEND, 0 , shadingLanguage);
sprintf(log_custom_shader, "ogles2Sold = %d", ogles2Solid);
Printer::log(log_custom_shader);
sprintf(log_custom_shader, "ogles2BlendTexture = %d", ogles2BlendTexture);
Printer::log(log_custom_shader);
sprintf(log_custom_shader, "ogles2TrasparentAlpha = %d", ogles2TrasparentAlpha);
Printer::log(log_custom_shader);
ALOGD("ogles2Sold = %d", ogles2Solid);
ALOGD("ogles2BlendTexture = %d", ogles2BlendTexture);
ALOGD("ogles2TrasparentAlpha = %d", ogles2TrasparentAlpha);
}
}
matManager.mCard.MaterialType = (video::E_MATERIAL_TYPE)ogles2BlendTexture;
......
......@@ -41,7 +41,6 @@ int GetListBoxIndex(IGUIListBox* listbox, const wchar_t * target){
}
void android_main(ANDROID_APP app) {
app->inputPollSource.process = android::process_input;
app_dummy();
#else
int main(int argc, char* argv[]) {
#endif
......
......@@ -85,6 +85,8 @@ private:
bool musicEnabled = false;
};
//extern SoundManager soundManager;
}
#endif //SOUNDMANAGER_H
\ No newline at end of file
......@@ -186,6 +186,8 @@ static void* join_game_thread(void* param) {
ygo::mainGame->gMutex.unlock();
return NULL;
}
//auto exit when join game by mycard.
exit_on_return = true;
irr::android::YGOGameOptions options = irr::android::YGOGameOptions(param);
irr::SEvent event;
......
......@@ -177,7 +177,8 @@
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:launchMode="singleTop"
android:theme="@style/AppTheme.Mycard"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"/>
<activity
android:name="cn.garymb.ygomobile.ui.mycard.mcchat.McchatActivity"
android:label="@string/app_name"
......
......@@ -114,7 +114,7 @@ public class GameUriManager {
return new File(dir, "tmp_" + System.currentTimeMillis() + ".ydk");
} else {
IOUtils.createFolder(dir);
file=new File(dir,name+".ydk");
file = new File(dir, name + ".ydk");
}
return file;
}
......@@ -197,7 +197,6 @@ public class GameUriManager {
}
private void doUri(Uri uri) {
Intent startSeting = new Intent(activity, SettingsActivity.class);
if ("file".equals(uri.getScheme()) || "content".equals(uri.getScheme())) {
File file = toLocalFile(uri);
......
......@@ -6,48 +6,39 @@ import cn.garymb.ygomobile.bean.TextSelect;
public class DeckFile extends TextSelect {
private String name;
private String path;
private Long date;
private final File path;
private final String fullName;
public DeckFile(String path) {
this.path = path;
name = new File(path).getName();
int end = name.lastIndexOf(".");
if (end != -1)
name = name.substring(0, end);
super.setName(name);
setObject(this);
this(new File(path));
}
public DeckFile(File file) {
path = file.getAbsolutePath();
name = file.getName();
name = name.substring(0, name.lastIndexOf("."));
date = file.lastModified();
path = file;
fullName = file.getName();
String name = fullName;
int index = name.lastIndexOf(".");
if(index > 0) {
name = name.substring(0, index);
}
super.setName(name);
setObject(this);
}
public String getName() {
return name;
}
public String getFileName(){
return new File(path).getName();
public String getFileName() {
return fullName;
}
public void setName(String name) {
this.name = name;
public File getPathFile() {
return path;
}
public String getPath() {
return path;
return path.getAbsolutePath();
}
public void setPath(String path) {
this.path = path;
public Long getDate() {
return path.lastModified();
}
public Long getDate() { return date; }
}
......@@ -3,8 +3,11 @@ package cn.garymb.ygomobile.loader;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.NonNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import ocgcore.DataManager;
import ocgcore.data.Card;
......@@ -72,10 +75,10 @@ public class CardKeyWord {
private final long setcode;
//包含系列,或者包含名字、描述
public NameFilter(String word, boolean exclude, boolean onlyText) {
public NameFilter(@NonNull String word, boolean exclude, boolean onlyText) {
this.setcode = onlyText ? 0 : DataManager.get().getStringManager().getSetCode(word);
this.exclude = exclude;
this.word = word;
this.word = word.toLowerCase(Locale.US);
if(this.setcode > 0){
Log.d(TAG, "filter:setcode=" + setcode + ", exclude=" + exclude + ", word=" + word);
}
......
......@@ -29,7 +29,6 @@ import ocgcore.enums.LimitType;
public class CardLoader implements ICardSearcher {
private final LimitManager mLimitManager;
private final CardManager mCardManager;
private final StringManager mStringManager;
private final Context context;
private CallBack mCallBack;
private LimitList mLimitList;
......@@ -50,7 +49,6 @@ public class CardLoader implements ICardSearcher {
this.context = context;
mLimitManager = DataManager.get().getLimitManager();
mCardManager = DataManager.get().getCardManager();
mStringManager = DataManager.get().getStringManager();
mLimitList = mLimitManager.getTopLimit();
}
......
......@@ -68,7 +68,7 @@ public class ImageLoader implements Closeable {
private final boolean useCache;
private static final String TAG = ImageLoader.class.getSimpleName();
private final Map<String, ZipFile> zipFileCache = new ConcurrentHashMap<>();
private final Map<Long, Cache> zipDataCache = new ConcurrentHashMap<>();
private final Map<Long, ImageLoader.Cache> zipDataCache = new ConcurrentHashMap<>();
private ZipFile mDefaultZipFile;
private File mPicsFile;
......@@ -182,7 +182,7 @@ public class ImageLoader implements Closeable {
try {
RequestBuilder<Drawable> resource = GlideCompat.with(imageview.getContext()).load(file);
setDefaults(resource,
new MediaStoreSignature("image/*", file.lastModified(), Type.origin.getId()),
new MediaStoreSignature("image/*", file.lastModified(), ImageLoader.Type.origin.getId()),
pre, type);
resource.into(imageview);
} catch (Exception e) {
......
package cn.garymb.ygomobile.ui.adapters;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.tubb.smrv.SwipeHorizontalMenuLayout;
import org.greenrobot.eventbus.EventBus;
......@@ -63,6 +66,14 @@ public class CardListAdapter extends BaseRecyclerAdapterPlus<Card, ViewHolder> i
return false;
}
public void notifyItemChanged(Card card) {
for (int i = 0; i < getItemCount(); i++) {
if (getCard(i).Code == card.Code) {
notifyItemChanged(i);
}
}
}
public void hideMenu(View view) {
if (view == null) {
view = mShowMenuView;
......@@ -88,6 +99,7 @@ public class CardListAdapter extends BaseRecyclerAdapterPlus<Card, ViewHolder> i
}
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflate(R.layout.item_search_card_swipe, parent, false);
......@@ -100,8 +112,8 @@ public class CardListAdapter extends BaseRecyclerAdapterPlus<Card, ViewHolder> i
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Card item = getItem(position);
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
Card item = getCard(position);
if(item == null){
return;
}
......
package cn.garymb.ygomobile.ui.adapters;
import androidx.annotation.NonNull;
public class SimpleSpinnerItem {
public long value;
public String text;
public Object tag;
public transient Object tag;
public SimpleSpinnerItem(long value, String text) {
this.value = value;
......@@ -20,8 +22,9 @@ public class SimpleSpinnerItem {
return this;
}
@NonNull
@Override
public String toString() {
return text;
return "" + text;
}
}
......@@ -107,6 +107,9 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
ll_bar.setVisibility(View.GONE);
imageLoader.bindImage(photoView, msg.arg1, ImageLoader.Type.origin);
imageLoader.bindImage(cardImage, msg.arg1, ImageLoader.Type.middle);
if(mListener != null){
mListener.onImageUpdate(mCardInfo);
}
break;
case TYPE_DOWNLOAD_CARD_IMAGE_ING:
tv_loading.setText(msg.arg1 + "%");
......@@ -128,32 +131,32 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
public CardDetail(BaseActivity context, ImageLoader imageLoader, StringManager stringManager) {
super(context.getLayoutInflater().inflate(R.layout.dialog_cardinfo, null));
mContext = context;
cardImage = bind(R.id.card_image);
cardImage = findViewById(R.id.card_image);
this.imageLoader = imageLoader;
mStringManager = stringManager;
name = bind(R.id.text_name);
desc = bind(R.id.text_desc);
close = bind(R.id.btn_close);
cardCode = bind(R.id.card_code);
level = bind(R.id.card_level);
linkArrow = bind(R.id.detail_link_arrows);
type = bind(R.id.card_type);
View faq = bind(R.id.btn_faq);
cardAtk = bind(R.id.card_atk);
cardDef = bind(R.id.card_def);
atkdefView = bind(R.id.layout_atkdef2);
mImageFav = bind(R.id.image_fav);
monsterLayout = bind(R.id.layout_monster);
layoutDetailPScale = bind(R.id.detail_p_scale);
detailCardScale = bind(R.id.detail_cardscale);
race = bind(R.id.card_race);
setName = bind(R.id.card_setname);
addMain = bind(R.id.btn_add_main);
addSide = bind(R.id.btn_add_side);
otView = bind(R.id.card_ot);
attrView = bind(R.id.card_attribute);
lbSetCode = bind(R.id.label_setcode);
name = findViewById(R.id.text_name);
desc = findViewById(R.id.text_desc);
close = findViewById(R.id.btn_close);
cardCode = findViewById(R.id.card_code);
level = findViewById(R.id.card_level);
linkArrow = findViewById(R.id.detail_link_arrows);
type = findViewById(R.id.card_type);
View faq = findViewById(R.id.btn_faq);
cardAtk = findViewById(R.id.card_atk);
cardDef = findViewById(R.id.card_def);
atkdefView = findViewById(R.id.layout_atkdef2);
mImageFav = findViewById(R.id.image_fav);
monsterLayout = findViewById(R.id.layout_monster);
layoutDetailPScale = findViewById(R.id.detail_p_scale);
detailCardScale = findViewById(R.id.detail_cardscale);
race = findViewById(R.id.card_race);
setName = findViewById(R.id.card_setname);
addMain = findViewById(R.id.btn_add_main);
addSide = findViewById(R.id.btn_add_side);
otView = findViewById(R.id.card_ot);
attrView = findViewById(R.id.card_attribute);
lbSetCode = findViewById(R.id.label_setcode);
cardManager = DataManager.get().getCardManager();
close.setOnClickListener((v) -> {
if (mListener != null) {
......@@ -187,10 +190,10 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
mListener.onOpenUrl(cardInfo);
}
});
bind(R.id.lastone).setOnClickListener((v) -> {
findViewById(R.id.lastone).setOnClickListener((v) -> {
onPreCard();
});
bind(R.id.nextone).setOnClickListener((v) -> {
findViewById(R.id.nextone).setOnClickListener((v) -> {
onNextCard();
});
mImageFav.setOnClickListener((v) -> {
......@@ -532,9 +535,6 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
}
}
private <T extends View> T bind(int id) {
return (T) findViewById(id);
}
public interface OnFavoriteChangedListener {
void onFavoriteChange(Card card, boolean favorite);
......@@ -547,6 +547,10 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
void onAddSideCard(Card cardInfo);
void onImageUpdate(Card cardInfo);
void onClose();
}
......@@ -563,6 +567,11 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
public void onClose() {
}
@Override
public void onImageUpdate(Card cardInfo) {
}
@Override
public void onAddSideCard(Card cardInfo) {
......
......@@ -291,6 +291,11 @@ public class CardSearchActivity extends BaseActivity implements CardLoader.CallB
WebActivity.openFAQ(getContext(), cardInfo);
}
@Override
public void onImageUpdate(Card cardInfo) {
mCardListAdapter.notifyItemChanged(cardInfo);
}
@Override
public void onClose() {
mDialog.dismiss();
......
......@@ -120,6 +120,7 @@ public class CardSearcher implements View.OnClickListener {
resetButton.setOnClickListener(this);
mCardLoader = dataLoader;
// setCodeSpinner.setFirstIndex(1);
OnEditorActionListener searchListener = (v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
......
......@@ -38,7 +38,6 @@ import com.feihua.dialogutils.util.DialogUtils;
import com.nightonke.boommenu.BoomButtons.BoomButton;
import com.nightonke.boommenu.BoomButtons.TextOutsideCircleButton;
import com.nightonke.boommenu.BoomMenuButton;
import com.ourygo.assistant.service.DuelAssistantService;
import com.ourygo.assistant.util.DuelAssistantManagement;
import org.greenrobot.eventbus.EventBus;
......@@ -420,6 +419,12 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
WebActivity.openFAQ(getContext(), cardInfo);
}
@Override
public void onImageUpdate(Card cardInfo) {
mDeckAdapater.notifyItemChanged(cardInfo);
mCardListAdapter.notifyItemChanged(cardInfo);
}
@Override
public void onClose() {
mDialog.dismiss();
......@@ -1117,7 +1122,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
@Override
public void onDeckSelect(DeckFile deckFile) {
loadDeckFromFile(new File(deckFile.getPath()));
loadDeckFromFile(deckFile.getPathFile());
}
@Override
......@@ -1127,7 +1132,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
return;
String currentDeckPath = deck.getAbsolutePath();
for (DeckFile deckFile : deckFileList) {
if (deckFile.getPath().equals(currentDeckPath)) {
if (TextUtils.equals(deckFile.getPath(), currentDeckPath)) {
List<File> files = getYdkFiles();
File file = null;
if (files != null && files.size() > 0) {
......@@ -1145,10 +1150,14 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
@Override
public void onDeckMove(List<DeckFile> deckFileList, DeckType toDeckType) {
String currentDeckPath = mDeckAdapater.getYdkFile().getAbsolutePath();
File ydk = mDeckAdapater.getYdkFile();
if(ydk == null){
return;
}
String currentDeckPath = ydk.getPath();
for (DeckFile deckFile : deckFileList) {
if (deckFile.getPath().equals(currentDeckPath)) {
loadDeckFromFile(new File(toDeckType.getPath(), deckFile.getName() + ".ydk"));
if (TextUtils.equals(currentDeckPath, deckFile.getPath())) {
loadDeckFromFile(new File(toDeckType.getPath(), deckFile.getFileName()));
return;
}
}
......@@ -1156,10 +1165,14 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
@Override
public void onDeckCopy(List<DeckFile> deckFileList, DeckType toDeckType) {
String currentDeckPath = mDeckAdapater.getYdkFile().getAbsolutePath();
File ydk = mDeckAdapater.getYdkFile();
if(ydk == null){
return;
}
String currentDeckPath = ydk.getPath();
for (DeckFile deckFile : deckFileList) {
if (deckFile.getPath().equals(currentDeckPath)) {
loadDeckFromFile(new File(toDeckType.getPath(), deckFile.getName() + ".ydk"));
if (TextUtils.equals(currentDeckPath, deckFile.getPath())) {
loadDeckFromFile(new File(toDeckType.getPath(), deckFile.getFileName()));
return;
}
}
......
......@@ -9,6 +9,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import java.io.File;
......@@ -189,7 +190,7 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
}
@Override
public Card getCard(int posotion) {
public @Nullable Card getCard(int posotion) {
int count = mMainCount;
int index = 0;
if (posotion < count) {
......@@ -388,7 +389,7 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
return mLimitList;
}
public File getYdkFile(){
public @Nullable File getYdkFile(){
if(mDeckInfo != null){
return mDeckInfo.source;
}
......@@ -477,6 +478,16 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
mItems.add(deckItem);
}
public void notifyItemChanged(Card card){
for (int i = 0; i < getItemCount(); i++) {
DeckItem item = getItem(i);
Card c = item.getCardInfo();
if (c != null && c.Code == card.Code) {
notifyItemChanged(i);
}
}
}
public void addItem(int pos, DeckItem deckItem) {
if (deckItem.getCardInfo() != null) {
if (pos >= DeckItem.MainStart && pos <= DeckItem.MainEnd) {
......
......@@ -142,6 +142,8 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
};
//x5内核初始化接口
QbSdk.initX5Environment(this, cb);
if(!BuildConfig.BUILD_TYPE.equals("debug")) {
//release才检查版本
if (!Constants.ACTION_OPEN_GAME.equals(getIntent().getAction())) {
Log.d(Constants.TAG, "start check update");
//check update
......@@ -149,6 +151,7 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
} else {
Log.d(Constants.TAG, "skip check update");
}
}
//初始化决斗助手
initDuelAssistant();
//萌卡
......
......@@ -3,7 +3,6 @@ package cn.garymb.ygomobile.ui.widget;
import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
......@@ -16,34 +15,35 @@ import android.widget.SpinnerAdapter;
import androidx.appcompat.widget.AppCompatSpinner;
import java.util.ArrayList;
import java.util.List;
import cn.garymb.ygomobile.lite.R;
public class SearchableSpinner extends AppCompatSpinner implements View.OnTouchListener,
SearchableListDialog.SearchableItem {
SearchableListDialog.onSearchItemClickListener {
public static final int NO_ITEM_SELECTED = -1;
private Context _context;
private List _items;
private SearchableListDialog _searchableListDialog;
private final ArrayList<Object> _items = new ArrayList<>();
private boolean _isDirty;
private BaseAdapter _arrayAdapter;
private String _strHintText;
private boolean _isFromInit;
private String mTitleString = "Select Item";
private int mFirstIndex = 0;
public SearchableSpinner(Context context) {
super(context);
this._context = context;
init();
this(context, null);
}
public SearchableSpinner(Context context, AttributeSet attrs) {
super(context, attrs);
this._context = context;
this(context, attrs, 0);
}
public SearchableSpinner(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SearchableSpinner);
if (a != null) {
final int N = a.getIndexCount();
for (int i = 0; i < N; ++i) {
int attr = a.getIndex(i);
......@@ -54,50 +54,42 @@ public class SearchableSpinner extends AppCompatSpinner implements View.OnTouchL
}
}
a.recycle();
init();
}
public SearchableSpinner(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this._context = context;
init();
}
private void init() {
_items = new ArrayList();
_searchableListDialog = SearchableListDialog.newInstance
(_items);
_searchableListDialog = new SearchableListDialog(getContext());
_searchableListDialog.setTitle(mTitleString);
_searchableListDialog.setOnSearchableItemClickListener(this);
setOnTouchListener(this);
_arrayAdapter = (BaseAdapter) getAdapter();
if (!TextUtils.isEmpty(_strHintText)) {
ArrayAdapter arrayAdapter = new ArrayAdapter(_context, android.R.layout
.simple_list_item_1, new String[]{_strHintText});
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getContext(),
android.R.layout.simple_list_item_1,
new String[]{_strHintText});
_isFromInit = true;
setAdapter(arrayAdapter);
}
}
public void setFirstIndex(int firstIndex) {
this.mFirstIndex = firstIndex;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
if (null != _arrayAdapter) {
// Refresh content #6
// Change Start
// Description: The items were only set initially, not reloading the data in the
// spinner every time it is loaded with items in the adapter.
// Change end.
//修复 重复点击 bug
if (!_searchableListDialog.isAdded()) {
if(!_searchableListDialog.isShowing()) {
_items.clear();
for (int i = 0; i < _arrayAdapter.getCount(); i++) {
int N = _arrayAdapter.getCount();
for (int i = mFirstIndex; i < N; i++) {
_items.add(_arrayAdapter.getItem(i));
}
_searchableListDialog.show(scanForActivity(_context).getFragmentManager(), "TAG");
_searchableListDialog.show(_items);
}
}
}
......@@ -109,7 +101,7 @@ public class SearchableSpinner extends AppCompatSpinner implements View.OnTouchL
if (!_isFromInit) {
_arrayAdapter = (BaseAdapter) adapter;
if (!TextUtils.isEmpty(_strHintText) && !_isDirty) {
ArrayAdapter arrayAdapter = new ArrayAdapter(_context, android.R.layout
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getContext(), android.R.layout
.simple_list_item_1, new String[]{_strHintText});
super.setAdapter(arrayAdapter);
} else {
......@@ -124,8 +116,7 @@ public class SearchableSpinner extends AppCompatSpinner implements View.OnTouchL
@Override
public void onSearchableItemClicked(Object item, int position) {
setSelection(_items.indexOf(item));
setSelection(_items.indexOf(item) + mFirstIndex);
if (!_isDirty) {
_isDirty = true;
setAdapter(_arrayAdapter);
......@@ -137,14 +128,6 @@ public class SearchableSpinner extends AppCompatSpinner implements View.OnTouchL
_searchableListDialog.setTitle(strTitle);
}
public void setPositiveButton(String strPositiveButtonText) {
_searchableListDialog.setPositiveButton(strPositiveButtonText);
}
public void setPositiveButton(String strPositiveButtonText, DialogInterface.OnClickListener onClickListener) {
_searchableListDialog.setPositiveButton(strPositiveButtonText, onClickListener);
}
public void setOnSearchTextChangedListener(SearchableListDialog.OnSearchTextChanged onSearchTextChanged) {
_searchableListDialog.setOnSearchTextChangedListener(onSearchTextChanged);
}
......
......@@ -10,40 +10,13 @@ public class CardUtils {
public static String getAllTypeString(Card card, StringManager stringManager) {
StringBuilder stringBuilder = new StringBuilder();
CardType[] cardTypes = CardType.values();
boolean isFrst = true;
if (card.isType(CardType.Spell)) {
boolean isFirst = true;
for (CardType type : cardTypes) {
if (card.isType(type)) {
if (!isFrst) {
stringBuilder.append("|");
} else {
isFrst = false;
}
stringBuilder.append(stringManager.getTypeString(type.getId()));
// break;
}
}
// stringBuilder.append(stringManager.getTypeString(CardType.Spell.value()));
} else if (card.isType(CardType.Trap)) {
for (CardType type : cardTypes) {
if (card.isType(type)) {
if (!isFrst) {
stringBuilder.append("|");
} else {
isFrst = false;
}
stringBuilder.append(stringManager.getTypeString(type.getId()));
}
// break;
}
// stringBuilder.append(stringManager.getTypeString(CardType.Trap.value()));
} else {
for (CardType type : cardTypes) {
if (card.isType(type)) {
if (!isFrst) {
if (!isFirst) {
stringBuilder.append("/");
} else {
isFrst = false;
isFirst = false;
}
String str = stringManager.getTypeString(type.getId());
if (TextUtils.isEmpty(str)) {
......@@ -54,7 +27,6 @@ public class CardUtils {
}
}
}
}
return stringBuilder.toString();
}
......
......@@ -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);
}
......
......@@ -40,18 +40,26 @@ 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) {
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){
DialogUtils du = DialogUtils.getdx(context);
View viewDialog = du.dialogBottomSheet(R.layout.dialog_deck_select, 0);
RecyclerView rv_type, rv_deck;
......@@ -61,7 +69,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);
......@@ -142,7 +150,7 @@ public class YGODialogUtil {
deckAdp.addManySelect(item);
deckAdp.notifyItemChanged(position);
} else {
dis();
dismiss();
onDeckMenuListener.onDeckSelect(item);
}
}
......@@ -186,9 +194,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)) {
......@@ -209,7 +215,7 @@ public class YGODialogUtil {
break;
case 1:
onDeckMenuListener.onDeckNew(typeList.get(typeAdp.getSelectPosition()));
dis();
dismiss();
break;
}
}
......@@ -280,7 +286,7 @@ public class YGODialogUtil {
public void onClick(DialogInterface dialog, int which) {
List<DeckFile> selectDeckList = deckAdp.getSelectList();
for (DeckFile deckFile : selectDeckList) {
new File(deckFile.getPath()).delete();
deckFile.getPathFile().delete();
deckList.remove(deckFile);
}
YGOUtil.show(context.getString(R.string.done));
......@@ -347,7 +353,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();
......@@ -356,7 +362,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());
......@@ -369,7 +375,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);
......@@ -381,7 +387,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);
......@@ -393,7 +399,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);
......@@ -405,16 +411,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);
......
......@@ -155,11 +155,11 @@ public class Card extends CardData implements Parcelable {
}
public boolean containsName(String key){
return Name != null && Name.toLowerCase(Locale.US).contains(key.toLowerCase(Locale.US));
return Name != null && Name.toLowerCase(Locale.US).contains(key);
}
public boolean containsDesc(String key){
return Desc != null && Desc.toLowerCase(Locale.US).contains(key.toLowerCase(Locale.US));
return Desc != null && Desc.toLowerCase(Locale.US).contains(key);
}
/**
......
......@@ -29,4 +29,7 @@
<color name="colorMain">#2196F3</color>
<color name="background">#ECEFF1</color>
<color name="transparent">#00000000</color>
<color name="search_text_color">#ff8800</color>
<color name="search_list_item_color">#b8be35</color>
</resources>
\ No newline at end of file
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