Commit 75f4e4f3 authored by fallenstardust's avatar fallenstardust

添加备选检查更新路线

parent e03e80e9
...@@ -157,6 +157,7 @@ public interface Constants { ...@@ -157,6 +157,7 @@ public interface Constants {
String URL_MASTER_RULE_CN = "https://ocg-rule.readthedocs.io/"; String URL_MASTER_RULE_CN = "https://ocg-rule.readthedocs.io/";
String WIKI_SEARCH_URL = "https://ygocdb.com/card/"; String WIKI_SEARCH_URL = "https://ygocdb.com/card/";
String URL_HOME_VERSION = "https://ygomobile.top/version.txt"; String URL_HOME_VERSION = "https://ygomobile.top/version.txt";
String URL_HOME_VERSION_ALT = "https://ygom.top/version.txt";
String URL_YGO233_DOWNLOAD_LINK = "https://ygo233.com/download/ygomobile"; String URL_YGO233_DOWNLOAD_LINK = "https://ygo233.com/download/ygomobile";
String URL_YGO233_ADVANCE = "https://ygo233.com/pre"; String URL_YGO233_ADVANCE = "https://ygo233.com/pre";
String URL_YGO233_DATAVER = "https://ygo233.com/pre/dataver"; String URL_YGO233_DATAVER = "https://ygo233.com/pre/dataver";
......
...@@ -67,7 +67,6 @@ public class WebActivity extends BaseActivity implements View.OnClickListener { ...@@ -67,7 +67,6 @@ public class WebActivity extends BaseActivity implements View.OnClickListener {
private EditText et_context_keyword; private EditText et_context_keyword;
private ImageButton btn_context_search_close, btn_context_search_last, btn_context_search_next; private ImageButton btn_context_search_close, btn_context_search_last, btn_context_search_next;
private Button btn_download; private Button btn_download;
private File xmlFile;
private int FailedCount; private int FailedCount;
@SuppressLint("HandlerLeak") @SuppressLint("HandlerLeak")
Handler handler = new Handler() { Handler handler = new Handler() {
...@@ -129,7 +128,6 @@ public class WebActivity extends BaseActivity implements View.OnClickListener { ...@@ -129,7 +128,6 @@ public class WebActivity extends BaseActivity implements View.OnClickListener {
mWebViewPlus = $(R.id.webbrowser); mWebViewPlus = $(R.id.webbrowser);
find_in_page = $(R.id.find_in_page); find_in_page = $(R.id.find_in_page);
et_context_keyword = $(R.id.context_keyword); et_context_keyword = $(R.id.context_keyword);
xmlFile = new File(this.getFilesDir(), Constants.SERVER_FILE);
initButton(); initButton();
//mWebViewPlus.enableHtml5(); //mWebViewPlus.enableHtml5();
mWebViewPlus.setWebChromeClient(new DefWebChromeClient() { mWebViewPlus.setWebChromeClient(new DefWebChromeClient() {
......
package cn.garymb.ygomobile.ui.home; package cn.garymb.ygomobile.ui.home;
import static cn.garymb.ygomobile.Constants.URL_HOME_VERSION; import static cn.garymb.ygomobile.Constants.URL_HOME_VERSION;
import static cn.garymb.ygomobile.Constants.URL_HOME_VERSION_ALT;
import static cn.garymb.ygomobile.Constants.URL_YGO233_FILE_ALT;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Intent; import android.content.Intent;
...@@ -82,6 +84,7 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat ...@@ -82,6 +84,7 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat
public SettingFragment fragment_settings; public SettingFragment fragment_settings;
public MycardChatFragment fragment_mycard_chatting_room; public MycardChatFragment fragment_mycard_chatting_room;
private Bundle mBundle; private Bundle mBundle;
private int FailedCount;
@SuppressLint("HandlerLeak") @SuppressLint("HandlerLeak")
Handler handlerHome = new Handler() { Handler handlerHome = new Handler() {
...@@ -110,6 +113,11 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat ...@@ -110,6 +113,11 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat
} }
break; break;
case TYPE_GET_VERSION_FAILED: case TYPE_GET_VERSION_FAILED:
++FailedCount;
if (FailedCount <= 2) {
Toast.makeText(getActivity(), R.string.Ask_to_Change_Other_Way, Toast.LENGTH_SHORT).show();
checkUpgrade(URL_HOME_VERSION_ALT);
}
String error = msg.obj.toString(); String error = msg.obj.toString();
break; break;
} }
...@@ -132,7 +140,7 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat ...@@ -132,7 +140,7 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat
initQbSdk(); initQbSdk();
// //
checkNotch(); checkNotch();
checkUpgrade(); checkUpgrade(URL_HOME_VERSION);
//showNewbieGuide("homePage"); //showNewbieGuide("homePage");
initBottomNavigationBar(); initBottomNavigationBar();
onNewIntent(getIntent()); onNewIntent(getIntent());
...@@ -393,8 +401,8 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat ...@@ -393,8 +401,8 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat
protected abstract void openGame(); protected abstract void openGame();
public void checkUpgrade() { public void checkUpgrade(String url) {
OkhttpUtil.get(URL_HOME_VERSION, new Callback() { OkhttpUtil.get(url, new Callback() {
@Override @Override
public void onFailure(Call call, IOException e) { public void onFailure(Call call, IOException e) {
Message message = new Message(); Message message = new Message();
......
...@@ -35,6 +35,7 @@ import static cn.garymb.ygomobile.Constants.SETTINGS_AVATAR; ...@@ -35,6 +35,7 @@ import static cn.garymb.ygomobile.Constants.SETTINGS_AVATAR;
import static cn.garymb.ygomobile.Constants.SETTINGS_CARD_BG; import static cn.garymb.ygomobile.Constants.SETTINGS_CARD_BG;
import static cn.garymb.ygomobile.Constants.SETTINGS_COVER; import static cn.garymb.ygomobile.Constants.SETTINGS_COVER;
import static cn.garymb.ygomobile.Constants.URL_HOME_VERSION; import static cn.garymb.ygomobile.Constants.URL_HOME_VERSION;
import static cn.garymb.ygomobile.Constants.URL_YGO233_FILE_ALT;
import static cn.garymb.ygomobile.ui.home.HomeActivity.Cache_pre_release_code; import static cn.garymb.ygomobile.ui.home.HomeActivity.Cache_pre_release_code;
import static cn.garymb.ygomobile.ui.home.HomeActivity.pre_code_list; import static cn.garymb.ygomobile.ui.home.HomeActivity.pre_code_list;
import static cn.garymb.ygomobile.ui.home.HomeActivity.released_code_list; import static cn.garymb.ygomobile.ui.home.HomeActivity.released_code_list;
...@@ -101,53 +102,16 @@ import okhttp3.Response; ...@@ -101,53 +102,16 @@ import okhttp3.Response;
public class SettingFragment extends PreferenceFragmentPlus { public class SettingFragment extends PreferenceFragmentPlus {
private static final int TYPE_SETTING_GET_VERSION_OK = 0; private static final int TYPE_SETTING_GET_VERSION_OK = 0;
private static final int TYPE_SETTING_GET_VERSION_FAILED = 1; private static final int TYPE_SETTING_GET_VERSION_FAILED = 1;
private AppsSettings mSettings;
public static String Version; public static String Version;
public static String Cache_link; public static String Cache_link;
private AppsSettings mSettings;
private boolean isInit = true; private boolean isInit = true;
private int FailedCount;
public SettingFragment() { public SettingFragment() {
} }
@SuppressLint("HandlerLeak")
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case TYPE_SETTING_GET_VERSION_OK:
Version = msg.obj.toString().substring(0, msg.obj.toString().indexOf("|"));//截取版本号
Cache_link = msg.obj.toString().substring(msg.obj.toString().indexOf("|") + 1);
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 (!Cache_pre_release_code.isEmpty()) {
arrangeCodeList(Cache_pre_release_code);//转换成两个数组
}
if (!Version.equals(BuildConfig.VERSION_NAME) && !Version.isEmpty() && !Cache_link.isEmpty()) {
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();
}
break;
case TYPE_SETTING_GET_VERSION_FAILED:
String error = msg.obj.toString();
Toast.makeText(getContext(), getString(R.string.Checking_Update_Failed) + error, Toast.LENGTH_SHORT).show();
break;
}
}
};
@Override @Override
protected SharedPreferences getSharedPreferences() { protected SharedPreferences getSharedPreferences() {
return AppsSettings.get().getSharedPreferences(); return AppsSettings.get().getSharedPreferences();
...@@ -196,6 +160,50 @@ public class SettingFragment extends PreferenceFragmentPlus { ...@@ -196,6 +160,50 @@ public class SettingFragment extends PreferenceFragmentPlus {
isInit = false; 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:
Version = msg.obj.toString().substring(0, msg.obj.toString().indexOf("|"));//截取版本号
Cache_link = msg.obj.toString().substring(msg.obj.toString().indexOf("|") + 1);
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 (!Cache_pre_release_code.isEmpty()) {
arrangeCodeList(Cache_pre_release_code);//转换成两个数组
}
if (!Version.equals(BuildConfig.VERSION_NAME) && !Version.isEmpty() && !Cache_link.isEmpty()) {
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();
}
break;
case TYPE_SETTING_GET_VERSION_FAILED:
String error = msg.obj.toString();
++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) + error, Toast.LENGTH_SHORT).show();
}
break;
}
}
};
@Override @Override
public boolean onPreferenceChange(Preference preference, Object value) { public boolean onPreferenceChange(Preference preference, Object value) {
super.onPreferenceChange(preference, value); super.onPreferenceChange(preference, value);
...@@ -298,24 +306,8 @@ public class SettingFragment extends PreferenceFragmentPlus { ...@@ -298,24 +306,8 @@ public class SettingFragment extends PreferenceFragmentPlus {
joinQQGroup(groupkey); joinQQGroup(groupkey);
} }
if (PREF_CHECK_UPDATE.equals(key)) { if (PREF_CHECK_UPDATE.equals(key)) {
OkhttpUtil.get(URL_HOME_VERSION, new Callback() { checkUpgrade(URL_HOME_VERSION);
@Override
public void onFailure(Call call, IOException e) {
Message message = new Message();
message.what = TYPE_SETTING_GET_VERSION_FAILED;
message.obj = e;
handler.sendMessage(message);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String json = response.body().string();
Message message = new Message();
message.what = TYPE_SETTING_GET_VERSION_OK;
message.obj = json;
handler.sendMessage(message);
}
});
} }
if (PREF_DEL_EX.equals(key)) { if (PREF_DEL_EX.equals(key)) {
File[] ypks = new File(mSettings.getExpansionsPath().getAbsolutePath()).listFiles(); File[] ypks = new File(mSettings.getExpansionsPath().getAbsolutePath()).listFiles();
...@@ -675,6 +667,27 @@ public class SettingFragment extends PreferenceFragmentPlus { ...@@ -675,6 +667,27 @@ public class SettingFragment extends PreferenceFragmentPlus {
} }
} }
public void checkUpgrade(String url) {
OkhttpUtil.get(url, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Message message = new Message();
message.what = TYPE_SETTING_GET_VERSION_FAILED;
message.obj = e;
handler.sendMessage(message);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String json = response.body().string();
Message message = new Message();
message.what = TYPE_SETTING_GET_VERSION_OK;
message.obj = json;
handler.sendMessage(message);
}
});
}
private void arrangeCodeList(String code) { private void arrangeCodeList(String code) {
BufferedReader br = new BufferedReader(new StringReader(code)); BufferedReader br = new BufferedReader(new StringReader(code));
try { try {
......
...@@ -268,7 +268,7 @@ ...@@ -268,7 +268,7 @@
<string name="Checking_Update">检查更新中,请稍候</string> <string name="Checking_Update">检查更新中,请稍候</string>
<string name="Found_Update">发现新版本,前往下载?</string> <string name="Found_Update">发现新版本,前往下载?</string>
<string name="Checking_Update_Failed">检查更新失败</string> <string name="Checking_Update_Failed">检查更新失败</string>
<string name="Ask_to_Change_Other_Way">主线下载失败,尝试备选线路中...</string> <string name="Ask_to_Change_Other_Way">主线获取失败,尝试备选线路中...</string>
<string name="DuelAssistant">决斗助手启用中</string> <string name="DuelAssistant">决斗助手启用中</string>
<string name="masterrule">学习大师规则</string> <string name="masterrule">学习大师规则</string>
<string name="tutorial">查看软件教程</string> <string name="tutorial">查看软件教程</string>
......
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