mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 23:51:21 +02:00
Clean up & documentation
This commit is contained in:
parent
8612598d94
commit
f43ee6b36c
11 changed files with 44 additions and 30 deletions
|
|
@ -15,7 +15,7 @@ plugins {
|
||||||
alias(libs.plugins.protobuf)
|
alias(libs.plugins.protobuf)
|
||||||
alias(libs.plugins.kotlin.plugin.serialization)
|
alias(libs.plugins.kotlin.plugin.serialization)
|
||||||
alias(libs.plugins.aboutLibraries)
|
alias(libs.plugins.aboutLibraries)
|
||||||
id("org.openapi.generator") version "7.17.0"
|
alias(libs.plugins.openapi.generator)
|
||||||
}
|
}
|
||||||
|
|
||||||
val isCI = if (System.getenv("CI") != null) System.getenv("CI").toBoolean() else false
|
val isCI = if (System.getenv("CI") != null) System.getenv("CI").toBoolean() else false
|
||||||
|
|
@ -72,14 +72,6 @@ android {
|
||||||
jvmTarget = JvmTarget.JVM_11
|
jvmTarget = JvmTarget.JVM_11
|
||||||
javaParameters = true
|
javaParameters = true
|
||||||
}
|
}
|
||||||
// sourceSets {
|
|
||||||
// main {
|
|
||||||
// java.srcDirs +=
|
|
||||||
// kotlin {
|
|
||||||
// srcDirs += files("$buildDir/generated/seerr_api/src/main/kotlin")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
buildConfig = true
|
buildConfig = true
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,9 @@ enum class SeerrAvailability(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An item provided by a discovery service (ie Seerr). It may exist on the JF server as well.
|
||||||
|
*/
|
||||||
@Serializable
|
@Serializable
|
||||||
data class DiscoverItem(
|
data class DiscoverItem(
|
||||||
val id: Int,
|
val id: Int,
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,17 @@
|
||||||
package com.github.damontecres.wholphin.services
|
package com.github.damontecres.wholphin.services
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.github.damontecres.wholphin.api.seerr.SeerrApiClient
|
import com.github.damontecres.wholphin.api.seerr.SeerrApiClient
|
||||||
import com.github.damontecres.wholphin.ui.isNotNullOrBlank
|
import com.github.damontecres.wholphin.ui.isNotNullOrBlank
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper for [SeerrApiClient]. In most cases, you should use [SeerrService] instead.
|
||||||
|
*/
|
||||||
class SeerrApi(
|
class SeerrApi(
|
||||||
@param:ApplicationContext private val context: Context,
|
|
||||||
private val okHttpClient: OkHttpClient,
|
private val okHttpClient: OkHttpClient,
|
||||||
) {
|
) {
|
||||||
// private val prefs: SharedPreferences =
|
|
||||||
// context.getSharedPreferences("seerr", Context.MODE_PRIVATE)
|
|
||||||
|
|
||||||
var api: SeerrApiClient =
|
var api: SeerrApiClient =
|
||||||
SeerrApiClient(
|
SeerrApiClient(
|
||||||
// prefs.getString("baseUrl", null)!! + "/api/v1",
|
|
||||||
// prefs.getString("apiKey", null)!!,
|
|
||||||
baseUrl = "",
|
baseUrl = "",
|
||||||
apiKey = null,
|
apiKey = null,
|
||||||
okHttpClient = okHttpClient,
|
okHttpClient = okHttpClient,
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,9 @@ import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages saves/loading Seerr servers from the local DB. Also will update the current [SeerrApi] as needed.
|
||||||
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
class SeerrServerRepository
|
class SeerrServerRepository
|
||||||
@Inject
|
@Inject
|
||||||
|
|
@ -147,6 +150,9 @@ class SeerrServerRepository
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A [SeerrUser] config
|
||||||
|
*/
|
||||||
typealias SeerrUserConfig = User
|
typealias SeerrUserConfig = User
|
||||||
|
|
||||||
data class CurrentSeerr(
|
data class CurrentSeerr(
|
||||||
|
|
@ -185,6 +191,9 @@ private suspend fun login(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listens for JF user switching in the app to also switch the Seerr user/server
|
||||||
|
*/
|
||||||
@ActivityScoped
|
@ActivityScoped
|
||||||
class UserSwitchListener
|
class UserSwitchListener
|
||||||
@Inject
|
@Inject
|
||||||
|
|
@ -196,11 +205,10 @@ class UserSwitchListener
|
||||||
private val seerrApi: SeerrApi,
|
private val seerrApi: SeerrApi,
|
||||||
) {
|
) {
|
||||||
init {
|
init {
|
||||||
Timber.v("Launching")
|
|
||||||
context as AppCompatActivity
|
context as AppCompatActivity
|
||||||
context.lifecycleScope.launchIO {
|
context.lifecycleScope.launchIO {
|
||||||
serverRepository.currentUser.asFlow().collect { user ->
|
serverRepository.currentUser.asFlow().collect { user ->
|
||||||
Timber.v("New user")
|
Timber.d("New user")
|
||||||
seerrServerRepository.clear()
|
seerrServerRepository.clear()
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
seerrServerDao
|
seerrServerDao
|
||||||
|
|
|
||||||
|
|
@ -4,21 +4,28 @@ import com.github.damontecres.wholphin.api.seerr.SeerrApiClient
|
||||||
import com.github.damontecres.wholphin.api.seerr.model.SearchGet200ResponseResultsInner
|
import com.github.damontecres.wholphin.api.seerr.model.SearchGet200ResponseResultsInner
|
||||||
import com.github.damontecres.wholphin.data.model.BaseItem
|
import com.github.damontecres.wholphin.data.model.BaseItem
|
||||||
import com.github.damontecres.wholphin.data.model.DiscoverItem
|
import com.github.damontecres.wholphin.data.model.DiscoverItem
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
import org.jellyfin.sdk.model.api.BaseItemKind
|
import org.jellyfin.sdk.model.api.BaseItemKind
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
typealias SeerrSearchResult = SearchGet200ResponseResultsInner
|
typealias SeerrSearchResult = SearchGet200ResponseResultsInner
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main access for the current Seerr server (if any)
|
||||||
|
*
|
||||||
|
* Exposes a [SeerrApiClient] for queries
|
||||||
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
class SeerrService
|
class SeerrService
|
||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
private val seerApi: SeerrApi,
|
private val seerApi: SeerrApi,
|
||||||
|
private val seerrServerRepository: SeerrServerRepository,
|
||||||
) {
|
) {
|
||||||
val api: SeerrApiClient get() = seerApi.api
|
val api: SeerrApiClient get() = seerApi.api
|
||||||
|
|
||||||
val active: Boolean get() = seerApi.active
|
val active get() = seerrServerRepository.active
|
||||||
|
|
||||||
suspend fun search(
|
suspend fun search(
|
||||||
query: String,
|
query: String,
|
||||||
|
|
@ -43,8 +50,15 @@ class SeerrService
|
||||||
?.map(::DiscoverItem)
|
?.map(::DiscoverItem)
|
||||||
.orEmpty()
|
.orEmpty()
|
||||||
|
|
||||||
suspend fun similar(item: BaseItem): List<DiscoverItem> =
|
/**
|
||||||
if (active) {
|
* Get [DiscoverItem]s similar to the JF items such as movies, series, or people
|
||||||
|
*
|
||||||
|
* If Seerr integration is not active, this short circuits to return null
|
||||||
|
*
|
||||||
|
* @return the discovered items or null if no Seerr server configured
|
||||||
|
*/
|
||||||
|
suspend fun similar(item: BaseItem): List<DiscoverItem>? =
|
||||||
|
if (active.first()) {
|
||||||
item.data.providerIds
|
item.data.providerIds
|
||||||
?.get("Tmdb")
|
?.get("Tmdb")
|
||||||
?.toIntOrNull()
|
?.toIntOrNull()
|
||||||
|
|
@ -88,6 +102,6 @@ class SeerrService
|
||||||
}
|
}
|
||||||
}.orEmpty()
|
}.orEmpty()
|
||||||
} else {
|
} else {
|
||||||
emptyList()
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,6 @@ object AppModule {
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun seerrApi(
|
fun seerrApi(
|
||||||
@ApplicationContext context: Context,
|
|
||||||
@StandardOkHttpClient okHttpClient: OkHttpClient,
|
@StandardOkHttpClient okHttpClient: OkHttpClient,
|
||||||
) = SeerrApi(context, okHttpClient)
|
) = SeerrApi(okHttpClient)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,7 @@ class PersonViewModel
|
||||||
episodes.setValueOnMain(RowLoadingState.Success(listOf()))
|
episodes.setValueOnMain(RowLoadingState.Success(listOf()))
|
||||||
}
|
}
|
||||||
viewModelScope.launchIO {
|
viewModelScope.launchIO {
|
||||||
val results = seerrService.similar(person)
|
val results = seerrService.similar(person).orEmpty()
|
||||||
discovered.update { results }
|
discovered.update { results }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ class MovieViewModel
|
||||||
this@MovieViewModel.extras.setValueOnMain(extras)
|
this@MovieViewModel.extras.setValueOnMain(extras)
|
||||||
}
|
}
|
||||||
viewModelScope.launchIO {
|
viewModelScope.launchIO {
|
||||||
val results = seerrService.similar(item)
|
val results = seerrService.similar(item).orEmpty()
|
||||||
discovered.update { results }
|
discovered.update { results }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -215,7 +215,7 @@ class SeriesViewModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
viewModelScope.launchIO {
|
viewModelScope.launchIO {
|
||||||
val results = seerrService.similar(item)
|
val results = seerrService.similar(item).orEmpty()
|
||||||
discovered.update { results }
|
discovered.update { results }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,7 @@ import com.github.damontecres.wholphin.util.GetItemsRequestHandler
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.jellyfin.sdk.api.client.ApiClient
|
import org.jellyfin.sdk.api.client.ApiClient
|
||||||
|
|
@ -144,8 +145,8 @@ class SearchViewModel
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun searchSeerr(query: String) {
|
private fun searchSeerr(query: String) {
|
||||||
if (seerrService.active) {
|
viewModelScope.launchIO {
|
||||||
viewModelScope.launchIO {
|
if (seerrService.active.first()) {
|
||||||
seerrResults.setValueOnMain(SearchResult.Searching)
|
seerrResults.setValueOnMain(SearchResult.Searching)
|
||||||
val results =
|
val results =
|
||||||
seerrService
|
seerrService
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ preferenceKtx = "1.2.1"
|
||||||
tvprovider = "1.1.0"
|
tvprovider = "1.1.0"
|
||||||
workRuntimeKtx = "2.11.0"
|
workRuntimeKtx = "2.11.0"
|
||||||
paletteKtx = "1.0.0"
|
paletteKtx = "1.0.0"
|
||||||
|
openapi-generator = "7.17.0"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
aboutlibraries-core = { module = "com.mikepenz:aboutlibraries-core", version.ref = "aboutLibraries" }
|
aboutlibraries-core = { module = "com.mikepenz:aboutlibraries-core", version.ref = "aboutLibraries" }
|
||||||
|
|
@ -130,3 +131,4 @@ protobuf = { id = "com.google.protobuf", version.ref = "protobuf" }
|
||||||
hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
|
hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
|
||||||
room = { id = "androidx.room", version.ref = "room" }
|
room = { id = "androidx.room", version.ref = "room" }
|
||||||
aboutLibraries = { id = "com.mikepenz.aboutlibraries.plugin.android", version.ref = "aboutLibraries" }
|
aboutLibraries = { id = "com.mikepenz.aboutlibraries.plugin.android", version.ref = "aboutLibraries" }
|
||||||
|
openapi-generator = { id = "org.openapi.generator", version.ref = "openapi-generator" }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue