fix check update

This commit is contained in:
世界 2020-05-16 11:26:07 +08:00
parent d05b6fc9c5
commit c6604a31e5
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
2 changed files with 73 additions and 3 deletions

View File

@ -1,12 +1,19 @@
package tw.nekomimi.nekogram.parts
import android.app.Activity
import android.content.IntentSender
import com.google.android.play.core.appupdate.AppUpdateManagerFactory
import com.google.android.play.core.install.InstallStateUpdatedListener
import com.google.android.play.core.install.model.AppUpdateType
import com.google.android.play.core.install.model.InstallStatus
import com.google.android.play.core.install.model.UpdateAvailability
import org.json.JSONObject
import org.telegram.messenger.BuildConfig
import org.telegram.messenger.LocaleController
import org.telegram.messenger.R
import org.telegram.ui.Cells.TextCell
import tw.nekomimi.nekogram.BottomBuilder
import tw.nekomimi.nekogram.ExternalGcm
import tw.nekomimi.nekogram.NekoXConfig
import tw.nekomimi.nekogram.utils.*
import java.util.*
@ -93,6 +100,65 @@ fun Activity.checkUpdate(force: Boolean = false) {
UIUtil.runOnIoDispatcher {
if (ExternalGcm.checkPlayServices() && !force) {
progress.uUpdate(LocaleController.getString("Checking", R.string.Checking) + " (Play Store)")
val manager = AppUpdateManagerFactory.create(this)
manager.registerListener(InstallStateUpdatedListener {
if (it.installStatus() == InstallStatus.DOWNLOADED) {
val builder = BottomBuilder(this)
builder.addTitle(LocaleController.getString("UpdateDownloaded", R.string.UpdateDownloaded), false)
builder.addItem(LocaleController.getString("UpdateUpdate", R.string.UpdateUpdate), R.drawable.baseline_system_update_24, false) {
manager.completeUpdate()
}
builder.addItem(LocaleController.getString("UpdateLater", R.string.UpdateLater), R.drawable.baseline_watch_later_24, false, null)
builder.show()
}
})
manager.appUpdateInfo.addOnSuccessListener {
progress.dismiss()
if (it.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && it.availableVersionCode() > BuildConfig.VERSION_CODE) {
try {
manager.startUpdateFlowForResult(it, AppUpdateType.FLEXIBLE, this, 114514)
} catch (ignored: IntentSender.SendIntentException) {
}
} else {
AlertUtil.showToast(LocaleController.getString("NoUpdate", R.string.NoUpdate))
}
}.addOnFailureListener {
progress.uDismiss()
AlertUtil.showToast(it.message ?: it.javaClass.simpleName)
}
return@runOnIoDispatcher
}
progress.uUpdate(LocaleController.getString("Checking", R.string.Checking) + " (Repo)")
val ex = LinkedList<Throwable>()

View File

@ -8,7 +8,11 @@ import okhttp3.Request
import okhttp3.Response
import okhttp3.internal.closeQuietly
import org.json.JSONObject
import org.telegram.messenger.*
import org.telegram.messenger.BuildVars
import org.telegram.messenger.FileLog
import org.telegram.messenger.LocaleController
import org.telegram.messenger.BuildConfig
import org.telegram.messenger.R
import org.tukaani.xz.XZInputStream
import tw.nekomimi.nekogram.BottomBuilder
import tw.nekomimi.nekogram.ExternalGcm
@ -46,7 +50,7 @@ object UpdateUtil {
FileLog.d("checking updates from repo")
if (System.currentTimeMillis() - NekoXConfig.preferences.getLong("ignored_update_at", -1) > 1 * 60 * 60 * 1000L) {
if (System.currentTimeMillis() - NekoXConfig.preferences.getLong("ignored_update_at", -1) < 1 * 60 * 60 * 1000L) {
FileLog.d("ignored")
@ -116,7 +120,7 @@ object UpdateUtil {
}
fun doUpdate(ctx: Activity, targetVer: Int, defFlavor: String,buildType: String = BuildConfig.BUILD_TYPE,flavor: String = BuildConfig.FLAVOR) {
fun doUpdate(ctx: Activity, targetVer: Int, defFlavor: String, buildType: String = BuildConfig.BUILD_TYPE, flavor: String = BuildConfig.FLAVOR) {
val pro = AlertUtil.showProgress(ctx)
pro.setCanCacnel(false)