Revert "Remove PIN & sign-in auto settings (#397)"

This reverts commit 82927d1968.
This commit is contained in:
damontecres 2025-12-08 10:13:58 -05:00 committed by GitHub
parent 82927d1968
commit e26add224d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 47 additions and 50 deletions

View file

@ -1,6 +1,7 @@
package com.github.damontecres.wholphin
import android.os.Bundle
import android.view.WindowManager
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.background
@ -9,6 +10,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
@ -43,6 +45,7 @@ import com.github.damontecres.wholphin.services.UpdateChecker
import com.github.damontecres.wholphin.services.hilt.AuthOkHttpClient
import com.github.damontecres.wholphin.ui.CoilConfig
import com.github.damontecres.wholphin.ui.LocalImageUrlService
import com.github.damontecres.wholphin.ui.isNotNullOrBlank
import com.github.damontecres.wholphin.ui.launchIO
import com.github.damontecres.wholphin.ui.nav.ApplicationContent
import com.github.damontecres.wholphin.ui.nav.Destination
@ -50,6 +53,8 @@ import com.github.damontecres.wholphin.ui.theme.WholphinTheme
import com.github.damontecres.wholphin.util.DebugLogTree
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import okhttp3.OkHttpClient
import org.jellyfin.sdk.model.serializer.toUUIDOrNull
@ -141,8 +146,7 @@ class MainActivity : AppCompatActivity() {
) {
var isRestoringSession by remember { mutableStateOf(true) }
LaunchedEffect(Unit) {
// TODO PIN-related
// if (appPreferences.signInAutomatically) {
if (appPreferences.signInAutomatically) {
try {
serverRepository.restoreSession(
appPreferences.currentServerId?.toUUIDOrNull(),
@ -151,7 +155,7 @@ class MainActivity : AppCompatActivity() {
} catch (ex: Exception) {
Timber.e(ex, "Exception restoring session")
}
// }
}
isRestoringSession = false
}
val current by serverRepository.current.observeAsState()
@ -173,34 +177,32 @@ class MainActivity : AppCompatActivity() {
)
}
} else {
// TODO PIN-related
// DisposableEffect(Unit) {
// onDispose {
// if (!appPreferences.signInAutomatically || current?.user?.hasPin == true) {
// serverRepository.closeSession()
// }
// }
// }
DisposableEffect(Unit) {
onDispose {
if (!appPreferences.signInAutomatically || current?.user?.hasPin == true) {
serverRepository.closeSession()
}
}
}
key(current?.server?.id, current?.user?.id) {
// TODO PIN-related
// LaunchedEffect(current?.user?.pin) {
// if (current?.user?.pin?.isNotNullOrBlank() == true) {
// // If user has a pin, then obscure the window in previews
// window?.setFlags(
// WindowManager.LayoutParams.FLAG_SECURE,
// WindowManager.LayoutParams.FLAG_SECURE,
// )
// } else {
// window?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
// }
// }
LaunchedEffect(current?.user?.pin) {
if (current?.user?.pin?.isNotNullOrBlank() == true) {
// If user has a pin, then obscure the window in previews
window?.setFlags(
WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE,
)
} else {
window?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
}
val initialDestination =
when {
current != null -> Destination.Home()
// TODO PIN-related
// !appPreferences.signInAutomatically -> Destination.ServerList
!appPreferences.signInAutomatically -> Destination.ServerList
// TODO user list?
else -> Destination.ServerList
}
val backStack = rememberNavBackStack(initialDestination)
@ -247,12 +249,11 @@ class MainActivity : AppCompatActivity() {
override fun onRestart() {
super.onRestart()
// TODO PIN-related
// val signInAutomatically =
// runBlocking { userPreferencesDataStore.data.firstOrNull()?.signInAutomatically } ?: true
// Timber.i("onRestart: signInAutomatically=$signInAutomatically")
// if (!signInAutomatically || serverRepository.currentUser.value?.hasPin == true) {
// serverRepository.closeSession()
// }
val signInAutomatically =
runBlocking { userPreferencesDataStore.data.firstOrNull()?.signInAutomatically } ?: true
Timber.i("onRestart: signInAutomatically=$signInAutomatically")
if (!signInAutomatically || serverRepository.currentUser.value?.hasPin == true) {
serverRepository.closeSession()
}
}
}

View file

@ -793,8 +793,7 @@ val basicPreferences =
title = R.string.ui_interface,
preferences =
listOf(
// TODO PIN-related
// AppPreference.SignInAuto,
AppPreference.SignInAuto,
AppPreference.HomePageItems,
AppPreference.CombineContinueNext,
AppPreference.RewatchNextUp,
@ -827,8 +826,7 @@ val basicPreferences =
title = R.string.profile_specific_settings,
preferences =
listOf(
// TODO PIN-related
// AppPreference.RequireProfilePin,
AppPreference.RequireProfilePin,
AppPreference.UserPinnedNavDrawerItems,
),
),

View file

@ -119,13 +119,11 @@ fun SwitchUserContent(
users = users,
currentUser = currentUser,
onSwitchUser = { user ->
// TODO PIN-related
// if (user.pin.isNotNullOrBlank()) {
// switchUserWithPin = user
// } else {
// viewModel.switchUser(user)
// }
if (user.pin.isNotNullOrBlank()) {
switchUserWithPin = user
} else {
viewModel.switchUser(user)
}
},
onAddUser = { showAddUser = true },
onRemoveUser = { user ->