Skip to content

Commit fc06121

Browse files
committed
timber
1 parent 27b36ca commit fc06121

File tree

7 files changed

+36
-34
lines changed

7 files changed

+36
-34
lines changed

channel-event-bus/api/channel-event-bus.api

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public final class com/hoc081098/channeleventbus/ChannelEventBusKt {
6161
}
6262

6363
public abstract interface class com/hoc081098/channeleventbus/ChannelEventBusLogger {
64+
public static final field Companion Lcom/hoc081098/channeleventbus/ChannelEventBusLogger$Companion;
6465
public abstract fun onClosed (Lcom/hoc081098/channeleventbus/ChannelEvent$Key;Lcom/hoc081098/channeleventbus/ChannelEventBus;)V
6566
public abstract fun onClosedAll (Ljava/util/Set;Lcom/hoc081098/channeleventbus/ChannelEventBus;)V
6667
public abstract fun onCreated (Lcom/hoc081098/channeleventbus/ChannelEvent$Key;Lcom/hoc081098/channeleventbus/ChannelEventBus;)V
@@ -69,6 +70,11 @@ public abstract interface class com/hoc081098/channeleventbus/ChannelEventBusLog
6970
public abstract fun onStopCollection (Lcom/hoc081098/channeleventbus/ChannelEvent$Key;Lcom/hoc081098/channeleventbus/ChannelEventBus;)V
7071
}
7172

73+
public final class com/hoc081098/channeleventbus/ChannelEventBusLogger$Companion {
74+
public final fun noop ()Lcom/hoc081098/channeleventbus/ChannelEventBusLogger;
75+
public final fun stdout ()Lcom/hoc081098/channeleventbus/ChannelEventBusLogger;
76+
}
77+
7278
public final class com/hoc081098/channeleventbus/ChannelEventBusValidationBeforeClosing : java/lang/Enum {
7379
public static final field ALL Ljava/util/Set;
7480
public static final field Companion Lcom/hoc081098/channeleventbus/ChannelEventBusValidationBeforeClosing$Companion;
@@ -84,23 +90,3 @@ public final class com/hoc081098/channeleventbus/ChannelEventBusValidationBefore
8490
public final fun getNONE ()Ljava/util/Set;
8591
}
8692

87-
public final class com/hoc081098/channeleventbus/ConsoleChannelEventBusLogger : com/hoc081098/channeleventbus/ChannelEventBusLogger {
88-
public static final field INSTANCE Lcom/hoc081098/channeleventbus/ConsoleChannelEventBusLogger;
89-
public fun onClosed (Lcom/hoc081098/channeleventbus/ChannelEvent$Key;Lcom/hoc081098/channeleventbus/ChannelEventBus;)V
90-
public fun onClosedAll (Ljava/util/Set;Lcom/hoc081098/channeleventbus/ChannelEventBus;)V
91-
public fun onCreated (Lcom/hoc081098/channeleventbus/ChannelEvent$Key;Lcom/hoc081098/channeleventbus/ChannelEventBus;)V
92-
public fun onSent (Lcom/hoc081098/channeleventbus/ChannelEvent;Lcom/hoc081098/channeleventbus/ChannelEventBus;)V
93-
public fun onStartCollection (Lcom/hoc081098/channeleventbus/ChannelEvent$Key;Lcom/hoc081098/channeleventbus/ChannelEventBus;)V
94-
public fun onStopCollection (Lcom/hoc081098/channeleventbus/ChannelEvent$Key;Lcom/hoc081098/channeleventbus/ChannelEventBus;)V
95-
}
96-
97-
public final class com/hoc081098/channeleventbus/EmptyChannelEventBusLogger : com/hoc081098/channeleventbus/ChannelEventBusLogger {
98-
public static final field INSTANCE Lcom/hoc081098/channeleventbus/EmptyChannelEventBusLogger;
99-
public fun onClosed (Lcom/hoc081098/channeleventbus/ChannelEvent$Key;Lcom/hoc081098/channeleventbus/ChannelEventBus;)V
100-
public fun onClosedAll (Ljava/util/Set;Lcom/hoc081098/channeleventbus/ChannelEventBus;)V
101-
public fun onCreated (Lcom/hoc081098/channeleventbus/ChannelEvent$Key;Lcom/hoc081098/channeleventbus/ChannelEventBus;)V
102-
public fun onSent (Lcom/hoc081098/channeleventbus/ChannelEvent;Lcom/hoc081098/channeleventbus/ChannelEventBus;)V
103-
public fun onStartCollection (Lcom/hoc081098/channeleventbus/ChannelEvent$Key;Lcom/hoc081098/channeleventbus/ChannelEventBus;)V
104-
public fun onStopCollection (Lcom/hoc081098/channeleventbus/ChannelEvent$Key;Lcom/hoc081098/channeleventbus/ChannelEventBus;)V
105-
}
106-

channel-event-bus/src/commonMain/kotlin/com/hoc081098/channeleventbus/ChannelEventBusLogger.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,18 @@ public interface ChannelEventBusLogger {
4040
* @see [ChannelEventBus.close]
4141
*/
4242
public fun onClosedAll(keys: Set<ChannelEventKey<*>>, bus: ChannelEventBus)
43+
44+
public companion object {
45+
public fun noop(): ChannelEventBusLogger = NoopChannelEventBusLogger
46+
47+
public fun stdout(): ChannelEventBusLogger = StdoutChannelEventBusLogger
48+
}
4349
}
4450

4551
/**
4652
* The [ChannelEventBusLogger] that simply prints events to the console via [println].
4753
*/
48-
public object ConsoleChannelEventBusLogger : ChannelEventBusLogger {
54+
private object StdoutChannelEventBusLogger : ChannelEventBusLogger {
4955
override fun onCreated(key: ChannelEventKey<*>, bus: ChannelEventBus): Unit =
5056
println("[$bus] onCreated: key=$key")
5157

@@ -68,7 +74,7 @@ public object ConsoleChannelEventBusLogger : ChannelEventBusLogger {
6874
/**
6975
* The [ChannelEventBusLogger] that do nothing.
7076
*/
71-
public object EmptyChannelEventBusLogger : ChannelEventBusLogger {
77+
private object NoopChannelEventBusLogger : ChannelEventBusLogger {
7278
override fun onCreated(key: ChannelEventKey<*>, bus: ChannelEventBus) {}
7379
override fun onSent(event: ChannelEvent<*>, bus: ChannelEventBus) {}
7480
override fun onStartCollection(key: ChannelEventKey<*>, bus: ChannelEventBus) {}

gradle/libs.versions.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ android-target = "33"
1616
# the Android compileSdkVersion to use
1717
android-compile = "33"
1818

19+
android-gradle = "8.1.2"
20+
1921
# the Android target to use in sample
2022
sample-android-target = "34"
2123
# the Android compileSdkVersion to use in sample
@@ -33,10 +35,10 @@ compose-rules-detekt = "0.3.2"
3335

3436
androidx-lifecycle = "2.6.2"
3537
androidx-annotation = "1.7.0"
36-
androidx-activity = "1.8.0"
38+
androidx-activity = "1.8.1"
3739
androidx-compose-compiler = "1.5.4"
38-
androidx-navigation = "2.7.4"
39-
android-gradle = "8.1.2"
40+
androidx-navigation = "2.7.5"
41+
timber = "5.0.1"
4042

4143
spotless = "6.22.0"
4244
detekt = "1.23.1"
@@ -83,6 +85,8 @@ androidx-compose-material3 = { module = "androidx.compose.material3:material3" }
8385
androidx-compose-runtime = { module = "androidx.compose.runtime:runtime" }
8486
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "androidx-navigation" }
8587

88+
timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }
89+
8690
[plugins]
8791
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
8892
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }

sample/app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ dependencies {
6060
implementation(libs.coil.compose)
6161

6262
implementation(libs.kotlinx.collections.immutable)
63+
implementation(libs.timber)
6364
}
6465

6566
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {

sample/app/src/main/java/com/hoc081098/channeleventbus/sample/android/MyApp.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@ package com.hoc081098.channeleventbus.sample.android
33
import RegisterModule
44
import android.app.Application
55
import com.hoc081098.channeleventbus.ChannelEventBus
6-
import com.hoc081098.channeleventbus.ConsoleChannelEventBusLogger
7-
import com.hoc081098.channeleventbus.EmptyChannelEventBusLogger
6+
import com.hoc081098.channeleventbus.ChannelEventBusLogger
87
import org.koin.android.ext.koin.androidContext
98
import org.koin.android.ext.koin.androidLogger
109
import org.koin.core.context.startKoin
1110
import org.koin.core.logger.Level
1211
import org.koin.dsl.module
12+
import timber.log.Timber
1313

1414
class MyApp : Application() {
1515
override fun onCreate() {
1616
super.onCreate()
1717

18+
if (BuildConfig.DEBUG) {
19+
Timber.plant(Timber.DebugTree())
20+
}
21+
1822
startKoin {
1923
androidContext(this@MyApp)
2024
androidLogger(
@@ -30,9 +34,9 @@ class MyApp : Application() {
3034
single {
3135
ChannelEventBus(
3236
if (BuildConfig.DEBUG) {
33-
ConsoleChannelEventBusLogger
37+
ChannelEventBusLogger.stdout()
3438
} else {
35-
EmptyChannelEventBusLogger
39+
ChannelEventBusLogger.noop()
3640
},
3741
)
3842
}

sample/app/src/main/java/com/hoc081098/channeleventbus/sample/android/ui/register/RegisterSharedVM.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.hoc081098.channeleventbus.sample.android.ui.register
22

3-
import android.util.Log
43
import androidx.lifecycle.SavedStateHandle
54
import androidx.lifecycle.ViewModel
65
import androidx.lifecycle.viewModelScope
@@ -9,24 +8,25 @@ import com.hoc081098.channeleventbus.ChannelEventBusValidationBeforeClosing.Comp
98
import kotlin.LazyThreadSafetyMode.PUBLICATION
109
import kotlinx.coroutines.flow.launchIn
1110
import kotlinx.coroutines.flow.onEach
11+
import timber.log.Timber
1212

1313
class RegisterSharedVM(
1414
private val channelEventBus: ChannelEventBus,
1515
private val savedStateHandle: SavedStateHandle,
1616
) : ViewModel() {
1717
init {
18-
Log.d("RegisterSharedVM", "$this::init")
18+
Timber.d("$this::init")
1919

2020
addCloseable {
21-
Log.d("RegisterSharedVM", "$this::close")
21+
Timber.d("$this::close")
2222
channelEventBus.closeKey(
2323
key = SubmitFirstNameEvent,
2424
validations = NONE,
2525
)
2626
}
2727
savedStateHandle
2828
.getStateFlow(FirstNameKey, null as String?)
29-
.onEach { Log.d("RegisterSharedVM", "$this FirstNameKey -> $it") }
29+
.onEach { Timber.d("$this FirstNameKey -> $it") }
3030
.launchIn(viewModelScope)
3131

3232
channelEventBus

sample/app/src/main/java/com/hoc081098/channeleventbus/sample/android/ui/register/stepone/RegisterStepOneVM.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class RegisterStepOneVM(
1515
private val savedStateHandle: SavedStateHandle,
1616
private val channelEventBus: ChannelEventBus,
1717
) : ViewModel() {
18-
internal val firstNameStateFlow: StateFlow<String?> = savedStateHandle.getStateFlow<String?>(FirstNameKey, null)
18+
internal val firstNameStateFlow: StateFlow<String?> = savedStateHandle
19+
.getStateFlow<String?>(FirstNameKey, null)
1920

2021
init {
2122
firstNameStateFlow

0 commit comments

Comments
 (0)