incognito header fix
This commit is contained in:
parent
4e6842862e
commit
51a5609395
12 changed files with 185 additions and 96 deletions
|
@ -24,7 +24,9 @@ import androidx.appcompat.app.AppCompatActivity
|
|||
import androidx.core.animation.doOnEnd
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.doOnAttach
|
||||
import androidx.core.view.marginTop
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.lifecycle.Lifecycle
|
||||
|
@ -45,6 +47,7 @@ import ani.dantotsu.home.NoInternet
|
|||
import ani.dantotsu.media.MediaDetailsActivity
|
||||
import ani.dantotsu.others.CustomBottomDialog
|
||||
import ani.dantotsu.others.LangSet
|
||||
import ani.dantotsu.others.SharedPreferenceBooleanLiveData
|
||||
import ani.dantotsu.settings.UserInterfaceSettings
|
||||
import ani.dantotsu.subcriptions.Subscription.Companion.startSubscription
|
||||
import ani.dantotsu.themes.ThemeManager
|
||||
|
@ -61,6 +64,7 @@ import java.io.Serializable
|
|||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
private lateinit var incognitoLiveData: SharedPreferenceBooleanLiveData
|
||||
private val scope = lifecycleScope
|
||||
private var load = false
|
||||
|
||||
|
@ -88,13 +92,48 @@ class MainActivity : AppCompatActivity() {
|
|||
backgroundDrawable.setColor(semiTransparentColor)
|
||||
_bottomBar.background = backgroundDrawable
|
||||
}
|
||||
val colorOverflow = this.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
|
||||
.getBoolean("colorOverflow", false)
|
||||
val sharedPreferences = getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
|
||||
val colorOverflow = sharedPreferences.getBoolean("colorOverflow", false)
|
||||
if (!colorOverflow) {
|
||||
_bottomBar.background = ContextCompat.getDrawable(this, R.drawable.bottom_nav_gray)
|
||||
|
||||
}
|
||||
|
||||
val layoutParams = binding.incognitoTextView.layoutParams as ViewGroup.MarginLayoutParams
|
||||
layoutParams.topMargin = 11 * statusBarHeight / 12
|
||||
binding.incognitoTextView.layoutParams = layoutParams
|
||||
incognitoLiveData = SharedPreferenceBooleanLiveData(
|
||||
sharedPreferences,
|
||||
"incognito",
|
||||
false
|
||||
)
|
||||
incognitoLiveData.observe(this) {
|
||||
if (it) {
|
||||
val slideDownAnim = ObjectAnimator.ofFloat(
|
||||
binding.incognitoTextView,
|
||||
View.TRANSLATION_Y,
|
||||
-(binding.incognitoTextView.height.toFloat() + statusBarHeight),
|
||||
0f
|
||||
)
|
||||
slideDownAnim.duration = 200
|
||||
slideDownAnim.start()
|
||||
binding.incognitoTextView.visibility = View.VISIBLE
|
||||
} else {
|
||||
val slideUpAnim = ObjectAnimator.ofFloat(
|
||||
binding.incognitoTextView,
|
||||
View.TRANSLATION_Y,
|
||||
0f,
|
||||
-(binding.incognitoTextView.height.toFloat() + statusBarHeight)
|
||||
)
|
||||
slideUpAnim.duration = 200
|
||||
slideUpAnim.start()
|
||||
//wait for animation to finish
|
||||
Handler(Looper.getMainLooper()).postDelayed(
|
||||
{ binding.incognitoTextView.visibility = View.GONE },
|
||||
200
|
||||
)
|
||||
}
|
||||
}
|
||||
incognitoNotification(this)
|
||||
|
||||
var doubleBackToExitPressedOnce = false
|
||||
|
|
|
@ -279,7 +279,6 @@ 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()
|
||||
}
|
||||
|
|
|
@ -93,7 +93,6 @@ class AnimePageAdapter : RecyclerView.Adapter<AnimePageAdapter.AnimePageViewHold
|
|||
)
|
||||
}
|
||||
|
||||
setIncognito()
|
||||
binding.animeSearchBar.setEndIconOnClickListener {
|
||||
binding.animeSearchBarText.performClick()
|
||||
}
|
||||
|
@ -150,19 +149,6 @@ 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
|
||||
|
|
|
@ -72,7 +72,6 @@ class HomeFragment : Fragment() {
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
val scope = lifecycleScope
|
||||
var uiSettings = loadData<UserInterfaceSettings>("ui_settings") ?: UserInterfaceSettings()
|
||||
setIncognito()
|
||||
fun load() {
|
||||
if (activity != null && _binding != null) lifecycleScope.launch(Dispatchers.Main) {
|
||||
binding.homeUserName.text = Anilist.username
|
||||
|
@ -359,30 +358,8 @@ class HomeFragment : Fragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun setIncognito() {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
if (!model.loaded) Refresh.activity[1]!!.postValue(true)
|
||||
setIncognito()
|
||||
super.onResume()
|
||||
}
|
||||
}
|
|
@ -254,7 +254,6 @@ class MangaFragment : Fragment() {
|
|||
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()
|
||||
}
|
||||
|
|
|
@ -98,7 +98,6 @@ class MangaPageAdapter : RecyclerView.Adapter<MangaPageAdapter.MangaPageViewHold
|
|||
dialogFragment.show((it.context as AppCompatActivity).supportFragmentManager, "dialog")
|
||||
}
|
||||
|
||||
setIncognito()
|
||||
binding.mangaSearchBar.setEndIconOnClickListener {
|
||||
binding.mangaSearchBarText.performClick()
|
||||
}
|
||||
|
@ -141,20 +140,6 @@ class MangaPageAdapter : RecyclerView.Adapter<MangaPageAdapter.MangaPageViewHold
|
|||
fun updateHeight() {
|
||||
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
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
package ani.dantotsu.others
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import androidx.lifecycle.LiveData
|
||||
|
||||
abstract class SharedPreferenceLiveData<T>(
|
||||
val sharedPrefs: SharedPreferences,
|
||||
val key: String,
|
||||
val defValue: T
|
||||
) : LiveData<T>() {
|
||||
|
||||
private val preferenceChangeListener =
|
||||
SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key ->
|
||||
if (key == this.key) {
|
||||
value = getValueFromPreferences(key, defValue)
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun getValueFromPreferences(key: String, defValue: T): T
|
||||
|
||||
override fun onActive() {
|
||||
super.onActive()
|
||||
value = getValueFromPreferences(key, defValue)
|
||||
sharedPrefs.registerOnSharedPreferenceChangeListener(preferenceChangeListener)
|
||||
}
|
||||
|
||||
override fun onInactive() {
|
||||
sharedPrefs.unregisterOnSharedPreferenceChangeListener(preferenceChangeListener)
|
||||
super.onInactive()
|
||||
}
|
||||
}
|
||||
|
||||
class SharedPreferenceIntLiveData(sharedPrefs: SharedPreferences, key: String, defValue: Int) :
|
||||
SharedPreferenceLiveData<Int>(sharedPrefs, key, defValue) {
|
||||
override fun getValueFromPreferences(key: String, defValue: Int): Int =
|
||||
sharedPrefs.getInt(key, defValue)
|
||||
}
|
||||
|
||||
class SharedPreferenceStringLiveData(
|
||||
sharedPrefs: SharedPreferences,
|
||||
key: String,
|
||||
defValue: String
|
||||
) :
|
||||
SharedPreferenceLiveData<String>(sharedPrefs, key, defValue) {
|
||||
override fun getValueFromPreferences(key: String, defValue: String): String =
|
||||
sharedPrefs.getString(key, defValue).toString()
|
||||
}
|
||||
|
||||
class SharedPreferenceBooleanLiveData(
|
||||
sharedPrefs: SharedPreferences,
|
||||
key: String,
|
||||
defValue: Boolean
|
||||
) :
|
||||
SharedPreferenceLiveData<Boolean>(sharedPrefs, key, defValue) {
|
||||
override fun getValueFromPreferences(key: String, defValue: Boolean): Boolean =
|
||||
sharedPrefs.getBoolean(key, defValue)
|
||||
}
|
||||
|
||||
class SharedPreferenceFloatLiveData(sharedPrefs: SharedPreferences, key: String, defValue: Float) :
|
||||
SharedPreferenceLiveData<Float>(sharedPrefs, key, defValue) {
|
||||
override fun getValueFromPreferences(key: String, defValue: Float): Float =
|
||||
sharedPrefs.getFloat(key, defValue)
|
||||
}
|
||||
|
||||
class SharedPreferenceLongLiveData(sharedPrefs: SharedPreferences, key: String, defValue: Long) :
|
||||
SharedPreferenceLiveData<Long>(sharedPrefs, key, defValue) {
|
||||
override fun getValueFromPreferences(key: String, defValue: Long): Long =
|
||||
sharedPrefs.getLong(key, defValue)
|
||||
}
|
||||
|
||||
class SharedPreferenceStringSetLiveData(
|
||||
sharedPrefs: SharedPreferences,
|
||||
key: String,
|
||||
defValue: Set<String>
|
||||
) :
|
||||
SharedPreferenceLiveData<Set<String>>(sharedPrefs, key, defValue) {
|
||||
override fun getValueFromPreferences(key: String, defValue: Set<String>): Set<String> =
|
||||
sharedPrefs.getStringSet(key, defValue)?.toSet() ?: defValue
|
||||
}
|
||||
|
||||
fun SharedPreferences.intLiveData(key: String, defValue: Int): SharedPreferenceLiveData<Int> {
|
||||
return SharedPreferenceIntLiveData(this, key, defValue)
|
||||
}
|
||||
|
||||
fun SharedPreferences.stringLiveData(
|
||||
key: String,
|
||||
defValue: String
|
||||
): SharedPreferenceLiveData<String> {
|
||||
return SharedPreferenceStringLiveData(this, key, defValue)
|
||||
}
|
||||
|
||||
fun SharedPreferences.booleanLiveData(
|
||||
key: String,
|
||||
defValue: Boolean
|
||||
): SharedPreferenceLiveData<Boolean> {
|
||||
return SharedPreferenceBooleanLiveData(this, key, defValue)
|
||||
}
|
||||
|
||||
fun SharedPreferences.floatLiveData(key: String, defValue: Float): SharedPreferenceLiveData<Float> {
|
||||
return SharedPreferenceFloatLiveData(this, key, defValue)
|
||||
}
|
||||
|
||||
fun SharedPreferences.longLiveData(key: String, defValue: Long): SharedPreferenceLiveData<Long> {
|
||||
return SharedPreferenceLongLiveData(this, key, defValue)
|
||||
}
|
||||
|
||||
fun SharedPreferences.stringSetLiveData(
|
||||
key: String,
|
||||
defValue: Set<String>
|
||||
): SharedPreferenceLiveData<Set<String>> {
|
||||
return SharedPreferenceStringSetLiveData(this, key, defValue)
|
||||
}
|
5
app/src/main/res/drawable/rounded_top_incognito.xml
Normal file
5
app/src/main/res/drawable/rounded_top_incognito.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="?attr/colorError"/>
|
||||
<corners android:radius="16dp" />
|
||||
</shape>
|
|
@ -1,6 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/bg"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -23,9 +22,31 @@
|
|||
android:id="@+id/included_navbar"
|
||||
layout="@layout/item_navbar" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fragmentContainer"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
</FrameLayout>
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/incognitoTextView"
|
||||
android:background="@drawable/rounded_top_incognito"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|center_horizontal"
|
||||
android:fontFamily="@font/poppins_bold"
|
||||
android:textAlignment="center"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:text="Incognito Mode"
|
||||
android:textColor="?attr/colorOnError"
|
||||
android:textSize="15sp"
|
||||
android:visibility="visible" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fragmentContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
|
|
@ -17,17 +17,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:id="@+id/incognitoTextView"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="Incognito Mode"
|
||||
android:fontFamily="@font/poppins_bold"
|
||||
android:textSize="15sp"
|
||||
android:textColor="?attr/colorPrimary"
|
||||
android:layout_gravity="bottom|center_horizontal"
|
||||
android:padding="8dp"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
|
|
@ -9,18 +9,6 @@
|
|||
android:layout_marginEnd="-16dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/incognitoTextView"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="Incognito Mode"
|
||||
android:fontFamily="@font/poppins_bold"
|
||||
android:textSize="15sp"
|
||||
android:textColor="?attr/colorPrimary"
|
||||
android:layout_gravity="bottom|center_horizontal"
|
||||
android:background="#00FFFFFF"
|
||||
android:padding="8dp"
|
||||
android:visibility="gone"/>
|
||||
<FrameLayout
|
||||
android:id="@+id/animeTrendingContainer"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -9,18 +9,6 @@
|
|||
android:layout_marginEnd="-16dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/incognitoTextView"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="Incognito Mode"
|
||||
android:fontFamily="@font/poppins_bold"
|
||||
android:textSize="15sp"
|
||||
android:textColor="?attr/colorPrimary"
|
||||
android:layout_gravity="bottom|center_horizontal"
|
||||
android:background="#00FFFFFF"
|
||||
android:padding="8dp"
|
||||
android:visibility="gone"/>
|
||||
<FrameLayout
|
||||
android:id="@+id/mangaTrendingContainer"
|
||||
android:layout_width="match_parent"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue