2022-09-04 22:52:40 -03:00
|
|
|
package com.geeksville.mesh.android
|
|
|
|
|
|
|
|
|
|
import android.app.Activity
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
import android.net.Uri
|
|
|
|
|
import android.widget.Toast
|
2022-12-28 17:37:25 -03:00
|
|
|
import com.geeksville.mesh.R
|
2022-09-04 22:52:40 -03:00
|
|
|
import java.util.*
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created by kevinh on 1/13/16.
|
|
|
|
|
*/
|
|
|
|
|
class ExpireChecker(val context: Activity) : Logging {
|
|
|
|
|
|
|
|
|
|
fun check(year: Int, month: Int, day: Int) {
|
|
|
|
|
val expireDate = DateUtils.dateUTC(year, month, day)
|
|
|
|
|
val now = Date()
|
|
|
|
|
|
|
|
|
|
debug("Expire check $now vs $expireDate")
|
|
|
|
|
if (now.after(expireDate))
|
|
|
|
|
doExpire()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun doExpire() {
|
|
|
|
|
val packageName = context.packageName
|
|
|
|
|
errormsg("$packageName is too old and must be updated at the Play store")
|
|
|
|
|
|
|
|
|
|
Toast.makeText(
|
|
|
|
|
context,
|
2022-12-28 17:37:25 -03:00
|
|
|
R.string.app_too_old,
|
2022-09-04 22:52:40 -03:00
|
|
|
Toast.LENGTH_LONG
|
|
|
|
|
).show()
|
|
|
|
|
val i = Intent(Intent.ACTION_VIEW)
|
|
|
|
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
|
|
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
|
|
|
|
i.setData(Uri.parse("market://details?id=$packageName&referrer=utm_source%3Dexpired"))
|
|
|
|
|
context.startActivity(i)
|
|
|
|
|
context.finish()
|
|
|
|
|
}
|
|
|
|
|
}
|