Enable secure screen when incognito mode is enabled (#5339)

* Enable secure screen when incognito mode is enabled

* Fix incognito banner not showing up after configuration changes
This commit is contained in:
Ivan Iskandar 2021-06-08 09:41:12 +07:00 committed by GitHub
parent 3d58b78062
commit fb8aafb69f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 8 deletions

View File

@ -4,11 +4,17 @@ import android.content.res.Configuration.UI_MODE_NIGHT_MASK
import android.content.res.Configuration.UI_MODE_NIGHT_YES
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DarkThemeVariant
import eu.kanade.tachiyomi.data.preference.PreferenceValues.LightThemeVariant
import eu.kanade.tachiyomi.data.preference.PreferenceValues.ThemeMode
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
import eu.kanade.tachiyomi.util.view.setSecureScreen
import kotlinx.coroutines.flow.launchIn
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
abstract class BaseThemedActivity : AppCompatActivity() {
@ -38,6 +44,13 @@ abstract class BaseThemedActivity : AppCompatActivity() {
}
}
setTheme(themeId)
Injekt.get<PreferencesHelper>().incognitoMode()
.asImmediateFlow {
window.setSecureScreen(it)
}
.launchIn(lifecycleScope)
super.onCreate(savedInstanceState)
}
}

View File

@ -237,6 +237,7 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
.asImmediateFlow { binding.downloadedOnly.isVisible = it }
.launchIn(lifecycleScope)
binding.incognitoMode.isVisible = preferences.incognitoMode().get()
preferences.incognitoMode().asFlow()
.drop(1)
.onEach {

View File

@ -1,11 +1,11 @@
package eu.kanade.tachiyomi.ui.security
import android.content.Intent
import android.view.WindowManager
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.lifecycleScope
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil
import eu.kanade.tachiyomi.util.view.setSecureScreen
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import uy.kohesive.injekt.injectLazy
@ -17,13 +17,7 @@ class SecureActivityDelegate(private val activity: FragmentActivity) {
fun onCreate() {
preferences.secureScreen().asFlow()
.onEach {
if (it) {
activity.window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
} else {
activity.window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
}
.onEach { activity.window.setSecureScreen(it || preferences.incognitoMode().get()) }
.launchIn(activity.lifecycleScope)
}

View File

@ -5,6 +5,7 @@ import android.graphics.Color
import android.os.Build
import android.view.View
import android.view.Window
import android.view.WindowManager
import eu.kanade.tachiyomi.util.system.InternalResourceHelper
import eu.kanade.tachiyomi.util.system.getResourceColor
@ -42,3 +43,11 @@ fun Window.setNavigationBarTransparentCompat(context: Context) {
context.getResourceColor(android.R.attr.navigationBarColor, 0.7F)
}
}
fun Window.setSecureScreen(enabled: Boolean) {
if (enabled) {
setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
} else {
clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
}