2020-12-15 06:44:38 +01:00
|
|
|
package org.thoughtcrime.securesms.util
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import java.io.IOException
|
|
|
|
import java.lang.RuntimeException
|
|
|
|
|
2021-01-15 06:51:53 +01:00
|
|
|
import org.session.libsession.utilities.TextSecurePreferences
|
|
|
|
|
2020-12-15 06:44:38 +01:00
|
|
|
object VersionTracker {
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
fun getLastSeenVersion(context: Context): Int {
|
|
|
|
var version = TextSecurePreferences.getLastVersionCode(context)
|
|
|
|
// Zero means the app is freshly installed = user is actually on the current version.
|
|
|
|
if (version == 0) {
|
|
|
|
version = updateLastSeenVersion(context)
|
|
|
|
}
|
|
|
|
return version
|
|
|
|
}
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
fun updateLastSeenVersion(context: Context): Int {
|
|
|
|
return try {
|
|
|
|
val currentVersionCode = Util.getCanonicalVersionCode()
|
|
|
|
TextSecurePreferences.setLastVersionCode(context, currentVersionCode)
|
|
|
|
currentVersionCode
|
|
|
|
} catch (e: IOException) {
|
|
|
|
throw RuntimeException("Failed to update the last seen app version.", e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|