From fc7dc68b62803ed1cef6f3022e302db2fb82d4f6 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Fri, 21 Oct 2022 20:23:51 +0200 Subject: [PATCH] Rename Source to Repository This is more in line with the repository google-developer-training/basic-android-kotlin-compose-training-mars-photos which contains good practices. --- .../talaria/data/{DialogSource.kt => DialogRepository.kt} | 6 +++--- .../talaria/data/{MessageSource.kt => MessageRepository.kt} | 2 +- app/src/main/java/dev/lonami/talaria/ui/ChatViewModel.kt | 4 ++-- app/src/main/java/dev/lonami/talaria/ui/DialogScreen.kt | 4 ++-- app/src/main/java/dev/lonami/talaria/ui/DialogViewModel.kt | 5 +++-- 5 files changed, 11 insertions(+), 10 deletions(-) rename app/src/main/java/dev/lonami/talaria/data/{DialogSource.kt => DialogRepository.kt} (88%) rename app/src/main/java/dev/lonami/talaria/data/{MessageSource.kt => MessageRepository.kt} (89%) diff --git a/app/src/main/java/dev/lonami/talaria/data/DialogSource.kt b/app/src/main/java/dev/lonami/talaria/data/DialogRepository.kt similarity index 88% rename from app/src/main/java/dev/lonami/talaria/data/DialogSource.kt rename to app/src/main/java/dev/lonami/talaria/data/DialogRepository.kt index ff9af59..3b8e15e 100644 --- a/app/src/main/java/dev/lonami/talaria/data/DialogSource.kt +++ b/app/src/main/java/dev/lonami/talaria/data/DialogRepository.kt @@ -3,11 +3,11 @@ package dev.lonami.talaria.data import dev.lonami.talaria.bindings.Native import dev.lonami.talaria.model.Dialog -interface DialogSource { +interface DialogRepository { fun loadDialogs(): List; } -class NativeDialogSource : DialogSource { +class NativeDialogRepository : DialogRepository { override fun loadDialogs(): List { val dialogs = mutableListOf() @@ -28,7 +28,7 @@ class NativeDialogSource : DialogSource { } } -class MockDialogSource : DialogSource { +class MockDialogRepository : DialogRepository { override fun loadDialogs(): List { val dialogs = mutableListOf() for (i in 0 until 10) { diff --git a/app/src/main/java/dev/lonami/talaria/data/MessageSource.kt b/app/src/main/java/dev/lonami/talaria/data/MessageRepository.kt similarity index 89% rename from app/src/main/java/dev/lonami/talaria/data/MessageSource.kt rename to app/src/main/java/dev/lonami/talaria/data/MessageRepository.kt index 2e47d48..0bd81bb 100644 --- a/app/src/main/java/dev/lonami/talaria/data/MessageSource.kt +++ b/app/src/main/java/dev/lonami/talaria/data/MessageRepository.kt @@ -2,7 +2,7 @@ package dev.lonami.talaria.data import dev.lonami.talaria.model.Message -object MessageSource { +object MessageRepository { fun loadMessages(): List { return generateSequence { Message("Alice", "Testing") diff --git a/app/src/main/java/dev/lonami/talaria/ui/ChatViewModel.kt b/app/src/main/java/dev/lonami/talaria/ui/ChatViewModel.kt index d06ce4f..e420e12 100644 --- a/app/src/main/java/dev/lonami/talaria/ui/ChatViewModel.kt +++ b/app/src/main/java/dev/lonami/talaria/ui/ChatViewModel.kt @@ -2,7 +2,7 @@ package dev.lonami.talaria.ui import androidx.lifecycle.ViewModel import dev.lonami.talaria.bindings.Native -import dev.lonami.talaria.data.MessageSource +import dev.lonami.talaria.data.MessageRepository import dev.lonami.talaria.model.Message import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -14,7 +14,7 @@ class ChatViewModel : ViewModel() { val uiState: StateFlow = _uiState.asStateFlow() private fun loadMessages() { - _uiState.value = ChatUiState(MessageSource.loadMessages().toMutableList()) + _uiState.value = ChatUiState(MessageRepository.loadMessages().toMutableList()) } fun sendMessage(dialog: String, message: String) { diff --git a/app/src/main/java/dev/lonami/talaria/ui/DialogScreen.kt b/app/src/main/java/dev/lonami/talaria/ui/DialogScreen.kt index 994bcb9..ee8dbb3 100644 --- a/app/src/main/java/dev/lonami/talaria/ui/DialogScreen.kt +++ b/app/src/main/java/dev/lonami/talaria/ui/DialogScreen.kt @@ -21,7 +21,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel import dev.lonami.talaria.R -import dev.lonami.talaria.data.MockDialogSource +import dev.lonami.talaria.data.MockDialogRepository import dev.lonami.talaria.model.Dialog import dev.lonami.talaria.ui.theme.TalariaTheme @@ -70,7 +70,7 @@ fun DialogScreen( @Preview @Composable fun DialogPreview() { - val viewModel = DialogViewModel(MockDialogSource()) + val viewModel = DialogViewModel(MockDialogRepository()) TalariaTheme { DialogScreen(onDialogSelected = { }, dialogViewModel = viewModel) } diff --git a/app/src/main/java/dev/lonami/talaria/ui/DialogViewModel.kt b/app/src/main/java/dev/lonami/talaria/ui/DialogViewModel.kt index ef48ad7..1f3dba8 100644 --- a/app/src/main/java/dev/lonami/talaria/ui/DialogViewModel.kt +++ b/app/src/main/java/dev/lonami/talaria/ui/DialogViewModel.kt @@ -2,12 +2,13 @@ package dev.lonami.talaria.ui import androidx.lifecycle.ViewModel import dev.lonami.talaria.data.DialogSource -import dev.lonami.talaria.data.NativeDialogSource +import dev.lonami.talaria.data.NativeDialogRepository import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow -class DialogViewModel(private val repository: DialogSource = NativeDialogSource()) : ViewModel() { +class DialogViewModel(private val repository: DialogSource = NativeDialogRepository()) : + ViewModel() { private val _uiState = MutableStateFlow(DialogUiState()) val uiState: StateFlow = _uiState.asStateFlow()