From 3039fd3c503c5fd447bcc26b38abf4d952eeb5c8 Mon Sep 17 00:00:00 2001 From: Lazyeraser Date: Tue, 9 Jan 2018 17:57:12 +0800 Subject: [PATCH] 0.9.8: release --- .../imas/cgss/service/CGSSService.java | 4 +- .../imas/cgss/utils/UpdateManager.java | 13 ++++- .../imas/cgss/view/MainActivity.java | 51 +++++++++---------- .../imas/cgss/viewmodel/MainViewModel.java | 45 ++++++++-------- .../lazyeraser/imas/main/BaseActivity.java | 6 --- app/src/main/res/layout/activity_beat_map.xml | 6 ++- appupdate/version.json | 12 ++--- 7 files changed, 74 insertions(+), 63 deletions(-) diff --git a/app/src/main/java/com/lazyeraser/imas/cgss/service/CGSSService.java b/app/src/main/java/com/lazyeraser/imas/cgss/service/CGSSService.java index e668e50..e521ec3 100644 --- a/app/src/main/java/com/lazyeraser/imas/cgss/service/CGSSService.java +++ b/app/src/main/java/com/lazyeraser/imas/cgss/service/CGSSService.java @@ -23,7 +23,9 @@ public interface CGSSService { @Headers("X-Unity-Version:" + SStaticR.UNITY_VERSION) Observable getResources(@Path("hash") String hash); + @GET("http://346lab.org/dl/cgss_assets/{version}/manifests/Android_AHigh_SHigh") + Observable getManifestsRP(@Path("version") String version); + @GET("http://346lab.org/dl/cgss_assets/resources/Generic/{hash}") -// @Headers("X-Unity-Version:" + SStaticR.UNITY_VERSION) Observable getResourcesRP(@Path("hash") String hash); } diff --git a/app/src/main/java/com/lazyeraser/imas/cgss/utils/UpdateManager.java b/app/src/main/java/com/lazyeraser/imas/cgss/utils/UpdateManager.java index bfef7c9..12dfc96 100644 --- a/app/src/main/java/com/lazyeraser/imas/cgss/utils/UpdateManager.java +++ b/app/src/main/java/com/lazyeraser/imas/cgss/utils/UpdateManager.java @@ -103,7 +103,15 @@ private void getCurVersion() { private boolean needNoUpdateHint = false; private String verjson, versionInfo; //检查更新 - public void checkUpdate(boolean needNoUpdateHint) { + private OnUpdateCheckedListener onUpdateCheckedListener; + public interface OnUpdateCheckedListener{ + void onChecked(); + } + public void checkUpdate(boolean needNoUpdateHint){ + checkUpdate(needNoUpdateHint, null); + } + public void checkUpdate(boolean needNoUpdateHint, OnUpdateCheckedListener listener) { + this.onUpdateCheckedListener = listener; this.needNoUpdateHint = needNoUpdateHint; Utils.mPrint("checkUpdate:" + needNoUpdateHint); hasNewVersion = false; @@ -309,6 +317,9 @@ public void downloadCanceled() //检查更新 public void checkUpdateCompleted(Boolean hasUpdate, CharSequence updateInfo) { + if (onUpdateCheckedListener != null){ + onUpdateCheckedListener.onChecked(); + } if (hasUpdate) { new SweetAlertDialog(mContext, SweetAlertDialog.NORMAL_TYPE) .setTitleText(mContext.getString(R.string.dialog_update_title)) diff --git a/app/src/main/java/com/lazyeraser/imas/cgss/view/MainActivity.java b/app/src/main/java/com/lazyeraser/imas/cgss/view/MainActivity.java index fbbe4f7..adc3941 100644 --- a/app/src/main/java/com/lazyeraser/imas/cgss/view/MainActivity.java +++ b/app/src/main/java/com/lazyeraser/imas/cgss/view/MainActivity.java @@ -168,10 +168,13 @@ private void askRestart(){ private void checkUpdate(boolean hint){ needUpdateHint = hint; + if (hint) { + umi.showLoading(); + } if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions((Activity) mContext, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); }else { - updateManager.checkUpdate(hint); + updateManager.checkUpdate(hint, () -> umi.dismissLoading()); } } @@ -180,7 +183,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == 1 && permissions[0].equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)){ if (grantResults[0] == PackageManager.PERMISSION_GRANTED){ - updateManager.checkUpdate(needUpdateHint); + updateManager.checkUpdate(needUpdateHint, () -> umi.dismissLoading()); }else { umi.makeToast(R.string.permission_denied_hint); } @@ -202,31 +205,27 @@ private void initDialog(MainViewModel mainViewModel){ Messenger.getDefault().sendNoMsg(TOKEN_DATA_UPDATED); }) .setConfirmClickListener(alertDialog -> { - if (!SStaticR.isCnMainLand){ - alertDialog.dismiss(); - mainViewModel.agree.set(true); + alertDialog.dismiss(); + if (SStaticR.isCnMainLand && TextUtils.isEmpty(umi.spRead(SharedHelper.KEY_USE_REVERSE_PROXY))){ + SweetAlertDialog askRPDialog = new SweetAlertDialog(mContext, SweetAlertDialog.WARNING_TYPE) + .setTitleText("开启下载加速?") + .setContentText("可以解决部分网络环境谱面下载过慢的问题\n\n加速由346lab.org提供") + .setConfirmText("开启加速") + .setCancelText("直接下载") + .setConfirmClickListener(dialog -> { + umi.spSave(SharedHelper.KEY_USE_REVERSE_PROXY, "true"); + dialog.dismiss(); + mainViewModel.agree.set(true); + }) + .setCancelClickListener(dialog ->{ + umi.spSave(SharedHelper.KEY_USE_REVERSE_PROXY, "false"); + dialog.dismiss(); + mainViewModel.agree.set(true); + }); + askRPDialog.setCanceledOnTouchOutside(false); + askRPDialog.show(); }else { - if (TextUtils.isEmpty(umi.spRead(SharedHelper.KEY_USE_REVERSE_PROXY))){ - SweetAlertDialog askRPDialog = new SweetAlertDialog(mContext, SweetAlertDialog.WARNING_TYPE) - .setTitleText("开启下载加速?") - .setContentText("可以解决部分网络环境谱面下载过慢的问题\n\n加速由346lab.org提供") - .setConfirmText("开启加速") - .setCancelText("直接下载") - .setConfirmClickListener(dialog -> { - umi.spSave(SharedHelper.KEY_USE_REVERSE_PROXY, "true"); - dialog.dismiss(); - alertDialog.dismiss(); - mainViewModel.agree.set(true); - }) - .setCancelClickListener(dialog ->{ - umi.spSave(SharedHelper.KEY_USE_REVERSE_PROXY, "false"); - dialog.dismiss(); - alertDialog.dismiss(); - mainViewModel.agree.set(true); - }); - askRPDialog.setCanceledOnTouchOutside(false); - askRPDialog.show(); - } + mainViewModel.agree.set(true); } }); progressDialog = new SweetAlertDialog(mContext, SweetAlertDialog.PROGRESS_TYPE) diff --git a/app/src/main/java/com/lazyeraser/imas/cgss/viewmodel/MainViewModel.java b/app/src/main/java/com/lazyeraser/imas/cgss/viewmodel/MainViewModel.java index e9aeb45..384b734 100644 --- a/app/src/main/java/com/lazyeraser/imas/cgss/viewmodel/MainViewModel.java +++ b/app/src/main/java/com/lazyeraser/imas/cgss/viewmodel/MainViewModel.java @@ -139,27 +139,27 @@ private void checkData() { } if (update){ haveUpdate.set(true); + android.databinding.Observable.OnPropertyChangedCallback agreeCallBack = new android.databinding.Observable.OnPropertyChangedCallback() { + @Override + public void onPropertyChanged(android.databinding.Observable observable, int i) { + if (agree.get()) { + agree.set(false); + solved = 0; + boolean isUpdateManifest = info != null && !TextUtils.isEmpty(info.getTruth_version()); + isShowProgress.set(true); + total = allIds_card.size(); + if (newIds_card.size() > 0 || isUpdateManifest) { + upDateDB(isUpdateManifest, isUpdateManifest ? info.getTruth_version() : null); + } + agree.removeOnPropertyChangedCallback(this); + } + } + }; + agree.addOnPropertyChangedCallback(agreeCallBack); }else { upToDate.set(true); } umi.dismissLoading(); - android.databinding.Observable.OnPropertyChangedCallback agreeCallBack = new android.databinding.Observable.OnPropertyChangedCallback() { - @Override - public void onPropertyChanged(android.databinding.Observable observable, int i) { - if (agree.get()) { - agree.set(false); - solved = 0; - boolean isUpdateManifest = info != null && !TextUtils.isEmpty(info.getTruth_version()); - isShowProgress.set(true); - total = allIds_card.size(); - if (newIds_card.size() > 0 || isUpdateManifest) { - upDateDB(isUpdateManifest, isUpdateManifest ? info.getTruth_version() : null); - } - agree.removeOnPropertyChangedCallback(this); - } - } - }; - agree.addOnPropertyChangedCallback(agreeCallBack); }, ExceptionHandler::handleException); @@ -170,10 +170,12 @@ public void onPropertyChanged(android.databinding.Observable observable, int i) private void updateManifest(String truthVersion) { progress.set(-1); progressTxt.set(mContext.getString(R.string.update_hint_manifest)); - RetrofitProvider.getInstance(false).create(CGSSService.class) - .getManifests(truthVersion) - .subscribeOn(Schedulers.io()) - .subscribe(body -> { + useReverseProxy = umi.getSP(SharedHelper.KEY_USE_REVERSE_PROXY); + Observable manifestFile = useReverseProxy ? + RetrofitProvider.getInstance(false).create(CGSSService.class).getManifestsRP(truthVersion) : + RetrofitProvider.getInstance(false).create(CGSSService.class).getManifests(truthVersion); + + manifestFile.subscribeOn(Schedulers.io()).subscribe(body -> { try { FileHelper.writeFile(LZ4Helper.uncompressCGSS(body.bytes()), mContext.getFilesDir().getAbsolutePath(), DBHelper.DB_NAME_manifest); @@ -186,7 +188,6 @@ private void updateManifest(String truthVersion) { fileToDownload = new HashMap<>(); hashToDownload = new ArrayList<>(); - useReverseProxy = umi.getSP(SharedHelper.KEY_USE_REVERSE_PROXY); if (!masterHash.equals(umi.spRead(SharedHelper.KEY_MasterDbHash))) { // update master.db addFileDownloadMission(masterHash, DBHelper.DB_NAME_master, mContext.getFilesDir().getAbsolutePath()); diff --git a/app/src/main/java/com/lazyeraser/imas/main/BaseActivity.java b/app/src/main/java/com/lazyeraser/imas/main/BaseActivity.java index f56f9f4..ea3e36a 100644 --- a/app/src/main/java/com/lazyeraser/imas/main/BaseActivity.java +++ b/app/src/main/java/com/lazyeraser/imas/main/BaseActivity.java @@ -239,16 +239,10 @@ public interface OnBackBtnClickedListener { @Override protected void onResume() { super.onResume(); - if (SStaticR.ANALYTICS_ON){ - - } } @Override protected void onPause() { super.onPause(); - if (SStaticR.ANALYTICS_ON){ - - } } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_beat_map.xml b/app/src/main/res/layout/activity_beat_map.xml index 165d915..7b3ca98 100644 --- a/app/src/main/res/layout/activity_beat_map.xml +++ b/app/src/main/res/layout/activity_beat_map.xml @@ -17,7 +17,9 @@ + android:id="@+id/scrollView" + android:layout_alignParentTop="true" + android:layout_alignParentStart="true">