Add old > new version indicator

This commit is contained in:
Rahul Kumar Patel
2021-02-25 17:40:59 +05:30
parent a0565384cc
commit 55e24c091f
2 changed files with 19 additions and 3 deletions

View File

@@ -51,6 +51,19 @@ object PackageUtil {
} }
} }
fun getInstalledVersion(context: Context, packageName: String): String {
return try {
val packageInfo = getPackageInfo(context, packageName)
if (packageInfo != null) {
"${packageInfo.versionName}.${packageInfo.versionCode}"
} else {
""
}
} catch (e: PackageManager.NameNotFoundException) {
""
}
}
fun isTv(context: Context): Boolean { fun isTv(context: Context): Boolean {
val uiMode = context.resources.configuration.uiMode val uiMode = context.resources.configuration.uiMode
return uiMode and Configuration.UI_MODE_TYPE_MASK == Configuration.UI_MODE_TYPE_TELEVISION return uiMode and Configuration.UI_MODE_TYPE_MASK == Configuration.UI_MODE_TYPE_TELEVISION

View File

@@ -490,12 +490,15 @@ class AppDetailsActivity : BaseDetailsActivity() {
app.versionCode.toLong() app.versionCode.toLong()
) )
val installedVersion = PackageUtil.getInstalledVersion(this, app.packageName)
if (isUpdatable) { if (isUpdatable) {
B.layoutDetailsApp.txtLine3.text =
("$installedVersion > ${app.versionName}.${app.versionCode}")
btn.setText(R.string.action_update) btn.setText(R.string.action_update)
btn.addOnClickListener { btn.addOnClickListener { startDownload() }
startDownload()
}
} else { } else {
B.layoutDetailsApp.txtLine3.text = installedVersion
btn.setText(R.string.action_open) btn.setText(R.string.action_open)
btn.addOnClickListener { openApp() } btn.addOnClickListener { openApp() }
} }