Review comments

This commit is contained in:
Yuri Schimke 2021-10-09 11:38:20 +01:00 committed by John O'Reilly
parent 5aaeea701c
commit d938b7aea5
4 changed files with 21 additions and 21 deletions

View file

@ -23,4 +23,7 @@ class PeopleInSpaceRepositoryFake: PeopleInSpaceRepositoryInterface {
override suspend fun fetchPeople(): List<Assignment> {
return emptyList()
}
override suspend fun fetchAndStorePeople() {
}
}

View file

@ -9,6 +9,10 @@ import io.ktor.client.*
import io.ktor.client.features.json.*
import io.ktor.client.features.json.serializer.*
import io.ktor.client.features.logging.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import kotlinx.serialization.json.Json
import org.koin.core.context.startKoin
import org.koin.dsl.KoinAppDeclaration
@ -26,7 +30,18 @@ fun initKoin() = initKoin(enableNetworkLogs = false) {}
fun commonModule(enableNetworkLogs: Boolean) = module {
single { createJson() }
single { createHttpClient(get(), enableNetworkLogs = enableNetworkLogs) }
single<PeopleInSpaceRepositoryInterface> { PeopleInSpaceRepository() }
single { CoroutineScope(Dispatchers.Default + SupervisorJob() ) }
single<PeopleInSpaceRepositoryInterface>(createdAtStart = true) {
PeopleInSpaceRepository()
.also {
get<CoroutineScope>().launch {
it.fetchAndStorePeople()
}
}
}
single { PeopleInSpaceApi(get()) }
single { Kermit(logger = get()) }
}

View file

@ -13,7 +13,6 @@ import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import kotlin.coroutines.CoroutineContext
interface PeopleInSpaceRepositoryInterface {
fun fetchPeopleAsFlow(): Flow<List<Assignment>>
fun pollISSPosition(): Flow<IssPosition>
@ -31,12 +30,6 @@ class PeopleInSpaceRepository : KoinComponent, PeopleInSpaceRepositoryInterface
var peopleJob: Job? = null
// init {
// coroutineScope.launch {
// fetchAndStorePeople()
// }
// }
override fun fetchPeopleAsFlow(): Flow<List<Assignment>> {
// the main reason we need to do this check is that sqldelight isn't currently
// setup for javascript client
@ -44,7 +37,7 @@ class PeopleInSpaceRepository : KoinComponent, PeopleInSpaceRepositoryInterface
mapper = { name, craft, personImageUrl, personBio ->
Assignment(name = name, craft = craft, personImageUrl = personImageUrl, personBio = personBio)
}
)?.asFlow()?.mapToList() ?: flowOf(emptyList<Assignment>())
)?.asFlow()?.mapToList() ?: flowOf(emptyList())
}
override suspend fun fetchAndStorePeople() {
@ -73,9 +66,6 @@ class PeopleInSpaceRepository : KoinComponent, PeopleInSpaceRepositoryInterface
success(it)
}
}
coroutineScope.launch {
fetchAndStorePeople()
}
}
fun stopObservingPeopleUpdates() {
@ -97,7 +87,7 @@ class PeopleInSpaceRepository : KoinComponent, PeopleInSpaceRepositoryInterface
get() = SupervisorJob() + Dispatchers.Main
}
fun iosPollISSPosition() = KotlinNativeFlowWrapper<IssPosition>(pollISSPosition())
fun iosPollISSPosition() = KotlinNativeFlowWrapper(pollISSPosition())
companion object {
private const val POLL_INTERVAL = 10000L

View file

@ -9,12 +9,8 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
@ -40,10 +36,6 @@ fun PersonList(
.fetchPeopleAsFlow()
.collectAsState(initial = listOf())
LaunchedEffect(true) {
peopleInSpaceRepository.fetchAndStorePeople()
}
val paddingHeight = if (LocalConfiguration.current.isScreenRound) 50.dp else 8.dp
ScalingLazyColumn(
contentPadding = PaddingValues(start = 8.dp, end = 8.dp, top = paddingHeight, bottom = paddingHeight)