Skip to content

Commit

Permalink
Merge pull request #58 from jellyfin/koin
Browse files Browse the repository at this point in the history
Add Koin (dependency injection)
  • Loading branch information
nielsvanvelzen authored Aug 25, 2020
2 parents 7b2e8c5 + 0b1ab30 commit 90e6a7d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ dependencies {
implementation(Dependencies.Core.activityKtx)
implementation(Dependencies.Core.exoPlayer)

// Koin
implementation(Dependencies.Koin.koinAndroid)

// Lifecycle
implementation(Dependencies.Lifecycle.viewModel)
implementation(Dependencies.Lifecycle.liveData)
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/org/jellyfin/mobile/ApplicationModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.jellyfin.mobile

import okhttp3.OkHttpClient
import org.koin.core.module.Module
import org.koin.dsl.module

val applicationModule: Module = module {
single { AppPreferences(get()) }
single { OkHttpClient() }
}
7 changes: 7 additions & 0 deletions app/src/main/java/org/jellyfin/mobile/JellyfinApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package org.jellyfin.mobile

import android.app.Application
import android.webkit.WebView
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin
import timber.log.Timber

class JellyfinApplication : Application() {
Expand All @@ -14,5 +16,10 @@ class JellyfinApplication : Application() {
// Enable WebView debugging
WebView.setWebContentsDebuggingEnabled(true)
}

startKoin {
androidContext(this@JellyfinApplication)
modules(applicationModule)
}
}
}
5 changes: 3 additions & 2 deletions app/src/main/java/org/jellyfin/mobile/WebappActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ import org.jellyfin.mobile.utils.Constants.INPUT_MANAGER_COMMAND_BACK
import org.jellyfin.mobile.webapp.ConnectionHelper
import org.jellyfin.mobile.webapp.RemotePlayerService
import org.jellyfin.mobile.webapp.WebViewController
import org.koin.android.ext.android.inject
import timber.log.Timber
import java.io.Reader

class WebappActivity : AppCompatActivity(), WebViewController {

val appPreferences: AppPreferences by lazy { AppPreferences(this) }
val httpClient = OkHttpClient()
val appPreferences: AppPreferences by inject()
val httpClient: OkHttpClient by inject()
val chromecast = Chromecast()
private val connectionHelper = ConnectionHelper(this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import org.jellyfin.mobile.utils.Constants.MUSIC_NOTIFICATION_CHANNEL_ID
import org.jellyfin.mobile.utils.Constants.SUPPORTED_MUSIC_PLAYER_PLAYBACK_ACTIONS
import org.jellyfin.mobile.utils.applyDefaultLocalAudioAttributes
import org.jellyfin.mobile.utils.setPlaybackState
import org.koin.android.ext.android.inject
import timber.log.Timber
import kotlin.coroutines.CoroutineContext

Expand All @@ -63,7 +64,7 @@ class RemotePlayerService : Service(), CoroutineScope {
override val coroutineContext: CoroutineContext
get() = job + Dispatchers.Main

private val appPreferences: AppPreferences by lazy { AppPreferences(this) }
private val appPreferences: AppPreferences by inject()

private val binder = ServiceBinder(this)

Expand Down
7 changes: 7 additions & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ object Dependencies {
const val okHttp = "4.8.0"
const val exoPlayer = "2.11.7"

// Koin
const val koin = "2.1.6"

// Lifecycle
const val lifecycleExtensions = "2.2.0"

Expand Down Expand Up @@ -57,6 +60,10 @@ object Dependencies {
val exoPlayer = exoPlayer("core")
}

object Koin {
const val koinAndroid = "org.koin:koin-android:${Versions.koin}"
}

object Lifecycle {
val viewModel = lifecycle("viewmodel-ktx")
val liveData = lifecycle("livedata-ktx")
Expand Down

0 comments on commit 90e6a7d

Please sign in to comment.