This commit is contained in:
rebelonion 2024-03-10 03:21:22 -05:00
commit 8e5e548e16
6 changed files with 61 additions and 50 deletions

View file

@ -135,7 +135,7 @@ fun logger(e: Any?, print: Boolean = true) {
} }
fun initActivity(a: Activity) { fun initActivityTheme(a: Activity) {
val window = a.window val window = a.window
WindowCompat.setDecorFitsSystemWindows(window, false) WindowCompat.setDecorFitsSystemWindows(window, false)
val darkMode = PrefManager.getVal<Int>(PrefName.DarkMode) val darkMode = PrefManager.getVal<Int>(PrefName.DarkMode)
@ -156,7 +156,7 @@ fun initActivity(a: Activity) {
navBarHeight = this.getInsets(WindowInsetsCompat.Type.systemBars()).bottom navBarHeight = this.getInsets(WindowInsetsCompat.Type.systemBars()).bottom
} }
} }
a.hideStatusBar() WindowInsetsControllerCompat(window, window.decorView).hide(WindowInsetsCompat.Type.statusBars())
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && statusBarHeight == 0 && a.resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && statusBarHeight == 0 && a.resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
window.decorView.rootWindowInsets?.displayCutout?.apply { window.decorView.rootWindowInsets?.displayCutout?.apply {
if (boundingRects.size > 0) { if (boundingRects.size > 0) {
@ -176,28 +176,34 @@ fun initActivity(a: Activity) {
} }
} }
@Suppress("DEPRECATION")
fun Activity.hideSystemBars() { fun Activity.hideSystemBars() {
window.decorView.systemUiVisibility = ( WindowInsetsControllerCompat(window, window.decorView).let { controller ->
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY controller.systemBarsBehavior =
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
or View.SYSTEM_UI_FLAG_FULLSCREEN controller.hide(WindowInsetsCompat.Type.systemBars())
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION }
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
)
} }
@Suppress("DEPRECATION") fun Activity.setNavigationTheme() {
fun Activity.hideStatusBar() { val a = TypedValue()
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN) theme.resolveAttribute(android.R.attr.colorBackground, a, true)
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && a.isColorType)
|| (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT)) {
window.navigationBarColor = a.data
}
} }
open class BottomSheetDialogFragment : BottomSheetDialogFragment() { open class BottomSheetDialogFragment : BottomSheetDialogFragment() {
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
val window = dialog?.window dialog?.window?.let { window ->
val decorView: View = window?.decorView ?: return WindowCompat.setDecorFitsSystemWindows(window, false)
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN val immersiveMode: Boolean = PrefManager.getVal(PrefName.ImmersiveMode)
if (immersiveMode) {
WindowInsetsControllerCompat(
window, window.decorView
).hide(WindowInsetsCompat.Type.statusBars())
}
if (this.resources.configuration.orientation != Configuration.ORIENTATION_PORTRAIT) { if (this.resources.configuration.orientation != Configuration.ORIENTATION_PORTRAIT) {
val behavior = BottomSheetBehavior.from(requireView().parent as View) val behavior = BottomSheetBehavior.from(requireView().parent as View)
behavior.state = BottomSheetBehavior.STATE_EXPANDED behavior.state = BottomSheetBehavior.STATE_EXPANDED
@ -211,6 +217,7 @@ open class BottomSheetDialogFragment : BottomSheetDialogFragment() {
) )
window.navigationBarColor = typedValue.data window.navigationBarColor = typedValue.data
} }
}
override fun show(manager: FragmentManager, tag: String?) { override fun show(manager: FragmentManager, tag: String?) {
val ft = manager.beginTransaction() val ft = manager.beginTransaction()

View file

@ -146,24 +146,14 @@ class MainActivity : AppCompatActivity() {
finish() finish()
} }
doubleBackToExitPressedOnce = true doubleBackToExitPressedOnce = true
WindowInsetsControllerCompat(window, window.decorView)
.show(WindowInsetsCompat.Type.navigationBars())
snackString(this@MainActivity.getString(R.string.back_to_exit)).apply { snackString(this@MainActivity.getString(R.string.back_to_exit)).apply {
this?.addCallback(object : BaseTransientBottomBar.BaseCallback<Snackbar>() { this?.addCallback(object : BaseTransientBottomBar.BaseCallback<Snackbar>() {
override fun onDismissed(transientBottomBar: Snackbar?, event: Int) { override fun onDismissed(transientBottomBar: Snackbar?, event: Int) {
super.onDismissed(transientBottomBar, event) super.onDismissed(transientBottomBar, event)
WindowInsetsControllerCompat(window, window.decorView).let { controller -> doubleBackToExitPressedOnce = false
controller.systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
controller.hide(WindowInsetsCompat.Type.navigationBars())
}
} }
}) })
} }
Handler(Looper.getMainLooper()).postDelayed(
{ doubleBackToExitPressedOnce = false },
2000
)
} }
val preferences: SourcePreferences = Injekt.get() val preferences: SourcePreferences = Injekt.get()
@ -219,7 +209,7 @@ class MainActivity : AppCompatActivity() {
binding.root.doOnAttach { binding.root.doOnAttach {
initActivity(this) initActivityTheme(this)
selectedOption = if (fragment != null) { selectedOption = if (fragment != null) {
when (fragment) { when (fragment) {
AnimeFragment::class.java.name -> 0 AnimeFragment::class.java.name -> 0
@ -369,13 +359,11 @@ class MainActivity : AppCompatActivity() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
initActivityTheme(this)
WindowCompat.setDecorFitsSystemWindows(window, false) binding.includedNavbar.navbarContainer.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = navBarHeight
WindowInsetsControllerCompat(window, window.decorView).let { controller ->
controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
controller.hide(WindowInsetsCompat.Type.navigationBars())
} }
window.navigationBarColor = getColor(android.R.color.transparent)
} }
//ViewPager //ViewPager

View file

@ -601,6 +601,7 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener {
super.onResume() super.onResume()
binding.mediaInfoProgressBar.visibility = progress binding.mediaInfoProgressBar.visibility = progress
binding.animeSourceRecycler.layoutManager?.onRestoreInstanceState(state) binding.animeSourceRecycler.layoutManager?.onRestoreInstanceState(state)
requireActivity().setNavigationTheme()
} }
override fun onPause() { override fun onPause() {

View file

@ -285,7 +285,7 @@ class MangaReaderActivity : AppCompatActivity() {
binding.mangaReaderNextChapter.performClick() binding.mangaReaderNextChapter.performClick()
} }
binding.mangaReaderNextChapter.setOnClickListener { binding.mangaReaderNextChapter.setOnClickListener {
if (defaultSettings.direction == RIGHT_TO_LEFT) { if (defaultSettings.direction == RIGHT_TO_LEFT || defaultSettings.direction == BOTTOM_TO_TOP) {
if (currentChapterIndex > 0) change(currentChapterIndex - 1) if (currentChapterIndex > 0) change(currentChapterIndex - 1)
else snackString(getString(R.string.first_chapter)) else snackString(getString(R.string.first_chapter))
} else { } else {
@ -298,7 +298,7 @@ class MangaReaderActivity : AppCompatActivity() {
binding.mangaReaderPreviousChapter.performClick() binding.mangaReaderPreviousChapter.performClick()
} }
binding.mangaReaderPreviousChapter.setOnClickListener { binding.mangaReaderPreviousChapter.setOnClickListener {
if (defaultSettings.direction == RIGHT_TO_LEFT) { if (defaultSettings.direction == RIGHT_TO_LEFT || defaultSettings.direction == BOTTOM_TO_TOP) {
if (chaptersArr.size > currentChapterIndex + 1) progress { change(currentChapterIndex + 1) } if (chaptersArr.size > currentChapterIndex + 1) progress { change(currentChapterIndex + 1) }
else snackString(getString(R.string.next_chapter_not_found)) else snackString(getString(R.string.next_chapter_not_found))
} else { } else {
@ -315,7 +315,7 @@ class MangaReaderActivity : AppCompatActivity() {
PrefManager.setCustomVal("${media.id}_current_chp", chap.number) PrefManager.setCustomVal("${media.id}_current_chp", chap.number)
currentChapterIndex = chaptersArr.indexOf(chap.number) currentChapterIndex = chaptersArr.indexOf(chap.number)
binding.mangaReaderChapterSelect.setSelection(currentChapterIndex) binding.mangaReaderChapterSelect.setSelection(currentChapterIndex)
if (defaultSettings.direction == RIGHT_TO_LEFT) { if (defaultSettings.direction == RIGHT_TO_LEFT || defaultSettings.direction == BOTTOM_TO_TOP) {
binding.mangaReaderNextChap.text = binding.mangaReaderNextChap.text =
chaptersTitleArr.getOrNull(currentChapterIndex - 1) ?: "" chaptersTitleArr.getOrNull(currentChapterIndex - 1) ?: ""
binding.mangaReaderPrevChap.text = binding.mangaReaderPrevChap.text =
@ -439,6 +439,10 @@ class MangaReaderActivity : AppCompatActivity() {
if ((defaultSettings.direction == TOP_TO_BOTTOM || defaultSettings.direction == BOTTOM_TO_TOP)) { if ((defaultSettings.direction == TOP_TO_BOTTOM || defaultSettings.direction == BOTTOM_TO_TOP)) {
binding.mangaReaderSwipy.vertical = true binding.mangaReaderSwipy.vertical = true
if (defaultSettings.direction == TOP_TO_BOTTOM) { if (defaultSettings.direction == TOP_TO_BOTTOM) {
binding.mangaReaderNextChap.text =
chaptersTitleArr.getOrNull(currentChapterIndex + 1) ?: ""
binding.mangaReaderPrevChap.text =
chaptersTitleArr.getOrNull(currentChapterIndex - 1) ?: ""
binding.BottomSwipeText.text = chaptersTitleArr.getOrNull(currentChapterIndex + 1) binding.BottomSwipeText.text = chaptersTitleArr.getOrNull(currentChapterIndex + 1)
?: getString(R.string.no_chapter) ?: getString(R.string.no_chapter)
binding.TopSwipeText.text = chaptersTitleArr.getOrNull(currentChapterIndex - 1) binding.TopSwipeText.text = chaptersTitleArr.getOrNull(currentChapterIndex - 1)
@ -450,6 +454,10 @@ class MangaReaderActivity : AppCompatActivity() {
binding.mangaReaderNextChapter.performClick() binding.mangaReaderNextChapter.performClick()
} }
} else { } else {
binding.mangaReaderNextChap.text =
chaptersTitleArr.getOrNull(currentChapterIndex - 1) ?: ""
binding.mangaReaderPrevChap.text =
chaptersTitleArr.getOrNull(currentChapterIndex + 1) ?: ""
binding.BottomSwipeText.text = chaptersTitleArr.getOrNull(currentChapterIndex - 1) binding.BottomSwipeText.text = chaptersTitleArr.getOrNull(currentChapterIndex - 1)
?: getString(R.string.no_chapter) ?: getString(R.string.no_chapter)
binding.TopSwipeText.text = chaptersTitleArr.getOrNull(currentChapterIndex + 1) binding.TopSwipeText.text = chaptersTitleArr.getOrNull(currentChapterIndex + 1)
@ -729,7 +737,7 @@ class MangaReaderActivity : AppCompatActivity() {
val screenWidth = Resources.getSystem().displayMetrics.widthPixels val screenWidth = Resources.getSystem().displayMetrics.widthPixels
//if in the 1st 1/5th of the screen width, left and lower than 1/5th of the screen height, left //if in the 1st 1/5th of the screen width, left and lower than 1/5th of the screen height, left
if (screenWidth / 5 in x + 1..<y) { if (screenWidth / 5 in x + 1..<y) {
pressLocation = if (defaultSettings.direction == RIGHT_TO_LEFT) { pressLocation = if (defaultSettings.direction == RIGHT_TO_LEFT || defaultSettings.direction == BOTTOM_TO_TOP) {
pressPos.RIGHT pressPos.RIGHT
} else { } else {
pressPos.LEFT pressPos.LEFT
@ -737,7 +745,7 @@ class MangaReaderActivity : AppCompatActivity() {
} }
//if in the last 1/5th of the screen width, right and lower than 1/5th of the screen height, right //if in the last 1/5th of the screen width, right and lower than 1/5th of the screen height, right
else if (x > screenWidth - screenWidth / 5 && y > screenWidth / 5) { else if (x > screenWidth - screenWidth / 5 && y > screenWidth / 5) {
pressLocation = if (defaultSettings.direction == RIGHT_TO_LEFT) { pressLocation = if (defaultSettings.direction == RIGHT_TO_LEFT || defaultSettings.direction == BOTTOM_TO_TOP) {
pressPos.LEFT pressPos.LEFT
} else { } else {
pressPos.RIGHT pressPos.RIGHT

View file

@ -25,6 +25,12 @@ class DevelopersDialogFragment : BottomSheetDialogFragment() {
"Contributor", "Contributor",
"https://github.com/aayush2622" "https://github.com/aayush2622"
), ),
Developer(
"AbandonedCart",
"https://avatars.githubusercontent.com/u/1173913?v=4",
"Contributor",
"https://github.com/AbandonedCart"
),
Developer( Developer(
"Sadwhy", "Sadwhy",
"https://avatars.githubusercontent.com/u/99601717?v=4", "https://avatars.githubusercontent.com/u/99601717?v=4",

View file

@ -1,6 +1,7 @@
<resources xmlns:tools="http://schemas.android.com/tools"> <resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.Base" parent="Theme.Material3.DayNight"> <style name="Theme.Base" parent="Theme.Material3.DayNight">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item> <item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">?android:colorBackground</item> <item name="android:navigationBarColor">?android:colorBackground</item>
<item name="android:windowTranslucentStatus">false</item> <item name="android:windowTranslucentStatus">false</item>