Commit 14d6c183 authored by fallenstardust's avatar fallenstardust

添加识别字符进行substring

parent f79bd774
......@@ -156,8 +156,11 @@ public interface Constants {
String URL_DONATE = "https://afdian.net/@ygomobile";
String URL_MASTER_RULE_CN = "https://ocg-rule.readthedocs.io/";
String WIKI_SEARCH_URL = "https://ygocdb.com/card/";
String URL_HOME_VERSION = "https://ygomobile.top/version.txt";
String URL_HOME_VERSION_ALT = "https://ygom.top/version.txt";
String URL_HOME_VERSION = "https://ygomobile.top/ver_code.txt";
String URL_HOME_VERSION_ALT = "https://ygom.top/ver_code.txt";
String ID1 = "[versionname]";
String ID2 = "[download_link]";
String ID3 = "#pre_release_code";
String URL_YGO233_DOWNLOAD_LINK = "https://ygo233.com/download/ygomobile";
String URL_YGO233_ADVANCE = "https://ygo233.com/pre";
String URL_YGO233_DATAVER = "https://ygo233.com/pre/dataver";
......
package cn.garymb.ygomobile.ui.home;
import static cn.garymb.ygomobile.Constants.ID1;
import static cn.garymb.ygomobile.Constants.ID2;
import static cn.garymb.ygomobile.Constants.ID3;
import static cn.garymb.ygomobile.Constants.URL_HOME_VERSION;
import static cn.garymb.ygomobile.Constants.URL_HOME_VERSION_ALT;
......@@ -160,17 +163,30 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat
mFragment = fragment_home;
getSupportFragmentManager().beginTransaction().add(R.id.fragment_content, fragment_home).commit();
getSupportActionBar().hide();
} @SuppressLint("HandlerLeak")
}
private void showNewsCounts() {
mTextBadgeItem = new TextBadgeItem()
.setBorderWidth(4)//文本大小
.setGravity(Gravity.LEFT)//位置 默认右上
.setBackgroundColorResource(R.color.holo_orange_bright)//背景颜色
.setAnimationDuration(200)//动画时间
.setText("3")
.setHideOnSelect(false)//true当选中状态时消失,非选中状态再次显示
.show();
}
@SuppressLint("HandlerLeak")
Handler handlerHome = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case TYPE_GET_VERSION_OK:
if (msg.obj.toString().contains("|") && msg.obj.toString().contains("\n")) {
Version = msg.obj.toString().substring(0, msg.obj.toString().indexOf("|"));//截取版本号
Cache_link = msg.obj.toString().substring(msg.obj.toString().indexOf("|") + 1, msg.obj.toString().indexOf("\n"));//截取下载地址
Cache_pre_release_code = msg.obj.toString().substring(msg.obj.toString().indexOf("\n") + 1);//截取先行-正式对照文本
if (msg.obj.toString().contains(ID1) && msg.obj.toString().contains(ID2) && msg.obj.toString().contains(ID3)) {
Version = msg.obj.toString().substring(msg.obj.toString().indexOf(ID1) + ID1.length(), msg.obj.toString().indexOf(";"));//截取版本号
Cache_link = msg.obj.toString().substring(msg.obj.toString().indexOf(ID2) + ID2.length(), msg.obj.toString().indexOf("$"));//截取下载地址
Cache_pre_release_code = msg.obj.toString().substring(msg.obj.toString().indexOf(ID3) + ID3.length() + 1);//截取先行-正式对照文本
if (!TextUtils.isEmpty(Cache_pre_release_code)) {
arrangeCodeList(Cache_pre_release_code);//转换成两个数组
}
......@@ -186,16 +202,12 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat
});
dialog.show();
}
} else {
Toast.makeText(getContext(), getString(R.string.Checking_Update_Failed) + msg.obj.toString(), Toast.LENGTH_SHORT).show();
}
break;
case TYPE_GET_VERSION_FAILED:
++FailedCount;
if (FailedCount <= 2) {
checkUpgrade(URL_HOME_VERSION_ALT);
} else {
Toast.makeText(getContext(), getString(R.string.Checking_Update_Failed) + msg.obj.toString(), Toast.LENGTH_SHORT).show();
}
break;
}
......@@ -203,17 +215,6 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat
}
};
private void showNewsCounts() {
mTextBadgeItem = new TextBadgeItem()
.setBorderWidth(4)//文本大小
.setGravity(Gravity.LEFT)//位置 默认右上
.setBackgroundColorResource(R.color.holo_orange_bright)//背景颜色
.setAnimationDuration(200)//动画时间
.setText("3")
.setHideOnSelect(false)//true当选中状态时消失,非选中状态再次显示
.show();
}
@Override
public void onTabSelected(int position) {
switch (position) {
......@@ -412,6 +413,7 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat
@Override
public void onResponse(Call call, Response response) throws IOException {
String json = response.body().string();
Log.e("seesee", json);
Message message = new Message();
message.what = TYPE_GET_VERSION_OK;
message.obj = json;
......@@ -425,7 +427,7 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat
try {
String line;
while ((line = br.readLine()) != null) {
String[] words = line.trim().split("[ ]+");
String[] words = line.trim().split("[\t ]+");
pre_code_list.add(Integer.valueOf(words[0]));
released_code_list.add(Integer.valueOf(words[1]));
......@@ -433,7 +435,6 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat
} catch (Exception e) {
Log.e(Constants.TAG, e + "");
} finally {
}
}
......
......@@ -4,6 +4,9 @@ import static cn.garymb.ygomobile.Constants.ACTION_RELOAD;
import static cn.garymb.ygomobile.Constants.CORE_SKIN_AVATAR_SIZE;
import static cn.garymb.ygomobile.Constants.CORE_SKIN_BG_SIZE;
import static cn.garymb.ygomobile.Constants.CORE_SKIN_CARD_COVER_SIZE;
import static cn.garymb.ygomobile.Constants.ID1;
import static cn.garymb.ygomobile.Constants.ID2;
import static cn.garymb.ygomobile.Constants.ID3;
import static cn.garymb.ygomobile.Constants.ORI_DECK;
import static cn.garymb.ygomobile.Constants.ORI_PICS;
import static cn.garymb.ygomobile.Constants.ORI_REPLAY;
......@@ -89,7 +92,6 @@ import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.ui.plus.VUiKit;
import cn.garymb.ygomobile.utils.FileUtils;
import cn.garymb.ygomobile.utils.IOUtils;
import cn.garymb.ygomobile.utils.LogUtil;
import cn.garymb.ygomobile.utils.OkhttpUtil;
import cn.garymb.ygomobile.utils.ServerUtil;
import cn.garymb.ygomobile.utils.SharedPreferenceUtil;
......@@ -161,52 +163,6 @@ public class SettingFragment extends PreferenceFragmentPlus {
isInit = false;
}
@SuppressLint("HandlerLeak")
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case TYPE_SETTING_GET_VERSION_OK:
if (msg.obj.toString().contains("|") && msg.obj.toString().contains("\n")) {
Version = msg.obj.toString().substring(0, msg.obj.toString().indexOf("|"));//截取版本号
Cache_link = msg.obj.toString().substring(msg.obj.toString().indexOf("|") + 1, msg.obj.toString().indexOf("\n"));//截取下载地址
Cache_pre_release_code = msg.obj.toString().substring(msg.obj.toString().indexOf("\n") + 1);//截取先行-正式对照文本
if (!TextUtils.isEmpty(Cache_pre_release_code)) {
arrangeCodeList(Cache_pre_release_code);//转换成两个数组
}
if (!Version.equals(BuildConfig.VERSION_NAME) && !TextUtils.isEmpty(Version) && !TextUtils.isEmpty(Cache_link)) {
DialogPlus dialog = new DialogPlus(getActivity());
dialog.setMessage(R.string.Found_Update);
dialog.setLeftButtonText(R.string.download_home);
dialog.setLeftButtonListener((dlg, s) -> {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(Cache_link));
startActivity(intent);
dialog.dismiss();
});
dialog.show();
} else {
Toast.makeText(getContext(), R.string.Already_Lastest, Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getContext(), getString(R.string.Checking_Update_Failed) + msg.obj.toString(), Toast.LENGTH_SHORT).show();
}
break;
case TYPE_SETTING_GET_VERSION_FAILED:
++FailedCount;
if (FailedCount <= 2) {
Toast.makeText(getActivity(), R.string.Ask_to_Change_Other_Way, Toast.LENGTH_SHORT).show();
checkUpgrade(URL_YGO233_FILE_ALT);
} else {
Toast.makeText(getContext(), getString(R.string.Checking_Update_Failed) + msg.obj.toString(), Toast.LENGTH_SHORT).show();
}
break;
}
}
};
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
super.onPreferenceChange(preference, value);
......@@ -290,7 +246,50 @@ public class SettingFragment extends PreferenceFragmentPlus {
return rs;
}
return true;
} @SuppressLint("HandlerLeak")
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case TYPE_SETTING_GET_VERSION_OK:
if (msg.obj.toString().contains(ID1) && msg.obj.toString().contains(ID2) && msg.obj.toString().contains(ID3)) {
Version = msg.obj.toString().substring(msg.obj.toString().indexOf(ID1) + ID1.length(), msg.obj.toString().indexOf(";"));//截取版本号
Cache_link = msg.obj.toString().substring(msg.obj.toString().indexOf(ID2) + ID2.length(), msg.obj.toString().indexOf("$"));//截取下载地址
Cache_pre_release_code = msg.obj.toString().substring(msg.obj.toString().indexOf(ID3) + ID3.length() + 1);//截取先行-正式对照文本
if (!TextUtils.isEmpty(Cache_pre_release_code)) {
arrangeCodeList(Cache_pre_release_code);//转换成两个数组
}
if (!Version.equals(BuildConfig.VERSION_NAME) && !TextUtils.isEmpty(Version) && !TextUtils.isEmpty(Cache_link)) {
DialogPlus dialog = new DialogPlus(getActivity());
dialog.setMessage(R.string.Found_Update);
dialog.setLeftButtonText(R.string.download_home);
dialog.setLeftButtonListener((dlg, s) -> {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(Cache_link));
startActivity(intent);
dialog.dismiss();
});
dialog.show();
} else {
Toast.makeText(getContext(), R.string.Already_Lastest, Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getContext(), getString(R.string.Checking_Update_Failed), Toast.LENGTH_SHORT).show();
}
break;
case TYPE_SETTING_GET_VERSION_FAILED:
++FailedCount;
if (FailedCount <= 2) {
checkUpgrade(URL_YGO233_FILE_ALT);
} else {
Toast.makeText(getContext(), getString(R.string.Checking_Update_Failed) + msg.obj.toString(), Toast.LENGTH_SHORT).show();
}
break;
}
}
};
@Override
public boolean onPreferenceClick(Preference preference) {
......
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