diff --git a/app/src/main/java/com/gh/gamecenter/LibaoDetailActivity.java b/app/src/main/java/com/gh/gamecenter/LibaoDetailActivity.java index 8070fa97d3..f1ef9f720e 100644 --- a/app/src/main/java/com/gh/gamecenter/LibaoDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/LibaoDetailActivity.java @@ -4,7 +4,6 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.os.Handler; import android.os.Message; import android.support.annotation.NonNull; import android.support.v7.widget.LinearLayoutManager; @@ -18,9 +17,9 @@ import com.gh.base.BaseActivity; import com.gh.base.OnRequestCallBackListener; import com.gh.common.util.ApkActiveUtils; import com.gh.common.util.DetailDownloadUtils; +import com.gh.common.util.DeviceTokenUtils; import com.gh.common.util.EntranceUtils; import com.gh.common.util.LibaoUtils; -import com.gh.common.util.DeviceTokenUtils; import com.gh.common.view.DownloadProgressBar; import com.gh.common.view.VerticalItemDecoration; import com.gh.download.DownloadManager; @@ -91,38 +90,35 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap protected String mDownloadAddWord; protected String mDownloadOffText; - private Handler handler = new Handler() { - @Override - public void handleMessage(Message msg) { - super.handleMessage(msg); - if (msg.what == 0) { - long time = Utils.getTime(LibaoDetailActivity.this) - 5; // -5 防止获取服务器时间延迟发生的计算错误() - Calendar calendar = Calendar.getInstance(); - Date date = new Date(time * 1000); - calendar.setTime(date); - calendar.set(Calendar.HOUR_OF_DAY, 24); - calendar.set(Calendar.SECOND, 0); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.MILLISECOND, 0); + @Override + protected void handleMessage(Message msg) { + super.handleMessage(msg); + if (msg.what == 0) { + long time = Utils.getTime(LibaoDetailActivity.this) - 5; // -5 防止获取服务器时间延迟发生的计算错误() + Calendar calendar = Calendar.getInstance(); + Date date = new Date(time * 1000); + calendar.setTime(date); + calendar.set(Calendar.HOUR_OF_DAY, 24); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.MILLISECOND, 0); - long targetTime = calendar.getTimeInMillis(); - long delayedTime = targetTime - time * 1000; - Utils.log("=========delayedTime::" + delayedTime); - if (BuildConfig.DEBUG) { - toast("领取时间剩余: " + (delayedTime / 1000) + " 秒"); - } - handler.sendEmptyMessageDelayed(1, delayedTime); - } else if (msg.what == 1) { - String beforeStatus = mLibaoEntity.getBeforeStatus(); - if ("ling".equals(beforeStatus)) { - mLibaoEntity.setStatus("repeatLinged"); // 可以重复领取 - } else { - mLibaoEntity.setStatus("repeatTaoed"); // 可以重复领取 - } - mAdapter.notifyItemChanged(0); + long targetTime = calendar.getTimeInMillis(); + long delayedTime = targetTime - time * 1000; + if (BuildConfig.DEBUG) { + toast("领取时间剩余: " + (delayedTime / 1000) + " 秒"); } + mBaseHandler.sendEmptyMessageDelayed(1, delayedTime); + } else if (msg.what == 1) { + String beforeStatus = mLibaoEntity.getBeforeStatus(); + if ("ling".equals(beforeStatus)) { + mLibaoEntity.setStatus("repeatLinged"); // 可以重复领取 + } else { + mLibaoEntity.setStatus("repeatTaoed"); // 可以重复领取 + } + mAdapter.notifyItemChanged(0); } - }; + } private DataWatcher dataWatcher = new DataWatcher() { @Override @@ -150,7 +146,6 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap @NonNull public static Intent getIntent(Context context, LibaoEntity libaoEntity, String entrance) { Intent intent = new Intent(context, LibaoDetailActivity.class); -// intent.putExtra(LibaoEntity.TAG, libaoEntity); HaloApp.put(LibaoEntity.TAG, libaoEntity); intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance); return intent; @@ -167,7 +162,6 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); -// outState.putParcelable(LibaoEntity.TAG, mAdapter.getLibaoEntity()); HaloApp.put(LibaoEntity.TAG, mAdapter.getLibaoEntity()); } @@ -176,7 +170,6 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap super.onCreate(savedInstanceState); mName = getString(R.string.libao_detail); setNavigationTitle(mName); -// mLibaoEntity = getIntent().getParcelableExtra(LibaoEntity.TAG); mLibaoEntity = (LibaoEntity) HaloApp.get(LibaoEntity.TAG, false); mIsScroll = true; @@ -196,12 +189,7 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap public void onClick(View v) { mNoConnection.setVisibility(View.GONE); mLlLoading.setVisibility(View.VISIBLE); - handler.postDelayed(new Runnable() { - @Override - public void run() { - getGameDigest(); - } - }, 1000); + mBaseHandler.postDelayed(() -> getGameDigest(), 1000); } }); @@ -277,7 +265,7 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap ("ling".equals(beforeStatus) || "tao".equals(beforeStatus))) { //检查是否到了重复领取时间 mListStatus = mLibaoEntity.getStatus(); if (isCanLing()) { - handler.sendEmptyMessage(1); + mBaseHandler.sendEmptyMessage(1); } else { if ("ling".equals(beforeStatus)) { mLibaoEntity.setStatus("repeatLing"); // 预备重复领取 @@ -287,7 +275,7 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap mAdapter.notifyItemChanged(0); DeviceTokenUtils.syncServerTime(LibaoDetailActivity.this); - handler.sendEmptyMessageDelayed(0, 5000); + mBaseHandler.sendEmptyMessageDelayed(0, 5000); } } } @@ -386,12 +374,6 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap mIsScroll = isScroll; } - @Override - protected void onDestroy() { - super.onDestroy(); - handler.removeCallbacksAndMessages(null); - } - @Override public boolean handleBackPressed() { // 重置领取状态 @@ -466,7 +448,7 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(EBUISwitch swith) { if (LibaoUtils.REFRESH_LIBAO_TIME.equals(swith.getFrom())) { - handler.sendEmptyMessageDelayed(1, swith.getPosition()); + mBaseHandler.sendEmptyMessageDelayed(1, swith.getPosition()); } } diff --git a/app/src/main/java/com/gh/gamecenter/entity/AppEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/AppEntity.kt index c2c1dd4eb7..707c283e97 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/AppEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/entity/AppEntity.kt @@ -6,6 +6,9 @@ class AppEntity { var version: String? = null + @SerializedName("version_code") + var versionCode: Int = 0 + var url: String? = null var size: String? = null diff --git a/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java b/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java index 44610b0fb4..df90dc3c6d 100644 --- a/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java +++ b/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java @@ -2,7 +2,6 @@ package com.gh.gamecenter.manager; import android.app.Dialog; import android.content.Context; -import android.content.DialogInterface; import android.content.SharedPreferences; import android.os.Handler; import android.os.Message; @@ -38,7 +37,6 @@ import java.util.Date; import java.util.Locale; import io.reactivex.android.schedulers.AndroidSchedulers; -import io.reactivex.functions.Function; import io.reactivex.schedulers.Schedulers; import retrofit2.HttpException; @@ -53,14 +51,15 @@ public class UpdateManager { private AppEntity appEntity; private Dialog downloadDialog; + private Dialog loadingDialog; + private ProgressBar app_pb_progress; private TextView app_tv_speed; private TextView app_tv_percent; - private Dialog loadingDialog; - private boolean isShowDownload; private boolean isChecking; + private DataWatcher dataWatcher = new DataWatcher() { @Override public void onDataChanged(DownloadEntity downloadEntity) { @@ -104,56 +103,40 @@ public class UpdateManager { } // 检查更新 - public void checkUpdate(final boolean isCheck, final Handler handler) { + public void checkUpdate(final boolean isAutoCheck, final Handler handler) { if (isChecking) { return; } isChecking = true; - if (!isCheck) { + if (!isAutoCheck) { loadingDialog = DialogUtils.showWaitDialog(mContext, "检查更新中..."); } String channel = HaloApp.getInstance().getChannel(); RetrofitManager.getInstance(mContext).getApi().getUpdate(PackageUtils.getVersionName(), channel) - .map(new Function() { - @Override - public String apply(AppEntity appEntity) { - String md5 = null; + .map(appEntity -> { + String md5 = null; - float version = Float.valueOf(appEntity.getVersion()); - float currentVersion = Float.valueOf(PackageUtils.getVersionName()); - if (version > currentVersion) { - // 助手有更新 - UpdateManager.this.appEntity = appEntity; + float version = Float.valueOf(appEntity.getVersion()); + float currentVersion = Float.valueOf(PackageUtils.getVersionName()); + if (version > currentVersion) { + // 助手有更新 + UpdateManager.this.appEntity = appEntity; - if (isCheck) { - if (appEntity.isForce()) { - // 强制更新 - md5 = MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent()); - } else { - // 非强制更新 - if ("EVERY_TIME_OPEN".equals(appEntity.getAlert())) { - // 每次都提示 - md5 = MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent()); - } else if (!"NEVER".equals(appEntity.getAlert())) { - // 一天提示一次 - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); - String showUpdateTime = sp.getString("show_update_tiem", null); - SimpleDateFormat format = new SimpleDateFormat( - "yyyy-MM-dd", Locale.getDefault()); - String today = format.format(new Date()); - if (!today.equals(showUpdateTime)) { - sp.edit().putString("show_update_tiem", today).apply(); - md5 = MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent()); - } - } - } - } else { + // 手动更新 强制更新 每次都提示 + if (!isAutoCheck || appEntity.isForce() || "EVERY_TIME_OPEN".equals(appEntity.getAlert())) { + md5 = MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent()); + } else if (!"NEVER".equals(appEntity.getAlert())) { // 一天提示一次 + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); + String showUpdateTime = sp.getString("show_update_tiem", null); + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); + String today = format.format(new Date()); + if (!today.equals(showUpdateTime)) { + sp.edit().putString("show_update_tiem", today).apply(); md5 = MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent()); } } - - return md5; } + return md5; }) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) @@ -172,7 +155,7 @@ public class UpdateManager { message.obj = appEntity.getVersion(); handler.sendMessage(message); } - } else if (!isCheck) { + } else if (!isAutoCheck) { Utils.toast(mContext, "已是最新版本"); if (handler != null) { handler.sendEmptyMessage(1); @@ -186,7 +169,7 @@ public class UpdateManager { if (loadingDialog != null) { loadingDialog.dismiss(); } - if (!isCheck) { + if (!isAutoCheck) { if (handler != null) { handler.sendEmptyMessage(1); } @@ -207,42 +190,36 @@ public class UpdateManager { View view = View.inflate(mContext, R.layout.app_update_hint_dialog, null); - TextView content = (TextView) view.findViewById(R.id.updeta_content); + TextView content = view.findViewById(R.id.updeta_content); content.setText(Html.fromHtml(appEntity.getContent())); - TextView version = (TextView) view.findViewById(R.id.update_app_version); + TextView version = view.findViewById(R.id.update_app_version); version.setText(String.format("光环助手V%s更新内容:", appEntity.getVersion())); - TextView size = (TextView) view.findViewById(R.id.update_app_size); + TextView size = view.findViewById(R.id.update_app_size); size.setText(String.format("大小:%s", appEntity.getSize())); view.findViewById(R.id.update_cancel).setOnClickListener( - new View.OnClickListener() { - @Override - public void onClick(View v) { - if (appEntity.isForce()) { - AppManager.getInstance().finishAllActivity(); - } else { - updateDialog.dismiss(); - } + v -> { + if (appEntity.isForce()) { + AppManager.getInstance().finishAllActivity(); + } else { + updateDialog.dismiss(); } }); view.findViewById(R.id.update_confirm).setOnClickListener( - new View.OnClickListener() { - @Override - public void onClick(View v) { - updateDialog.dismiss(); - String path = FileUtils.getDownloadPath(mContext, - "光环助手V" + appEntity.getVersion() + "_" + md5 + ".apk"); - File file = new File(path); - if (file.exists() && file.length() > 0) { - DataLogUtils.uploadUpgradeLog(mContext, "install"); //上传更新安装数据 - mContext.startActivity(PackageUtils.getInstallIntent(mContext, path)); - } else { - DataUtils.onEvent(mContext, "软件更新", "下载开始"); - showDownloadDialog(md5); - } + v -> { + updateDialog.dismiss(); + String path = FileUtils.getDownloadPath(mContext, + "光环助手V" + appEntity.getVersion() + "_" + md5 + ".apk"); + File file = new File(path); + if (file.exists() && file.length() > 0) { + DataLogUtils.uploadUpgradeLog(mContext, "install"); //上传更新安装数据 + mContext.startActivity(PackageUtils.getInstallIntent(mContext, path)); + } else { + DataUtils.onEvent(mContext, "软件更新", "下载开始"); + showDownloadDialog(md5); } }); @@ -262,28 +239,22 @@ public class UpdateManager { View view = View.inflate(mContext, R.layout.app_updating_dialog, null); - app_pb_progress = (ProgressBar) view.findViewById(R.id.app_pb_progress); - app_tv_speed = (TextView) view.findViewById(R.id.app_tv_speed); - app_tv_percent = (TextView) view.findViewById(R.id.app_tv_percent); + app_pb_progress = view.findViewById(R.id.app_pb_progress); + app_tv_speed = view.findViewById(R.id.app_tv_speed); + app_tv_percent = view.findViewById(R.id.app_tv_percent); - view.findViewById(R.id.app_tv_cancel).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - DownloadManager.getInstance(mContext).cancel(appEntity.getUrl()); - if (appEntity.isForce()) { - AppManager.getInstance().finishAllActivity(); - } else { - downloadDialog.dismiss(); - } + view.findViewById(R.id.app_tv_cancel).setOnClickListener(v -> { + DownloadManager.getInstance(mContext).cancel(appEntity.getUrl()); + if (appEntity.isForce()) { + AppManager.getInstance().finishAllActivity(); + } else { + downloadDialog.dismiss(); } }); - downloadDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - DownloadManager.getInstance(mContext).removeObserver(dataWatcher); - isShowDownload = false; - } + downloadDialog.setOnDismissListener(dialog -> { + DownloadManager.getInstance(mContext).removeObserver(dataWatcher); + isShowDownload = false; }); downloadDialog.setCanceledOnTouchOutside(false); diff --git a/app/src/main/java/com/gh/gamecenter/subject/SubjectActivity.kt b/app/src/main/java/com/gh/gamecenter/subject/SubjectActivity.kt index 4e6be06136..d5c4f7f0e5 100644 --- a/app/src/main/java/com/gh/gamecenter/subject/SubjectActivity.kt +++ b/app/src/main/java/com/gh/gamecenter/subject/SubjectActivity.kt @@ -48,7 +48,7 @@ class SubjectActivity : BaseActivity() { mViewModel?.subjectNameLD?.observe(this, Observer { setNavigationTitle(it) }) - + mLoading.setOnClickListener {} mNoConn.setOnClickListener { mLoading.visibility = View.VISIBLE mNoConn.visibility = View.GONE diff --git a/app/src/main/java/com/halo/assistant/fragment/AboutFragment.java b/app/src/main/java/com/halo/assistant/fragment/AboutFragment.java index a44b56ed87..adcf1f4f81 100644 --- a/app/src/main/java/com/halo/assistant/fragment/AboutFragment.java +++ b/app/src/main/java/com/halo/assistant/fragment/AboutFragment.java @@ -2,7 +2,6 @@ package com.halo.assistant.fragment; import android.content.Intent; import android.os.Bundle; -import android.os.Handler; import android.os.Message; import android.support.v4.content.ContextCompat; import android.text.TextUtils; @@ -21,8 +20,6 @@ import com.gh.gamecenter.normal.NormalFragment; import com.halo.assistant.HaloApp; import com.tencent.bugly.beta.tinker.TinkerManager; -import java.lang.ref.WeakReference; - import butterknife.BindView; import butterknife.OnClick; import butterknife.OnLongClick; @@ -44,7 +41,18 @@ public class AboutFragment extends NormalFragment { @BindView(R.id.about_gh_icon) View mIcon; - private Handler handler = new MyHandler(this); + // update callback + @Override + protected void handleMessage(Message msg) { + super.handleMessage(msg); + if (msg.what == 0) { + final String version = (String) msg.obj; + mAboutVersion.setText(StringUtils.buildString("发现新版本 V", version)); + mAboutVersion.setTextColor(ContextCompat.getColor(getContext(), R.color.theme)); + } else if (msg.what == 1) { + mAboutVersion.setText(R.string.toast_upload_latest); + } + } @Override protected int getLayoutId() { @@ -59,7 +67,7 @@ public class AboutFragment extends NormalFragment { mVersionName.setText(("V" + PackageUtils.getVersionName())); if (getArguments() != null && getArguments().getBoolean(EntranceUtils.KEY_VERSION_UPDATE)) { - UpdateManager.getInstance(getContext()).checkUpdate(false, handler); // 检查更新 + UpdateManager.getInstance(getContext()).checkUpdate(false, mBaseHandler); // 检查更新 } mIcon.setOnLongClickListener(v -> { @@ -68,16 +76,10 @@ public class AboutFragment extends NormalFragment { }); } - @Override - public void onDestroy() { - super.onDestroy(); - handler.removeCallbacksAndMessages(null); - } - @OnClick({R.id.about_shengming, R.id.setting_rl_update}) public void OnClick(View view) { if (view.getId() == R.id.setting_rl_update) { - UpdateManager.getInstance(getContext()).checkUpdate(false, handler); // 检查更新 + UpdateManager.getInstance(getContext()).checkUpdate(false, mBaseHandler); // 检查更新 } else if (view.getId() == R.id.about_shengming) { Intent intent = WebActivity.getWebIntent(getContext()); startActivity(intent); @@ -96,29 +98,4 @@ public class AboutFragment extends NormalFragment { } return false; } - - private static class MyHandler extends Handler { - - private WeakReference mWeakReference; - - public MyHandler(AboutFragment fragment) { - mWeakReference = new WeakReference<>(fragment); - } - - @Override - public void handleMessage(Message msg) { - super.handleMessage(msg); - final AboutFragment fragment = mWeakReference.get(); - if (fragment != null) { - if (msg.what == 0) { - final String version = (String) msg.obj; - fragment.mAboutVersion.setText(StringUtils.buildString("发现新版本 V", version)); - fragment.mAboutVersion.setTextColor(ContextCompat.getColor(fragment.getContext(), R.color.theme)); - } else if (msg.what == 1) { - fragment.mAboutVersion.setText(R.string.toast_upload_latest); - } - } - } - } - }