mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-10 16:33:27 +00:00
Replace with interface delegation using "by" in the class header
Replace abstract class with an interface
This commit is contained in:
+4
-15
@@ -20,27 +20,16 @@
|
||||
*/
|
||||
package com.vitorpamplona.amethyst.ui.navigation.navs
|
||||
|
||||
import androidx.compose.material3.DrawerState
|
||||
import com.vitorpamplona.amethyst.ui.navigation.routes.Route
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
class ObservableNav(
|
||||
val sourceNav: INav,
|
||||
private val sourceNav: INav,
|
||||
override val navigationScope: CoroutineScope,
|
||||
val onBeforeNavigate: () -> Unit,
|
||||
) : INav {
|
||||
override val drawerState: DrawerState = sourceNav.drawerState
|
||||
|
||||
override fun closeDrawer() {
|
||||
sourceNav.closeDrawer()
|
||||
}
|
||||
|
||||
override fun openDrawer() {
|
||||
sourceNav.openDrawer()
|
||||
}
|
||||
|
||||
) : INav by sourceNav {
|
||||
override fun nav(route: Route) {
|
||||
navigationScope.launch {
|
||||
onBeforeNavigate()
|
||||
@@ -71,11 +60,11 @@ class ObservableNav(
|
||||
|
||||
override fun <T : Route> popUpTo(
|
||||
route: Route,
|
||||
upToClass: KClass<T>,
|
||||
klass: KClass<T>,
|
||||
) {
|
||||
navigationScope.launch {
|
||||
onBeforeNavigate()
|
||||
}
|
||||
sourceNav.popUpTo(route, upToClass)
|
||||
sourceNav.popUpTo(route, klass)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-29
@@ -20,20 +20,16 @@
|
||||
*/
|
||||
package com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.rooms.twopane
|
||||
|
||||
import androidx.compose.material3.DrawerState
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import com.vitorpamplona.amethyst.ui.navigation.navs.INav
|
||||
import com.vitorpamplona.amethyst.ui.navigation.routes.Route
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
class TwoPaneNav(
|
||||
val nav: INav,
|
||||
private val nav: INav,
|
||||
override val navigationScope: CoroutineScope,
|
||||
) : INav {
|
||||
override val drawerState: DrawerState = nav.drawerState
|
||||
|
||||
) : INav by nav {
|
||||
val innerNav = mutableStateOf<Route?>(null)
|
||||
|
||||
override fun nav(route: Route) {
|
||||
@@ -56,27 +52,4 @@ class TwoPaneNav(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun newStack(route: Route) {
|
||||
nav.newStack(route)
|
||||
}
|
||||
|
||||
override fun popBack() {
|
||||
nav.popBack()
|
||||
}
|
||||
|
||||
override fun <T : Route> popUpTo(
|
||||
route: Route,
|
||||
klass: KClass<T>,
|
||||
) {
|
||||
nav.popUpTo<T>(route, klass)
|
||||
}
|
||||
|
||||
override fun closeDrawer() {
|
||||
nav.closeDrawer()
|
||||
}
|
||||
|
||||
override fun openDrawer() {
|
||||
nav.openDrawer()
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -33,16 +33,16 @@ import kotlinx.collections.immutable.toImmutableMap
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
||||
@Immutable
|
||||
abstract class Card {
|
||||
abstract fun createdAt(): Long
|
||||
interface Card {
|
||||
fun createdAt(): Long
|
||||
|
||||
abstract fun id(): String
|
||||
fun id(): String
|
||||
}
|
||||
|
||||
@Immutable
|
||||
class BadgeCard(
|
||||
val note: Note,
|
||||
) : Card() {
|
||||
) : Card {
|
||||
override fun createdAt(): Long = note.createdAt() ?: 0L
|
||||
|
||||
override fun id() = note.idHex
|
||||
@@ -51,7 +51,7 @@ class BadgeCard(
|
||||
@Immutable
|
||||
class NoteCard(
|
||||
val note: Note,
|
||||
) : Card() {
|
||||
) : Card {
|
||||
override fun createdAt(): Long = note.createdAt() ?: 0L
|
||||
|
||||
override fun id() = note.idHex
|
||||
@@ -61,7 +61,7 @@ class NoteCard(
|
||||
class ZapUserSetCard(
|
||||
val user: User,
|
||||
val zapEvents: ImmutableList<CombinedZap>,
|
||||
) : Card() {
|
||||
) : Card {
|
||||
val createdAt = zapEvents.maxOfOrNull { it.createdAt() ?: 0L } ?: 0L
|
||||
|
||||
override fun createdAt(): Long = createdAt
|
||||
@@ -75,7 +75,7 @@ class MultiSetCard(
|
||||
val boostEvents: ImmutableList<Note>,
|
||||
val likeEvents: ImmutableList<Note>,
|
||||
val zapEvents: ImmutableList<CombinedZap>,
|
||||
) : Card() {
|
||||
) : Card {
|
||||
val maxCreatedAt =
|
||||
maxOf(
|
||||
zapEvents.maxOfOrNull { it.createdAt() ?: 0L } ?: 0L,
|
||||
@@ -108,7 +108,7 @@ class MultiSetCard(
|
||||
@Immutable
|
||||
class MessageSetCard(
|
||||
val note: Note,
|
||||
) : Card() {
|
||||
) : Card {
|
||||
override fun createdAt(): Long = note.createdAt() ?: 0L
|
||||
|
||||
override fun id() = note.idHex
|
||||
|
||||
Reference in New Issue
Block a user