Skip to content

Commit

Permalink
refactor: use koin as dependency injection.
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardPaligot committed Dec 21, 2023
1 parent cddae3e commit 7e710f0
Show file tree
Hide file tree
Showing 85 changed files with 666 additions and 521 deletions.
7 changes: 6 additions & 1 deletion androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ android {
}

dependencies {
implementation(projects.themeM3.main)
implementation(projects.themeM3.main.main)
implementation(projects.themeM3.main.mainDi)
implementation(projects.shared.core)
implementation(projects.shared.coreDi)
implementation(libs.settings)

implementation(libs.android.material)
Expand All @@ -88,6 +90,9 @@ dependencies {
implementation(libs.androidx.compose.navigation)
implementation(libs.androidx.profile)

implementation(libs.koin.core)
implementation(libs.koin.android)

implementation(libs.coil.compose)
implementation(libs.coil.svg)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.gdglille.devfest.android

import android.app.AlarmManager
import android.content.Context
import android.content.Intent
import android.net.Uri
Expand All @@ -16,31 +15,12 @@ import androidx.core.app.ShareCompat
import androidx.core.content.FileProvider
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.russhwolf.settings.AndroidSettings
import com.russhwolf.settings.ExperimentalSettingsApi
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import org.gdglille.devfest.AlarmScheduler
import org.gdglille.devfest.AndroidContext
import org.gdglille.devfest.Platform
import org.gdglille.devfest.QrCodeGeneratorAndroid
import org.gdglille.devfest.android.theme.Main
import org.gdglille.devfest.android.theme.m3.style.R
import org.gdglille.devfest.database.DatabaseWrapper
import org.gdglille.devfest.database.EventDao
import org.gdglille.devfest.database.FeaturesActivatedDao
import org.gdglille.devfest.database.PartnerDao
import org.gdglille.devfest.database.ScheduleDao
import org.gdglille.devfest.database.SpeakerDao
import org.gdglille.devfest.database.TalkDao
import org.gdglille.devfest.database.UserDao
import org.gdglille.devfest.network.ConferenceApi
import org.gdglille.devfest.repositories.AgendaRepository
import org.gdglille.devfest.repositories.EventRepository
import org.gdglille.devfest.repositories.SpeakerRepository
import org.gdglille.devfest.repositories.UserRepository
import java.io.File
import java.util.Locale

@Suppress("LongMethod")
@FlowPreview
Expand All @@ -57,46 +37,6 @@ class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
val baseUrl = BuildConfig.BASE_URL
val db = DatabaseWrapper(context = this).createDb()
val platform = Platform(AndroidContext(this.applicationContext))
val api = ConferenceApi.create(
platform = platform,
baseUrl = baseUrl,
acceptLanguage = Locale.getDefault().toLanguageTag(),
enableNetworkLogs = BuildConfig.DEBUG
)
val settings = AndroidSettings(
getSharedPreferences(BuildConfig.APPLICATION_ID, MODE_PRIVATE)
)
val eventRepository = EventRepository.Factory.create(
api = api,
eventDao = EventDao(db, settings)
)
val agendaRepository = AgendaRepository.Factory.create(
api = api,
scheduleDao = ScheduleDao(db, settings, platform),
speakerDao = SpeakerDao(db, platform),
talkDao = TalkDao(db, platform),
eventDao = EventDao(db, settings),
partnerDao = PartnerDao(db = db, platform = platform),
featuresDao = FeaturesActivatedDao(db, settings),
qrCodeGenerator = QrCodeGeneratorAndroid()
)
val userRepository = UserRepository.Factory.create(
userDao = UserDao(db, platform),
eventDao = EventDao(db, settings),
qrCodeGenerator = QrCodeGeneratorAndroid()
)
val speakerRepository = SpeakerRepository.Factory.create(
speakerDao = SpeakerDao(db, platform),
eventDao = EventDao(db, settings)
)
val scheduler = AlarmScheduler(
agendaRepository,
getSystemService(ALARM_SERVICE) as AlarmManager,
AlarmIntentFactoryImpl
)
val openfeedbackFirebaseConfig = (application as MainApplication).openFeedbackConfig
setContent {
val inDarkTheme = isSystemInDarkTheme()
Expand All @@ -115,11 +55,6 @@ class MainActivity : ComponentActivity() {
val reportSubject = stringResource(id = R.string.text_report_subject)
val reportAppTarget = stringResource(id = R.string.text_report_app_target)
Main(
eventRepository = eventRepository,
agendaRepository = agendaRepository,
userRepository = userRepository,
speakerRepository = speakerRepository,
alarmScheduler = scheduler,
openfeedbackFirebaseConfig = openfeedbackFirebaseConfig,
launchUrl = { launchUrl(it) },
onContactExportClicked = { export ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import coil.decode.SvgDecoder
import coil.disk.DiskCache
import coil.memory.MemoryCache
import io.openfeedback.android.viewmodels.OpenFeedbackFirebaseConfig
import org.gdglille.devfest.android.di.appModule
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin

private const val MemoryCacheSize = 0.25
private const val DiskCacheSize = 0.10
Expand All @@ -23,6 +26,11 @@ class MainApplication : Application(), ImageLoaderFactory {
apiKey = BuildConfig.FIREBASE_API_KEY,
databaseUrl = "https://${BuildConfig.FIREBASE_PROJECT_ID}.firebaseio.com"
)

startKoin {
androidContext(this@MainApplication)
modules(appModule)
}
}

override fun newImageLoader(): ImageLoader = ImageLoader.Builder(this)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.gdglille.devfest.android.di

import android.app.AlarmManager
import androidx.activity.ComponentActivity
import org.gdglille.devfest.AlarmScheduler
import org.gdglille.devfest.android.AlarmIntentFactoryImpl
import org.gdglille.devfest.android.theme.m3.main.di.mainModule
import org.koin.android.ext.koin.androidContext
import org.koin.dsl.module

val appModule = module {
includes(buildConfigModule, mainModule)
single {
AlarmScheduler(
get(),
androidContext().getSystemService(ComponentActivity.ALARM_SERVICE) as AlarmManager,
AlarmIntentFactoryImpl
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.gdglille.devfest.android.di

import org.gdglille.devfest.ApplicationIdNamed
import org.gdglille.devfest.Conference4HallBaseUrlNamed
import org.gdglille.devfest.IsDebugNamed
import org.gdglille.devfest.android.BuildConfig
import org.koin.core.qualifier.named
import org.koin.dsl.module

val buildConfigModule = module {
single(named(IsDebugNamed)) { BuildConfig.DEBUG }
single(named(ApplicationIdNamed)) { BuildConfig.APPLICATION_ID }
single(named(Conference4HallBaseUrlNamed)) { BuildConfig.BASE_URL }
}
6 changes: 6 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ kotlinxDatetime = "0.4.1"
kotlinxCollection = "0.3.6"
kmpNativeCoroutines = "0.13.3"
ktor = "2.3.3"
koin = "3.5.3"
accompanist = "0.30.1"
androidGradlePlugin = "8.2.0"
androidMaterial = "1.11.0"
Expand Down Expand Up @@ -67,6 +68,11 @@ ktor-server-conditional = { group = "io.ktor", name = "ktor-server-conditional-h

ktor-serialization-json = { group = "io.ktor", name = "ktor-serialization-kotlinx-json", version.ref = "ktor" }

koin-core = { group = "io.insert-koin", name = "koin-core", version.ref = "koin" }
koin-android = { group = "io.insert-koin", name = "koin-android", version.ref = "koin" }
koin-androidx-compose = { group = "io.insert-koin", name = "koin-androidx-compose", version.ref = "koin" }
koin-androidx-workmanager = { group = "io.insert-koin", name = "koin-androidx-workmanager", version.ref = "koin" }

android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "androidGradlePlugin" }
android-material = { group = "com.google.android.material", name = "material", version.ref = "androidMaterial" }

Expand Down
6 changes: 2 additions & 4 deletions iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
D5C92ED3283AD00800D5CF2D /* MenusVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C92ED2283AD00800D5CF2D /* MenusVM.swift */; };
D5C92ED5283ADDC900D5CF2D /* NoFavoriteTalksView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C92ED4283ADDC900D5CF2D /* NoFavoriteTalksView.swift */; };
D5CAA6512821BCC7005BB242 /* RemoteImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5CAA6502821BCC7005BB242 /* RemoteImage.swift */; };
D5CAA6532821C306005BB242 /* PartnerRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5CAA6522821C306005BB242 /* PartnerRowView.swift */; };
D5D5ABF5282071D2004E2F78 /* ShareSheetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5D5ABF4282071D2004E2F78 /* ShareSheetView.swift */; };
D5D6166C27B15C7400C59EC9 /* AgendaViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5D6166B27B15C7400C59EC9 /* AgendaViewModel.swift */; };
D5F324A327C6E2DE007CA4C1 /* QrCodeGeneratoriOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5F324A227C6E2DE007CA4C1 /* QrCodeGeneratoriOS.swift */; };
Expand Down Expand Up @@ -186,7 +185,6 @@
D5C92ED2283AD00800D5CF2D /* MenusVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenusVM.swift; sourceTree = "<group>"; };
D5C92ED4283ADDC900D5CF2D /* NoFavoriteTalksView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoFavoriteTalksView.swift; sourceTree = "<group>"; };
D5CAA6502821BCC7005BB242 /* RemoteImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteImage.swift; sourceTree = "<group>"; };
D5CAA6522821C306005BB242 /* PartnerRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PartnerRowView.swift; sourceTree = "<group>"; };
D5D5ABF328207025004E2F78 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = "<group>"; };
D5D5ABF4282071D2004E2F78 /* ShareSheetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareSheetView.swift; sourceTree = "<group>"; };
D5D6166B27B15C7400C59EC9 /* AgendaViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgendaViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -503,7 +501,6 @@
isa = PBXGroup;
children = (
D57028A927B550BF008EF4AD /* PartnerDividerView.swift */,
D5CAA6522821C306005BB242 /* PartnerRowView.swift */,
);
path = partners;
sourceTree = "<group>";
Expand Down Expand Up @@ -744,7 +741,6 @@
D538BED72954F6B700F25CBE /* AlarmScheduler.swift in Sources */,
D59944C02833D45A00F59C1B /* TicketQrCodeView.swift in Sources */,
D53256C429219DF200EA0DE7 /* DecorativeTagView.swift in Sources */,
D5CAA6532821C306005BB242 /* PartnerRowView.swift in Sources */,
D5C92ECC283ACBB000D5CF2D /* MenuItemView.swift in Sources */,
D5C92EC9283AC6D400D5CF2D /* PartnersViewModel.swift in Sources */,
D544C7E7295487D00038CB80 /* SpeakerAvatarBorderedView.swift in Sources */,
Expand Down Expand Up @@ -921,6 +917,7 @@
MARKETING_VERSION = 2.0.1;
OTHER_LDFLAGS = (
"$(inherited)",
"-lsqlite3",
"-framework",
shared,
);
Expand Down Expand Up @@ -954,6 +951,7 @@
MARKETING_VERSION = 2.0.1;
OTHER_LDFLAGS = (
"$(inherited)",
"-lsqlite3",
"-framework",
shared,
);
Expand Down
Binary file not shown.
46 changes: 0 additions & 46 deletions iosApp/iosApp/components/partners/PartnerRowView.swift

This file was deleted.

2 changes: 0 additions & 2 deletions iosApp/iosApp/navigations/PartnerItemNavigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import shared
struct PartnerItemNavigation: View {
@EnvironmentObject var viewModelFactory: ViewModelFactory
let partner: PartnerItemUi
let size: CGFloat

var body: some View {
NavigationLink {
Expand All @@ -26,7 +25,6 @@ struct PartnerItemNavigation: View {
id: partner.id
)
.padding()
.frame(width: size, height: size)
.background(Color.white)
.clipShape(RoundedRectangle(cornerRadius: 8))
}
Expand Down
11 changes: 5 additions & 6 deletions iosApp/iosApp/screens/partners/Partners.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ struct Partners: View {
LazyVStack(spacing: 8) {
ForEach(partners.groups, id: \.type) { partnerGroup in
Section {
ForEach(partnerGroup.partners, id: \.[0].id) { partners in
PartnerRowView(
partners: partners,
parentWidth: parentWidth
)
}
LazyVGrid(columns: [GridItem(.adaptive(minimum: parentWidth)), GridItem(.adaptive(minimum: parentWidth)), GridItem(.adaptive(minimum: parentWidth))], content: {
ForEach(partnerGroup.partners, id: \.id) { partner in
PartnerItemNavigation(partner: partner)
}
})
} header : {
PartnerDividerView(text: partnerGroup.type)
.padding(.horizontal, self.horizontalSpacing)
Expand Down
10 changes: 9 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,35 @@ pluginManagement {
rootProject.name = "conferences4hall"
include(":androidApp")
include(":shared:core")
include(":shared:core-di")
include(":shared:models")
include(":shared:ui-models")
include(":backend")
include(":benchmark")
include(":theme-m3:main")
include(":theme-m3:main:main")
include(":theme-m3:main:main-di")
include(":theme-m3:schedules:schedules-ui")
include(":theme-m3:schedules:schedules-screens")
include(":theme-m3:schedules:schedules-feature")
include(":theme-m3:schedules:schedules-di")
include(":theme-m3:speakers:speakers-ui")
include(":theme-m3:speakers:speakers-screens")
include(":theme-m3:speakers:speakers-feature")
include(":theme-m3:speakers:speakers-di")
include(":theme-m3:networking:networking-ui")
include(":theme-m3:networking:networking-screens")
include(":theme-m3:networking:networking-feature")
include(":theme-m3:networking:networking-di")
include(":theme-m3:partners:partners-ui")
include(":theme-m3:partners:partners-screens")
include(":theme-m3:partners:partners-feature")
include(":theme-m3:partners:partners-di")
include(":theme-m3:infos:infos-ui")
include(":theme-m3:infos:infos-feature")
include(":theme-m3:infos:infos-di")
include(":theme-m3:event-list:event-list-ui")
include(":theme-m3:event-list:event-list-feature")
include(":theme-m3:event-list:event-list-di")
include(":theme-m3:navigation")
include(":theme-m3:style:networking")
include(":theme-m3:style:partners")
Expand Down
Loading

0 comments on commit 7e710f0

Please sign in to comment.