Skip to content

Commit

Permalink
feat: Placeholder screen update
Browse files Browse the repository at this point in the history
Signed-off-by: Hu Shenghao <[email protected]>
  • Loading branch information
hushenghao committed Nov 4, 2024
1 parent a03ad69 commit a9e8788
Show file tree
Hide file tree
Showing 14 changed files with 412 additions and 288 deletions.
7 changes: 5 additions & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions app/src/main/java/com/dede/android_eggs/util/LocalEventExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.dede.android_eggs.util

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext

@Composable
fun LocalEvent.DisposableReceiver(action: String, eventCallback: EventCallback) {
val context = LocalContext.current
val receiver = remember { DisposedReceiver(eventCallback) }
DisposableEffect(action) {
context.localBroadcastManager.registerReceiver(receiver, IntentFilter(action))
onDispose {
context.localBroadcastManager.unregisterReceiver(receiver)
}
}
}

private class DisposedReceiver(val callback: EventCallback) : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
callback.invoke(intent)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.dede.android_eggs.ui.drawables.AlterableAdaptiveIconDrawable
import com.dede.android_eggs.util.LocalEvent
import com.dede.android_eggs.util.DisposableReceiver
import com.dede.android_eggs.views.main.util.EasterEggHelp
import com.dede.android_eggs.views.main.util.EasterEggLogoSensorMatrixConvert
import com.dede.android_eggs.views.settings.compose.basic.SettingPrefUtil
Expand Down Expand Up @@ -56,7 +57,7 @@ fun EasterEggLogo(
val drawable = remember(maskPath, res, context.theme) {
AlterableAdaptiveIconDrawable(context, res, maskPath)
}
LocalEvent.receiver().register(IconShapePrefUtil.ACTION_CHANGED) {
LocalEvent.DisposableReceiver(IconShapePrefUtil.ACTION_CHANGED) {
val newMaskPath = it.getStringExtra(SettingPrefUtil.EXTRA_VALUE)
if (newMaskPath != null) {
drawable.setMaskPath(newMaskPath)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import androidx.compose.ui.unit.TextUnitType
import androidx.compose.ui.unit.dp
import com.dede.android_eggs.BuildConfig
import com.dede.android_eggs.R
import com.dede.android_eggs.util.DisposableReceiver
import com.dede.android_eggs.util.LocalEvent
import com.dede.android_eggs.util.SplitUtils
import com.dede.android_eggs.views.main.compose.DrawableImage
Expand Down Expand Up @@ -80,7 +81,7 @@ fun SettingsScreen(drawerState: DrawerState = rememberDrawerState(DrawerValue.Cl
closeDrawer()
}

LocalEvent.receiver().register(action = SettingPrefUtil.ACTION_CLOSE_SETTING) {
LocalEvent.DisposableReceiver(SettingPrefUtil.ACTION_CLOSE_SETTING) {
closeDrawer()
}

Expand Down
1 change: 1 addition & 0 deletions basic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ dependencies {
implementation(libs.androidx.viewmodel)
implementation(libs.androidx.startup)
implementation(libs.androidx.activity)
implementation(libs.androidx.localbroadcastmanager)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import android.content.Intent
import android.content.IntentFilter
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
Expand All @@ -19,6 +15,9 @@ typealias EventCallback = (intent: Intent) -> Unit

object LocalEvent {

val Context.localBroadcastManager: LocalBroadcastManager
get() = LocalBroadcastManager.getInstance(this)

fun poster(context: Context): Poster {
return Poster(context)
}
Expand All @@ -27,32 +26,6 @@ object LocalEvent {
return Receiver(owner)
}

@Composable
fun receiver(): ComposeReceiver {
val context = LocalContext.current
return remember { ComposeReceiver(context) }
}

class ComposeReceiver(private val context: Context) {

private class DisposedReceiver(val callback: EventCallback) : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
callback.invoke(intent)
}
}

@Composable
fun register(action: String, eventCallback: EventCallback) {
DisposableEffect(key1 = action) {
val receiver = DisposedReceiver(eventCallback)
context.localBroadcastManager.registerReceiver(receiver, IntentFilter(action))
onDispose {
context.localBroadcastManager.unregisterReceiver(receiver)
}
}
}
}

class Receiver(private val owner: LifecycleOwner) {

private class LifecycleReceiver(val callback: EventCallback) :
Expand Down Expand Up @@ -91,6 +64,3 @@ private val LifecycleOwner.context: Context
is Fragment -> requireContext()
else -> throw IllegalArgumentException(this.toString())
}

private val Context.localBroadcastManager: LocalBroadcastManager
get() = LocalBroadcastManager.getInstance(this)
2 changes: 1 addition & 1 deletion feature/embedding-splits/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies {
implementation(libs.androidx.window)
implementation(libs.google.material)
implementation(libs.androidx.startup)

implementation(libs.androidx.shapes)
implementation(libs.androidx.compose.activity)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.compose.ui)
Expand Down
2 changes: 2 additions & 0 deletions feature/embedding-splits/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
android:name="com.dede.android_eggs.embedding_splits.SplitInitializer"
android:value="androidx.startup" />
</provider>

<activity android:name=".PlaceholderActivity" />
</application>

</manifest>
Loading

0 comments on commit a9e8788

Please sign in to comment.