Add Jellyfin Kotlin SDK
This commit is contained in:
parent
4eac70ff69
commit
b3b19cef04
5 changed files with 60 additions and 3 deletions
|
@ -39,6 +39,7 @@ android {
|
|||
|
||||
dependencies {
|
||||
def room_version = "2.3.0"
|
||||
def jellyfin_version = "1.0.0-beta.7"
|
||||
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation 'androidx.core:core-ktx:1.5.0'
|
||||
|
@ -49,10 +50,15 @@ dependencies {
|
|||
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
|
||||
|
||||
// Room
|
||||
implementation "androidx.room:room-runtime:$room_version"
|
||||
kapt "androidx.room:room-compiler:$room_version"
|
||||
implementation "androidx.room:room-ktx:$room_version"
|
||||
|
||||
// Jellyfin
|
||||
implementation "org.jellyfin.sdk:jellyfin-platform-android:$jellyfin_version"
|
||||
|
||||
// Testing
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
|
|
47
app/src/main/java/dev/jdtech/jellyfin/api/JellyfinApi.kt
Normal file
47
app/src/main/java/dev/jdtech/jellyfin/api/JellyfinApi.kt
Normal file
|
@ -0,0 +1,47 @@
|
|||
package dev.jdtech.jellyfin.api
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import dev.jdtech.jellyfin.BuildConfig
|
||||
import org.jellyfin.sdk.Jellyfin
|
||||
import org.jellyfin.sdk.android
|
||||
import org.jellyfin.sdk.api.operations.SystemApi
|
||||
import org.jellyfin.sdk.model.ClientInfo
|
||||
|
||||
class JellyfinApi(context: Context, baseUrl: String) {
|
||||
val jellyfin = Jellyfin {
|
||||
clientInfo =
|
||||
ClientInfo(name = BuildConfig.APPLICATION_ID, version = BuildConfig.VERSION_NAME)
|
||||
android(context)
|
||||
}
|
||||
val api = jellyfin.createApi(baseUrl = baseUrl)
|
||||
val systemApi = SystemApi(api)
|
||||
|
||||
init {
|
||||
Log.i("JellyfinApi", "Constructor called!")
|
||||
}
|
||||
|
||||
companion object {
|
||||
@Volatile
|
||||
private var INSTANCE: JellyfinApi? = null
|
||||
|
||||
fun getInstance(context: Context, baseUrl: String): JellyfinApi {
|
||||
synchronized(this) {
|
||||
var instance = INSTANCE
|
||||
if (instance == null) {
|
||||
instance = JellyfinApi(context.applicationContext, baseUrl)
|
||||
INSTANCE = instance
|
||||
}
|
||||
return instance
|
||||
}
|
||||
}
|
||||
|
||||
fun newInstance(context: Context, baseUrl: String): JellyfinApi {
|
||||
synchronized(this) {
|
||||
val instance = JellyfinApi(context.applicationContext, baseUrl)
|
||||
INSTANCE = instance
|
||||
return instance
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,7 +25,7 @@ class ServerSelectFragment : Fragment() {
|
|||
|
||||
val dataSource = ServerDatabase.getInstance(application).serverDatabaseDao
|
||||
|
||||
val viewModelFactory = ServerSelectViewModelFactory(dataSource)
|
||||
val viewModelFactory = ServerSelectViewModelFactory(dataSource, application)
|
||||
val viewModel = ViewModelProvider(this, viewModelFactory).get(ServerSelectViewModel::class.java)
|
||||
|
||||
binding.lifecycleOwner = this
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package dev.jdtech.jellyfin.serverselect
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
|
@ -12,6 +13,7 @@ import java.util.*
|
|||
|
||||
class ServerSelectViewModel(
|
||||
val database: ServerDatabaseDao,
|
||||
val application: Application,
|
||||
) : ViewModel() {
|
||||
private val _servers = database.getAllServers()
|
||||
val servers: LiveData<List<Server>>
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
package dev.jdtech.jellyfin.serverselect
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import dev.jdtech.jellyfin.database.ServerDatabaseDao
|
||||
import java.lang.IllegalArgumentException
|
||||
|
||||
class ServerSelectViewModelFactory(
|
||||
private val dataSource: ServerDatabaseDao
|
||||
private val dataSource: ServerDatabaseDao,
|
||||
private val application: Application
|
||||
) : ViewModelProvider.Factory {
|
||||
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
||||
if (modelClass.isAssignableFrom(ServerSelectViewModel::class.java)) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return ServerSelectViewModel(dataSource) as T
|
||||
return ServerSelectViewModel(dataSource, application) as T
|
||||
}
|
||||
throw IllegalArgumentException("Unknown ViewModel class")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue