Commit cdde8627 authored by fallenstardust's avatar fallenstardust

发送版本号和下载地址供更新直达

parent 0167d4a0
......@@ -156,7 +156,7 @@ 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 = "https://ygomobile.top/verndwnload.txt";
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";
......
......@@ -47,6 +47,7 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat
long exitLasttime = 0;
public static String Version;
public static String Cache_link;
private static final int TYPE_GET_VERSION_OK = 0;
private static final int TYPE_GET_VERSION_FAILED = 1;
......@@ -71,15 +72,16 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat
super.handleMessage(msg);
switch (msg.what) {
case TYPE_GET_VERSION_OK:
Version = msg.obj.toString();
Log.i(BuildConfig.VERSION_NAME, Version);
if (!Version.equals(BuildConfig.VERSION_NAME) && !Version.isEmpty()) {
Version = msg.obj.toString().substring(0, msg.obj.toString().indexOf("|"));//截取版本号
Cache_link = msg.obj.toString().substring(msg.obj.toString().indexOf("|") + 1);
Log.i(BuildConfig.VERSION_NAME, Version + "和" + Cache_link);
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("https://netdisk.link/YGOMobile_" + Version + ".apk/links"));
intent.setData(Uri.parse(Cache_link));
startActivity(intent);
dialog.dismiss();
});
......@@ -174,7 +176,7 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat
private void showNewsCounts() {
mTextBadgeItem = new TextBadgeItem()
.setBorderWidth(4)//文本大小
.setGravity(Gravity.LEFT )//位置 默认右上
.setGravity(Gravity.LEFT)//位置 默认右上
.setBackgroundColorResource(R.color.holo_orange_bright)//背景颜色
.setAnimationDuration(200)//动画时间
.setText("3")
......@@ -356,12 +358,12 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat
message.what = TYPE_GET_VERSION_FAILED;
message.obj = e;
handlerHome.sendMessage(message);
Log.i(BuildConfig.VERSION_NAME, "error" + e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String json = response.body().string();
Log.i(BuildConfig.VERSION_NAME, json);
Message message = new Message();
message.what = TYPE_GET_VERSION_OK;
message.obj = json;
......
......@@ -93,6 +93,7 @@ public class SettingFragment extends PreferenceFragmentPlus {
private static final int TYPE_SETTING_GET_VERSION_FAILED = 1;
private AppsSettings mSettings;
public static String Version;
public static String Cache_link;
private boolean isInit = true;
public SettingFragment() {
......@@ -106,15 +107,16 @@ public class SettingFragment extends PreferenceFragmentPlus {
super.handleMessage(msg);
switch (msg.what) {
case TYPE_SETTING_GET_VERSION_OK:
Version = msg.obj.toString();
Log.i(BuildConfig.VERSION_NAME, Version);
if (!Version.equals(BuildConfig.VERSION_NAME) && !Version.isEmpty()) {
DialogPlus dialog = new DialogPlus(getContext());
Version = msg.obj.toString().substring(0, msg.obj.toString().indexOf("|"));//截取版本号
Cache_link = msg.obj.toString().substring(msg.obj.toString().indexOf("|") + 1);
Log.i(BuildConfig.VERSION_NAME, Version + "和" + Cache_link);
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("https://netdisk.link/YGOMobile_" + Version + ".apk/links"));
intent.setData(Uri.parse(Cache_link));
startActivity(intent);
dialog.dismiss();
});
......@@ -134,7 +136,7 @@ public class SettingFragment extends PreferenceFragmentPlus {
@Override
protected SharedPreferences getSharedPreferences() {
return mSettings.getSharedPreferences();
return AppsSettings.get().getSharedPreferences();
}
@Override
......@@ -250,7 +252,6 @@ public class SettingFragment extends PreferenceFragmentPlus {
}
}
mSettings.setDataLanguage(Integer.valueOf(listPreference.getValue()));
Log.i(BuildConfig.VERSION_NAME, mSettings.getDataLanguage() + preference.getKey() + listPreference.getValue());
Toast.makeText(getContext(), R.string.restart_app, Toast.LENGTH_LONG).show();
DataManager.get().load(true);
}
......@@ -287,12 +288,12 @@ public class SettingFragment extends PreferenceFragmentPlus {
message.what = TYPE_SETTING_GET_VERSION_FAILED;
message.obj = e;
handler.sendMessage(message);
Log.i(BuildConfig.VERSION_NAME, "error" + e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String json = response.body().string();
Log.i(BuildConfig.VERSION_NAME, json);
Message message = new Message();
message.what = TYPE_SETTING_GET_VERSION_OK;
message.obj = json;
......
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