Skip to content

Commit

Permalink
AppControl: Display more specific result messages
Browse files Browse the repository at this point in the history
  • Loading branch information
d4rken committed Jul 3, 2024
1 parent d4f742c commit 3029f60
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package eu.darken.sdmse.appcontrol.ui.list

import android.content.Intent
import eu.darken.sdmse.appcontrol.core.export.AppExporter
import eu.darken.sdmse.appcontrol.core.forcestop.ForceStopTask
import eu.darken.sdmse.common.pkgs.features.Installed
import eu.darken.sdmse.appcontrol.core.AppControlTask

sealed class AppControlListEvents {
data class ConfirmDeletion(val items: List<AppControlListAdapter.Item>) : AppControlListEvents()
Expand All @@ -14,13 +12,6 @@ sealed class AppControlListEvents {
val items: List<AppControlListAdapter.Item>,
val intent: Intent
) : AppControlListEvents()

data class ExportResult(
val successful: Collection<AppExporter.Result>,
val failed: Collection<Installed.InstallId>,
) : AppControlListEvents()

data class ForceStopResult(val result: ForceStopTask.Result) : AppControlListEvents()

data class ConfirmForceStop(val items: List<AppControlListAdapter.Item>) : AppControlListEvents()
data class ShowResult(val result: AppControlTask.Result) : AppControlListEvents()
}
Original file line number Diff line number Diff line change
Expand Up @@ -356,18 +356,6 @@ class AppControlListFragment : Fragment3(R.layout.appcontrol_list_fragment) {
exportPath.launch(event.intent)
}

is AppControlListEvents.ExportResult -> {
val msgSuccessful = getQuantityString2(
eu.darken.sdmse.common.R.plurals.result_x_successful,
event.successful.size
)
val msgFailed = getQuantityString2(
eu.darken.sdmse.common.R.plurals.result_x_failed,
event.failed.size
)
Snackbar.make(requireView(), "$msgSuccessful, $msgFailed", Snackbar.LENGTH_SHORT).show()
}

is AppControlListEvents.ConfirmForceStop -> MaterialAlertDialogBuilder(requireContext()).apply {
setTitle(R.string.appcontrol_force_stop_confirm_title)
setMessage(
Expand All @@ -380,16 +368,12 @@ class AppControlListFragment : Fragment3(R.layout.appcontrol_list_fragment) {
setNeutralButton(eu.darken.sdmse.common.R.string.general_cancel_action) { _, _ -> }
}.show()

is AppControlListEvents.ForceStopResult -> {
val msgSuccessful = getQuantityString2(
eu.darken.sdmse.common.R.plurals.result_x_successful,
event.result.success.size
)
val msgFailed = getQuantityString2(
eu.darken.sdmse.common.R.plurals.result_x_failed,
event.result.failed.size
)
Snackbar.make(requireView(), "$msgSuccessful, $msgFailed", Snackbar.LENGTH_SHORT).show()
is AppControlListEvents.ShowResult -> {
Snackbar.make(
requireView(),
event.result.primaryInfo.get(requireContext()),
Snackbar.LENGTH_SHORT
).show()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ class AppControlListViewModel @Inject constructor(
return@launch
}
val targets = items.map { it.appInfo.installId }.toSet()
taskManager.submit(UninstallTask(targets = targets))
val result = taskManager.submit(UninstallTask(targets = targets)) as UninstallTask.Result
events.postValue(AppControlListEvents.ShowResult(result))
}

fun export(items: Collection<AppControlListAdapter.Item>, saveDir: Uri? = null) = launch {
Expand All @@ -367,7 +368,7 @@ class AppControlListViewModel @Inject constructor(
val targets = items.map { it.appInfo.installId }.toSet()
val result = taskManager.submit(AppExportTask(targets = targets, saveDir)) as AppExportTask.Result

events.postValue(AppControlListEvents.ExportResult(result.success, result.failed))
events.postValue(AppControlListEvents.ShowResult(result))
}

fun forceStop(items: Collection<AppControlListAdapter.Item>, confirmed: Boolean = false) = launch {
Expand All @@ -383,7 +384,7 @@ class AppControlListViewModel @Inject constructor(
}
val targets = items.map { it.appInfo.installId }.toSet()
val result = taskManager.submit(ForceStopTask(targets = targets)) as ForceStopTask.Result
events.postValue(AppControlListEvents.ForceStopResult(result))
events.postValue(AppControlListEvents.ShowResult(result))
}

data class State(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.snackbar.Snackbar
import dagger.hilt.android.AndroidEntryPoint
import eu.darken.sdmse.appcontrol.core.export.AppExportType
import eu.darken.sdmse.common.R
import eu.darken.sdmse.common.coil.loadAppIcon
import eu.darken.sdmse.common.debug.logging.Logging.Priority.WARN
import eu.darken.sdmse.common.debug.logging.log
import eu.darken.sdmse.common.debug.logging.logTag
import eu.darken.sdmse.common.error.asErrorDialogBuilder
import eu.darken.sdmse.common.lists.differ.update
import eu.darken.sdmse.common.lists.setupDefaults
import eu.darken.sdmse.common.navigation.getQuantityString2
import eu.darken.sdmse.common.pkgs.isArchived
import eu.darken.sdmse.common.pkgs.isEnabled
import eu.darken.sdmse.common.pkgs.isSystemApp
Expand Down Expand Up @@ -92,26 +90,10 @@ class AppActionDialog : BottomSheetDialogFragment2() {
}
}

is AppActionEvents.ExportResult -> {
val msgSuccessful = getQuantityString2(
R.plurals.result_x_successful,
event.successful.size
)
val msgFailed = getQuantityString2(
R.plurals.result_x_failed,
event.failed.size
)
Snackbar.make(requireView(), "$msgSuccessful, $msgFailed", Snackbar.LENGTH_SHORT).show()
}

is AppActionEvents.ForceStopResult -> {
is AppActionEvents.ShowResult -> {
Snackbar.make(
requireView(),
if (event.result.isSuccess) {
getString(R.string.general_result_success_message)
} else {
getString(R.string.general_result_failure_message)
},
event.result.primaryInfo.get(requireContext()),
Snackbar.LENGTH_SHORT
).show()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
package eu.darken.sdmse.appcontrol.ui.list.actions

import android.content.Intent
import eu.darken.sdmse.appcontrol.core.AppControlTask
import eu.darken.sdmse.appcontrol.core.AppInfo
import eu.darken.sdmse.appcontrol.core.export.AppExporter
import eu.darken.sdmse.appcontrol.core.forcestop.ForceStopTask
import eu.darken.sdmse.common.pkgs.features.Installed

sealed class AppActionEvents {
data class SelectExportPath(
val appInfo: AppInfo,
val intent: Intent,
) : AppActionEvents()

data class ForceStopResult(
val result: ForceStopTask.Result,
) : AppActionEvents()

data class ExportResult(
val successful: Collection<AppExporter.Result>,
val failed: Collection<Installed.InstallId>,
data class ShowResult(
val result: AppControlTask.Result,
) : AppActionEvents()
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class AppActionViewModel @Inject constructor(
onForceStop = {
launch {
val result = taskManager.submit(ForceStopTask(setOf(appInfo.installId))) as ForceStopTask.Result
events.postValue(AppActionEvents.ForceStopResult(result))
events.postValue(AppActionEvents.ShowResult(result))
}
}
)
Expand Down Expand Up @@ -200,6 +200,7 @@ class AppActionViewModel @Inject constructor(
launch {
val result = taskManager.submit(task) as UninstallTask.Result
if (result.failed.isNotEmpty()) throw UninstallException(result.failed.first())
else events.postValue(AppActionEvents.ShowResult(result))
}
}
)
Expand All @@ -212,7 +213,10 @@ class AppActionViewModel @Inject constructor(
appInfo = appInfo,
onToggle = {
val task = AppControlToggleTask(setOf(appInfo.installId))
launch { taskManager.submit(task) }
launch {
val result = taskManager.submit(task) as AppControlToggleTask.Result
events.postValue(AppActionEvents.ShowResult(result))
}
}
)
} else {
Expand Down Expand Up @@ -262,7 +266,7 @@ class AppActionViewModel @Inject constructor(
)
) as AppExportTask.Result

events.postValue(AppActionEvents.ExportResult(result.success, result.failed))
events.postValue(AppActionEvents.ShowResult(result))
}

data class State(
Expand Down

0 comments on commit 3029f60

Please sign in to comment.