Skip to content

Commit

Permalink
Fix rebase changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bpedryc committed Jul 5, 2023
1 parent 5700704 commit 99379a3
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import co.touchlab.kampkit.android.R
import co.touchlab.kampkit.domain.breed.Breed
import co.touchlab.kampkit.ui.breeds.BreedsNavRequest
import co.touchlab.kampkit.ui.breeds.BreedsViewModel
import co.touchlab.kampkit.ui.breeds.BreedsViewState
import co.touchlab.kermit.Logger
Expand Down Expand Up @@ -83,7 +84,7 @@ fun BreedsScreenContent(
LaunchedEffect(breeds) {
onSuccess(breeds)
}
Success(successData = breeds, favoriteBreed = onFavorite)
Success(successData = breeds, onBreedClick = onBreedClick)
}
}

Expand Down
2 changes: 1 addition & 1 deletion ios/KaMPKitiOS/Breeds/BreedsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BreedsViewModel: ObservableObject {
.store(in: &cancellables)
}

private func handleNavRequests(breedsState: BreedViewState) {
private func handleNavRequests(breedsState: BreedsViewState) {
if let navRequest = breedsState.breedsNavRequest as? BreedsNavRequest.ToDetails {
self.navCoordinator.onBreedDetailsRequest(breedId: navRequest.breedId)
self.viewModelDelegate.onBreedDetailsNavRequestCompleted()
Expand Down
4 changes: 0 additions & 4 deletions shared/src/commonMain/kotlin/co/touchlab/kampkit/core/Koin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import co.touchlab.kampkit.data.dog.DogApiImpl
import co.touchlab.kampkit.data.dog.DogDatabaseHelper
import co.touchlab.kampkit.data.dog.NetworkBreedRepository
import co.touchlab.kampkit.domain.breed.BreedRepository
import co.touchlab.kampkit.data.dog.DogApi
import co.touchlab.kampkit.data.dog.DogApiImpl
import co.touchlab.kampkit.data.dog.DogDatabaseHelper
import co.touchlab.kampkit.data.dog.DogRepository
import co.touchlab.kermit.Logger
import co.touchlab.kermit.StaticConfig
import co.touchlab.kermit.platformLogWriter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package co.touchlab.kampkit.data.dog

import co.touchlab.kampkit.core.transactionWithContext
import co.touchlab.kampkit.db.Breed
import co.touchlab.kampkit.core.transactionWithContext
import co.touchlab.kampkit.db.DbBreed
import co.touchlab.kampkit.db.KaMPKitDb
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class NetworkBreedRepository(
private val clock: Clock
) : BreedRepository {

private val log = log.withTag("DogRepository")
private val log = log.withTag("NetworkBreedRepository")

companion object {
internal const val DB_TIMESTAMP_KEY = "DbTimestampKey"
Expand All @@ -28,10 +28,15 @@ class NetworkBreedRepository(
ensureNeverFrozen()
}

override fun getBreed(id: Long): Flow<Breed?> {
return dbHelper
.selectById(id)
.map { dbBreed -> dbBreed?.toDomain() }
}
override fun getBreeds(): Flow<List<Breed>> {
return dbHelper.selectAllItems().map { list ->
list.map { dbBreed -> dbBreed.toDomain() }
}
return dbHelper
.selectAllItems()
.map { list -> list.map { dbBreed -> dbBreed.toDomain() } }
}

override suspend fun refreshBreedsIfStale() {
Expand All @@ -53,8 +58,10 @@ class NetworkBreedRepository(
}

override suspend fun updateBreedFavorite(breedId: Long) {
val foundBreedsWithId = dbHelper.selectById(breedId).first()
foundBreedsWithId.firstOrNull()?.let { breed ->
dbHelper
.selectById(breedId)
.first()
?.let { breed ->
dbHelper.updateFavorite(breed.id, !breed.favorite)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package co.touchlab.kampkit.domain.breed
import kotlinx.coroutines.flow.Flow

interface BreedRepository {
fun getBreed(id: Long): Flow<Breed?>
fun getBreeds(): Flow<List<Breed>>
suspend fun refreshBreedsIfStale()
suspend fun refreshBreeds()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package co.touchlab.kampkit.ui.breedDetails

import co.touchlab.kampkit.core.ViewModel
import co.touchlab.kampkit.data.dog.DogRepository
import co.touchlab.kampkit.domain.breed.BreedRepository
import co.touchlab.kermit.Logger
import com.rickclephas.kmp.nativecoroutines.NativeCoroutinesState
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -13,7 +13,7 @@ import kotlin.native.ObjCName
@ObjCName("BreedDetailsViewModelDelegate")
class BreedDetailsViewModel(
private val breedId: Long,
private val dogRepository: DogRepository,
private val breedRepository: BreedRepository,
log: Logger
) : ViewModel() {
private val log = log.withTag("BreedDetailsViewModel")
Expand All @@ -30,7 +30,7 @@ class BreedDetailsViewModel(

private fun loadDetails() {
viewModelScope.launch {
dogRepository.getBreed(breedId).collect { breed ->
breedRepository.getBreed(breedId).collect { breed ->
mutableDetailsState.update { previousState ->
val error = if (breed == null) "Couldn't load the breed details" else null
val newBreed = breed?.toDisplayable() ?: previousState.breed
Expand All @@ -46,7 +46,7 @@ class BreedDetailsViewModel(

fun onFavoriteClick() {
viewModelScope.launch {
dogRepository.updateBreedFavorite(breedId)
breedRepository.updateBreedFavorite(breedId)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package co.touchlab.kampkit.ui.breedDetails

import co.touchlab.kampkit.db.Breed
import co.touchlab.kampkit.domain.breed.Breed

data class BreedDisplayable(
val id: Long = 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package co.touchlab.kampkit.ui.breeds

import co.touchlab.kampkit.core.ViewModel
import co.touchlab.kampkit.domain.breed.Breed
import co.touchlab.kampkit.domain.breed.BreedRepository
import co.touchlab.kermit.Logger
import com.rickclephas.kmp.nativecoroutines.NativeCoroutinesState
Expand Down Expand Up @@ -105,17 +104,3 @@ class BreedsViewModel(
}
}
}

data class BreedViewState(
val breeds: List<Breed> = emptyList(),
val error: String? = null,
val isLoading: Boolean = false,
val isEmpty: Boolean = false,
val breedsNavRequest: BreedsNavRequest? = null
) {
companion object {
// This method lets you use the default constructor values in Swift. When accessing the
// constructor directly, they will not work there and would need to be provided explicitly.
fun default() = BreedViewState()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ data class BreedsViewState(
val breeds: List<Breed> = emptyList(),
val error: String? = null,
val isLoading: Boolean = false,
val isEmpty: Boolean = false
val isEmpty: Boolean = false,
val breedsNavRequest: BreedsNavRequest? = null
) {
companion object {
// This method lets you use the default constructor values in Swift. When accessing the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class BreedsViewModelTest {
dbHelper.insertBreeds(breedNames)
viewModel.onBreedClick(1).join()

viewModel.breedState.test {
viewModel.breedsState.test {
val state = awaitItem()
assertEquals(BreedsNavRequest.ToDetails(1), state.breedsNavRequest)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import kotlin.test.assertEquals
import kotlin.test.assertFails
import kotlin.time.Duration.Companion.hours

class NetworkDogRepositoryTest {
class NetworkBreedRepositoryTest {

private var kermit = Logger(StaticConfig())
private var testDbConnection = testDbConnection()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package co.touchlab.kampkit.core

import co.touchlab.kampkit.db.KaMPKitDb
import co.touchlab.kampkit.ui.breeds.BreedsViewModel
import co.touchlab.kampkit.ui.breedDetails.BreedDetailsViewModel
import co.touchlab.kampkit.ui.breeds.BreedsViewModel
import co.touchlab.kermit.Logger
Expand Down

0 comments on commit 99379a3

Please sign in to comment.