-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from DroidKaigi/takahirom/add-empty-eventmap-m…
…odule/2024-06-15 Add empty eventmap module
- Loading branch information
Showing
27 changed files
with
608 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
.../src/androidMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/EventMapApiModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.github.droidkaigi.confsched.data.eventmap | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
public class EventMapApiModule { | ||
@Provides | ||
public fun provideEventMapApi(): EventMapApiClient { | ||
return FakeEventMapApiClient() | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...droidMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/EventMapRepositoryModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.github.droidkaigi.confsched.data.eventmap | ||
|
||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import dagger.multibindings.ClassKey | ||
import dagger.multibindings.IntoMap | ||
import io.github.droidkaigi.confsched.data.di.RepositoryQualifier | ||
import io.github.droidkaigi.confsched.model.EventMapRepository | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
public abstract class EventMapRepositoryModule { | ||
@Binds | ||
@RepositoryQualifier | ||
@IntoMap | ||
@ClassKey(EventMapRepository::class) | ||
public abstract fun bind(repository: EventMapRepository): Any | ||
|
||
public companion object { | ||
@Provides | ||
@Singleton | ||
public fun provideEventMapRepository( | ||
eventMapApi: EventMapApiClient, | ||
): EventMapRepository { | ||
return DefaultEventMapRepository( | ||
eventMapApi = eventMapApi, | ||
) | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...mmonMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/DefaultEventMapRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.github.droidkaigi.confsched.data.eventmap | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import io.github.droidkaigi.confsched.compose.SafeLaunchedEffect | ||
import io.github.droidkaigi.confsched.compose.safeCollectAsState | ||
import io.github.droidkaigi.confsched.model.EventMapEvent | ||
import io.github.droidkaigi.confsched.model.EventMapRepository | ||
import kotlinx.collections.immutable.PersistentList | ||
import kotlinx.collections.immutable.persistentListOf | ||
import kotlinx.collections.immutable.toPersistentList | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
|
||
public class DefaultEventMapRepository( | ||
private val eventMapApi: EventMapApiClient, | ||
) : EventMapRepository { | ||
private val eventMapStateFlow = | ||
MutableStateFlow<PersistentList<EventMapEvent>>(persistentListOf()) | ||
|
||
@Composable | ||
override fun eventMapEvents(): PersistentList<EventMapEvent> { | ||
val eventMap by eventMapStateFlow.safeCollectAsState() | ||
SafeLaunchedEffect(Unit) { | ||
if (eventMap.isEmpty()) { | ||
refresh() | ||
} | ||
} | ||
return eventMap | ||
} | ||
|
||
override suspend fun refresh() { | ||
eventMapApi | ||
.eventMapEvents() | ||
.toPersistentList().also { eventMapStateFlow.value = it } | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...a/src/commonMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/EventMapApiClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.github.droidkaigi.confsched.data.eventmap | ||
|
||
import de.jensklingenberg.ktorfit.http.GET | ||
import io.github.droidkaigi.confsched.data.eventmap.response.EventMapResponse | ||
import io.github.droidkaigi.confsched.model.EventMapEvent | ||
import kotlinx.collections.immutable.PersistentList | ||
import kotlinx.collections.immutable.toPersistentList | ||
|
||
internal interface EventMapApi { | ||
@GET("/events/droidkaigi2023/eventmap") | ||
suspend fun getEventMap(): EventMapResponse | ||
} | ||
|
||
public interface EventMapApiClient { | ||
|
||
public suspend fun eventMapEvents(): PersistentList<EventMapEvent> | ||
} | ||
|
||
public fun EventMapResponse.toEventMapList(): PersistentList<EventMapEvent> { | ||
return listOf(EventMapEvent()).toPersistentList() | ||
} |
33 changes: 33 additions & 0 deletions
33
...c/commonMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/FakeEventMapApiClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.github.droidkaigi.confsched.data.eventmap | ||
|
||
import io.github.droidkaigi.confsched.data.eventmap.response.EventMapResponse | ||
import io.github.droidkaigi.confsched.model.EventMapEvent | ||
import kotlinx.collections.immutable.PersistentList | ||
import okio.IOException | ||
|
||
public class FakeEventMapApiClient : EventMapApiClient { | ||
|
||
public sealed class Status : EventMapApiClient { | ||
public data object Operational : Status() { | ||
override suspend fun eventMapEvents(): PersistentList<EventMapEvent> { | ||
return EventMapResponse().toEventMapList() | ||
} | ||
} | ||
|
||
public data object Error : Status() { | ||
override suspend fun eventMapEvents(): PersistentList<EventMapEvent> { | ||
throw IOException("Fake IO Exception") | ||
} | ||
} | ||
} | ||
|
||
private var status: Status = Status.Operational | ||
|
||
public fun setup(status: Status) { | ||
this.status = status | ||
} | ||
|
||
override suspend fun eventMapEvents(): PersistentList<EventMapEvent> { | ||
return status.eventMapEvents() | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...mmonMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/response/EventMapResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package io.github.droidkaigi.confsched.data.eventmap.response | ||
|
||
public class EventMapResponse |
3 changes: 3 additions & 0 deletions
3
core/model/src/commonMain/kotlin/io/github/droidkaigi/confsched/model/EventMapEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package io.github.droidkaigi.confsched.model | ||
|
||
class EventMapEvent |
18 changes: 18 additions & 0 deletions
18
core/model/src/commonMain/kotlin/io/github/droidkaigi/confsched/model/EventMapRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.github.droidkaigi.confsched.model | ||
|
||
import androidx.compose.runtime.Composable | ||
import io.github.droidkaigi.confsched.model.compositionlocal.LocalRepositories | ||
import kotlinx.collections.immutable.PersistentList | ||
|
||
interface EventMapRepository { | ||
|
||
suspend fun refresh() | ||
|
||
@Composable | ||
fun eventMapEvents(): PersistentList<EventMapEvent> | ||
} | ||
|
||
@Composable | ||
fun localEventMapRepository(): EventMapRepository { | ||
return LocalRepositories.current[EventMapRepository::class] as EventMapRepository | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
plugins { | ||
id("droidkaigi.convention.kmpfeature") | ||
} | ||
|
||
android.namespace = "io.github.droidkaigi.confsched.feature.eventMap" | ||
kotlin { | ||
sourceSets { | ||
commonMain { | ||
dependencies { | ||
implementation(projects.core.model) | ||
implementation(projects.core.ui) | ||
implementation(libs.kotlinxCoroutinesCore) | ||
implementation(projects.core.designsystem) | ||
implementation(libs.moleculeRuntime) | ||
} | ||
} | ||
androidUnitTest { | ||
dependencies { | ||
implementation(projects.core.testing) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle.kts. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Oops, something went wrong.