AppDetails: Show ongoing installation
This commit is contained in:
@@ -55,6 +55,11 @@ sealed class InstallerEvent: Event() {
|
||||
var extra: String? = ""
|
||||
) : InstallerEvent()
|
||||
|
||||
data class Installing(
|
||||
var packageName: String? = "",
|
||||
var progress: Int = 0
|
||||
) : InstallerEvent()
|
||||
|
||||
data class Cancelled(
|
||||
var packageName: String? = "",
|
||||
var extra: String? = ""
|
||||
|
||||
@@ -36,7 +36,9 @@ import com.aurora.extensions.isSAndAbove
|
||||
import com.aurora.extensions.isTAndAbove
|
||||
import com.aurora.extensions.isUAndAbove
|
||||
import com.aurora.extensions.runOnUiThread
|
||||
import com.aurora.store.AuroraApp
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.event.InstallerEvent
|
||||
import com.aurora.store.data.installer.AppInstaller.Companion.ACTION_INSTALL_STATUS
|
||||
import com.aurora.store.data.installer.AppInstaller.Companion.EXTRA_DISPLAY_NAME
|
||||
import com.aurora.store.data.installer.AppInstaller.Companion.EXTRA_PACKAGE_NAME
|
||||
@@ -70,7 +72,21 @@ class SessionInstaller @Inject constructor(
|
||||
|
||||
override fun onActiveChanged(sessionId: Int, active: Boolean) {}
|
||||
|
||||
override fun onProgressChanged(sessionId: Int, progress: Float) {}
|
||||
override fun onProgressChanged(sessionId: Int, progress: Float) {
|
||||
val packageName = enqueuedSessions
|
||||
.find { set -> set.any { it.sessionId == sessionId } }
|
||||
?.first()
|
||||
?.packageName
|
||||
|
||||
if (packageName != null && progress > 0.0) {
|
||||
AuroraApp.flowEvent.emitEvent(
|
||||
InstallerEvent.Installing(
|
||||
packageName = packageName,
|
||||
progress = (progress * 100).toInt()
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFinished(sessionId: Int, success: Boolean) {
|
||||
enqueuedSessions.find { set -> set.any { it.sessionId == sessionId } }
|
||||
@@ -89,9 +105,6 @@ class SessionInstaller @Inject constructor(
|
||||
enqueuedSessions.firstOrNull()?.let { sessionSet ->
|
||||
commitInstall(sessionSet.first())
|
||||
}
|
||||
} else {
|
||||
// Nothing else in queue, unregister callback
|
||||
packageInstaller.unregisterSessionCallback(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,5 +29,6 @@ enum class State {
|
||||
QUEUED,
|
||||
PROGRESS,
|
||||
COMPLETE,
|
||||
CANCELED
|
||||
CANCELED,
|
||||
INSTALLING,
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import android.util.AttributeSet
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.aurora.extensions.getString
|
||||
import com.aurora.extensions.runOnUiThread
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.model.State
|
||||
import com.aurora.store.databinding.ViewActionButtonBinding
|
||||
@@ -101,19 +100,21 @@ class ActionButton : RelativeLayout {
|
||||
binding.btn.text = getString(text)
|
||||
}
|
||||
|
||||
fun setButtonState(enabled: Boolean = true) {
|
||||
binding.btn.isEnabled = enabled
|
||||
}
|
||||
|
||||
fun updateState(state: State) {
|
||||
val displayChild = when (state) {
|
||||
State.IDLE -> 0
|
||||
State.PROGRESS -> 1
|
||||
State.COMPLETE -> 2
|
||||
else -> 0
|
||||
}
|
||||
|
||||
if (binding.viewFlipper.displayedChild != displayChild) {
|
||||
runOnUiThread {
|
||||
binding.viewFlipper.displayedChild = displayChild
|
||||
if (displayChild == 2) updateState(State.IDLE)
|
||||
}
|
||||
binding.viewFlipper.displayedChild = displayChild
|
||||
|
||||
if (displayChild == 2) updateState(State.IDLE)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,8 +55,8 @@ import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.gplayapi.data.models.Review
|
||||
import com.aurora.gplayapi.data.models.StreamBundle
|
||||
import com.aurora.gplayapi.data.models.StreamCluster
|
||||
import com.aurora.store.AuroraApp
|
||||
import com.aurora.store.AppStreamStash
|
||||
import com.aurora.store.AuroraApp
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.event.BusEvent
|
||||
import com.aurora.store.data.event.Event
|
||||
@@ -69,6 +69,7 @@ import com.aurora.store.data.model.ViewState.Loading.getDataAs
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
import com.aurora.store.databinding.FragmentDetailsBinding
|
||||
import com.aurora.store.util.CommonUtil
|
||||
import com.aurora.store.util.Log
|
||||
import com.aurora.store.util.PackageUtil
|
||||
import com.aurora.store.util.PathUtil
|
||||
import com.aurora.store.util.Preferences
|
||||
@@ -166,14 +167,23 @@ class AppDetailsFragment : BaseFragment<FragmentDetailsBinding>() {
|
||||
}
|
||||
|
||||
is InstallerEvent.Failed -> {
|
||||
findNavController().navigate(
|
||||
AppDetailsFragmentDirections.actionAppDetailsFragmentToInstallErrorDialogSheet(
|
||||
app,
|
||||
event.packageName ?: "",
|
||||
event.error ?: "",
|
||||
event.extra ?: ""
|
||||
if (app.packageName == event.packageName) {
|
||||
findNavController().navigate(
|
||||
AppDetailsFragmentDirections.actionAppDetailsFragmentToInstallErrorDialogSheet(
|
||||
app,
|
||||
event.packageName ?: "",
|
||||
event.error ?: "",
|
||||
event.extra ?: ""
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
is InstallerEvent.Installing -> {
|
||||
if (event.packageName == app.packageName) {
|
||||
attachActions()
|
||||
updateActionState(State.INSTALLING)
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
@@ -507,7 +517,15 @@ class AppDetailsFragment : BaseFragment<FragmentDetailsBinding>() {
|
||||
}
|
||||
|
||||
private fun updateActionState(state: State) {
|
||||
binding.layoutDetailsInstall.btnDownload.updateState(state)
|
||||
runOnUiThread {
|
||||
binding.layoutDetailsInstall.btnDownload.apply {
|
||||
updateState(state)
|
||||
if (state == State.INSTALLING) {
|
||||
setButtonState(false)
|
||||
setText(R.string.action_installing)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun openApp() {
|
||||
@@ -589,9 +607,8 @@ class AppDetailsFragment : BaseFragment<FragmentDetailsBinding>() {
|
||||
app.isInstalled = PackageUtil.isInstalled(requireContext(), app.packageName)
|
||||
|
||||
runOnUiThread {
|
||||
app.isInstalled = PackageUtil.isInstalled(requireContext(), app.packageName)
|
||||
|
||||
binding.layoutDetailsInstall.btnDownload.let { btn ->
|
||||
btn.setButtonState(true)
|
||||
if (app.isInstalled) {
|
||||
isUpdatable = PackageUtil.isUpdatable(
|
||||
requireContext(),
|
||||
|
||||
Reference in New Issue
Block a user