Fixed Language download
This commit is contained in:
parent
0c8ed326bf
commit
525c5f8aa4
1 changed files with 19 additions and 2 deletions
|
@ -10,6 +10,8 @@ import com.google.android.gms.cast.framework.CastButtonFactory
|
|||
import com.google.android.play.core.splitcompat.SplitCompat
|
||||
import com.google.android.play.core.splitinstall.SplitInstallManagerFactory
|
||||
import com.google.android.play.core.splitinstall.SplitInstallRequest
|
||||
import com.google.android.play.core.splitinstall.SplitInstallSessionState
|
||||
import com.google.android.play.core.splitinstall.SplitInstallStateUpdatedListener
|
||||
import java.util.*
|
||||
|
||||
fun Context.setUpMediaRouteButton(menu: Menu) {
|
||||
|
@ -17,7 +19,19 @@ fun Context.setUpMediaRouteButton(menu: Menu) {
|
|||
}
|
||||
|
||||
fun FragmentActivity.installLanguageAndRecreate(code: String) {
|
||||
var mySessionId = 0
|
||||
|
||||
val manager = SplitInstallManagerFactory.create(this)
|
||||
val listener = object: SplitInstallStateUpdatedListener{
|
||||
override fun onStateUpdate(state: SplitInstallSessionState) {
|
||||
if (state.sessionId() == mySessionId) {
|
||||
recreate()
|
||||
manager.unregisterListener(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
manager.registerListener(listener)
|
||||
|
||||
if (code != "auto") {
|
||||
// Try to download language resources
|
||||
val request =
|
||||
|
@ -25,8 +39,11 @@ fun FragmentActivity.installLanguageAndRecreate(code: String) {
|
|||
.build()
|
||||
manager.startInstall(request)
|
||||
// Recreate the activity on download complete
|
||||
.addOnCompleteListener {
|
||||
recreate()
|
||||
.addOnSuccessListener {
|
||||
mySessionId = it
|
||||
}
|
||||
.addOnFailureListener {
|
||||
showToast("Language download failed.")
|
||||
}
|
||||
} else {
|
||||
recreate()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue