Commit 4eaf430d authored by fallenstardust's avatar fallenstardust Committed by GitHub

Merge pull request #113 from zhuhongbozhuhongbo/master

小修改
parents 2631359a 06d3c355
......@@ -54,13 +54,15 @@ import java.util.Locale;
import cn.garymb.ygomobile.core.IrrlichtBridge;
import cn.garymb.ygomobile.lite.BuildConfig;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.settings.PreferenceFragmentPlus;
import cn.garymb.ygomobile.ui.settings.SharedPreferencesPlus;
import cn.garymb.ygomobile.utils.DeckUtil;
import cn.garymb.ygomobile.utils.DensityUtils;
import cn.garymb.ygomobile.utils.FileUtils;
import cn.garymb.ygomobile.utils.IOUtils;
/**
* 静态类
*/
public class AppsSettings {
private static final String TAG = "AppsSettings";
private static final String PREF_VERSION = "app_version";
......@@ -231,7 +233,7 @@ public class AppsSettings {
return options;
}
public File getDataBaseFile() {
public File getDatabaseFile() {
return new File(getDataBasePath(), Constants.DATABASE_NAME);
}
......@@ -269,9 +271,14 @@ public class AppsSettings {
}
}
}
pathList.add(getDataBaseFile().getAbsolutePath());
pathList.add(getDatabaseFile().getAbsolutePath());
}
/**
* 返回扩展卡路径,在app-specific external storage下
*
* @return 扩展卡路径
*/
public File getExpansionsPath() {
return new File(getResourcePath(), CORE_EXPANSIONS);
}
......@@ -497,10 +504,24 @@ public class AppsSettings {
}
/***
* 游戏根目录
* 返回存储游戏资源的根目录,为app-specific external storage
* 优先返回sharedPreference中存储的设置值,该值为空时返回context.getExternalFilesDir()
*/
public String getResourcePath() {
String defPath;
/* 注意,调用的函数context.getExternalFilesDir()获取的是外部存储目录,只是安卓系统会将一部分内部存储模拟
外部存储,此时返回的/storage/emulated/0其实是指向内部存储的一部分的链接,但在语义上它是external storage。
context.getExternalFilesDir()的部分注释:If a shared storage device is emulated (as determined
by Environment.isExternalStorageEmulated(File)),
it's contents are backed by a private user data partition, which means there is little benefit
to storing data here instead of the private directories returned by getFilesDir(), etc.
可以用Environment.isExternalStorageEmulated()验证,nova10实测返回值为true
To put it simply, the Android storage/emulated/0 folder is the full name of the root
directory that you access all your files from in the file explorer on your Android device.
However, as its name suggets, this folder is emulated storage, which means that it is merely
a link to the actual internal storage of your device's operating system. This is done for security reasons.
*/
defPath = new File(String.valueOf(context.getExternalFilesDir(Constants.PREF_DEF_GAME_DIR))).getAbsolutePath();
return mSharedPreferences.getString(Constants.PREF_GAME_PATH, defPath);
}
......@@ -718,6 +739,21 @@ public class AppsSettings {
mSharedPreferences.putString(Constants.PREF_LAST_ROOM_LIST, array.toString());
}
public enum languageEnum {
//todo 逐步将设置语言的代码都更改为languageEnum
Chinese(0, "zh"),
Korean(1, "ko"),
English(2, "en");
public Integer code;
public String name;
languageEnum(Integer code, String name) {
this.code = code;
this.name = name;
}
}
public void copyCnData() throws IOException {
//复制数据库
copyCdbFile(getDatapath(DATABASE_NAME));
......@@ -730,7 +766,7 @@ public class AppsSettings {
fixString(stringConfPath);
fixString(botConfPath);
//设置语言为0=中文
setDataLanguage(0);
setDataLanguage(languageEnum.Chinese.code);
}
public void copyKorData() throws IOException {
......@@ -747,8 +783,8 @@ public class AppsSettings {
String botConfPath = new File(getResourcePath(), BOT_CONF).getAbsolutePath();
fixString(stringConfPath);
fixString(botConfPath);
//设置语言为1=조선말
setDataLanguage(1);
//设置语言为1=???
setDataLanguage(languageEnum.Korean.code);
}
public void copyEnData() throws IOException {
......@@ -768,7 +804,7 @@ public class AppsSettings {
fixString(stringConfPath);
fixString(botConfPath);
//设置语言为2=English
setDataLanguage(2);
setDataLanguage(languageEnum.English.code);
}
public void fixString(String stringPath) {
......
......@@ -253,4 +253,5 @@ public interface Constants {
23923758, 69133798, 64583600, 13302026, 57511992, 90583279, 76352503, 77672444, 75311421, 12527118, 27657173, 50699850, 96084564, 86605515, 15464375, 15198996, 78077209, 64475743, 9627468, 62967433, 98462037, 5182107, 67853262, 8085950, 31464658, 8910240, 76823930, 97534104, 36629635, 33099732, 93347961, 30342076, 35026117, 62411811, 8505920, 34904525, 61398234, 97783338, 34771947, 60176682, 96661780, 33055499, 23446369, 50834074, 86239173, 22723778, 59712426, 85106525, 12501230, 58996839, 84384943, 11489642, 47873397, 84262395, 10666000, 47051709, 73046708, 19544412, 46939151, 72323266, 19322865, 45716579, 71101678, 8690387, 44094981, 71089030, 7473735, 33872334, 70366448, 6351147, 33750856, 49858495, 5916510, 3103067, 38105306, 85758066, 33331231, 9726840, 36114945, 62219643, 9603252, 35098357, 89839552, 77590412, 88617904, 42228966, 86469231, 47077697, 84900597, 1683982, 64104037, 99370594, 61103515, 35705817, 20994205, 57499304, 83888009, 19272658, 56677752, 82661461, 19050066, 55554175, 70551291, 6556909, 43940008, 79339613, 5833312, 32828466, 78217065, 5611760, 31006879, 68490573, 4599182, 30983281, 67378935, 93777634, 30761649, 66156348, 92644052, 39049051, 65433790, 92428405, 28827503, 64211118, 91706817, 27104921, 54878729, 91262474, 26988374, 11020863, 58415502, 76076738, 84813516, 11808215, 47292920, 84797028, 10186633, 46570372, 83575471, 19963185, 46358784, 72843899, 18847598, 45236142, 71620241, 39396763, 75780818, 8025950, 44413654, 70508653, 7903368, 33391067, 70786111, 6180710, 32175429, 79663524, 5068132, 32453837, 68441986, 4836680, 31230289, 67725394, 94113093, 30118701, 62503746, 99991455, 25396150, 62480168, 98875863, 25273572, 61668670, 97053215, 24151924, 50546029, 37930737, 23099524, 59494222, 85888377, 59094601, 85182315, 11587414, 47961342, 73355951, 844056, 36848764, 72233469, 5829717, 31817415, 77202120, 4606229, 30095833, 77189532, 91479482, 34456146, 63013339, 32549749, 31600513, 53754104, 3574681, 39973386, 61322713, 66367984, 54594017, 2752099, 35756798, 61245403, 97639441, 34034150, 60023855, 97417863, 23812568, 60306277, 96795312, 22790910, 26050548, 52445243, 39943352, 65938950, 1259814, 91434602, 38529357, 64927055, 90312154, 37706769, 63101468, 90290572, 26684111, 41406613, 77895328, 3289027, 30284022, 76672730, 3167439, 39552584, 65956182, 19096726, 45484331, 82489470, 18973184, 44362883, 81767888, 17751597, 44146295, 70534340, 12877076, 58371671, 85766789, 11155484, 47149093, 84544192, 10938846, 49027020, 75416738, 12801833, 48805472, 75294187, 1688285, 48183890, 74577599, 98396890, 51779204, 98173209, 24662957, 50056656, 87451661, 62991792, 25784595, 13179234, 2347656, 48745395, 75730490, 1225009, 37629703, 74018812, 2511, 33407125, 69895264, 5380979, 32785578, 68779682, 5168381, 92107604, 29595202, 31562086, 68957034, 94445733, 66712905, 30430448, 67835547, 20618850, 93229151, 55990317, 92385016, 28373620, 49131917, 15130912, 41525660, 88919365, 14418464, 41802073, 87897777, 13291886, 40680521, 76075139, 49568943, 75952542, 38339996, 65734501, 91222209, 37617348, 64612053, 90000652, 37495766, 63899465, 99984170, 26372118, 62777823, 99162522, 25550531, 52645235, 98049934, 24434049, 51822687, 83827392, 20212491, 56700100, 82105704, 29599813, 55584558, 82983267, 18377261, 54862960, 81260679, 17255673, 44649322, 80044027, 16433136, 43527730, 79912449, 16310544, 42705243, 78199891, 5852388, 31241087, 67745632, 94130731, 30128445, 67523044, 93918159, 29302858, 66401502, 92895501, 29280200, 55688914, 91073013, 28168628, 54562327, 91951471, 27345070, 53330789, 80738884, 26223582, 53618197, 89016236, 15001940, 52495649, 88890658, 15388353, 41773061, 87778106, 14166715, 40551410, 87955518, 61496006, 98881700, 34876719, 61374414, 97769122, 23153227, 60158866, 96546575, 23931679, 69436288, 95824983, 22819092, 58203736, 95602345, 21057444, 57541158, 84546257, 20934852, 57329501, 83723605, 19712214, 38082437, 1876841, 64487132, 37260946, 63265554, 90659259, 36148308, 63542003, 99937011, 25926710, 62320425, 98715423, 25209168, 51208877, 97692972, 24087580, 50486289, 97870394, 23965033, 59353647, 86758746, 11962031, 57357130, 84755744, 10140443, 57134592, 83533296, 19027895, 46412900, 22411609, 59805313, 85250352, 11654067, 58143766, 84138874, 11522479, 47921178, 83315222, 10300821, 46804536, 83293635, 19688343, 48784854, 67127799, 20001443, 56495147, 93490856, 29884951, 55273560, 82777208, 28762303, 55151012, 81555617, 53212882, 18940725, 54334420, 80433039, 17827173, 80611581, 16605586, 42090294, 89594399, 15983048, 42377643, 78362751, 14761450, 41255165, 73640163, 44818, 46033517, 72427512, 9822220, 35311929, 72305034, 8700633, 34198387, 71583486, 34072799, 6855503, 60461804, 33250142, 69248256, 96633955, 32138660, 69522668, 95911373, 21915012, 68300121, 94798725, 21293424, 67288539, 93672138, 56465981, 93850690, 29948294, 55343303, 82738008, 28126717, 55521751, 81615450, 17000165, 54408264, 80893872, 17888577, 53286626, 89771220, 16165939, 42560034, 89558743, 15943341, 41348446, 78836195, 14821890, 41215808, 77610503, 4008212, 40493210, 16598965, 43986064, 79371769, 20295753, 56790702, 82184400, 25573115, 51578214, 88962829, 14357527, 50855622, 87240371, 13234975, 40633084, 93612434, 7987191, 20071842, 46123974, 31699677, 77683371, 3078380, 30576089, 66961194, 3355732, 39354437, 66749546, 92133240, 38628859, 65626958, 91011603, 28406301, 64804316, 90299015, 27383719, 53782828, 90176467, 26561172, 52566270, 99054885, 25449584, 52843699, 88232397, 24226942, 51611041, 87116749, 14504454, 50599453, 86993168, 13382806, 49776811, 86271510, 12266229, 48654323, 85059922, 11443677, 48832775, 74936480, 11321089, 47710198, 73104892, 109401, 46593546, 73082255, 9486959, 35871958, 72860663, 8264361, 35659410, 71143015, 7142724, 34536828, 60921537, 7320132, 33814281, 69809989, 96203584, 32692693, 69087397, 95471006, 21570001, 64964750, 90359458, 27753563, 53742162, 99137266, 26631975, 52020510, 99414629, 25419323, 52807032, 28292031, 64797746, 91781484, 27170599, 54564198, 90969892, 26357901, 53442500, 84462118, 10851853, 57946551, 83340560, 19739265, 82128978, 19516687, 45001322, 71406430, 18890039, 44889144, 16312943, 21949879, 58938528, 84332527, 21727231, 57111330, 83610035, 10604644, 56099748, 83488497, 19882096, 46877100, 82361809, 18760514, 45154513, 71549257, 18548966, 44932065, 70427670, 17825378, 43210483, 70204022, 6609736, 42198835, 79582540, 5577149, 52253888, 32975247, 78360952, 4754691, 31259606, 67248304, 4632019, 30037118, 66425726, 3410461, 39915560, 66309175, 92798873, 38192988, 65187687, 91575236, 24070330, 60465049, 97453744, 23848752, 59242457, 96637156, 22125101, 59120809, 95515518, 21903613, 58308221, 84792926, 21887075, 57285770, 83670388, 10065487, 56063182, 83558891, 19942835, 45337544, 82735249, 18720257, 45115956, 81613061, 17008760, 44092304, 70491413, 17885118, 43270827, 79775821, 6763530, 42158279, 79552283, 5941982, 32335697, 78420796, 4825390, 31213049, 7608148, 54656181, 80040886, 26435595, 53923690, 89328238, 52707042, 88106656, 15590355, 41085464, 88083109, 14478717, 72309040, 13256226, 40740224, 76145933, 13533678, 49928686, 75922381, 2311090, 48806195, 75290703, 1295442, 37683547, 74078255, 37961969, 572850, 73956664, 9350312, 36745317, 62133026, 9238125, 35622739, 61011438, 98416533, 34800281, 1855886, 37343995, 63748694, 132308, 36521307, 63526052, 99910751, 35405755, 62803464, 98898163, 35283277, 61681816, 94076521, 20560620, 66569334, 93953933, 29348048, 56733747, 92731385, 28226490, 55610199, 81019803, 28403802, 54498517, 80993256, 27381364, 53776969, 80170678, 16169772, 89058026, 52553471, 15443125, 42431833, 88836438, 14220547, 41619242, 77103950, 14108995, 40597694, 76981308, 13386407, 49370016, 76869711, 2263869, 49658464, 75047173, 1041278, 38436986, 74920585, 1329620, 37313338, 63708033, 197042, 36591747, 63086455, 9070454, 35479109, 84366728, 11765832, 47759571, 73244186, 10632284, 46037983, 73421698, 9416697, 46815301, 8794055, 45792753, 3259760, 71187462, 8571567, 34976176, 70465810, 7459919, 33854624, 60242223, 6637331, 32731036, 69120785, 95515789, 32909498, 68304193, 94392192, 31887806, 67282505, 94670654, 20065259, 66069967, 93454062, 29942771, 56347375, 92332424, 28720123, 55125728, 81519836, 28004531, 54092240, 12061457, 81497285, 27882993, 53270092, 80275707, 16769305, 53154400, 89552119, 15947754, 42932862, 84330567, 11825276, 47219274, 73218989, 10602628, 46057733, 73542331, 9940036, 45935145, 72329844, 8728498, 45112597, 71607202, 7602800, 34090915, 70485614, 7889323, 33878367, 60362066, 6767771, 32152870, 69540484, 95545183, 32939238, 8428836, 34813545, 71817640, 7206349, 34690953, 60095092, 6589707, 33578406, 69973414, 96367119, 32756828, 68250822, 95245571, 21639276, 68038375, 94423983, 20417688, 67906797, 4472318, 40460013, 77855162, 30748475, 76133574, 3137279, 39522887, 65910922, 2405631, 38409239, 65898344, 73478096, 863795, 46261704, 72656408, 5141117, 31149212, 78534861, 4928565, 30327674, 77312273, 3806388, 30291086, 66699781, 3084730, 39078434, 65477143, 92962242, 38356857, 65351555, 91749600, 27134209, 64538914, 90027012, 27012717, 53416326, 99801464, 26259179, 52254878, 99748883, 25137581, 51522296, 88926295, 24915933, 51409648, 87804747, 13298352, 50687050, 86682165, 13076804, 49565413, 85969517, 12954226, 48348921, 85747929, 11132674, 48626373, 74615388, 10019086, 47404795, 73898890, 897409, 46382143, 72776252, 9175957, 35569555, 72554664, 8953369, 34447918, 71832012, 7236721, 34225426, 60619435, 6004133, 33503878, 9597987, 36982581, 72386290, 8775395, 35269904, 61264008, 8653757, 34047456, 60442460, 7436169, 33925864, 60329973, 92714517, 39103226, 65107325, 91592030, 61845881, 97240499, 24634594, 60623203, 96127902, 59900655, 96305350, 22390469, 58884063, 95283172, 21677871, 23512906, 20455229, 57940938, 83334932, 10333641, 56727340, 82112494, 19510093, 45005708, 82090807, 18494511, 45883110, 71277255, 17272964, 44760562, 70155677, 17550376, 43944080, 79933029, 6327734, 42822433, 79210531, 5205146, 31600845, 78098950, 4483598, 31987203, 67972302, 3361010, 30765615, 66150724, 3248469, 39643167, 65037172, 92422871, 38811586, 65815684, 91300233, 28798938, 64193046, 90587641, 27572350, 53971455, 90465153, 22850702, 58858807, 95243515, 21637210, 58036229, 84521924, 20515672, 57900671, 83308376, 10793085, 56787189, 82286798, 19671433, 45065541, 82460246, 18458255, 44843954, 21347668, 57736667, 84121302, 10125011, 56510115, 83008724, 19403423, 46497537, 82886276, 19271881, 45675980, 71164684, 18158393, 44553392, 71948047, 7336745, 43331750, 70825459, 6214163, 43618262, 66736715, 93125329, 29510428, 65914127, 91323605, 92003832, 28497830, 65892585, 91286284, 27275398, 54670997, 90164606, 15845914, 60283232, 97682931, 23076639, 55461744, 92565383, 28954097, 55349196, 81743801, 27132400, 54126514, 80621253, 27015862, 53404966, 89809665, 16893370, 52382379, 89776023, 15171722, 41165831, 88554436, 14959144, 41443249, 77832858, 13836592, 40221691, 76615300, 13014905, 49109013, 76593718, 2992467, 48386462, 75771170, 1769875, 38264974, 74659582, 43227, 821049, 36320744, 62714453, 9709452, 35103106, 62592805, 98986900, 34481518, 61470213, 97864322, 24269961, 63136489, 99531088, 36920182, 62314831, 98319530, 25807544, 61292243, 98696958, 24081957, 61070601, 97474300, 23969415, 50357013, 96352712, 23746827, 59131526, 22024279, 58019984, 85407683, 11802691, 57296396, 84281045, 10780049, 53174748, 89569453, 15967552, 42952160, 88346805, 37442336, 63436931, 653675, 36742774, 85520170
};
public final String officialExCardPackageName = "ygo233.com-pre-release.ypk";//官方扩展卡包ypk文件的名称
}
......@@ -23,12 +23,15 @@ import android.widget.Toast;
import com.ourygo.lib.duelassistant.util.YGODAUtil;
import org.greenrobot.eventbus.EventBus;
import java.io.File;
import java.io.FileInputStream;
import java.util.Locale;
import cn.garymb.ygodata.YGOGameOptions;
import cn.garymb.ygomobile.bean.Deck;
import cn.garymb.ygomobile.bean.events.ExCardEvent;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.home.HomeActivity;
import cn.garymb.ygomobile.ui.home.MainActivity;
......@@ -51,6 +54,12 @@ public class GameUriManager {
stringManager = new StringManager();
}
/**
* 根据intent的getData()和getXXXExtra()执行逻辑,
*
* @param intent
* @return false当传入的intent.getAction()不符合可处理的action时,不做处理,返回false
*/
public boolean doIntent(Intent intent) {
Log.i(Constants.TAG, "doIntent");
if (ACTION_OPEN_DECK.equals(intent.getAction())) {
......@@ -225,12 +234,14 @@ public class GameUriManager {
} else if (isYpk) {
if (!AppsSettings.get().isReadExpansions()) {
startSetting.putExtra("flag", 4);
activity.startActivity(startSetting);
activity.startActivity(startSetting);//todo ??再次打开MainActivity?
Toast.makeText(activity, R.string.ypk_go_setting, Toast.LENGTH_LONG).show();
} else {
DataManager.get().load(true);
Toast.makeText(activity, R.string.ypk_installed, Toast.LENGTH_LONG).show();
loadServerInfoFromZipOrYpk(getActivity(), file);
//ypk不与excard机制相干涉
}
} else if (isYrp) {
if (!YGOStarter.isGameRunning(getActivity())) {
......
......@@ -107,6 +107,12 @@ public class YGOStarter {
quitFullScreen(activity, activityShowInfo);
}
/**
* 对添加用于展示的相关信息
*
* @param activity
* @return
*/
public static ActivityShowInfo onCreated(Activity activity) {
ActivityShowInfo activityShowInfo = Infos.get(activity);
if (activityShowInfo == null) {
......@@ -157,7 +163,6 @@ public class YGOStarter {
private static long lasttime = 0;
/**
*
* @param activity
* @param options
* @param args 例如(播放完退出游戏):-r 1111.yrp
......@@ -184,6 +189,7 @@ public class YGOStarter {
Log.e(TAG, "跳转后" + System.currentTimeMillis());
}
/* 维护activity的用于展示的相关信息 */
private static final HashMap<Activity, ActivityShowInfo> Infos = new HashMap<>();
private static class ActivityShowInfo {
......
package cn.garymb.ygomobile.bean.events;
/**
* 用于EventBus发布的时间类型。
*/
public class ExCardEvent {
public enum EventType {
exCardPackageChange,exCardPrefChange
exCardPackageChange,//扩展卡包变化
exCardPrefChange//扩展卡设置变化
}
private EventType eventType;
......
package cn.garymb.ygomobile.ex_card;
import static cn.garymb.ygomobile.Constants.ASSET_SERVER_LIST;
import static cn.garymb.ygomobile.Constants.URL_YGO233_ADVANCE;
import static cn.garymb.ygomobile.Constants.URL_YGO233_FILE;
import static cn.garymb.ygomobile.Constants.URL_YGO233_FILE_ALT;
......@@ -30,31 +29,18 @@ import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.bean.ServerInfo;
import cn.garymb.ygomobile.bean.ServerList;
import cn.garymb.ygomobile.bean.events.ExCardEvent;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.activities.WebActivity;
import cn.garymb.ygomobile.ui.home.MainActivity;
import cn.garymb.ygomobile.ui.home.ServerListManager;
import cn.garymb.ygomobile.ui.plus.VUiKit;
import cn.garymb.ygomobile.utils.DownloadUtil;
import cn.garymb.ygomobile.utils.FileUtils;
import cn.garymb.ygomobile.utils.IOUtils;
import cn.garymb.ygomobile.utils.LogUtil;
import cn.garymb.ygomobile.utils.ServerUtil;
import cn.garymb.ygomobile.utils.SharedPreferenceUtil;
import cn.garymb.ygomobile.utils.SystemUtils;
import cn.garymb.ygomobile.utils.UnzipUtils;
import cn.garymb.ygomobile.utils.XmlUtils;
import cn.garymb.ygomobile.utils.YGOUtil;
import ocgcore.DataManager;
......@@ -145,6 +131,10 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener
} else if (ServerUtil.exCardState == ServerUtil.ExCardState.ERROR) {
Toast.makeText(getActivity(), R.string.ex_card_check_toast_message_iii, Toast.LENGTH_LONG).show();
WebActivity.open(getActivity(), getString(R.string.ex_card_list_title), URL_YGO233_ADVANCE);
} else if (ServerUtil.exCardState == ServerUtil.ExCardState.UNCHECKED) {
//do nothing
//状态UNCHECKED仅在app启动后调用哦你Create()之前短暂存在,所以该情况进行处理
//the UNCHECKED state only exists temporarily before the check action, so we need not handle it.
}
}
//TODO eventbus receive event
......@@ -233,6 +223,7 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener
changeDownloadText();
}
}
private void downloadfromWeb(String fileUrl) {
textDownload.setText("0%");//点击下载后,距离onDownloading触发要等几秒,这一延迟会造成软件响应慢的错觉,因此在下载函数开始就设置文本
File file = new File(AppsSettings.get().getResourcePath() + "-preRlease.zip");
......
......@@ -11,11 +11,11 @@ import com.google.android.material.tabs.TabLayout;
import cn.garymb.ygomobile.lite.R;
/**
* 先行卡相关Fragment的Tab的适配器,用来实现页面切换
* 先行卡相关Fragment的Tab的适配器,用来实现页面切换
*/
public class ExPackageTabAdapter extends FragmentStatePagerAdapter {
TabLayout tabLayout;
/* 仅用于获取strings.xml中的字符串。It's used just for getting strings from strings.xml */
/* 仅用于获取strings.xml中的字符串。It's used just for getting strings from strings.xml */
Context context;
public ExPackageTabAdapter(FragmentManager fm, TabLayout _tabLayout, Context context) {
......
......@@ -28,8 +28,7 @@ import ocgcore.enums.LimitType;
/**
* 包括LimitManager、CardManager、LimitList
* LimitList负责判断禁止卡等
*
*
* field包括LimitManager、CardManager
*/
public class CardLoader implements ICardSearcher {
private final LimitManager mLimitManager;
......
......@@ -14,6 +14,9 @@ import cn.garymb.ygomobile.loader.ICardSearcher;
import cn.garymb.ygomobile.utils.FileUtils;
import ocgcore.data.Card;
/**
* 静态类,
*/
public class CardFavorites {
private final List<Integer> mList = new ArrayList<>();
private static final String TAG = "CardFavorites";
......@@ -55,6 +58,12 @@ public class CardFavorites {
return mList;
}
/**
* 从cardLoader查询收藏的卡片
*
* @param cardLoader
* @return 排序后的列表
*/
public List<Card> getCards(ICardSearcher cardLoader) {
SparseArray<Card> id = cardLoader.readCards(mList, false);
List<Card> list = new ArrayList<>();
......@@ -89,6 +98,9 @@ public class CardFavorites {
Log.d(TAG, "load favorites success:" + mList.size());
}
/**
* 将卡片收藏保存到sharedStorage中
*/
public void save() {
List<String> ret = new ArrayList<>();
if (!mList.isEmpty()) {
......
......@@ -26,13 +26,8 @@ import com.tencent.smtt.export.external.TbsCoreSettings;
import com.tencent.smtt.sdk.QbSdk;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -141,7 +136,7 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat
//showNewbieGuide("homePage");
initBottomNavigationBar();
onNewIntent(getIntent());
ServerUtil.initExCardState();//检查扩展卡版本
ServerUtil.initExCardState();//检查扩展卡版本 todo 移动到LogoActivity中
}
@Override
......
......@@ -289,6 +289,10 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene
} else if (ServerUtil.exCardState == ServerUtil.ExCardState.ERROR) {
Toast.makeText(getActivity(), R.string.ex_card_check_toast_message_iii, Toast.LENGTH_SHORT).show();
ll_new_notice.setVisibility(View.GONE);
} else if (ServerUtil.exCardState == ServerUtil.ExCardState.UNCHECKED) {
//do nothing
//由于UNCHECKED状态仅在app刚启动时短暂存在,因此不需要对其进行处理
//the UNCHECKED state only exists temporarily before the check action, so we need not handle it.
}
}
......
......@@ -69,6 +69,9 @@ public class MainActivity extends HomeActivity implements BottomNavigationBar.On
}
/**
* 资源复制
*/
private void checkRes() {
checkResourceDownload((error, isNew) -> {
//加载收藏夹
......@@ -210,7 +213,6 @@ public class MainActivity extends HomeActivity implements BottomNavigationBar.On
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == Constants.REQUEST_SETTINGS_CODE) {
......
......@@ -30,11 +30,13 @@ import java.io.IOException;
import java.util.List;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.AppsSettings.languageEnum;
import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.utils.FileUtils;
import cn.garymb.ygomobile.utils.IOUtils;
import cn.garymb.ygomobile.utils.LogUtil;
import cn.garymb.ygomobile.utils.SystemUtils;
import libwindbot.windbot.WindBot;
import ocgcore.CardManager;
......@@ -151,12 +153,15 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
mContext.unregisterReceiver(mReceiver);
}
/**
* 查询sharedPreference中的版本号和package的版本号,比较后得出是否需要更新,将结果存入isNewVersion。
*/
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = DialogPlus.show(mContext, null, mContext.getString(R.string.check_res));
int vercode = SystemUtils.getVersion(mContext);
if (mSettings.getAppVersion() < vercode) {
if (mSettings.getAppVersion() < vercode) {//刚安装app时,mSettings.getAppVersion()返回值为0
mSettings.setAppVersion(vercode);
isNewVersion = true;
} else {
......@@ -186,6 +191,13 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
});
}
/**
* 清除下载缓存
* 如果是新安装ygomobile,则将资源文件从assets拷贝到游戏目录中。游戏目录为app-specific external storage
*
* @param params The parameters of the task.
* @return
*/
@Override
protected Integer doInBackground(Void... params) {
Log.d(TAG, "check start");
......@@ -214,12 +226,13 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
checkDirs();
if (mSettings.isUseExtraCards()) {
//自定义数据库无效,则用默认的
if (!CardManager.checkDataBase(mSettings.getDataBaseFile())) {
if (!CardManager.checkDataBase(mSettings.getDatabaseFile())) {
mSettings.setUseExtraCards(false);
}
}
//如果是新版本
if (needsUpdate) {
LogUtil.i(TAG, "needsUpdate");
//复制卡组
File deckFiles = new File(mSettings.getDeckDir());
if (deckFiles.list().length == 0) {
......@@ -277,17 +290,18 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
String language = mContext.getResources().getConfiguration().locale.getLanguage();
if (!language.isEmpty()) {
if (mSettings.getDataLanguage() == -1) {
if (language.equals("zh")) {
if (language.equals(languageEnum.Chinese.name)) {
copyCnData(true);
} else if (language.equals("ko")) {
} else if (language.equals(languageEnum.Korean.name)) {
copyKorData(true);
} else {
copyEnData(true);
}
} else {
if (mSettings.getDataLanguage() == 0) copyCnData(true);
if (mSettings.getDataLanguage() == 1) copyKorData(true);
if (mSettings.getDataLanguage() == 2) copyEnData(true);
if (mSettings.getDataLanguage() == languageEnum.Chinese.code)
copyCnData(true);
if (mSettings.getDataLanguage() == languageEnum.Korean.code) copyKorData(true);
if (mSettings.getDataLanguage() == languageEnum.English.code) copyEnData(true);
}
}
han.sendEmptyMessage(0);
......
......@@ -342,10 +342,12 @@ public class SettingFragment extends PreferenceFragmentPlus {
FileUtils.delFile(mSettings.getExpansionsPath().getAbsolutePath() + "/" + name);
DataManager.get().load(true);
Toast.makeText(getContext(), R.string.done, Toast.LENGTH_LONG).show();
if (name.equals(Constants.officialExCardPackageName)) {//如果删除的是官方先行卡ypk,则更新其相关UI状态
SharedPreferenceUtil.setExpansionDataVer(null);//删除先行卡后,更新版本状态
ServerUtil.exCardState = ServerUtil.ExCardState.NEED_UPDATE;
EventBus.getDefault().postSticky(new ExCardEvent(ExCardEvent.EventType.exCardPackageChange));//删除后,通知UI做更新
}
}
return true;
});
/*
......@@ -672,6 +674,7 @@ public class SettingFragment extends PreferenceFragmentPlus {
return false;
}
}
private void arrangeCodeList(String code) {
BufferedReader br = new BufferedReader(new StringReader(code));
try {
......
......@@ -226,7 +226,7 @@ public class BitmapUtil {
return bitmap;
}
public static Paint getPaint(int saturation){
public static Paint getPaint(int saturation) {
Paint mPaint = new Paint();
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(saturation);
......
......@@ -103,6 +103,9 @@ public class IOUtils {
return new File(path).getName();
}
/**
* 将文件从工程的assets文件夹拷贝到目录中
*/
public static int copyFilesFromAssets(Context context, String assets, String toPath, boolean update) throws IOException {
AssetManager am = context.getAssets();
String[] files = am.list(assets);
......@@ -162,8 +165,15 @@ public class IOUtils {
createFolder(file.getParentFile());
}
/**
* 根据file创建目录,如果file指向的目录已存在,则直接返回true。
* 创建失败时返回false。
* 创建成功时返回true
* @param file
* @return
*/
public static boolean createFolder(@Nullable File file) {
if(file == null){
if (file == null) {
return false;
}
if (!file.exists()) {
......
......@@ -37,8 +37,14 @@ import okhttp3.Response;
public class ServerUtil {
private static final String TAG = ServerUtil.class.getSimpleName();
public enum ExCardState {
/* 已安装最新版扩展卡,扩展卡不是最新版本,无法查询到服务器版本 */
UNCHECKED, UPDATED, NEED_UPDATE, ERROR
}
/* 存储了当前先行卡是否需要更新的状态,UI逻辑直接读取该变量就能获知是否已安装先行卡 */
public volatile static ExCardState exCardState = ExCardState.ERROR;//TODO 可能有并发问题
public volatile static ExCardState exCardState = ExCardState.UNCHECKED;//TODO 可能有并发问题
public volatile static String serverExCardVersion = "";
private volatile static int failCounter = 0;
......@@ -122,9 +128,12 @@ public class ServerUtil {
}
if (serverName != null && (isHost(serverHost) || isValidIP(serverHost)) && isNumeric(serverPort)) {
AddServer(context, serverName, serverHost, Integer.valueOf(serverPort), "Knight of Hanoi");
} else {
YGOUtil.showTextToast("can't parse ex-server properly");
}
LogUtil.w("看看", serverName + isHost(serverHost) + serverHost + isNumeric(serverPort) + serverPort);
zipFile.close();
} catch (IOException e) {
e.printStackTrace();
}
......@@ -202,8 +211,4 @@ public class ServerUtil {
}
public enum ExCardState {
/* 已安装最新版扩展卡,扩展卡不是最新版本,无法查询到服务器版本 */
UPDATED, NEED_UPDATE, ERROR
}
}
package cn.garymb.ygomobile.utils;
import org.apache.commons.lang3.math.NumberUtils;
import android.text.TextUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -65,6 +65,10 @@ public class StringUtils {
* 检查字符串是否是域名
*/
public static boolean isHost(String hostStr) {
if (TextUtils.isEmpty(hostStr)) {
return false;
}
boolean isurl = false;
String regex = "(((https|http)?://)?([a-z0-9]+[.])|(www.))"
+ "\\w+[.|\\/]([a-z0-9]{0,})?[[.]([a-z0-9]{0,})]+((/[\\S&&[^,;\u4E00-\u9FA5]]+)+)?([.][a-z0-9]{0,}+|/?)";//设置正则表达式
......@@ -82,7 +86,7 @@ public class StringUtils {
* 检查字符串是否是IPv4
*/
public static boolean isValidIP(String s) {
if (s == null || s.length() == 0) {
if (TextUtils.isEmpty(s)) {
return false;
}
String[] arr = s.split("\\.");
......
......@@ -134,10 +134,14 @@ public class CardManager {
return cardDataHashMap;
}
/**
* 清空cardDataHashMap,之后从cdb文件读取卡牌,到cardDataHashMap
* 如果开启了先行卡,
*/
@WorkerThread
public void loadCards() {
cardDataHashMap.clear();
int count = readAllCards(AppsSettings.get().getDataBaseFile(), cardDataHashMap);
int count = readAllCards(AppsSettings.get().getDatabaseFile(), cardDataHashMap);
Log.i(TAG, "load defualt cdb:" + count);
if (!TextUtils.isEmpty(exDbPath)) {
if (AppsSettings.get().isReadExpansions()) {
......
package ocgcore;
import org.greenrobot.eventbus.EventBus;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.ex_card.ExCardListAdapter;
import cn.garymb.ygomobile.bean.events.ExCardEvent;
import cn.garymb.ygomobile.loader.CardLoader;
/**
* 单例模式,使用get()方式自动获取单例
* 单例模式,使用get()方式自动获取单例
* 其field包括StringManager、LimitManager、CardManager
*/
public class DataManager {
private static DataManager sLoader = null;
private static final String TAG = String.valueOf(DataManager.class);
public static DataManager get() {
if (sLoader != null) {
return sLoader;
......@@ -50,8 +54,7 @@ public class DataManager {
private boolean mInit;
public void load(boolean force) {
//Log.i("webCrawler", "DataManager load data");
//LogUtil.i("webCrawler", "DataManager load data");
boolean needLoad = false;
synchronized (this) {
if (!mInit || force) {
......@@ -59,7 +62,7 @@ public class DataManager {
}
mInit = true;
}
if(needLoad) {
if (needLoad) {
mStringManager.load();
mLimitManager.load();
mCardManager.loadCards();
......
......@@ -22,7 +22,9 @@ import cn.garymb.ygomobile.utils.IOUtils;
import ocgcore.data.LimitList;
public class LimitManager implements Closeable {
/* key为时间,如“2023.7” ,value为禁止卡、限制卡、准限制卡的列表 */
private final Map<String, LimitList> mLimitLists = new HashMap<>();
/* 只存储key的列表,其元素形如“2023.7” */
private final List<String> mLimitNames = new ArrayList<>();
private int mCount;
......@@ -74,6 +76,12 @@ public class LimitManager implements Closeable {
return rs1 && rs2;
}
/**
* 解析限制卡配置文件lflist.conf的内容
*
* @param file
* @return
*/
public boolean loadFile(File file) {
if (file.isDirectory() || !file.exists()) {
return false;
......
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