Skip to content

Instantly share code, notes, and snippets.

@EdgeJH
Created May 18, 2020 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EdgeJH/4f320c7acb78429a0ebb7974073bdd39 to your computer and use it in GitHub Desktop.
Save EdgeJH/4f320c7acb78429a0ebb7974073bdd39 to your computer and use it in GitHub Desktop.
class InheritInAppUpdateActivity : InAppUpdateActivity() {
private lateinit var progressBar:ProgressBar
private lateinit var progressTv : TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_inherit_in_app_update)
initView()
checkUpdate()
}
private fun initView(){
progressBar = findViewById(R.id.progress_bar)
progressTv = findViewById(R.id.progress_tv)
}
override fun onUpdateAvailable(appUpdateInfo: AppUpdateInfo, updateAvailable: Boolean) {
if (updateAvailable){
startUpdate(appUpdateInfo)
}
}
override fun onInstallState(installState: InstallState, bytesDownLoaded: Long, totalBytesToDownLoaded: Long) {
when(installState.installStatus()){
InstallStatus.DOWNLOADING->{
setProgressPercent(bytesDownLoaded, totalBytesToDownLoaded)
}
InstallStatus.DOWNLOADED->{
restart()
}
}
}
override fun onUpdateFailure(exception: Exception?) {
Toast.makeText(this,"업데이트 체크에 실패하였습니다", Toast.LENGTH_SHORT).show()
}
private fun setProgressPercent( bytesDownLoaded: Long, totalBytesToDownLoaded: Long){
val downLoadPercent = bytesDownLoaded.toDouble()/totalBytesToDownLoaded.toDouble()*100
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
progressBar.setProgress(downLoadPercent.toInt(),true)
} else{
progressBar.progress = downLoadPercent.toInt()
}
progressTv.text="$bytesDownLoaded / $totalBytesToDownLoaded"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment