Created
May 18, 2020 07:28
-
-
Save EdgeJH/4f320c7acb78429a0ebb7974073bdd39 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 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