Skip to content

Commit 11ee4cd

Browse files
committed
Add little easter egg 🎄
1 parent 897cd85 commit 11ee4cd

File tree

4 files changed

+47
-22
lines changed

4 files changed

+47
-22
lines changed

app/src/main/java/eu/darken/sdmse/main/ui/dashboard/DashboardFragment.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ class DashboardFragment : Fragment3(R.layout.dashboard_fragment) {
4646
layouter = GridLayoutManager(context, getSpanCount(), GridLayoutManager.VERTICAL, false)
4747
)
4848

49-
vm.listItems.observe2(ui) {
50-
listProgress.isVisible = it.isEmpty()
51-
list.isVisible = it.isNotEmpty()
52-
dashAdapter.update(it)
49+
vm.listState.observe2(ui) { state ->
50+
mascotOverlay.isVisible = state.items.isEmpty() || state.isEasterEgg
51+
list.isVisible = state.items.isNotEmpty()
52+
dashAdapter.update(state.items)
5353
}
5454

5555
ui.bottomBar.apply {

app/src/main/java/eu/darken/sdmse/main/ui/dashboard/DashboardViewModel.kt

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package eu.darken.sdmse.main.ui.dashboard
22

3-
import android.content.Context
4-
import androidx.lifecycle.SavedStateHandle
53
import androidx.lifecycle.asLiveData
64
import dagger.hilt.android.lifecycle.HiltViewModel
7-
import dagger.hilt.android.qualifiers.ApplicationContext
85
import eu.darken.sdmse.App
96
import eu.darken.sdmse.MainDirections
107
import eu.darken.sdmse.analyzer.core.Analyzer
@@ -39,7 +36,6 @@ import eu.darken.sdmse.common.flow.intervalFlow
3936
import eu.darken.sdmse.common.flow.replayingShare
4037
import eu.darken.sdmse.common.flow.setupCommonEventHandlers
4138
import eu.darken.sdmse.common.flow.throttleLatest
42-
import eu.darken.sdmse.common.pkgs.PkgRepo
4339
import eu.darken.sdmse.common.review.ReviewTool
4440
import eu.darken.sdmse.common.rngString
4541
import eu.darken.sdmse.common.uix.ViewModel3
@@ -103,10 +99,8 @@ import kotlin.time.Duration.Companion.seconds
10399

104100
@HiltViewModel
105101
class DashboardViewModel @Inject constructor(
106-
@Suppress("unused") private val handle: SavedStateHandle,
107102
dispatcherProvider: DispatcherProvider,
108103
private val areaManager: DataAreaManager,
109-
private val pkgRepo: PkgRepo,
110104
private val taskManager: TaskManager,
111105
private val setupManager: SetupManager,
112106
private val corpseFinder: CorpseFinder,
@@ -125,8 +119,7 @@ class DashboardViewModel @Inject constructor(
125119
private val motdRepo: MotdRepo,
126120
private val releaseManager: ReleaseManager,
127121
private val reviewTool: ReviewTool,
128-
private val statsRepo: StatsRepo,
129-
@ApplicationContext private val context: Context,
122+
statsRepo: StatsRepo,
130123
) : ViewModel3(dispatcherProvider = dispatcherProvider) {
131124

132125
init {
@@ -187,6 +180,8 @@ class DashboardViewModel @Inject constructor(
187180
.setupCommonEventHandlers(TAG) { "upgradeInfo" }
188181
.replayingShare(vmScope)
189182

183+
private val easterEggTriggered = MutableStateFlow(false)
184+
190185
private val titleCardItem = combine(
191186
upgradeInfo,
192187
taskManager.state,
@@ -196,6 +191,7 @@ class DashboardViewModel @Inject constructor(
196191
webpageTool = webpageTool,
197192
isWorking = !taskState.isIdle,
198193
onRibbonClicked = { webpageTool.open(SdmSeLinks.ISSUES) },
194+
onMascotTriggered = { easterEggTriggered.value = it }
199195
)
200196
}
201197

@@ -447,7 +443,7 @@ class DashboardViewModel @Inject constructor(
447443
)
448444
}
449445

450-
private val listItemsInternal: Flow<List<DashboardAdapter.Item>> = eu.darken.sdmse.common.flow.combine(
446+
private val listStateInternal: Flow<ListState> = eu.darken.sdmse.common.flow.combine(
451447
recorderModule.state,
452448
debugCardProvider.create(this),
453449
titleCardItem,
@@ -465,6 +461,7 @@ class DashboardViewModel @Inject constructor(
465461
motdItem,
466462
reviewItem,
467463
statsItem,
464+
easterEggTriggered,
468465
refreshTrigger,
469466
) { recorderState: RecorderModule.State,
470467
debugItem: DebugCardVH.Item?,
@@ -483,6 +480,7 @@ class DashboardViewModel @Inject constructor(
483480
motdItem: MotdCardVH.Item?,
484481
reviewItem: ReviewCardVH.Item?,
485482
statsItem: StatsDashCardVH.Item?,
483+
easterEggTriggered,
486484
_ ->
487485
val items = mutableListOf<DashboardAdapter.Item>(titleInfo)
488486

@@ -546,7 +544,11 @@ class DashboardViewModel @Inject constructor(
546544
}
547545

548546
debugItem?.let { items.add(it) }
549-
items
547+
548+
ListState(
549+
items = items,
550+
isEasterEgg = easterEggTriggered,
551+
)
550552
}
551553
.onEach {
552554
if (!Bugs.isDebug) return@onEach
@@ -556,8 +558,12 @@ class DashboardViewModel @Inject constructor(
556558
.throttleLatest(500)
557559
.replayingShare(vmScope)
558560

559-
val listItems = listItemsInternal.asLiveData()
561+
val listState = listStateInternal.asLiveData()
560562

563+
data class ListState(
564+
val items: List<DashboardAdapter.Item>,
565+
val isEasterEgg: Boolean = false,
566+
)
561567

562568
data class BottomBarState(
563569
val isReady: Boolean,
@@ -584,7 +590,7 @@ class DashboardViewModel @Inject constructor(
584590
systemCleaner.state,
585591
appCleaner.state,
586592
generalSettings.enableDashboardOneClick.flow,
587-
listItemsInternal.map { items -> items.any { it is MainActionItem } },
593+
listStateInternal.map { state -> state.items.any { it is MainActionItem } },
588594
) { upgradeInfo,
589595
taskState,
590596
corpseState,

app/src/main/java/eu/darken/sdmse/main/ui/dashboard/items/TitleCardVH.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package eu.darken.sdmse.main.ui.dashboard.items
22

33
import android.text.SpannableStringBuilder
4+
import android.view.MotionEvent
5+
import android.view.View
46
import android.view.ViewGroup
57
import androidx.annotation.StringRes
68
import androidx.core.view.isVisible
@@ -58,13 +60,30 @@ class TitleCardVH(parent: ViewGroup) :
5860
BuildConfigWrap.BuildType.RELEASE -> ""
5961
}
6062
ribbonSecondary.text = BuildConfigWrap.VERSION_NAME
63+
64+
mascotContainer.apply {
65+
val touchListener = View.OnTouchListener { _, event ->
66+
if (event.action == MotionEvent.ACTION_UP || event.action == MotionEvent.ACTION_CANCEL) {
67+
item.onMascotTriggered(false)
68+
setOnTouchListener(null)
69+
performClick()
70+
}
71+
false
72+
}
73+
setOnLongClickListener {
74+
item.onMascotTriggered(true)
75+
setOnTouchListener(touchListener)
76+
true
77+
}
78+
}
6179
}
6280

6381
data class Item(
6482
val upgradeInfo: UpgradeRepo.Info?,
6583
val isWorking: Boolean,
6684
val onRibbonClicked: () -> Unit,
6785
val webpageTool: WebpageTool,
86+
val onMascotTriggered: (Boolean) -> Unit,
6887
) : DashboardAdapter.Item {
6988

7089
override val stableId: Long = this.javaClass.hashCode().toLong()

app/src/main/res/layout/dashboard_fragment.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
android:layout_width="match_parent"
66
android:layout_height="match_parent">
77

8-
<eu.darken.sdmse.common.MascotView
9-
android:id="@+id/list_progress"
10-
android:layout_width="wrap_content"
11-
android:layout_height="match_parent"
12-
android:layout_gravity="center" />
13-
148
<androidx.recyclerview.widget.RecyclerView
159
android:id="@+id/list"
1610
style="@style/BaseRecyclerList"
@@ -26,6 +20,12 @@
2620
tools:listitem="@layout/dashboard_preview_layout"
2721
tools:visibility="visible" />
2822

23+
<eu.darken.sdmse.common.MascotView
24+
android:id="@+id/mascot_overlay"
25+
android:layout_width="match_parent"
26+
android:layout_height="match_parent"
27+
android:layout_gravity="center" />
28+
2929
<com.google.android.material.bottomappbar.BottomAppBar
3030
android:id="@+id/bottom_bar"
3131
style="@style/Widget.MaterialComponents.BottomAppBar.PrimarySurface"

0 commit comments

Comments
 (0)