From 11ee4cdb924c74db5a4ebee95f93ba8b07e872a2 Mon Sep 17 00:00:00 2001 From: darken Date: Thu, 19 Dec 2024 16:27:56 +0100 Subject: [PATCH] =?UTF-8?q?Add=20little=20easter=20egg=20=F0=9F=8E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ui/dashboard/DashboardFragment.kt | 8 ++--- .../main/ui/dashboard/DashboardViewModel.kt | 30 +++++++++++-------- .../main/ui/dashboard/items/TitleCardVH.kt | 19 ++++++++++++ .../main/res/layout/dashboard_fragment.xml | 12 ++++---- 4 files changed, 47 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/eu/darken/sdmse/main/ui/dashboard/DashboardFragment.kt b/app/src/main/java/eu/darken/sdmse/main/ui/dashboard/DashboardFragment.kt index abe00055f..5ae052ca9 100644 --- a/app/src/main/java/eu/darken/sdmse/main/ui/dashboard/DashboardFragment.kt +++ b/app/src/main/java/eu/darken/sdmse/main/ui/dashboard/DashboardFragment.kt @@ -46,10 +46,10 @@ class DashboardFragment : Fragment3(R.layout.dashboard_fragment) { layouter = GridLayoutManager(context, getSpanCount(), GridLayoutManager.VERTICAL, false) ) - vm.listItems.observe2(ui) { - listProgress.isVisible = it.isEmpty() - list.isVisible = it.isNotEmpty() - dashAdapter.update(it) + vm.listState.observe2(ui) { state -> + mascotOverlay.isVisible = state.items.isEmpty() || state.isEasterEgg + list.isVisible = state.items.isNotEmpty() + dashAdapter.update(state.items) } ui.bottomBar.apply { diff --git a/app/src/main/java/eu/darken/sdmse/main/ui/dashboard/DashboardViewModel.kt b/app/src/main/java/eu/darken/sdmse/main/ui/dashboard/DashboardViewModel.kt index d389edfdc..f54d1f86e 100644 --- a/app/src/main/java/eu/darken/sdmse/main/ui/dashboard/DashboardViewModel.kt +++ b/app/src/main/java/eu/darken/sdmse/main/ui/dashboard/DashboardViewModel.kt @@ -1,10 +1,7 @@ package eu.darken.sdmse.main.ui.dashboard -import android.content.Context -import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.asLiveData import dagger.hilt.android.lifecycle.HiltViewModel -import dagger.hilt.android.qualifiers.ApplicationContext import eu.darken.sdmse.App import eu.darken.sdmse.MainDirections import eu.darken.sdmse.analyzer.core.Analyzer @@ -39,7 +36,6 @@ import eu.darken.sdmse.common.flow.intervalFlow import eu.darken.sdmse.common.flow.replayingShare import eu.darken.sdmse.common.flow.setupCommonEventHandlers import eu.darken.sdmse.common.flow.throttleLatest -import eu.darken.sdmse.common.pkgs.PkgRepo import eu.darken.sdmse.common.review.ReviewTool import eu.darken.sdmse.common.rngString import eu.darken.sdmse.common.uix.ViewModel3 @@ -103,10 +99,8 @@ import kotlin.time.Duration.Companion.seconds @HiltViewModel class DashboardViewModel @Inject constructor( - @Suppress("unused") private val handle: SavedStateHandle, dispatcherProvider: DispatcherProvider, private val areaManager: DataAreaManager, - private val pkgRepo: PkgRepo, private val taskManager: TaskManager, private val setupManager: SetupManager, private val corpseFinder: CorpseFinder, @@ -125,8 +119,7 @@ class DashboardViewModel @Inject constructor( private val motdRepo: MotdRepo, private val releaseManager: ReleaseManager, private val reviewTool: ReviewTool, - private val statsRepo: StatsRepo, - @ApplicationContext private val context: Context, + statsRepo: StatsRepo, ) : ViewModel3(dispatcherProvider = dispatcherProvider) { init { @@ -187,6 +180,8 @@ class DashboardViewModel @Inject constructor( .setupCommonEventHandlers(TAG) { "upgradeInfo" } .replayingShare(vmScope) + private val easterEggTriggered = MutableStateFlow(false) + private val titleCardItem = combine( upgradeInfo, taskManager.state, @@ -196,6 +191,7 @@ class DashboardViewModel @Inject constructor( webpageTool = webpageTool, isWorking = !taskState.isIdle, onRibbonClicked = { webpageTool.open(SdmSeLinks.ISSUES) }, + onMascotTriggered = { easterEggTriggered.value = it } ) } @@ -447,7 +443,7 @@ class DashboardViewModel @Inject constructor( ) } - private val listItemsInternal: Flow> = eu.darken.sdmse.common.flow.combine( + private val listStateInternal: Flow = eu.darken.sdmse.common.flow.combine( recorderModule.state, debugCardProvider.create(this), titleCardItem, @@ -465,6 +461,7 @@ class DashboardViewModel @Inject constructor( motdItem, reviewItem, statsItem, + easterEggTriggered, refreshTrigger, ) { recorderState: RecorderModule.State, debugItem: DebugCardVH.Item?, @@ -483,6 +480,7 @@ class DashboardViewModel @Inject constructor( motdItem: MotdCardVH.Item?, reviewItem: ReviewCardVH.Item?, statsItem: StatsDashCardVH.Item?, + easterEggTriggered, _ -> val items = mutableListOf(titleInfo) @@ -546,7 +544,11 @@ class DashboardViewModel @Inject constructor( } debugItem?.let { items.add(it) } - items + + ListState( + items = items, + isEasterEgg = easterEggTriggered, + ) } .onEach { if (!Bugs.isDebug) return@onEach @@ -556,8 +558,12 @@ class DashboardViewModel @Inject constructor( .throttleLatest(500) .replayingShare(vmScope) - val listItems = listItemsInternal.asLiveData() + val listState = listStateInternal.asLiveData() + data class ListState( + val items: List, + val isEasterEgg: Boolean = false, + ) data class BottomBarState( val isReady: Boolean, @@ -584,7 +590,7 @@ class DashboardViewModel @Inject constructor( systemCleaner.state, appCleaner.state, generalSettings.enableDashboardOneClick.flow, - listItemsInternal.map { items -> items.any { it is MainActionItem } }, + listStateInternal.map { state -> state.items.any { it is MainActionItem } }, ) { upgradeInfo, taskState, corpseState, diff --git a/app/src/main/java/eu/darken/sdmse/main/ui/dashboard/items/TitleCardVH.kt b/app/src/main/java/eu/darken/sdmse/main/ui/dashboard/items/TitleCardVH.kt index cfe945c42..bbee10add 100644 --- a/app/src/main/java/eu/darken/sdmse/main/ui/dashboard/items/TitleCardVH.kt +++ b/app/src/main/java/eu/darken/sdmse/main/ui/dashboard/items/TitleCardVH.kt @@ -1,6 +1,8 @@ package eu.darken.sdmse.main.ui.dashboard.items import android.text.SpannableStringBuilder +import android.view.MotionEvent +import android.view.View import android.view.ViewGroup import androidx.annotation.StringRes import androidx.core.view.isVisible @@ -58,6 +60,22 @@ class TitleCardVH(parent: ViewGroup) : BuildConfigWrap.BuildType.RELEASE -> "" } ribbonSecondary.text = BuildConfigWrap.VERSION_NAME + + mascotContainer.apply { + val touchListener = View.OnTouchListener { _, event -> + if (event.action == MotionEvent.ACTION_UP || event.action == MotionEvent.ACTION_CANCEL) { + item.onMascotTriggered(false) + setOnTouchListener(null) + performClick() + } + false + } + setOnLongClickListener { + item.onMascotTriggered(true) + setOnTouchListener(touchListener) + true + } + } } data class Item( @@ -65,6 +83,7 @@ class TitleCardVH(parent: ViewGroup) : val isWorking: Boolean, val onRibbonClicked: () -> Unit, val webpageTool: WebpageTool, + val onMascotTriggered: (Boolean) -> Unit, ) : DashboardAdapter.Item { override val stableId: Long = this.javaClass.hashCode().toLong() diff --git a/app/src/main/res/layout/dashboard_fragment.xml b/app/src/main/res/layout/dashboard_fragment.xml index cbbea1d7b..c052ef6c6 100644 --- a/app/src/main/res/layout/dashboard_fragment.xml +++ b/app/src/main/res/layout/dashboard_fragment.xml @@ -5,12 +5,6 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - + +