0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-12-01 15:27:26 +00:00

fix installation screen not receiving input after installation completes

This commit is contained in:
X1nto 2021-11-22 16:17:46 +04:00
parent 5369121f2c
commit c7e54ba6fa
3 changed files with 24 additions and 15 deletions

View file

@ -23,11 +23,11 @@ import com.vanced.manager.ui.theme.ManagerTheme
import com.vanced.manager.ui.theme.isDark import com.vanced.manager.ui.theme.isDark
import com.vanced.manager.ui.util.Screen import com.vanced.manager.ui.util.Screen
import com.vanced.manager.ui.viewmodel.InstallViewModel import com.vanced.manager.ui.viewmodel.InstallViewModel
import org.koin.android.ext.android.inject import org.koin.androidx.viewmodel.ext.android.viewModel
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
private val installViewModel: InstallViewModel by inject() private val installViewModel: InstallViewModel by viewModel()
private val backPressHandler = BackPressHandler() private val backPressHandler = BackPressHandler()

View file

@ -45,6 +45,9 @@ fun InstallScreen(
var startedProcess by rememberSaveable { mutableStateOf(false) } var startedProcess by rememberSaveable { mutableStateOf(false) }
val logs = viewModel.logs
val status = viewModel.status
// I don't know why, I don't know how, // I don't know why, I don't know how,
// but it works as intended // but it works as intended
LaunchedEffect(startedProcess) { LaunchedEffect(startedProcess) {
@ -60,7 +63,7 @@ fun InstallScreen(
ManagerTopAppBar( ManagerTopAppBar(
title = managerString(R.string.toolbar_install), title = managerString(R.string.toolbar_install),
) )
when (val status = viewModel.status) { when (status) {
is InstallViewModel.Status.Progress -> { is InstallViewModel.Status.Progress -> {
ManagerProgressIndicator(status.progress) ManagerProgressIndicator(status.progress)
} }
@ -72,9 +75,9 @@ fun InstallScreen(
} }
}, },
floatingActionButton = { floatingActionButton = {
if (viewModel.status is InstallViewModel.Status.Installed) { if (status is InstallViewModel.Status.Installed) {
ExtendedFloatingActionButton( ExtendedFloatingActionButton(
text = { /*TODO*/ }, text = { ManagerText("Finish") },
icon = { icon = {
Icon(Icons.Rounded.Done, null) Icon(Icons.Rounded.Done, null)
}, },
@ -88,7 +91,7 @@ fun InstallScreen(
.fillMaxSize() .fillMaxSize()
.padding(paddingValues), .padding(paddingValues),
) { ) {
items(viewModel.logs) { log -> items(logs) { log ->
when (log) { when (log) {
is InstallViewModel.Log.Success -> { is InstallViewModel.Log.Success -> {
ManagerText( ManagerText(

View file

@ -63,12 +63,14 @@ class InstallViewModel(
} }
fun postInstallStatus(pmStatus: Int, extra: String) { fun postInstallStatus(pmStatus: Int, extra: String) {
if (pmStatus == PackageInstaller.STATUS_SUCCESS) { viewModelScope.launch(Dispatchers.IO) {
status = Status.Installed if (pmStatus == PackageInstaller.STATUS_SUCCESS) {
logs.add(Log.Success("Successfully installed")) status = Status.Installed
} else { log(Log.Success("Successfully installed"))
status = Status.Failure } else {
logs.add(Log.Error("Failed to install app", extra)) status = Status.Failure
log(Log.Error("Failed to install app", extra))
}
} }
} }
@ -80,14 +82,14 @@ class InstallViewModel(
downloader.download(appVersions) { downloadStatus -> downloader.download(appVersions) { downloadStatus ->
when (downloadStatus) { when (downloadStatus) {
is DownloadStatus.File -> logs.add(Log.Info("Downloading ${downloadStatus.fileName}")) is DownloadStatus.File -> log(Log.Info("Downloading ${downloadStatus.fileName}"))
is DownloadStatus.Error -> logs.add(Log.Error( is DownloadStatus.Error -> log(Log.Error(
displayText = downloadStatus.displayError, displayText = downloadStatus.displayError,
stacktrace = downloadStatus.stacktrace stacktrace = downloadStatus.stacktrace
)) ))
is DownloadStatus.Progress -> status = Status.Progress(downloadStatus.progress / 100) is DownloadStatus.Progress -> status = Status.Progress(downloadStatus.progress / 100)
is DownloadStatus.StartInstall -> { is DownloadStatus.StartInstall -> {
logs.add(Log.Success("Successfully downloaded $appName")) log(Log.Success("Successfully downloaded $appName"))
installApp(appName, appVersions) installApp(appName, appVersions)
} }
} }
@ -123,6 +125,10 @@ class InstallViewModel(
else -> throw IllegalArgumentException("$appName is not a valid app") else -> throw IllegalArgumentException("$appName is not a valid app")
} }
private fun log(data: Log) {
logs.add(data)
}
private fun clear() { private fun clear() {
logs.clear() logs.clear()
status = Status.Idle status = Status.Idle