Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pluralise MyModel for Screen and ViewModel #53

Open
wants to merge 1 commit into
base: base
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package android.template.ui.mymodel
package android.template.ui.mymodels

import androidx.activity.ComponentActivity
import androidx.compose.ui.test.junit4.createAndroidComposeRule
Expand All @@ -27,18 +27,18 @@ import org.junit.Test
import org.junit.runner.RunWith

/**
* UI tests for [MyModelScreen].
* UI tests for [MyModelsScreen].
*/
@RunWith(AndroidJUnit4::class)
class MyModelScreenTest {
class MyModelsScreenTest {

@get:Rule
val composeTestRule = createAndroidComposeRule<ComponentActivity>()

@Before
fun setup() {
composeTestRule.setContent {
MyModelScreen(FAKE_DATA, onSave = {})
MyModelsScreen(FAKE_DATA, onSave = {})
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/android/template/ui/Navigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import androidx.compose.ui.unit.dp
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import android.template.ui.mymodel.MyModelScreen
import android.template.ui.mymodels.MyModelsScreen

@Composable
fun MainNavigation() {
val navController = rememberNavController()

NavHost(navController = navController, startDestination = "main") {
composable("main") { MyModelScreen(modifier = Modifier.padding(16.dp)) }
composable("main") { MyModelsScreen(modifier = Modifier.padding(16.dp)) }
// TODO: Add more destinations
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package android.template.ui.mymodel
package android.template.ui.mymodels

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -42,7 +42,7 @@ import android.template.ui.theme.MyApplicationTheme
import androidx.compose.material3.ExperimentalMaterial3Api

@Composable
fun MyModelScreen(modifier: Modifier = Modifier, viewModel: MyModelViewModel = hiltViewModel()) {
fun MyModelsScreen(modifier: Modifier = Modifier, viewModel: MyModelsViewModel = hiltViewModel()) {
val lifecycle = LocalLifecycleOwner.current.lifecycle
val items by produceState<MyModelUiState>(
initialValue = MyModelUiState.Loading,
Expand All @@ -54,7 +54,7 @@ fun MyModelScreen(modifier: Modifier = Modifier, viewModel: MyModelViewModel = h
}
}
if (items is MyModelUiState.Success) {
MyModelScreen(
MyModelsScreen(
items = (items as MyModelUiState.Success).data,
onSave = viewModel::addMyModel,
modifier = modifier
Expand All @@ -64,7 +64,7 @@ fun MyModelScreen(modifier: Modifier = Modifier, viewModel: MyModelViewModel = h

@OptIn(ExperimentalMaterial3Api::class)
@Composable
internal fun MyModelScreen(
internal fun MyModelsScreen(
items: List<String>,
onSave: (name: String) -> Unit,
modifier: Modifier = Modifier
Expand Down Expand Up @@ -96,14 +96,14 @@ internal fun MyModelScreen(
@Composable
private fun DefaultPreview() {
MyApplicationTheme {
MyModelScreen(listOf("Compose", "Room", "Kotlin"), onSave = {})
MyModelsScreen(listOf("Compose", "Room", "Kotlin"), onSave = {})
}
}

@Preview(showBackground = true, widthDp = 480)
@Composable
private fun PortraitPreview() {
MyApplicationTheme {
MyModelScreen(listOf("Compose", "Room", "Kotlin"), onSave = {})
MyModelsScreen(listOf("Compose", "Room", "Kotlin"), onSave = {})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package android.template.ui.mymodel
package android.template.ui.mymodels

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
Expand All @@ -26,13 +26,13 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import android.template.data.MyModelRepository
import android.template.ui.mymodel.MyModelUiState.Error
import android.template.ui.mymodel.MyModelUiState.Loading
import android.template.ui.mymodel.MyModelUiState.Success
import android.template.ui.mymodels.MyModelUiState.Error
import android.template.ui.mymodels.MyModelUiState.Loading
import android.template.ui.mymodels.MyModelUiState.Success
import javax.inject.Inject

@HiltViewModel
class MyModelViewModel @Inject constructor(
class MyModelsViewModel @Inject constructor(
private val myModelRepository: MyModelRepository
) : ViewModel() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package android.template.ui.mymodel
package android.template.ui.mymodels


import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand All @@ -32,16 +32,16 @@ import android.template.data.MyModelRepository
* See [testing documentation](http://d.android.com/tools/testing).
*/
@OptIn(ExperimentalCoroutinesApi::class) // TODO: Remove when stable
class MyModelViewModelTest {
class MyModelsViewModelTest {
@Test
fun uiState_initiallyLoading() = runTest {
val viewModel = MyModelViewModel(FakeMyModelRepository())
val viewModel = MyModelsViewModel(FakeMyModelRepository())
assertEquals(viewModel.uiState.first(), MyModelUiState.Loading)
}

@Test
fun uiState_onItemSaved_isDisplayed() = runTest {
val viewModel = MyModelViewModel(FakeMyModelRepository())
val viewModel = MyModelsViewModel(FakeMyModelRepository())
assertEquals(viewModel.uiState.first(), MyModelUiState.Loading)
}
}
Expand Down
2 changes: 1 addition & 1 deletion customizer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ then
fi
# directories
echo "Renaming directories to $DATAMODEL"
find ./ -name "mymodel" -type d | sed "p;s/mymodel/${DATAMODEL,,}/" | tr '\n' '\0' | xargs -0 -n 2 mv
find ./ -name "mymodels" -type d | sed "p;s/mymodels/${DATAMODEL,,}s/" | tr '\n' '\0' | xargs -0 -n 2 mv

# Rename app
if [[ $APPNAME ]]
Expand Down