Skip to content

Commit

Permalink
refactor(shared): Remove AgendaRepository and move impl to other exit…
Browse files Browse the repository at this point in the history
…ing repos.
  • Loading branch information
GerardPaligot committed Dec 1, 2024
1 parent a4add62 commit 8b23654
Show file tree
Hide file tree
Showing 53 changed files with 539 additions and 658 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package com.paligot.confily.core.sample
import android.content.Context
import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters
import com.paligot.confily.core.agenda.AgendaRepository
import com.paligot.confily.core.events.EventRepository
import org.koin.core.component.KoinComponent

class ScheduleWorkManager(
context: Context,
parameters: WorkerParameters,
private val repository: AgendaRepository
private val repository: EventRepository
) : CoroutineWorker(context, parameters), KoinComponent {
override suspend fun doWork(): Result {
return try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import androidx.glance.appwidget.updateAll
import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters
import com.paligot.confily.android.widgets.AgendaAppWidget
import com.paligot.confily.core.agenda.AgendaRepository
import com.paligot.confily.core.events.EventRepository
import org.koin.core.component.KoinComponent

class ScheduleWorkManager(
private val context: Context,
parameters: WorkerParameters,
private val repository: AgendaRepository
private val repository: EventRepository
) : CoroutineWorker(context, parameters), KoinComponent {
override suspend fun doWork(): Result {
return try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ val infosModule = module {
includes(repositoriesModule)
viewModel { CoCViewModel(get()) }
viewModel { EventViewModel(get()) }
viewModel { InfoViewModel(get(), get()) }
viewModel { InfoViewModel(get()) }
viewModel { MenusViewModel(get()) }
viewModel { QAndAListViewModel(get()) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.paligot.confily.infos.presentation

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.paligot.confily.core.agenda.AgendaRepository
import com.paligot.confily.core.events.EventRepository
import com.paligot.confily.navigation.FabActions
import com.paligot.confily.navigation.Screen
Expand Down Expand Up @@ -34,14 +33,13 @@ sealed class InfoUiState {
}

class InfoViewModel(
private val agendaRepository: AgendaRepository,
private val eventRepository: EventRepository
) : ViewModel() {
private val _innerRoute = MutableStateFlow<String?>(null)
val uiState = combine(
_innerRoute,
agendaRepository.scaffoldConfig(),
transform = { route, config ->
flow = _innerRoute,
flow2 = eventRepository.featureFlags(),
transform = { route, features ->
InfoUiState.Success(
topActionsUi = TopActionsUi(
actions = persistentListOf(TopActions.disconnect),
Expand All @@ -51,17 +49,17 @@ class InfoViewModel(
scrollable = true,
actions = arrayListOf<TabAction>().apply {
add(TabActions.event)
if (config.hasMenus) {
if (features.hasMenus) {
add(TabActions.menus)
}
if (config.hasQAndA) {
if (features.hasQAndA) {
add(TabActions.qanda)
}
add(TabActions.coc)
}.toImmutableList()
),
fabAction = when (route) {
Screen.Event.route -> if (config.hasBilletWebTicket) FabActions.scanTicket else null
Screen.Event.route -> if (features.hasTicketIntegration) FabActions.scanTicket else null
else -> null
}
) as InfoUiState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ val mainModule = module {
scheduleModule,
speakersModule
)
viewModel { MainNavigationViewModel(get(), get(), get()) }
viewModel { MainNavigationViewModel(get(), get()) }
viewModel { parameters -> MainViewModel(parameters.get(), get()) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase
import com.paligot.confily.core.agenda.AgendaRepository
import com.paligot.confily.core.events.EventRepository
import com.paligot.confily.core.events.entities.FeatureFlags
import com.paligot.confily.core.networking.UserRepository
import com.paligot.confily.core.networking.entities.UserItem
import com.paligot.confily.models.ui.ScaffoldConfigUi
import com.paligot.confily.models.ui.VCardModel
import com.paligot.confily.navigation.BottomActions
import com.paligot.confily.style.theme.actions.NavigationAction
Expand All @@ -28,11 +27,10 @@ sealed class MainNavigationUiState {
}

class MainNavigationViewModel(
agendaRepository: AgendaRepository,
private val eventRepository: EventRepository,
private val userRepository: UserRepository
) : ViewModel() {
val uiState: StateFlow<MainNavigationUiState> = agendaRepository.scaffoldConfig()
val uiState: StateFlow<MainNavigationUiState> = eventRepository.featureFlags()
.map { MainNavigationUiState.Success(navActions(it)) }
.catch {
Firebase.crashlytics.recordException(it)
Expand All @@ -52,15 +50,15 @@ class MainNavigationViewModel(
userRepository.insertUserScanned(model.mapToEntity())
}

private fun navActions(config: ScaffoldConfigUi): NavigationActionsUi =
private fun navActions(features: FeatureFlags): NavigationActionsUi =
NavigationActionsUi(
actions = arrayListOf<NavigationAction>().apply {
add(BottomActions.agenda)
add(BottomActions.speakers)
if (config.hasNetworking) {
if (features.hasNetworking) {
add(BottomActions.myProfile)
}
if (config.hasPartnerList) {
if (features.hasPartnerList) {
add(BottomActions.partners)
}
add(BottomActions.event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ val networkingModule = module {
includes(repositoriesModule)
viewModel { ContactsViewModel(get()) }
viewModel { MyProfileViewModel(get()) }
viewModel { NetworkingViewModel(get(), get()) }
viewModel { NetworkingViewModel(get()) }
viewModel { ProfileInputViewModel(get()) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.paligot.confily.networking.presentation

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.paligot.confily.core.agenda.AgendaRepository
import com.paligot.confily.core.networking.UserRepository
import com.paligot.confily.core.networking.entities.mapToUi
import com.paligot.confily.models.ui.ExportNetworkingUi
Expand Down Expand Up @@ -36,28 +35,27 @@ sealed class NetworkingUiState {
}

class NetworkingViewModel(
agendaRepository: AgendaRepository,
private val userRepository: UserRepository
) : ViewModel() {
private val _exportPath = MutableSharedFlow<ExportNetworkingUi>(replay = 1)
val exportPath: SharedFlow<ExportNetworkingUi> = _exportPath

private val _innerRoute = MutableStateFlow<String?>(null)
val uiState = combine(
_innerRoute,
agendaRepository.scaffoldConfig(),
flow = _innerRoute,
flow2 = userRepository.fetchConfiguration(),
transform = { route, config ->
NetworkingUiState.Success(
topActionsUi = TopActionsUi(
actions = if (config.hasUsersInNetworking) {
actions = if (config.countUsersScanned > 0) {
persistentListOf(TopActions.export)
} else {
persistentListOf()
}
),
tabActionsUi = TabActionsUi(
scrollable = true,
actions = if (config.hasProfile) {
actions = if (config.hasProfileCompleted) {
persistentListOf(
TabActions.myProfile,
TabActions.contacts
Expand All @@ -67,7 +65,7 @@ class NetworkingViewModel(
}
),
fabAction = when (route) {
Screen.MyProfile.route -> if (!config.hasProfile) FabActions.createProfile else null
Screen.MyProfile.route -> if (!config.hasProfileCompleted) FabActions.createProfile else null
Screen.Contacts.route -> FabActions.scanContact
else -> null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import cafe.adriel.lyricist.Lyricist
import com.paligot.confily.core.AlarmScheduler
import com.paligot.confily.core.agenda.AgendaRepository
import com.paligot.confily.core.events.EventRepository
import com.paligot.confily.core.events.entities.mapToDays
import com.paligot.confily.core.schedules.SessionRepository
import com.paligot.confily.core.schedules.entities.mapToListUi
import com.paligot.confily.models.ui.AgendaUi
Expand All @@ -26,9 +27,6 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import kotlinx.datetime.LocalDate
import kotlinx.datetime.format
import kotlinx.datetime.format.byUnicodePattern
import org.jetbrains.compose.resources.InternalResourceApi
import org.jetbrains.compose.resources.StringResource

Expand All @@ -48,29 +46,24 @@ sealed class ScheduleGridUiState {
@FlowPreview
@ExperimentalCoroutinesApi
class ScheduleGridViewModel(
agendaRepository: AgendaRepository,
eventRepository: EventRepository,
sessionRepository: SessionRepository,
lyricist: Lyricist<Strings>,
private val alarmScheduler: AlarmScheduler
) : ViewModel() {
private val _tabsStates = agendaRepository.scaffoldConfig()
.map {
TabActionsUi(
scrollable = true,
actions = it.agendaTabs.sorted().map {
val label = LocalDate.parse(it).format(
LocalDate.Format {
byUnicodePattern("dd/MM")
}
)
TabAction(
route = it,
StringResource("", "", emptySet()),
label
)
}.toImmutableList()
)
}
private val _tabsStates = eventRepository.event().map { event ->
if (event == null) return@map TabActionsUi()
return@map TabActionsUi(
scrollable = true,
actions = event.mapToDays().map {
TabAction(
route = it,
labelId = StringResource("", "", emptySet()),
label = it
)
}.toImmutableList()
)
}
private val _uiHasFiltersState = sessionRepository.countFilters().map {
TopActionsUi(
actions = persistentListOf(if (it > 0) TopActions.filtersFilled else TopActions.filters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.paligot.confily.schedules.sample
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.core.app.ActivityScenario
import androidx.test.platform.app.InstrumentationRegistry
import com.paligot.confily.core.agenda.AgendaDao
import com.paligot.confily.core.kvalue.ConferenceSettings
import com.paligot.confily.core.sample.BuildConfig
import com.paligot.confily.core.schedules.SessionDao
Expand Down Expand Up @@ -39,13 +38,12 @@ class FilteringScheduleTest : KoinTest {
}

private val settings by inject<ConferenceSettings>()
private val agendaDao by inject<AgendaDao>()
private val sessionDao by inject<SessionDao>()

@Before
fun setup() {
settings.insertEventId(BuildConfig.DEFAULT_EVENT)
agendaDao.saveAgenda(BuildConfig.DEFAULT_EVENT, agenda)
sessionDao.insertAgenda(BuildConfig.DEFAULT_EVENT, agenda)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package com.paligot.confily.schedules.sample
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.core.app.ActivityScenario
import androidx.test.platform.app.InstrumentationRegistry
import com.paligot.confily.core.agenda.AgendaDao
import com.paligot.confily.core.events.EventDao
import com.paligot.confily.core.kvalue.ConferenceSettings
import com.paligot.confily.core.sample.BuildConfig
import com.paligot.confily.core.schedules.SessionDao
import com.paligot.confily.core.test.instrumentedModule
import com.paligot.confily.core.test.patterns.navigation.RobotNavigator
import com.paligot.confily.core.test.patterns.navigation.robotHost
Expand Down Expand Up @@ -38,13 +39,14 @@ class ScheduleDetailsTest : KoinTest {
}

private val settings by inject<ConferenceSettings>()
private val agendaDao by inject<AgendaDao>()
private val eventDao by inject<EventDao>()
private val sessionDao by inject<SessionDao>()

@Before
fun setup() {
settings.insertEventId(BuildConfig.DEFAULT_EVENT)
agendaDao.insertEvent(event, emptyList())
agendaDao.saveAgenda(BuildConfig.DEFAULT_EVENT, agenda)
eventDao.insertEvent(event, emptyList())
sessionDao.insertAgenda(BuildConfig.DEFAULT_EVENT, agenda)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package com.paligot.confily.speakers.sample
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.core.app.ActivityScenario
import androidx.test.platform.app.InstrumentationRegistry
import com.paligot.confily.core.agenda.AgendaDao
import com.paligot.confily.core.events.EventDao
import com.paligot.confily.core.kvalue.ConferenceSettings
import com.paligot.confily.core.sample.BuildConfig
import com.paligot.confily.core.schedules.SessionDao
import com.paligot.confily.core.test.instrumentedModule
import com.paligot.confily.core.test.patterns.navigation.RobotNavigator
import com.paligot.confily.core.test.patterns.navigation.robotHost
Expand Down Expand Up @@ -39,13 +40,14 @@ class SpeakerInfoItemDetailsTest : KoinTest {
}

private val settings by inject<ConferenceSettings>()
private val agendaDao by inject<AgendaDao>()
private val eventDao by inject<EventDao>()
private val sessionDao by inject<SessionDao>()

@Before
fun setup() {
settings.insertEventId(BuildConfig.DEFAULT_EVENT)
agendaDao.insertEvent(event, emptyList())
agendaDao.saveAgenda(BuildConfig.DEFAULT_EVENT, agenda)
eventDao.insertEvent(event, emptyList())
sessionDao.insertAgenda(BuildConfig.DEFAULT_EVENT, agenda)
}

@Test
Expand Down
4 changes: 0 additions & 4 deletions iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/* Begin PBXBuildFile section */
0060F46B2C8BC231000BCD06 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 0060F46A2C8BC231000BCD06 /* GoogleService-Info.plist */; };
009DACF52C69384200A7F42E /* AgendaRepositoryExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 009DACF42C69384200A7F42E /* AgendaRepositoryExt.swift */; };
058557BB273AAA24004C7B11 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557BA273AAA24004C7B11 /* Assets.xcassets */; };
058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */; };
2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2152FB032600AC8F00CF470E /* iOSApp.swift */; };
Expand Down Expand Up @@ -117,7 +116,6 @@

/* Begin PBXFileReference section */
0060F46A2C8BC231000BCD06 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
009DACF42C69384200A7F42E /* AgendaRepositoryExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgendaRepositoryExt.swift; sourceTree = "<group>"; };
058557BA273AAA24004C7B11 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
2152FB032600AC8F00CF470E /* iOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSApp.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -341,7 +339,6 @@
D51C2CD028383719006EED5D /* UIApplicationExt.swift */,
D52F3B992961CDCC00535233 /* ViewExt.swift */,
D5C1B3BA29F26D9E00D94391 /* BundleExt.swift */,
009DACF42C69384200A7F42E /* AgendaRepositoryExt.swift */,
);
path = extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -778,7 +775,6 @@
D538BED72954F6B700F25CBE /* AlarmScheduler.swift in Sources */,
D59944C02833D45A00F59C1B /* TicketQrCodeView.swift in Sources */,
D5B5E8582B4CA63900129758 /* AgendaFiltersNavigation.swift in Sources */,
009DACF52C69384200A7F42E /* AgendaRepositoryExt.swift in Sources */,
D53256C429219DF200EA0DE7 /* DecorativeTagView.swift in Sources */,
D5C92ECC283ACBB000D5CF2D /* MenuItemView.swift in Sources */,
D5C92EC9283AC6D400D5CF2D /* PartnersViewModel.swift in Sources */,
Expand Down
Binary file not shown.
16 changes: 0 additions & 16 deletions iosApp/iosApp/extensions/AgendaRepositoryExt.swift

This file was deleted.

Loading

0 comments on commit 8b23654

Please sign in to comment.