Skip to content

Commit

Permalink
Analyzer: Add action to refresh individual apps when browsing their d…
Browse files Browse the repository at this point in the history
…etails
  • Loading branch information
d4rken committed Sep 24, 2024
1 parent 86ca7af commit 3a5c806
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.darken.sdmse.analyzer.ui.storage.app

import android.os.Bundle
import android.view.MenuItem
import android.view.View
import androidx.core.view.isInvisible
import androidx.fragment.app.viewModels
Expand All @@ -21,17 +22,23 @@ class AppDetailsFragment : Fragment3(R.layout.analyzer_app_fragment) {
override val vm: AppDetailsViewModel by viewModels()
override val ui: AnalyzerAppFragmentBinding by viewBinding()

private val menuRefreshAction: MenuItem?
get() = ui.toolbar.menu?.findItem(R.id.menu_action_refresh)

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
ui.toolbar.apply {
setupWithNavController(findNavController())
setOnMenuItemClickListener {
when (it.itemId) {
R.id.menu_action_refresh -> {
vm.refresh()
true
}

else -> false
}
}

}

val adapter = AppDetailsAdapter()
ui.list.setupDefaults(adapter, verticalDividers = false)

Expand All @@ -42,6 +49,7 @@ class AppDetailsFragment : Fragment3(R.layout.analyzer_app_fragment) {
adapter.update(state.items)
loadingOverlay.setProgress(state.progress)
list.isInvisible = state.progress != null
menuRefreshAction?.isVisible = state.progress == null
}

super.onViewCreated(view, savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AppDetailsViewModel @Inject constructor(
@Suppress("unused") private val handle: SavedStateHandle,
dispatcherProvider: DispatcherProvider,
@Suppress("StaticFieldLeak") @ApplicationContext private val context: Context,
analyzer: Analyzer,
private val analyzer: Analyzer,
) : ViewModel3(dispatcherProvider) {

private val navArgs by handle.navArgs<AppDetailsFragmentArgs>()
Expand Down Expand Up @@ -70,6 +70,11 @@ class AppDetailsViewModel @Inject constructor(
return appContent?.pkgStats?.get(targetInstallId)
}

fun refresh() = launch {
log(TAG) { "refresh()" }
analyzer.submit(AppDeepScanTask(targetStorageId, targetInstallId))
}

val state = combine(
// Handle process death+restore
analyzer.data.filter { it.findPkg() != null },
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/res/layout/analyzer_app_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,27 @@
android:id="@+id/toolbar"
style="@style/Widget.MaterialComponents.Toolbar.Primary"
android:layout_width="0dp"
android:minHeight="?actionBarSize"
android:layout_height="wrap_content"
android:minHeight="?actionBarSize"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:menu="@menu/menu_analyzer_appdetails_list"
app:title="@string/analyzer_storage_content_type_app_label" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
style="@style/BaseRecyclerList"
android:layout_width="match_parent"
android:layout_height="0dp"
android:clipToPadding="false"
android:contentDescription="Analyzer app details"
tools:ignore="HardcodedText"
android:paddingVertical="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar"
tools:ignore="HardcodedText"
tools:listitem="@layout/analyzer_app_vh_appcode" />

<eu.darken.sdmse.common.progress.ProgressOverlayView
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/res/menu/menu_analyzer_appdetails_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">


<item
android:id="@+id/menu_action_refresh"
android:icon="@drawable/ic_baseline_refresh_24"
android:orderInCategory="90"
android:title="@string/general_refresh_action"
android:visible="false"
app:showAsAction="ifRoom"
tools:visible="true" />

</menu>

0 comments on commit 3a5c806

Please sign in to comment.