-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
3b2f61f
commit dd6458c
Showing
21 changed files
with
398 additions
and
30 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
18 changes: 18 additions & 0 deletions
18
...use/src/commonMain/kotlin/org/mobilenativefoundation/market/warehouse/WarehouseFactory.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 org.mobilenativefoundation.market.warehouse | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
import org.mobilenativefoundation.market.Market | ||
|
||
class WarehouseFactory<S : Warehouse.State, A : Warehouse.Action, MS : Market.State, M : Market<MS>>( | ||
private val market: M, | ||
) { | ||
fun create( | ||
actionHandler: (A, MS) -> Unit, | ||
selector: Market.Selector<MS, S>, | ||
coroutineDispatcher: CoroutineDispatcher | ||
): Warehouse<S, A> { | ||
return Warehouse.from( | ||
coroutineDispatcher, market, selector, actionHandler | ||
) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...e/src/commonMain/kotlin/org/mobilenativefoundation/market/warehouse/impl/RealWarehouse.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,30 @@ | ||
package org.mobilenativefoundation.market.warehouse.impl | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.flow.* | ||
import org.mobilenativefoundation.market.Market | ||
import org.mobilenativefoundation.market.warehouse.Warehouse | ||
|
||
|
||
internal class RealWarehouse<S : Warehouse.State, A : Warehouse.Action, MS : Market.State, M : Market<MS>>( | ||
coroutineDispatcher: CoroutineDispatcher, | ||
private val market: M, | ||
private val selector: Market.Selector<MS, S>, | ||
private val actionHandler: (A, MS) -> Unit | ||
) : Warehouse<S, A> { | ||
|
||
private val coroutineScope = CoroutineScope(coroutineDispatcher) | ||
|
||
override val state: StateFlow<S> = market.state.map { | ||
selector.select(it) | ||
}.stateIn(coroutineScope, SharingStarted.Eagerly, selector.select(market.state.value)) | ||
|
||
|
||
override fun <D : Any> subscribe(selector: Warehouse.Selector<S, D>): Flow<D> = | ||
state.map { selector.select(it) } | ||
|
||
override fun dispatch(action: A) { | ||
actionHandler(action, market.state.value) | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
...op/android/app/src/main/kotlin/monster/scoop/android/app/circuit/ScoopPresenterFactory.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,19 @@ | ||
package monster.scoop.android.app.circuit | ||
|
||
import com.slack.circuit.runtime.CircuitContext | ||
import com.slack.circuit.runtime.Navigator | ||
import com.slack.circuit.runtime.presenter.Presenter | ||
import com.slack.circuit.runtime.screen.Screen | ||
import me.tatarka.inject.annotations.Inject | ||
import monster.scoop.xplat.foundation.di.UserScope | ||
|
||
@Inject | ||
@UserScope | ||
class ScoopPresenterFactory : Presenter.Factory { | ||
override fun create(screen: Screen, navigator: Navigator, context: CircuitContext): Presenter<*>? { | ||
return when (screen) { | ||
else -> null | ||
} | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...scoop/android/app/src/main/kotlin/monster/scoop/android/app/circuit/ScoopScreenFactory.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,9 @@ | ||
package monster.scoop.android.app.circuit | ||
|
||
import me.tatarka.inject.annotations.Inject | ||
import monster.scoop.xplat.foundation.di.UserScope | ||
|
||
@Inject | ||
@UserScope | ||
class ScoopScreenFactory : ScreenFactory { | ||
} |
17 changes: 17 additions & 0 deletions
17
...ple/scoop/android/app/src/main/kotlin/monster/scoop/android/app/circuit/ScoopUiFactory.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,17 @@ | ||
package monster.scoop.android.app.circuit | ||
|
||
import com.slack.circuit.runtime.CircuitContext | ||
import com.slack.circuit.runtime.screen.Screen | ||
import com.slack.circuit.runtime.ui.Ui | ||
import me.tatarka.inject.annotations.Inject | ||
import monster.scoop.xplat.foundation.di.UserScope | ||
|
||
@Inject | ||
@UserScope | ||
class ScoopUiFactory : Ui.Factory { | ||
override fun create(screen: Screen, context: CircuitContext): Ui<*>? { | ||
return when (screen) { | ||
else -> null | ||
} | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...mple/scoop/android/app/src/main/kotlin/monster/scoop/android/app/circuit/ScreenFactory.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,4 @@ | ||
package monster.scoop.android.app.circuit | ||
|
||
interface ScreenFactory | ||
|
31 changes: 31 additions & 0 deletions
31
...al/sample/scoop/android/app/src/main/kotlin/monster/scoop/android/app/di/CoreComponent.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,31 @@ | ||
package monster.scoop.android.app.di | ||
|
||
import com.slack.circuit.runtime.presenter.Presenter | ||
import com.slack.circuit.runtime.ui.Ui | ||
import me.tatarka.inject.annotations.Component | ||
import me.tatarka.inject.annotations.Provides | ||
import monster.scoop.android.app.circuit.ScoopPresenterFactory | ||
import monster.scoop.android.app.circuit.ScoopScreenFactory | ||
import monster.scoop.android.app.circuit.ScoopUiFactory | ||
import monster.scoop.android.app.circuit.ScreenFactory | ||
import monster.scoop.xplat.foundation.di.UserScope | ||
|
||
@UserScope | ||
@Component | ||
abstract class CoreComponent { | ||
|
||
abstract val presenterFactory: Presenter.Factory | ||
abstract val screenFactory: ScreenFactory | ||
abstract val uiFactory: Ui.Factory | ||
|
||
@Provides | ||
fun bindPresenterFactory(impl: ScoopPresenterFactory): Presenter.Factory = impl | ||
|
||
@Provides | ||
fun bindUiFactory(impl: ScoopUiFactory): Ui.Factory = impl | ||
|
||
@Provides | ||
fun bindScreenFactory(impl: ScoopScreenFactory): ScreenFactory = impl | ||
|
||
companion object | ||
} |
7 changes: 7 additions & 0 deletions
7
.../scoop/android/app/src/main/kotlin/monster/scoop/android/app/market/MutableScoopMarket.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,7 @@ | ||
package monster.scoop.android.app.market | ||
|
||
import monster.scoop.xplat.common.market.ScoopState | ||
import org.mobilenativefoundation.market.MutableMarket | ||
|
||
|
||
typealias MutableScoopMarket = MutableMarket<ScoopState> |
18 changes: 18 additions & 0 deletions
18
...op/android/app/src/main/kotlin/monster/scoop/android/app/market/RealMutableScoopMarket.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 monster.scoop.android.app.market | ||
|
||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import me.tatarka.inject.annotations.Inject | ||
import monster.scoop.xplat.common.market.ScoopState | ||
|
||
@Inject | ||
class RealMutableScoopMarket : MutableScoopMarket { | ||
private val _state = MutableStateFlow(ScoopState()) | ||
|
||
override val state: StateFlow<ScoopState> = _state.asStateFlow() | ||
|
||
override fun updateState(nextState: ScoopState) { | ||
_state.value = nextState | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...scoop/android/app/src/main/kotlin/monster/scoop/android/app/market/RealScoopDispatcher.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 monster.scoop.android.app.market | ||
|
||
import me.tatarka.inject.annotations.Inject | ||
import monster.scoop.xplat.common.market.ScoopAction | ||
import monster.scoop.xplat.common.market.ScoopDispatcher | ||
|
||
@Inject | ||
class RealScoopDispatcher( | ||
private val mutableMarket: MutableScoopMarket, | ||
private val rootReducer: RootReducer | ||
) : ScoopDispatcher { | ||
override fun dispatch(action: ScoopAction) { | ||
val nextState = rootReducer.reduce(mutableMarket.state.value, action) | ||
mutableMarket.updateState(nextState) | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
7 changes: 7 additions & 0 deletions
7
.../sample/scoop/android/app/src/main/kotlin/monster/scoop/android/app/market/RootReducer.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,7 @@ | ||
package monster.scoop.android.app.market | ||
|
||
import monster.scoop.xplat.common.market.ScoopAction | ||
import monster.scoop.xplat.common.market.ScoopState | ||
import org.mobilenativefoundation.market.Market | ||
|
||
typealias RootReducer = Market.Reducer<ScoopState, ScoopAction> |
144 changes: 144 additions & 0 deletions
144
...al/sample/scoop/android/app/src/main/kotlin/monster/scoop/android/app/theme/ScoopTheme.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,144 @@ | ||
package monster.scoop.android.app.theme | ||
|
||
|
||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Typography | ||
import androidx.compose.material3.darkColorScheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.font.Font | ||
import androidx.compose.ui.text.font.FontFamily | ||
import androidx.compose.ui.text.font.FontStyle | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.sp | ||
import monster.scoop.android.app.R | ||
|
||
@Composable | ||
fun ScoopTheme( | ||
content: @Composable () -> Unit | ||
) { | ||
val darkColorScheme = darkColorScheme( | ||
primary = Color(0xFFFFA726), | ||
onPrimary = Color.Black, | ||
secondary = Color(0xFF6D4C41), | ||
onSecondary = Color.White, | ||
background = Color(0xFF010101), | ||
onBackground = Color.White, | ||
surface = Color(0xFF25262B), | ||
onSurface = Color.White, | ||
error = Color(0xFFCF6679), | ||
onError = Color.White | ||
) | ||
|
||
MaterialTheme( | ||
colorScheme = darkColorScheme, | ||
content = content, | ||
typography = ScoopTypography | ||
) | ||
} | ||
|
||
val scoopFontFamily = FontFamily( | ||
Font(R.font.roboto_regular), | ||
Font(R.font.roboto_medium, FontWeight.Medium), | ||
Font(R.font.roboto_thin, FontWeight.Thin), | ||
Font(R.font.roboto_bold, FontWeight.Bold), | ||
Font(R.font.roboto_italic, FontWeight.Normal, FontStyle.Italic) | ||
) | ||
|
||
val ScoopTypography = Typography( | ||
displayLarge = TextStyle( | ||
fontFamily = scoopFontFamily, | ||
fontWeight = FontWeight.Bold, | ||
fontSize = 57.sp, | ||
lineHeight = 64.sp, | ||
letterSpacing = (-0.25).sp | ||
), | ||
displayMedium = TextStyle( | ||
fontFamily = scoopFontFamily, | ||
fontWeight = FontWeight.Bold, | ||
fontSize = 45.sp, | ||
lineHeight = 52.sp | ||
), | ||
displaySmall = TextStyle( | ||
fontFamily = scoopFontFamily, | ||
fontWeight = FontWeight.Bold, | ||
fontSize = 36.sp, | ||
lineHeight = 44.sp | ||
), | ||
headlineLarge = TextStyle( | ||
fontFamily = scoopFontFamily, | ||
fontWeight = FontWeight.Thin, | ||
fontSize = 32.sp, | ||
lineHeight = 40.sp | ||
), | ||
headlineMedium = TextStyle( | ||
fontFamily = scoopFontFamily, | ||
fontWeight = FontWeight.Thin, | ||
fontSize = 28.sp, | ||
lineHeight = 36.sp | ||
), | ||
headlineSmall = TextStyle( | ||
fontFamily = scoopFontFamily, | ||
fontWeight = FontWeight.Thin, | ||
fontSize = 24.sp, | ||
lineHeight = 32.sp | ||
), | ||
titleLarge = TextStyle( | ||
fontFamily = scoopFontFamily, | ||
fontWeight = FontWeight.Medium, | ||
fontSize = 22.sp, | ||
lineHeight = 28.sp | ||
), | ||
titleMedium = TextStyle( | ||
fontFamily = scoopFontFamily, | ||
fontWeight = FontWeight.Medium, | ||
fontSize = 16.sp, | ||
lineHeight = 24.sp | ||
), | ||
titleSmall = TextStyle( | ||
fontFamily = scoopFontFamily, | ||
fontWeight = FontWeight.Medium, | ||
fontSize = 14.sp, | ||
lineHeight = 20.sp | ||
), | ||
bodyLarge = TextStyle( | ||
fontFamily = scoopFontFamily, | ||
fontWeight = FontWeight.Normal, | ||
fontSize = 16.sp, | ||
lineHeight = 24.sp | ||
), | ||
bodyMedium = TextStyle( | ||
fontFamily = scoopFontFamily, | ||
fontWeight = FontWeight.Normal, | ||
fontSize = 14.sp, | ||
lineHeight = 20.sp | ||
), | ||
bodySmall = TextStyle( | ||
fontFamily = scoopFontFamily, | ||
fontWeight = FontWeight.Normal, | ||
fontSize = 12.sp, | ||
lineHeight = 16.sp | ||
), | ||
labelLarge = TextStyle( | ||
fontFamily = scoopFontFamily, | ||
fontWeight = FontWeight.Medium, | ||
fontSize = 14.sp, | ||
lineHeight = 20.sp, | ||
letterSpacing = 0.1.sp | ||
), | ||
labelMedium = TextStyle( | ||
fontFamily = scoopFontFamily, | ||
fontWeight = FontWeight.Medium, | ||
fontSize = 12.sp, | ||
lineHeight = 16.sp, | ||
letterSpacing = 0.5.sp | ||
), | ||
labelSmall = TextStyle( | ||
fontFamily = scoopFontFamily, | ||
fontWeight = FontWeight.Medium, | ||
fontSize = 11.sp, | ||
lineHeight = 16.sp, | ||
letterSpacing = 0.5.sp | ||
) | ||
) |
5 changes: 5 additions & 0 deletions
5
...plat/common/market/src/commonMain/kotlin/monster/scoop/xplat/common/market/ScoopAction.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,5 @@ | ||
package monster.scoop.xplat.common.market | ||
|
||
import org.mobilenativefoundation.market.Market | ||
|
||
sealed interface ScoopAction : Market.Action |
5 changes: 5 additions & 0 deletions
5
.../common/market/src/commonMain/kotlin/monster/scoop/xplat/common/market/ScoopDispatcher.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,5 @@ | ||
package monster.scoop.xplat.common.market | ||
|
||
import org.mobilenativefoundation.market.Market | ||
|
||
typealias ScoopDispatcher = Market.Dispatcher<ScoopAction> |
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
24 changes: 24 additions & 0 deletions
24
...common/market/src/commonMain/kotlin/monster/scoop/xplat/common/market/Store.contribute.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,24 @@ | ||
package monster.scoop.xplat.common.market | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
import org.mobilenativefoundation.market.Market | ||
import org.mobilenativefoundation.store.store5.Store | ||
import org.mobilenativefoundation.store.store5.impl.extensions.fresh | ||
|
||
|
||
fun <A : Market.Action, D : Market.Dispatcher<A>, K : Any, V : Any> Store<K, V>.contribute( | ||
key: K, | ||
marketDispatcher: D, | ||
coroutineDispatcher: CoroutineDispatcher, | ||
actionFactory: (V) -> A | ||
) { | ||
|
||
val coroutineScope = CoroutineScope(coroutineDispatcher) | ||
coroutineScope.launch { | ||
val response = fresh(key) | ||
val marketAction = actionFactory(response) | ||
marketDispatcher.dispatch(marketAction) | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...main/story/api/src/commonMain/kotlin/monster/scoop/xplat/domain/story/api/StoriesState.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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package monster.scoop.xplat.domain.story.api | ||
|
||
data class StoriesState( | ||
val byId: Map<Int, Story>, | ||
val allIds: List<Int> | ||
val byId: Map<Int, Story> = mapOf(), | ||
val allIds: List<Int> = listOf() | ||
) |