Skip to content

Commit f031f35

Browse files
committed
[#102] Rename method names to be consistent and remove callback from HomeScreen
1 parent 9a89135 commit f031f35

File tree

6 files changed

+14
-22
lines changed

6 files changed

+14
-22
lines changed

app/src/main/java/co/nimblehq/compose/crypto/ui/navigation/AppNavigation.kt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package co.nimblehq.compose.crypto.ui.navigation
22

33
import androidx.compose.runtime.Composable
4+
import androidx.compose.ui.res.stringResource
45
import androidx.hilt.navigation.compose.hiltViewModel
56
import androidx.navigation.*
67
import androidx.navigation.compose.*
@@ -38,19 +39,16 @@ fun AppNavigation(
3839
) {
3940
composable(AppDestination.Home) {
4041
HomeScreen(
41-
navigator = { destination -> navController.navigate(destination) },
42-
onInternetRestore = {
43-
onInternetRestore = it
44-
}
42+
navigator = { destination -> navController.navigate(destination) }
4543
)
4644
}
4745

4846
composable(AppDestination.CoinDetail) {
4947
DetailScreen(
5048
navigator = { destination -> navController.navigate(destination) },
5149
coinId = it.arguments?.getString(KEY_COIN_ID).orEmpty(),
52-
onInternetRestore = {
53-
onInternetRestore = it
50+
onNetworkReconnected = { callback ->
51+
onInternetRestore = callback
5452
}
5553
)
5654
}
@@ -62,9 +60,9 @@ fun AppNavigation(
6260
navController.popBackStack()
6361
onInternetRestore.invoke()
6462
},
65-
message = R.string.no_internet_message,
66-
actionText = android.R.string.ok,
67-
title = R.string.no_internet_title
63+
message = stringResource(id = R.string.no_internet_message),
64+
actionText = stringResource(id = android.R.string.ok),
65+
title = stringResource(id = R.string.no_internet_title)
6866
)
6967
}
7068
}

app/src/main/java/co/nimblehq/compose/crypto/ui/screens/MainViewModel.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package co.nimblehq.compose.crypto.ui.screens
22

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

1717
@HiltViewModel
1818
class MainViewModel @Inject constructor(
19-
getConnectionStatusUseCase: GetConnectionStatusUseCase,
19+
isNetworkConnectedUseCase: IsNetworkConnectedUseCase,
2020
dispatchersProvider: DispatchersProvider,
2121
) : BaseViewModel(dispatchersProvider), Input, Output {
2222
private val _isNetworkConnected = MutableSharedFlow<Boolean?>()
@@ -27,7 +27,7 @@ class MainViewModel @Inject constructor(
2727
override val output: BaseOutput = this
2828

2929
init {
30-
getConnectionStatusUseCase()
30+
isNetworkConnectedUseCase()
3131
.catch {
3232
_error.emit(it)
3333
}

app/src/main/java/co/nimblehq/compose/crypto/ui/screens/detail/DetailScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fun DetailScreen(
5454
viewModel: DetailViewModel = hiltViewModel(),
5555
navigator: (destination: AppDestination) -> Unit,
5656
coinId: String,
57-
onInternetRestore: (() -> Unit) -> Unit
57+
onNetworkReconnected: (() -> Unit) -> Unit
5858
) {
5959
val context = LocalContext.current
6060
LaunchedEffect(Unit) {
@@ -85,7 +85,7 @@ fun DetailScreen(
8585
viewModel.input.getCoinId(coinId = coinId)
8686
}
8787

88-
onInternetRestore {
88+
onNetworkReconnected {
8989
viewModel.input.getCoinId(coinId = coinId)
9090
}
9191
}

app/src/main/java/co/nimblehq/compose/crypto/ui/screens/home/HomeScreen.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ const val TestTagCoinsLoader = "CoinsLoader"
4141
fun HomeScreen(
4242
viewModel: HomeViewModel = hiltViewModel(),
4343
navigator: (destination: AppDestination) -> Unit,
44-
onInternetRestore: (() -> Unit) -> Unit
4544
) {
4645

4746
val context = LocalContext.current
@@ -58,10 +57,6 @@ fun HomeScreen(
5857
}
5958
}
6059

61-
onInternetRestore {
62-
viewModel.input.loadData(isRefreshing = true)
63-
}
64-
6560
val showMyCoinsLoading: IsLoading by viewModel.output.showMyCoinsLoading.collectAsState()
6661
val showTrendingCoinsLoading: LoadingState by viewModel.output.showTrendingCoinsLoading.collectAsState()
6762
val myCoins: List<CoinItemUiModel> by viewModel.output.myCoins.collectAsState()

app/src/test/java/co/nimblehq/compose/crypto/ui/screens/detail/DetailScreenTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class DetailScreenTest : BaseViewModelTest() {
6969
viewModel = viewModel,
7070
navigator = { destination -> appDestination = destination },
7171
coinId = "Bitcoin",
72-
onInternetRestore = {}
72+
onNetworkReconnected = {}
7373
)
7474
}
7575
}

app/src/test/java/co/nimblehq/compose/crypto/ui/screens/home/HomeScreenTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ class HomeScreenTest : BaseViewModelTest() {
6363
composeAndroidTestRule.activity.setContent {
6464
HomeScreen(
6565
viewModel = viewModel,
66-
navigator = { destination -> appDestination = destination },
67-
onInternetRestore = {}
66+
navigator = { destination -> appDestination = destination }
6867
)
6968
}
7069
}

0 commit comments

Comments
 (0)