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

Rename PresetsRepository #458

Merged
merged 1 commit into from
Dec 28, 2023
Merged
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
6 changes: 3 additions & 3 deletions app/src/main/java/com/willowtree/vocable/AppKoinModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.willowtree.vocable
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import com.willowtree.vocable.facetracking.FaceTrackingViewModel
import com.willowtree.vocable.presets.IPresetsRepository
import com.willowtree.vocable.presets.ILegacyCategoriesAndPhrasesRepository
import com.willowtree.vocable.presets.PresetCategoriesRepository
import com.willowtree.vocable.presets.PresetsRepository
import com.willowtree.vocable.presets.LegacyCategoriesAndPhrasesRepository
import com.willowtree.vocable.presets.PresetsViewModel
import com.willowtree.vocable.presets.RoomPresetCategoriesRepository
import com.willowtree.vocable.room.RoomStoredCategoriesRepository
Expand Down Expand Up @@ -34,7 +34,7 @@ object AppKoinModule {

single { FaceTrackingPermissions(get()) } bind IFaceTrackingPermissions::class
single { VocableSharedPreferences() } bind IVocableSharedPreferences::class
single { PresetsRepository(get()) } bind IPresetsRepository::class
single { LegacyCategoriesAndPhrasesRepository(get()) } bind ILegacyCategoriesAndPhrasesRepository::class
single { Moshi.Builder().add(KotlinJsonAdapterFactory()).build() }
single { LocalizedResourceUtility() } bind ILocalizedResourceUtility::class
single { CategoriesUseCase(get(), get(), get(), get(), get()) } bind ICategoriesUseCase::class
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.willowtree.vocable

import com.willowtree.vocable.presets.Category
import com.willowtree.vocable.presets.IPresetsRepository
import com.willowtree.vocable.presets.ILegacyCategoriesAndPhrasesRepository
import com.willowtree.vocable.presets.PresetCategoriesRepository
import com.willowtree.vocable.presets.asCategory
import com.willowtree.vocable.room.CategorySortOrder
Expand All @@ -13,7 +13,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

class CategoriesUseCase(
private val presetsRepository: IPresetsRepository,
private val presetsRepository: ILegacyCategoriesAndPhrasesRepository,
private val uuidProvider: UUIDProvider,
private val localeProvider: LocaleProvider,
private val storedCategoriesRepository: StoredCategoriesRepository,
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/willowtree/vocable/PhrasesUseCase.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.willowtree.vocable

import com.willowtree.vocable.presets.IPresetsRepository
import com.willowtree.vocable.presets.ILegacyCategoriesAndPhrasesRepository
import com.willowtree.vocable.presets.Phrase
import com.willowtree.vocable.presets.PresetCategories
import com.willowtree.vocable.presets.asPhrase
Expand All @@ -9,7 +9,7 @@ import com.willowtree.vocable.utils.DateProvider
import com.willowtree.vocable.utils.locale.LocalesWithText

class PhrasesUseCase(
private val presetsRepository: IPresetsRepository,
private val presetsRepository: ILegacyCategoriesAndPhrasesRepository,
private val dateProvider: DateProvider
) {
suspend fun getPhrasesForCategory(categoryId: String): List<Phrase> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import com.willowtree.vocable.room.PhraseDto
import com.willowtree.vocable.utils.locale.LocalesWithText
import kotlinx.coroutines.flow.Flow

//TODO: PK - Rename this once we make the jump to rename [PresetsRepository] -> "RoomPresetsRepository"
interface IPresetsRepository {
@Deprecated("This is the old way of accessing categories and phrases. Prefer using" +
" ICategoriesUseCase instead.")
Comment on lines +9 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit but would we want PhrasesUseCase mentioned in here as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I forgot that existed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'ma fix this forward in a following PR 👍

interface ILegacyCategoriesAndPhrasesRepository {
suspend fun getPhrasesForCategory(categoryId: String): List<PhraseDto>

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.koin.core.component.KoinComponent
import org.koin.core.component.get
import java.util.Locale

class PresetsRepository(val context: Context) : KoinComponent, IPresetsRepository {
class LegacyCategoriesAndPhrasesRepository(val context: Context) : KoinComponent, ILegacyCategoriesAndPhrasesRepository {

private val database = VocableDatabase.getVocableDatabase(context)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.willowtree.vocable.PhrasesUseCase
import com.willowtree.vocable.presets.PresetsRepository
import com.willowtree.vocable.presets.LegacyCategoriesAndPhrasesRepository
import com.willowtree.vocable.utils.locale.LocalesWithText
import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent
Expand All @@ -14,7 +14,7 @@ import java.util.Locale

class AddPhraseViewModel : ViewModel(), KoinComponent {

private val presetsRepository: PresetsRepository by inject()
private val presetsRepository: LegacyCategoriesAndPhrasesRepository by inject()
private val phrasesUseCase: PhrasesUseCase by inject()

private val liveShowPhraseAdded = MutableLiveData<Boolean>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import androidx.lifecycle.viewModelScope
import com.willowtree.vocable.CategoriesUseCase
import com.willowtree.vocable.presets.Category
import com.willowtree.vocable.presets.PresetCategories
import com.willowtree.vocable.presets.PresetsRepository
import com.willowtree.vocable.presets.LegacyCategoriesAndPhrasesRepository
import com.willowtree.vocable.room.CategorySortOrder
import kotlinx.coroutines.launch

class EditCategoryMenuViewModel(
private val presetsRepository: PresetsRepository,
private val presetsRepository: LegacyCategoriesAndPhrasesRepository,
private val categoriesUseCase: CategoriesUseCase
) : ViewModel() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.willowtree.vocable.settings

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.willowtree.vocable.presets.PresetsRepository
import com.willowtree.vocable.utils.VocableSharedPreferences
import com.willowtree.vocable.presets.LegacyCategoriesAndPhrasesRepository
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject

class SettingsViewModel : ViewModel(), KoinComponent {

private val presetsRepository: PresetsRepository by inject()
private val presetsRepository: LegacyCategoriesAndPhrasesRepository by inject()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.willowtree.vocable.presets.PresetsRepository
import com.willowtree.vocable.presets.LegacyCategoriesAndPhrasesRepository
import com.willowtree.vocable.utils.VocableSharedPreferences
import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject

class SplashViewModel : ViewModel(), KoinComponent {

private val presetsRepository: PresetsRepository by inject()
private val presetsRepository: LegacyCategoriesAndPhrasesRepository by inject()

private val sharedPrefs: VocableSharedPreferences by inject()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.willowtree.vocable

import com.willowtree.vocable.presets.Category
import com.willowtree.vocable.presets.FakePresetCategoriesRepository
import com.willowtree.vocable.presets.FakePresetsRepository
import com.willowtree.vocable.presets.FakeLegacyCategoriesAndPhrasesRepository
import com.willowtree.vocable.room.CategoryDto
import com.willowtree.vocable.room.CategorySortOrder
import com.willowtree.vocable.room.FakeStoredCategoriesRepository
Expand All @@ -17,7 +17,7 @@ import org.junit.Test

class CategoriesUseCaseTest {

private val fakePresetsRepository = FakePresetsRepository()
private val fakePresetsRepository = FakeLegacyCategoriesAndPhrasesRepository()
private val fakeStoredCategoriesRepository = FakeStoredCategoriesRepository()
private val fakePresetCategoriesRepository = FakePresetCategoriesRepository()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.willowtree.vocable

import com.willowtree.vocable.presets.CustomPhrase
import com.willowtree.vocable.presets.FakePresetsRepository
import com.willowtree.vocable.presets.FakeLegacyCategoriesAndPhrasesRepository
import com.willowtree.vocable.presets.PresetCategories
import com.willowtree.vocable.room.PhraseDto
import com.willowtree.vocable.utils.FakeDateProvider
Expand All @@ -11,7 +11,7 @@ import org.junit.Test

class PhrasesUseCaseTest {

private val presetsRepository = FakePresetsRepository()
private val presetsRepository = FakeLegacyCategoriesAndPhrasesRepository()

private fun createUseCase(): PhrasesUseCase {
return PhrasesUseCase(presetsRepository, FakeDateProvider())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.update

class FakePresetsRepository : IPresetsRepository {
class FakeLegacyCategoriesAndPhrasesRepository : ILegacyCategoriesAndPhrasesRepository {

val _allCategories = MutableStateFlow(
listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PresetsViewModelTest {
@get:Rule
val instantTaskExecutorRule = InstantTaskExecutorRule()

private val fakePresetsRepository = FakePresetsRepository()
private val fakePresetsRepository = FakeLegacyCategoriesAndPhrasesRepository()
private val fakeCategoriesUseCase = FakeCategoriesUseCase()

private fun createViewModel(): PresetsViewModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.willowtree.vocable.FakeCategoriesUseCase
import com.willowtree.vocable.MainDispatcherRule
import com.willowtree.vocable.PhrasesUseCase
import com.willowtree.vocable.presets.FakePresetsRepository
import com.willowtree.vocable.presets.FakeLegacyCategoriesAndPhrasesRepository
import com.willowtree.vocable.presets.createStoredCategory
import com.willowtree.vocable.utils.FakeDateProvider
import com.willowtree.vocable.utils.FakeLocalizedResourceUtility
Expand All @@ -21,7 +21,7 @@ class EditCategoriesViewModelTest {
@get:Rule
val instantTaskExecutorRule = InstantTaskExecutorRule()

private val fakePresetsRepository = FakePresetsRepository()
private val fakePresetsRepository = FakeLegacyCategoriesAndPhrasesRepository()
private val categoriesUseCase = FakeCategoriesUseCase()

private fun createViewModel(): EditCategoriesViewModel {
Expand Down