Skip to content

Commit

Permalink
Remove Koin Annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrivoruchko committed Oct 20, 2024
1 parent 70fd680 commit 5ef8788
Show file tree
Hide file tree
Showing 31 changed files with 108 additions and 130 deletions.
2 changes: 0 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.compose)
alias(libs.plugins.ksp)
alias(libs.plugins.googleServices)
alias(libs.plugins.firebaseCrashlytics)
}
Expand Down Expand Up @@ -104,7 +103,6 @@ android {
dependencies {
coreLibraryDesugaring(libs.android.tools.desugar)

ksp(libs.koin.ksp)
// implementation(libs.koin.startup)

implementation(projects.common)
Expand Down
5 changes: 2 additions & 3 deletions app/src/FDroid/java/info/dvkr/screenstream/AdMob.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package info.dvkr.screenstream

import android.app.Activity
import android.content.Context
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import org.koin.core.annotation.Single

@Single
public class AdMob {
public class AdMob(context: Context) {
public val isPrivacyOptionsRequired: Boolean = false

public fun showPrivacyOptionsForm(activity: Activity) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import info.dvkr.screenstream.common.CommonKoinModule
import info.dvkr.screenstream.logger.AppLogger
import info.dvkr.screenstream.mjpeg.MjpegKoinModule
import org.koin.core.module.Module
import org.koin.ksp.generated.module

public class ScreenStreamApp : BaseApp() {

Expand All @@ -20,5 +19,5 @@ public class ScreenStreamApp : BaseApp() {
})
}

override val streamingModules: Array<Module> = arrayOf(CommonKoinModule().module, MjpegKoinModule().module)
override val streamingModules: Array<Module> = arrayOf(CommonKoinModule, MjpegKoinModule)
}
2 changes: 0 additions & 2 deletions app/src/PlayStore/java/info/dvkr/screenstream/AdMob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.json.JSONArray
import org.koin.compose.koinInject
import org.koin.core.annotation.Single
import java.util.UUID
import java.util.concurrent.atomic.AtomicBoolean

@Single(createdAtStart = true)
public class AdMob(private val context: Context) {

private data class AdUnit(val id: String, var lastUsedMillis: Long = 0, var inComposition: Boolean = false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import info.dvkr.screenstream.logger.AppLogger
import info.dvkr.screenstream.mjpeg.MjpegKoinModule
import info.dvkr.screenstream.webrtc.WebRtcKoinModule
import org.koin.core.module.Module
import org.koin.ksp.generated.module

public class ScreenStreamApp : BaseApp() {

Expand All @@ -33,6 +32,5 @@ public class ScreenStreamApp : BaseApp() {
})
}

override val streamingModules: Array<Module> =
arrayOf(CommonKoinModule().module, MjpegKoinModule().module, WebRtcKoinModule().module)
override val streamingModules: Array<Module> = arrayOf(CommonKoinModule, MjpegKoinModule, WebRtcKoinModule)
}
16 changes: 15 additions & 1 deletion app/src/main/java/info/dvkr/screenstream/BaseApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ import android.os.Build
import android.os.StrictMode
import com.elvishew.xlog.LogConfiguration
import com.jakewharton.processphoenix.ProcessPhoenix
import info.dvkr.screenstream.common.ModuleSettings
import info.dvkr.screenstream.common.notification.NotificationHelper
import info.dvkr.screenstream.logger.AppLogger
import info.dvkr.screenstream.notification.NotificationHelperImpl
import info.dvkr.screenstream.ui.tabs.settings.SettingsTabViewModel
import info.dvkr.screenstream.ui.tabs.settings.app.AppModuleSettings
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin
import org.koin.core.module.Module
import org.koin.ksp.generated.defaultModule
import org.koin.core.module.dsl.viewModel
import org.koin.dsl.bind
import org.koin.dsl.module

public abstract class BaseApp : Application() {

Expand Down Expand Up @@ -55,6 +62,13 @@ public abstract class BaseApp : Application() {

AppLogger.init(this, ::configureLogger)

val defaultModule = module {
single(createdAtStart = true) { AdMob(get()) }
single { NotificationHelperImpl(get()) } bind (NotificationHelper::class)
single { AppModuleSettings() } bind (ModuleSettings::class)
viewModel { SettingsTabViewModel(get(), get(), get()) }
}

startKoin {
allowOverride(false)
androidContext(this@BaseApp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import info.dvkr.screenstream.SingleActivity
import info.dvkr.screenstream.common.getLog
import info.dvkr.screenstream.common.isPermissionGranted
import info.dvkr.screenstream.common.notification.NotificationHelper
import org.koin.core.annotation.Single

@Single
internal class NotificationHelperImpl(context: Context) : NotificationHelper {
private companion object {
private const val CHANNEL_STREAMING = "info.dvkr.screenstream.NOTIFICATION_CHANNEL_STREAMING"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import org.koin.android.annotation.KoinViewModel

@KoinViewModel
internal class SettingsTabViewModel(
appModuleSettings: AppModuleSettings,
streamingModulesManager: StreamingModuleManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import androidx.compose.ui.unit.sp
import info.dvkr.screenstream.R
import info.dvkr.screenstream.common.ModuleSettings
import info.dvkr.screenstream.ui.tabs.settings.app.settings.GeneralGroup
import org.koin.core.annotation.Single

@Single
internal class AppModuleSettings : ModuleSettings {
override val id: String = "APP"
override val groups: List<ModuleSettings.Group> =
Expand Down
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ plugins {
alias(libs.plugins.kotlinAndroid) apply false
alias(libs.plugins.kotlinParcelize) apply false
alias(libs.plugins.compose) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.googleServices) apply false
alias(libs.plugins.firebaseCrashlytics) apply false
}
Expand Down
3 changes: 0 additions & 3 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ plugins {
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.kotlinParcelize)
alias(libs.plugins.compose)
alias(libs.plugins.ksp)
}

kotlin {
Expand Down Expand Up @@ -40,8 +39,6 @@ dependencies {
api(libs.androidx.compose.material3.window)

api(libs.koin.android.compose)
api(libs.koin.annotations)
ksp(libs.koin.ksp)

api(libs.xlog)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package info.dvkr.screenstream.common

import org.koin.core.annotation.ComponentScan
import org.koin.core.annotation.Module
import info.dvkr.screenstream.common.module.StreamingModuleManager
import info.dvkr.screenstream.common.settings.AppSettings
import info.dvkr.screenstream.common.settings.AppSettingsImpl
import org.koin.core.module.Module
import org.koin.dsl.bind
import org.koin.dsl.module

@Module
@ComponentScan
public class CommonKoinModule
public val CommonKoinModule: Module = module {
single(createdAtStart = true) { AppSettingsImpl(get()) } bind (AppSettings::class)
single { StreamingModuleManager(getAll(), get()) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.runBlocking
import org.koin.core.annotation.Single

@Single
@Immutable
public class StreamingModuleManager(modules: List<StreamingModule>, private val appSettings: AppSettings) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.withContext
import org.koin.core.annotation.Single
import java.io.IOException

@Single(createdAtStart = true)
internal class AppSettingsImpl(context: Context) : AppSettings {

private val dataStore: DataStore<Preferences> = PreferenceDataStoreFactory.create(
Expand Down
5 changes: 0 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
[versions]
agp = "8.7.1"
kotlin = "2.0.21"
ksp = "2.0.21-1.0.25"
android-tools-r8 = "8.5.35"
android-tools-desugar = "2.1.2"

koin-android = "4.0.0"
koin-ksp = "1.3.1"

kotlinx-coroutines = "1.9.0"

Expand Down Expand Up @@ -52,8 +50,6 @@ kotlinReflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref =

koin-android-compose = { module = "io.insert-koin:koin-androidx-compose", version.ref = "koin-android" }
koin-startup = { module = "io.insert-koin:koin-androidx-startup", version.ref = "koin-android" }
koin-annotations = { module = "io.insert-koin:koin-annotations", version.ref = "koin-ksp" }
koin-ksp = { module = "io.insert-koin:koin-ksp-compiler", version.ref = "koin-ksp" }

kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinx-coroutines" }

Expand Down Expand Up @@ -109,7 +105,6 @@ androidLibrary = { id = "com.android.library", version.ref = "agp" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlinParcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }

#PlayStore
googleServices = { id = "com.google.gms.google-services", version.ref = "google-services" }
Expand Down
3 changes: 0 additions & 3 deletions mjpeg/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ plugins {
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.kotlinParcelize)
alias(libs.plugins.compose)
alias(libs.plugins.ksp)
}

kotlin {
Expand All @@ -28,8 +27,6 @@ android {
dependencies {
implementation(projects.common)

ksp(libs.koin.ksp)

implementation(libs.ktor.server.cio)
implementation(libs.ktor.server.compression)
implementation(libs.ktor.server.caching.headers)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
package info.dvkr.screenstream.mjpeg

import org.koin.core.annotation.ComponentScan
import org.koin.core.annotation.Module
import info.dvkr.screenstream.common.module.StreamingModule
import info.dvkr.screenstream.mjpeg.internal.MjpegStreamingService
import info.dvkr.screenstream.mjpeg.internal.NetworkHelper
import info.dvkr.screenstream.mjpeg.settings.MjpegSettings
import info.dvkr.screenstream.mjpeg.settings.MjpegSettingsImpl
import org.koin.core.component.KoinScopeComponent
import org.koin.core.component.createScope
import org.koin.core.qualifier.Qualifier
import org.koin.core.qualifier.StringQualifier
import org.koin.core.scope.Scope

@Module
@ComponentScan
public class MjpegKoinModule
import org.koin.dsl.bind
import org.koin.dsl.module

public class MjpegKoinScope : KoinScopeComponent {
override val scope: Scope by lazy(LazyThreadSafetyMode.NONE) { createScope(this) }
}

internal const val MjpegKoinQualifier: String = "MjpegStreamingModule"
internal val MjpegKoinQualifier: Qualifier = StringQualifier("MjpegStreamingModule")

public val MjpegKoinModule: org.koin.core.module.Module = module {
single(MjpegKoinQualifier) { MjpegStreamingModule() } bind (StreamingModule::class)
single { MjpegSettingsImpl(context = get()) } bind (MjpegSettings::class)
scope<MjpegKoinScope> {
scoped { NetworkHelper(get()) }
scoped { params -> MjpegStreamingService(params.get(), params.get(), get(), get()) } bind (MjpegStreamingService::class)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import info.dvkr.screenstream.mjpeg.internal.MjpegEvent
import info.dvkr.screenstream.mjpeg.ui.MjpegError
import kotlinx.coroutines.runBlocking
import org.koin.android.ext.android.inject
import org.koin.core.qualifier.named

public class MjpegModuleService : StreamingModuleService() {

Expand All @@ -28,7 +27,7 @@ public class MjpegModuleService : StreamingModuleService() {
override val notificationIdForeground: Int = 100
override val notificationIdError: Int = 110

private val mjpegStreamingModule: MjpegStreamingModule by inject(named(MjpegKoinQualifier), LazyThreadSafetyMode.NONE)
private val mjpegStreamingModule: MjpegStreamingModule by inject(MjpegKoinQualifier, LazyThreadSafetyMode.NONE)

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if (intent == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.withContext
import org.koin.core.annotation.Named
import org.koin.core.annotation.Single
import org.koin.core.parameter.parametersOf

@Single
@Named(MjpegKoinQualifier)
public class MjpegStreamingModule : StreamingModule {

public companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import androidx.annotation.MainThread
import androidx.window.layout.WindowMetricsCalculator
import com.elvishew.xlog.XLog
import info.dvkr.screenstream.common.getLog
import info.dvkr.screenstream.mjpeg.MjpegKoinScope
import info.dvkr.screenstream.mjpeg.MjpegModuleService
import info.dvkr.screenstream.mjpeg.R
import info.dvkr.screenstream.mjpeg.settings.MjpegSettings
Expand All @@ -48,18 +47,14 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeoutOrNull
import org.koin.core.annotation.InjectedParam
import org.koin.core.annotation.Scope
import org.koin.core.annotation.Scoped
import kotlin.math.max
import kotlin.math.min
import kotlin.random.Random

@Scope(MjpegKoinScope::class)
@Scoped(binds = [MjpegStreamingService::class])

internal class MjpegStreamingService(
@InjectedParam private val service: MjpegModuleService,
@InjectedParam private val mutableMjpegStateFlow: MutableStateFlow<MjpegState>,
private val service: MjpegModuleService,
private val mutableMjpegStateFlow: MutableStateFlow<MjpegState>,
private val networkHelper: NetworkHelper,
private val mjpegSettings: MjpegSettings
) : HandlerThread("MJPEG-HT", android.os.Process.THREAD_PRIORITY_DISPLAY), Handler.Callback {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ import android.net.wifi.WifiManager
import androidx.core.content.ContextCompat
import com.elvishew.xlog.XLog
import info.dvkr.screenstream.common.getLog
import info.dvkr.screenstream.mjpeg.MjpegKoinScope
import org.koin.core.annotation.Scope
import java.net.Inet4Address
import java.net.Inet6Address
import java.net.InetAddress
import java.net.NetworkInterface
import java.util.Collections
import java.util.Enumeration

@Scope(MjpegKoinScope::class)
@SuppressLint("WifiManagerPotentialLeak")
internal class NetworkHelper(context: Context) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.withContext
import org.koin.core.annotation.Single
import java.io.IOException

@Single
internal class MjpegSettingsImpl(
context: Context
) : MjpegSettings {
Expand Down
Loading

0 comments on commit 5ef8788

Please sign in to comment.