--- a/app/src/google/java/com/geekorum/ttrss/PlayStoreModuleManager.kt Sat Jun 01 18:32:03 2019 -0700
+++ b/app/src/google/java/com/geekorum/ttrss/PlayStoreModuleManager.kt Sat Jun 01 20:46:36 2019 -0700
@@ -74,7 +74,6 @@
override val installedModules: Set<String>
get() = splitInstallManager.installedModules
-
}
private class SplitInstallSession(
@@ -87,7 +86,6 @@
if (it.sessionId() != id) {
return@runBlocking
}
- Timber.d("receive split install state $it")
val installState = it.toInstallSessionState()
channel.send(installState)
if (it.isTerminal) {
@@ -96,13 +94,10 @@
}
}
}
- Timber.d("register listener for send states")
splitInstallManager.registerListener(listener)
- Timber.d("suspend sendStatesTo coroutines")
suspendCoroutine<Unit> {cont ->
channel.invokeOnClose {
- Timber.d("unregister listener for send states")
splitInstallManager.unregisterListener(listener)
cont.resume(Unit)
}
@@ -144,11 +139,9 @@
splitInstallManager.unregisterListener(splitListener)
}
}
-
}
private fun SplitInstallSessionState.toInstallSessionState(): InstallSession.State {
- Timber.d("convert split install state status ${status()}")
val status = when (val status = status()) {
SplitInstallSessionStatus.PENDING -> InstallSession.State.Status.PENDING
SplitInstallSessionStatus.DOWNLOADING -> InstallSession.State.Status.DOWNLOADING
--- a/app/src/main/java/com/geekorum/ttrss/Application.kt Sat Jun 01 18:32:03 2019 -0700
+++ b/app/src/main/java/com/geekorum/ttrss/Application.kt Sat Jun 01 20:46:36 2019 -0700
@@ -26,7 +26,6 @@
import com.geekorum.ttrss.di.ApplicationComponent
import com.geekorum.ttrss.di.DaggerApplicationComponent
import dagger.android.support.DaggerApplication
-
import javax.inject.Inject
/**
--- a/app/src/main/java/com/geekorum/ttrss/features_manager/InstallModuleViewModel.kt Sat Jun 01 18:32:03 2019 -0700
+++ b/app/src/main/java/com/geekorum/ttrss/features_manager/InstallModuleViewModel.kt Sat Jun 01 20:46:36 2019 -0700
@@ -58,28 +58,8 @@
value = InstallSession.State(PENDING, 0, 0)
}
- val progress = _sessionState.map {
- Timber.d("install session state is ${it}")
- val message = when (it.status) {
- DOWNLOADING -> R.string.lbl_download_in_progress
- INSTALLING -> R.string.lbl_install_in_progress
- INSTALLED -> R.string.lbl_install_complete
- FAILED -> R.string.lbl_failed_to_install
- else -> R.string.lbl_other
- }
- val max = 100
- val percent = when (it.status) {
- DOWNLOADING -> Math.round((it.bytesDownloaded.toFloat() / it.totalBytesDownloaded) * max)
- INSTALLED -> 100
- else -> 0
- }
- val progressIndeterminate = when (it.status) {
- PENDING, INSTALLING, REQUIRES_USER_CONFIRMATION, CANCELING -> true
- DOWNLOADING, INSTALLED, FAILED, CANCELED -> false
- }
-
- InstallProgression(message, percent, max, progressIndeterminate)
- }
+ val sessionState: LiveData<InstallSession.State> = _sessionState
+ val progress = sessionState.map(this::mapStateToProgression)
private var session: InstallSession? = null
@@ -103,13 +83,33 @@
this@InstallModuleViewModel.session = session
sessionStates.consumeEach {
- Timber.d("received new state $it")
_sessionState.value = it
}
- Timber.d("end of consumeeach, state channel is closed for receive? ${sessionStates.isClosedForReceive}")
+ }
+ private fun mapStateToProgression(state: InstallSession.State): InstallProgression {
+ Timber.d("install session state is $state")
+ val message = when (state.status) {
+ PENDING, DOWNLOADING -> R.string.lbl_download_in_progress
+ INSTALLING -> R.string.lbl_install_in_progress
+ INSTALLED -> R.string.lbl_install_complete
+ FAILED -> R.string.lbl_failed_to_install
+ else -> R.string.lbl_other
+ }
+ val max = 100
+ val percent = when (state.status) {
+ DOWNLOADING -> Math.round((state.bytesDownloaded.toFloat() / state.totalBytesDownloaded) * max)
+ INSTALLED -> 100
+ else -> 0
+ }
+ val progressIndeterminate = when (state.status) {
+ PENDING, INSTALLING, REQUIRES_USER_CONFIRMATION, CANCELING -> true
+ DOWNLOADING, INSTALLED, FAILED, CANCELED -> false
+ }
+ return InstallProgression(message, percent, max, progressIndeterminate)
}
+
fun installModule(vararg modules: String): LiveData<InstallSession.State> {
val sessionDeferred = viewModelScope.async { moduleManager.startInstallModule(*modules) }
return liveData {
--- a/app/src/main/java/com/geekorum/ttrss/settings/manage_modules/InstallFeatureActivity.kt Sat Jun 01 18:32:03 2019 -0700
+++ b/app/src/main/java/com/geekorum/ttrss/settings/manage_modules/InstallFeatureActivity.kt Sat Jun 01 20:46:36 2019 -0700
@@ -22,10 +22,14 @@
import android.os.Bundle
import androidx.databinding.DataBindingUtil
+import androidx.lifecycle.observe
import com.geekorum.ttrss.BaseActivity
import com.geekorum.ttrss.R
import com.geekorum.ttrss.databinding.ActivityInstallFeatureBinding
import com.geekorum.ttrss.features_manager.InstallModuleViewModel
+import com.geekorum.ttrss.features_manager.InstallSession.State.Status.CANCELED
+import com.geekorum.ttrss.features_manager.InstallSession.State.Status.FAILED
+import com.geekorum.ttrss.features_manager.InstallSession.State.Status.INSTALLED
import com.geekorum.ttrss.viewModels
/**
@@ -41,14 +45,51 @@
val viewModel: InstallModuleViewModel by viewModels()
+ private var animationIsRunning = false
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_install_feature)
binding.lifecycleOwner = this
binding.viewModel = viewModel
+
+ viewModel.sessionState.observe(this) {
+ when (it.status) {
+ INSTALLED,
+ FAILED,
+ CANCELED -> stopAnimation()
+ else -> startAnimation()
+ }
+ }
val features = intent.getStringArrayExtra(EXTRA_FEATURES_LIST)
viewModel.startInstallModules(*features)
}
+
+ private fun startAnimation() {
+ if (animationIsRunning) {
+ return
+ }
+ binding.moduleLogo.animate()
+ .rotationBy(360f)
+ .withEndAction {
+ animationIsRunning = false
+ startAnimation()
+ }
+ .setInterpolator(null)
+ .setDuration(2000L)
+ .start()
+ animationIsRunning = true
+ }
+
+ private fun stopAnimation() {
+ binding.moduleLogo.animate().cancel()
+ animationIsRunning = false
+ }
+
+ override fun onPause() {
+ super.onPause()
+ stopAnimation()
+ }
}
--- a/app/src/main/res/layout/activity_install_feature.xml Sat Jun 01 18:32:03 2019 -0700
+++ b/app/src/main/res/layout/activity_install_feature.xml Sat Jun 01 20:46:36 2019 -0700
@@ -70,9 +70,9 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/install_status"
app:layout_constraintWidth_percent="0.6"
+ android:indeterminate="@{viewModel.progress.progressIndeterminate}"
android:progress="@{viewModel.progress.progress}"
android:max="@{viewModel.progress.max}"
- android:indeterminate="@{viewModel.progress.progressIndeterminate}"
tools:progress="33"
/>
</androidx.constraintlayout.widget.ConstraintLayout>