Skip to content

Commit

Permalink
[#102] Rename method names to be consistent and remove callback from …
Browse files Browse the repository at this point in the history
…HomeScreen
  • Loading branch information
kaungkhantsoe committed Aug 3, 2023
1 parent 9a89135 commit f031f35
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package co.nimblehq.compose.crypto.ui.navigation

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.*
import androidx.navigation.compose.*
Expand Down Expand Up @@ -38,19 +39,16 @@ fun AppNavigation(
) {
composable(AppDestination.Home) {
HomeScreen(
navigator = { destination -> navController.navigate(destination) },
onInternetRestore = {
onInternetRestore = it
}
navigator = { destination -> navController.navigate(destination) }
)
}

composable(AppDestination.CoinDetail) {
DetailScreen(
navigator = { destination -> navController.navigate(destination) },
coinId = it.arguments?.getString(KEY_COIN_ID).orEmpty(),
onInternetRestore = {
onInternetRestore = it
onNetworkReconnected = { callback ->
onInternetRestore = callback
}
)
}
Expand All @@ -62,9 +60,9 @@ fun AppNavigation(
navController.popBackStack()
onInternetRestore.invoke()
},
message = R.string.no_internet_message,
actionText = android.R.string.ok,
title = R.string.no_internet_title
message = stringResource(id = R.string.no_internet_message),
actionText = stringResource(id = android.R.string.ok),
title = stringResource(id = R.string.no_internet_title)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package co.nimblehq.compose.crypto.ui.screens

import androidx.lifecycle.viewModelScope
import co.nimblehq.compose.crypto.domain.usecase.GetConnectionStatusUseCase
import co.nimblehq.compose.crypto.domain.usecase.IsNetworkConnectedUseCase
import co.nimblehq.compose.crypto.ui.base.*
import co.nimblehq.compose.crypto.util.DispatchersProvider
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -16,7 +16,7 @@ interface Output : BaseOutput {

@HiltViewModel
class MainViewModel @Inject constructor(
getConnectionStatusUseCase: GetConnectionStatusUseCase,
isNetworkConnectedUseCase: IsNetworkConnectedUseCase,
dispatchersProvider: DispatchersProvider,
) : BaseViewModel(dispatchersProvider), Input, Output {
private val _isNetworkConnected = MutableSharedFlow<Boolean?>()
Expand All @@ -27,7 +27,7 @@ class MainViewModel @Inject constructor(
override val output: BaseOutput = this

init {
getConnectionStatusUseCase()
isNetworkConnectedUseCase()
.catch {
_error.emit(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fun DetailScreen(
viewModel: DetailViewModel = hiltViewModel(),
navigator: (destination: AppDestination) -> Unit,
coinId: String,
onInternetRestore: (() -> Unit) -> Unit
onNetworkReconnected: (() -> Unit) -> Unit
) {
val context = LocalContext.current
LaunchedEffect(Unit) {
Expand Down Expand Up @@ -85,7 +85,7 @@ fun DetailScreen(
viewModel.input.getCoinId(coinId = coinId)
}

onInternetRestore {
onNetworkReconnected {
viewModel.input.getCoinId(coinId = coinId)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const val TestTagCoinsLoader = "CoinsLoader"
fun HomeScreen(
viewModel: HomeViewModel = hiltViewModel(),
navigator: (destination: AppDestination) -> Unit,
onInternetRestore: (() -> Unit) -> Unit
) {

val context = LocalContext.current
Expand All @@ -58,10 +57,6 @@ fun HomeScreen(
}
}

onInternetRestore {
viewModel.input.loadData(isRefreshing = true)
}

val showMyCoinsLoading: IsLoading by viewModel.output.showMyCoinsLoading.collectAsState()
val showTrendingCoinsLoading: LoadingState by viewModel.output.showTrendingCoinsLoading.collectAsState()
val myCoins: List<CoinItemUiModel> by viewModel.output.myCoins.collectAsState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class DetailScreenTest : BaseViewModelTest() {
viewModel = viewModel,
navigator = { destination -> appDestination = destination },
coinId = "Bitcoin",
onInternetRestore = {}
onNetworkReconnected = {}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ class HomeScreenTest : BaseViewModelTest() {
composeAndroidTestRule.activity.setContent {
HomeScreen(
viewModel = viewModel,
navigator = { destination -> appDestination = destination },
onInternetRestore = {}
navigator = { destination -> appDestination = destination }
)
}
}
Expand Down

0 comments on commit f031f35

Please sign in to comment.