Skip to content

Commit

Permalink
Add little easter egg 🎄
Browse files Browse the repository at this point in the history
  • Loading branch information
d4rken committed Dec 19, 2024
1 parent 897cd85 commit 11ee4cd
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -196,6 +191,7 @@ class DashboardViewModel @Inject constructor(
webpageTool = webpageTool,
isWorking = !taskState.isIdle,
onRibbonClicked = { webpageTool.open(SdmSeLinks.ISSUES) },
onMascotTriggered = { easterEggTriggered.value = it }
)
}

Expand Down Expand Up @@ -447,7 +443,7 @@ class DashboardViewModel @Inject constructor(
)
}

private val listItemsInternal: Flow<List<DashboardAdapter.Item>> = eu.darken.sdmse.common.flow.combine(
private val listStateInternal: Flow<ListState> = eu.darken.sdmse.common.flow.combine(
recorderModule.state,
debugCardProvider.create(this),
titleCardItem,
Expand All @@ -465,6 +461,7 @@ class DashboardViewModel @Inject constructor(
motdItem,
reviewItem,
statsItem,
easterEggTriggered,
refreshTrigger,
) { recorderState: RecorderModule.State,
debugItem: DebugCardVH.Item?,
Expand All @@ -483,6 +480,7 @@ class DashboardViewModel @Inject constructor(
motdItem: MotdCardVH.Item?,
reviewItem: ReviewCardVH.Item?,
statsItem: StatsDashCardVH.Item?,
easterEggTriggered,
_ ->
val items = mutableListOf<DashboardAdapter.Item>(titleInfo)

Expand Down Expand Up @@ -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
Expand All @@ -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<DashboardAdapter.Item>,
val isEasterEgg: Boolean = false,
)

data class BottomBarState(
val isReady: Boolean,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -58,13 +60,30 @@ 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(
val upgradeInfo: UpgradeRepo.Info?,
val isWorking: Boolean,
val onRibbonClicked: () -> Unit,
val webpageTool: WebpageTool,
val onMascotTriggered: (Boolean) -> Unit,
) : DashboardAdapter.Item {

override val stableId: Long = this.javaClass.hashCode().toLong()
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/layout/dashboard_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<eu.darken.sdmse.common.MascotView
android:id="@+id/list_progress"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
style="@style/BaseRecyclerList"
Expand All @@ -26,6 +20,12 @@
tools:listitem="@layout/dashboard_preview_layout"
tools:visibility="visible" />

<eu.darken.sdmse.common.MascotView
android:id="@+id/mascot_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />

<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottom_bar"
style="@style/Widget.MaterialComponents.BottomAppBar.PrimarySurface"
Expand Down

0 comments on commit 11ee4cd

Please sign in to comment.