Last active
December 13, 2020 12:07
-
-
Save gokmenbayram/89f8f12ee4c917277d2eb33ea7cb5d60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity() { | |
private val apiClient by lazy { FirebaseClient() } | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
apiClient.getAppVersionFromApi { isSuccess, response, message -> | |
if (isSuccess) { | |
var newVersion = response?.documents?.first()?.fields?.app_version?.version | |
var appVersion = appVersion(this) | |
if (appVersion != newVersion) | |
showAlert(this) | |
} | |
} | |
} | |
private fun appVersion(context: Context): String { | |
var manager = context.packageManager | |
var info = manager.getPackageInfo(context.packageName, 0) | |
return info.versionName | |
} | |
private fun showAlert(context: AppCompatActivity) { | |
val alert = AlertView("Force Update", "Uygulamanızın yeni versiyonu mevcuttur. Güncellemek için tıklayın.", AlertStyle.DIALOG) | |
alert.addAction(AlertAction("Güncelle", AlertActionStyle.POSITIVE, { | |
// Play Store'a yonlendir. | |
})) | |
alert.addAction(AlertAction("Vazgeç", AlertActionStyle.NEGATIVE, { | |
})) | |
alert.show(context) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment