mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 15:50:16 +02:00
Can remove seerr server
This commit is contained in:
parent
70fd36ccab
commit
921ffadc1c
5 changed files with 52 additions and 17 deletions
|
|
@ -139,6 +139,12 @@ class SeerrServerRepository
|
|||
return LoadingState.Error(ex)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun removeServer() {
|
||||
val current = _current.value ?: return
|
||||
seerrServerDao.deleteUser(current.server.id, current.user.jellyfinUserRowId)
|
||||
clear()
|
||||
}
|
||||
}
|
||||
|
||||
typealias SeerrUserConfig = User
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import androidx.tv.material3.surfaceColorAtElevation
|
|||
import coil3.SingletonImageLoader
|
||||
import coil3.imageLoader
|
||||
import com.github.damontecres.wholphin.R
|
||||
import com.github.damontecres.wholphin.data.model.SeerrAuthMethod
|
||||
import com.github.damontecres.wholphin.preferences.AppPreference
|
||||
import com.github.damontecres.wholphin.preferences.AppPreferences
|
||||
import com.github.damontecres.wholphin.preferences.PlayerBackend
|
||||
|
|
@ -51,6 +52,7 @@ import com.github.damontecres.wholphin.preferences.basicPreferences
|
|||
import com.github.damontecres.wholphin.preferences.uiPreferences
|
||||
import com.github.damontecres.wholphin.preferences.updatePlaybackPreferences
|
||||
import com.github.damontecres.wholphin.services.UpdateChecker
|
||||
import com.github.damontecres.wholphin.ui.components.ConfirmDialog
|
||||
import com.github.damontecres.wholphin.ui.ifElse
|
||||
import com.github.damontecres.wholphin.ui.isNotNullOrBlank
|
||||
import com.github.damontecres.wholphin.ui.nav.Destination
|
||||
|
|
@ -60,9 +62,11 @@ import com.github.damontecres.wholphin.ui.preferences.subtitle.SubtitleSettings
|
|||
import com.github.damontecres.wholphin.ui.preferences.subtitle.SubtitleStylePage
|
||||
import com.github.damontecres.wholphin.ui.setup.UpdateViewModel
|
||||
import com.github.damontecres.wholphin.ui.setup.seerr.AddSeerServerDialog
|
||||
import com.github.damontecres.wholphin.ui.setup.seerr.SwitchSeerrViewModel
|
||||
import com.github.damontecres.wholphin.ui.showToast
|
||||
import com.github.damontecres.wholphin.ui.tryRequestFocus
|
||||
import com.github.damontecres.wholphin.util.ExceptionHandler
|
||||
import com.github.damontecres.wholphin.util.LoadingState
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
|
|
@ -73,6 +77,7 @@ fun PreferencesContent(
|
|||
modifier: Modifier = Modifier,
|
||||
viewModel: PreferencesViewModel = hiltViewModel(),
|
||||
updateVM: UpdateViewModel = hiltViewModel(),
|
||||
seerrVm: SwitchSeerrViewModel = hiltViewModel(),
|
||||
onFocus: (Int, Int) -> Unit = { _, _ -> },
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
|
@ -461,12 +466,35 @@ fun PreferencesContent(
|
|||
}
|
||||
}
|
||||
if (showSeerrServerDialog) {
|
||||
if (seerrIntegrationEnabled) {
|
||||
ConfirmDialog(
|
||||
title = stringResource(R.string.remove_seerr_server),
|
||||
body = "",
|
||||
onCancel = { showSeerrServerDialog = false },
|
||||
onConfirm = {
|
||||
seerrVm.removeServer()
|
||||
showSeerrServerDialog = false
|
||||
},
|
||||
)
|
||||
} else {
|
||||
val currentUser by seerrVm.currentUser.observeAsState()
|
||||
val status by seerrVm.serverConnectionStatus.collectAsState(LoadingState.Pending)
|
||||
AddSeerServerDialog(
|
||||
currentUsername = currentUser?.name,
|
||||
status = status,
|
||||
onSubmit = { url: String, username: String?, passwordOrApiKey: String, method: SeerrAuthMethod ->
|
||||
if (method == SeerrAuthMethod.API_KEY) {
|
||||
seerrVm.submitServer(url, passwordOrApiKey)
|
||||
} else {
|
||||
seerrVm.submitServer(url, username ?: "", passwordOrApiKey, method)
|
||||
}
|
||||
},
|
||||
onDismissRequest = { showSeerrServerDialog = false },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun PreferencesPage(
|
||||
|
|
|
|||
|
|
@ -2,13 +2,10 @@ package com.github.damontecres.wholphin.ui.setup.seerr
|
|||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
||||
import com.github.damontecres.wholphin.data.model.SeerrAuthMethod
|
||||
import com.github.damontecres.wholphin.ui.components.BasicDialog
|
||||
import com.github.damontecres.wholphin.ui.components.DialogItem
|
||||
|
|
@ -18,12 +15,12 @@ import com.github.damontecres.wholphin.util.LoadingState
|
|||
|
||||
@Composable
|
||||
fun AddSeerServerDialog(
|
||||
currentUsername: String?,
|
||||
status: LoadingState,
|
||||
onSubmit: (url: String, username: String?, passwordOrApiKey: String, method: SeerrAuthMethod) -> Unit,
|
||||
onDismissRequest: () -> Unit,
|
||||
viewModel: SwitchSeerrViewModel = hiltViewModel(),
|
||||
) {
|
||||
val currentUser by viewModel.currentUser.observeAsState()
|
||||
var authMethod by remember { mutableStateOf<SeerrAuthMethod?>(null) }
|
||||
val status by viewModel.serverConnectionStatus.collectAsState(LoadingState.Pending)
|
||||
LaunchedEffect(status) {
|
||||
if (status is LoadingState.Success) {
|
||||
onDismissRequest.invoke()
|
||||
|
|
@ -38,14 +35,9 @@ fun AddSeerServerDialog(
|
|||
) {
|
||||
AddSeerrServerUsername(
|
||||
onSubmit = { url, username, password ->
|
||||
viewModel.submitServer(
|
||||
url,
|
||||
username,
|
||||
password,
|
||||
auth,
|
||||
)
|
||||
onSubmit.invoke(url, username, password, auth)
|
||||
},
|
||||
username = currentUser?.name ?: "",
|
||||
username = currentUsername ?: "",
|
||||
status = status,
|
||||
)
|
||||
}
|
||||
|
|
@ -56,7 +48,9 @@ fun AddSeerServerDialog(
|
|||
onDismissRequest = { authMethod = null },
|
||||
) {
|
||||
AddSeerrServerApiKey(
|
||||
onSubmit = { url, apiKey -> viewModel.submitServer(url, apiKey) },
|
||||
onSubmit = { url, apiKey ->
|
||||
onSubmit.invoke(url, null, apiKey, SeerrAuthMethod.API_KEY)
|
||||
},
|
||||
status = status,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,4 +81,10 @@ class SwitchSeerrViewModel
|
|||
serverConnectionStatus.update { result }
|
||||
}
|
||||
}
|
||||
|
||||
fun removeServer() {
|
||||
viewModelScope.launchIO {
|
||||
seerrServerRepository.removeServer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -408,6 +408,7 @@
|
|||
<string name="request">Request</string>
|
||||
<string name="pending">Pending</string>
|
||||
<string name="seerr_integration">Seerr integration</string>
|
||||
<string name="remove_seerr_server">Remove Seerr Server</string>
|
||||
|
||||
<string-array name="theme_song_volume">
|
||||
<item>Disabled</item>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue