Commit 8f7e91ef authored by fallenstardust's avatar fallenstardust

我的->检查更新功能更改

parent 1e4d28ef
......@@ -36,12 +36,14 @@ import static cn.garymb.ygomobile.Constants.SETTINGS_COVER;
import static cn.garymb.ygomobile.Constants.URL_YGO233_DOWNLOAD_LINK;
import static cn.garymb.ygomobile.ui.home.ResCheckTask.getDatapath;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
......@@ -74,7 +76,6 @@ import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.lite.BuildConfig;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.adapters.SimpleListAdapter;
import cn.garymb.ygomobile.ui.home.HomeFragment;
import cn.garymb.ygomobile.ui.home.MainActivity;
import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.ui.plus.VUiKit;
......@@ -89,14 +90,49 @@ import okhttp3.Callback;
import okhttp3.Response;
public class SettingFragment extends PreferenceFragmentPlus {
private static final int TYPE_GET_VERSION_OK = 0;
private static final int TYPE_GET_VERSION_FAILED = 1;
private AppsSettings mSettings;
private HomeFragment mHomeFragment;
public static String Version;
private boolean isInit = true;
public SettingFragment() {
}
@SuppressLint("HandlerLeak")
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
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)) {
DialogPlus dialog = new DialogPlus(getContext());
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"));
startActivity(intent);
dialog.dismiss();
});
dialog.show();
} else {
Toast.makeText(getContext(), R.string.Already_Lastest, Toast.LENGTH_SHORT).show();
}
break;
case TYPE_GET_VERSION_FAILED:
String error = msg.obj.toString();
Toast.makeText(getContext(), getString(R.string.Checking_Update_Failed) + error, Toast.LENGTH_SHORT).show();
break;
}
}
};
@Override
protected SharedPreferences getSharedPreferences() {
return AppsSettings.get().getSharedPreferences();
......@@ -107,7 +143,6 @@ public class SettingFragment extends PreferenceFragmentPlus {
super.onCreate(savedInstanceState);
setHasOptionsMenu(false);
mSettings = AppsSettings.get();
mHomeFragment = new HomeFragment();
addPreferencesFromResource(R.xml.preference_game);
bind(PREF_GAME_PATH, mSettings.getResourcePath());
......@@ -218,19 +253,7 @@ public class SettingFragment extends PreferenceFragmentPlus {
joinQQGroup(groupkey);
}
if (PREF_CHECK_UPDATE.equals(key)) {
OkhttpUtil.get(URL_YGO233_DOWNLOAD_LINK, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
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, StringUtils.substringBetween(json,"https://netdisk.link/", "/links"));
}
});
//Beta.checkUpgrade();
checkUpgrade();
}
if (PREF_DEL_EX.equals(key)) {
File[] ypks = new File(AppsSettings.get().getExpansionsPath().getAbsolutePath()).listFiles();
......@@ -565,6 +588,28 @@ public class SettingFragment extends PreferenceFragmentPlus {
});
}
public void checkUpgrade(){
OkhttpUtil.get(URL_YGO233_DOWNLOAD_LINK, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Message message = new Message();
message.what = TYPE_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();
Message message = new Message();
message.what = TYPE_GET_VERSION_OK;
message.obj = StringUtils.substringBetween(json, "https://netdisk.link/YGOMobile_", ".apk/links");
handler.sendMessage(message);
}
});
}
public boolean joinQQGroup(String key) {
Intent intent = new Intent();
intent.setData(Uri.parse("mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26k%3D" + key));
......
......@@ -251,6 +251,7 @@
<string name="OK">확인</string>
<string name="Cancel">취소</string>
<string name="Checking_Update">업데이트를 확인하는 중입니다. 잠시 기다려 주십시오.</string>
<string name="Found_Update">새 업그레이드 버전을 찾아 다운로드하시겠습니까?</string>
<string name="Checking_Update_Failed">업데이트 확인 실패</string>
<string name="Ask_to_Change_Other_Way">다른 방식을 시도해 봐...</string>
<string name="DuelAssistant">듀얼 어시스턴트가 활성화되었습니다</string>
......
......@@ -251,6 +251,7 @@
<string name="OK">确定</string>
<string name="Cancel">取消</string>
<string name="Checking_Update">检查更新中,请稍候</string>
<string name="Found_Update">发现新版本,前往下载?</string>
<string name="Checking_Update_Failed">检查更新失败</string>
<string name="Ask_to_Change_Other_Way">主线下载失败,尝试备选线路中...</string>
<string name="DuelAssistant">决斗助手启用中</string>
......
......@@ -249,6 +249,7 @@
<string name="OK">OK</string>
<string name="Cancel">Cancel</string>
<string name="Checking_Update">Now Checking Update</string>
<string name="Found_Update">New upGrade is Founded, Download?</string>
<string name="Checking_Update_Failed">Checking Update Failed</string>
<string name="Ask_to_Change_Other_Way">trying other way...</string>
<string name="DuelAssistant">DuelAssiatant is On</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