incognito does not require app restart

This commit is contained in:
Finnley Somdahl 2023-12-27 10:30:50 -06:00
parent a8711241a7
commit 42c3b42c05
9 changed files with 121 additions and 60 deletions

View file

@ -2,6 +2,7 @@ package ani.dantotsu.home
import android.animation.ObjectAnimator
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
@ -26,6 +27,7 @@ import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.connections.anilist.AnilistAnimeViewModel
import ani.dantotsu.connections.anilist.SearchResults
import ani.dantotsu.connections.anilist.getUserId
import ani.dantotsu.currContext
import ani.dantotsu.databinding.FragmentAnimeBinding
import ani.dantotsu.loadData
import ani.dantotsu.media.MediaAdaptor
@ -47,6 +49,7 @@ import kotlin.math.min
class AnimeFragment : Fragment() {
private var _binding: FragmentAnimeBinding? = null
private val binding get() = _binding!!
private lateinit var animePageAdapter: AnimePageAdapter
private var uiSettings: UserInterfaceSettings =
loadData("ui_settings") ?: UserInterfaceSettings()
@ -95,7 +98,7 @@ class AnimeFragment : Fragment() {
binding.animePageRecyclerView.updatePaddingRelative(bottom = navBarHeight + 160f.px)
val animePageAdapter = AnimePageAdapter()
animePageAdapter = AnimePageAdapter()
var loading = true
if (model.notSet) {
@ -277,6 +280,12 @@ class AnimeFragment : Fragment() {
override fun onResume() {
if (!model.loaded) Refresh.activity[this.hashCode()]!!.postValue(true)
if (animePageAdapter.trendingViewPager != null) {
animePageAdapter.setIncognito()
binding.root.requestApplyInsets()
binding.root.requestLayout()
}
super.onResume()
}
}

View file

@ -157,6 +157,19 @@ class AnimePageAdapter : RecyclerView.Adapter<AnimePageAdapter.AnimePageViewHold
trendingViewPager!!.updateLayoutParams { height += statusBarHeight }
}
fun setIncognito() {
val incognito = currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
?.getBoolean("incognito", false) ?: false
if(incognito) {
binding.incognitoTextView.visibility = View.VISIBLE
if (!uiSettings.immersiveMode) {
binding.root.fitsSystemWindows = true
}
} else {
binding.incognitoTextView.visibility = View.GONE
}
}
fun updateTrending(adaptor: MediaAdaptor) {
binding.animeTrendingProgressBar.visibility = View.GONE
binding.animeTrendingViewPager.adapter = adaptor

View file

@ -10,6 +10,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.view.animation.LayoutAnimationController
import androidx.core.content.ContextCompat
import androidx.core.view.updateLayoutParams
@ -371,6 +372,23 @@ class HomeFragment : Fragment() {
override fun onResume() {
if (!model.loaded) Refresh.activity[1]!!.postValue(true)
val incognito = currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
?.getBoolean("incognito", false) ?: false
if(incognito) {
val uiSettings = loadData<UserInterfaceSettings>("ui_settings") ?: UserInterfaceSettings()
binding.incognitoTextView.visibility = View.VISIBLE
if (!uiSettings.immersiveMode) {
binding.root.fitsSystemWindows = true
//holy deprecation
binding.root.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
binding.root.requestApplyInsets()
binding.root.requestLayout()
}
} else {
binding.incognitoTextView.visibility = View.GONE
}
super.onResume()
}
}

View file

@ -2,6 +2,7 @@ package ani.dantotsu.home
import android.animation.ObjectAnimator
import android.annotation.SuppressLint
import android.content.Context
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
@ -24,6 +25,7 @@ import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.connections.anilist.AnilistMangaViewModel
import ani.dantotsu.connections.anilist.SearchResults
import ani.dantotsu.connections.anilist.getUserId
import ani.dantotsu.currContext
import ani.dantotsu.databinding.FragmentMangaBinding
import ani.dantotsu.loadData
import ani.dantotsu.media.MediaAdaptor
@ -43,6 +45,7 @@ import kotlin.math.min
class MangaFragment : Fragment() {
private var _binding: FragmentMangaBinding? = null
private val binding get() = _binding!!
private lateinit var mangaPageAdapter: MangaPageAdapter
private var uiSettings: UserInterfaceSettings =
loadData("ui_settings") ?: UserInterfaceSettings()
@ -90,7 +93,7 @@ class MangaFragment : Fragment() {
binding.mangaPageRecyclerView.updatePaddingRelative(bottom = navBarHeight + 160f.px)
val mangaPageAdapter = MangaPageAdapter()
mangaPageAdapter = MangaPageAdapter()
var loading = true
if (model.notSet) {
model.notSet = false
@ -251,6 +254,12 @@ class MangaFragment : Fragment() {
override fun onResume() {
if (!model.loaded) Refresh.activity[this.hashCode()]!!.postValue(true)
//make sure mangaPageAdapter is initialized
if (mangaPageAdapter.trendingViewPager != null) {
mangaPageAdapter.setIncognito()
binding.root.requestApplyInsets()
binding.root.requestLayout()
}
super.onResume()
}

View file

@ -150,6 +150,19 @@ class MangaPageAdapter : RecyclerView.Adapter<MangaPageAdapter.MangaPageViewHold
trendingViewPager!!.updateLayoutParams { height += statusBarHeight }
}
fun setIncognito() {
val incognito = currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
?.getBoolean("incognito", false) ?: false
if(incognito) {
binding.incognitoTextView.visibility = View.VISIBLE
if (!uiSettings.immersiveMode) {
binding.root.fitsSystemWindows = true
}
} else {
binding.incognitoTextView.visibility = View.GONE
}
}
fun updateTrending(adaptor: MediaAdaptor) {
binding.mangaTrendingProgressBar.visibility = View.GONE
binding.mangaTrendingViewPager.adapter = adaptor

View file

@ -413,7 +413,6 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListen
binding.settingsIncognito.setOnCheckedChangeListener { _, isChecked ->
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit()
.putBoolean("incognito", isChecked).apply()
restartApp()
}
var previousStart: View = when (uiSettings.defaultStartUpTab) {

View file

@ -24,7 +24,7 @@
android:text="Incognito Mode"
android:fontFamily="@font/poppins_bold"
android:textSize="15sp"
android:textColor="#4f2dbd"
android:textColor="?attr/colorPrimary"
android:layout_gravity="bottom|center_horizontal"
android:padding="8dp"
android:visibility="gone"/>

View file

@ -16,7 +16,7 @@
android:text="Incognito Mode"
android:fontFamily="@font/poppins_bold"
android:textSize="15sp"
android:textColor="#4f2dbd"
android:textColor="?attr/colorPrimary"
android:layout_gravity="bottom|center_horizontal"
android:background="#00FFFFFF"
android:padding="8dp"

View file

@ -16,7 +16,7 @@
android:text="Incognito Mode"
android:fontFamily="@font/poppins_bold"
android:textSize="15sp"
android:textColor="#4f2dbd"
android:textColor="?attr/colorPrimary"
android:layout_gravity="bottom|center_horizontal"
android:background="#00FFFFFF"
android:padding="8dp"