fix: search bars
This commit is contained in:
parent
60752e83ed
commit
449485f06a
16 changed files with 439 additions and 142 deletions
|
@ -217,7 +217,6 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
binding.includedNavbar.navbarContainer.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
bottomMargin = navBarHeight
|
||||
|
||||
}
|
||||
}
|
||||
intent.extras?.let { extras ->
|
||||
|
|
|
@ -2,7 +2,9 @@ package ani.dantotsu.media
|
|||
|
||||
import android.animation.ObjectAnimator
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.graphics.Rect
|
||||
import android.os.Bundle
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.util.TypedValue
|
||||
|
@ -10,7 +12,9 @@ import android.view.GestureDetector
|
|||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.WindowManager
|
||||
import android.view.animation.AccelerateDecelerateInterpolator
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.ImageView
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
@ -18,6 +22,7 @@ import androidx.appcompat.content.res.AppCompatResources
|
|||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.text.bold
|
||||
import androidx.core.text.color
|
||||
import androidx.core.view.marginBottom
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
|
@ -25,7 +30,6 @@ import androidx.lifecycle.Lifecycle
|
|||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import ani.dantotsu.CustomBottomNavBar
|
||||
import ani.dantotsu.GesturesListener
|
||||
import ani.dantotsu.R
|
||||
import ani.dantotsu.Refresh
|
||||
|
@ -41,6 +45,7 @@ import ani.dantotsu.media.manga.MangaReadFragment
|
|||
import ani.dantotsu.media.novel.NovelReadFragment
|
||||
import ani.dantotsu.navBarHeight
|
||||
import ani.dantotsu.openLinkInBrowser
|
||||
import ani.dantotsu.others.AndroidBug5497Workaround
|
||||
import ani.dantotsu.others.ImageViewDialog
|
||||
import ani.dantotsu.others.getSerialized
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
|
@ -50,7 +55,6 @@ import ani.dantotsu.statusBarHeight
|
|||
import ani.dantotsu.themes.ThemeManager
|
||||
import com.flaviofaria.kenburnsview.RandomTransitionGenerator
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import com.google.android.material.navigation.NavigationBarView
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
|
@ -65,7 +69,7 @@ class MediaDetailsActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedLi
|
|||
lateinit var binding: ActivityMediaBinding
|
||||
private val scope = lifecycleScope
|
||||
private val model: MediaDetailsViewModel by viewModels()
|
||||
private lateinit var tabLayout: NavigationBarView
|
||||
lateinit var tabLayout: TripleNavAdapter
|
||||
var selected = 0
|
||||
var anime = true
|
||||
private var adult = false
|
||||
|
@ -96,19 +100,30 @@ class MediaDetailsActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedLi
|
|||
setContentView(binding.root)
|
||||
screenWidth = resources.displayMetrics.widthPixels.toFloat()
|
||||
|
||||
val isVertical = resources.configuration.orientation
|
||||
//Ui init
|
||||
|
||||
initActivity(this)
|
||||
|
||||
val oldMargin = binding.mediaViewPager.marginBottom
|
||||
AndroidBug5497Workaround.assistActivity(this) {
|
||||
if (it) {
|
||||
binding.mediaViewPager.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
bottomMargin = 0
|
||||
}
|
||||
binding.mediaTabContainer.visibility = View.GONE
|
||||
} else {
|
||||
binding.mediaViewPager.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
bottomMargin = oldMargin
|
||||
}
|
||||
binding.mediaTabContainer.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
binding.mediaBanner.updateLayoutParams { height += statusBarHeight }
|
||||
binding.mediaBannerNoKen.updateLayoutParams { height += statusBarHeight }
|
||||
binding.mediaClose.updateLayoutParams<ViewGroup.MarginLayoutParams> { topMargin += statusBarHeight }
|
||||
binding.incognito.updateLayoutParams<ViewGroup.MarginLayoutParams> { topMargin += statusBarHeight }
|
||||
binding.mediaCollapsing.minimumHeight = statusBarHeight
|
||||
|
||||
if (binding.mediaTab is CustomBottomNavBar) binding.mediaTab.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
bottomMargin = navBarHeight
|
||||
}
|
||||
//binding.mediaViewPager.updateLayoutParams<ViewGroup.MarginLayoutParams> { bottomMargin = navBarHeight }
|
||||
|
||||
binding.mediaTitle.isSelected = true
|
||||
|
||||
|
@ -131,7 +146,7 @@ class MediaDetailsActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedLi
|
|||
val banner =
|
||||
if (bannerAnimations) binding.mediaBanner else binding.mediaBannerNoKen
|
||||
val viewPager = binding.mediaViewPager
|
||||
tabLayout = binding.mediaTab as NavigationBarView
|
||||
//tabLayout = binding.mediaTab as AnimatedBottomBar
|
||||
viewPager.isUserInputEnabled = false
|
||||
viewPager.setPageTransformer(ZoomOutPageTransformer())
|
||||
|
||||
|
@ -325,12 +340,18 @@ class MediaDetailsActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedLi
|
|||
progress()
|
||||
}
|
||||
}
|
||||
tabLayout = TripleNavAdapter(
|
||||
binding.mediaTab1,
|
||||
binding.mediaTab2,
|
||||
binding.mediaTab3,
|
||||
media.anime != null,
|
||||
media.format ?: "",
|
||||
isVertical == 1
|
||||
)
|
||||
adult = media.isAdult
|
||||
tabLayout.menu.clear()
|
||||
if (media.anime != null) {
|
||||
viewPager.adapter =
|
||||
ViewPagerAdapter(supportFragmentManager, lifecycle, SupportedMedia.ANIME, media, intent.getIntExtra("commentId", -1))
|
||||
tabLayout.inflateMenu(R.menu.anime_menu_detail)
|
||||
} else if (media.manga != null) {
|
||||
viewPager.adapter = ViewPagerAdapter(
|
||||
supportFragmentManager,
|
||||
|
@ -339,30 +360,23 @@ class MediaDetailsActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedLi
|
|||
media,
|
||||
intent.getIntExtra("commentId", -1)
|
||||
)
|
||||
if (media.format == "NOVEL") {
|
||||
tabLayout.inflateMenu(R.menu.novel_menu_detail)
|
||||
} else {
|
||||
tabLayout.inflateMenu(R.menu.manga_menu_detail)
|
||||
}
|
||||
anime = false
|
||||
}
|
||||
|
||||
|
||||
selected = media.selected!!.window
|
||||
binding.mediaTitle.translationX = -screenWidth
|
||||
tabLayout.visibility = View.VISIBLE
|
||||
|
||||
tabLayout.setOnItemSelectedListener { item ->
|
||||
selectFromID(item.itemId)
|
||||
tabLayout.selectionListener = { selected, newId ->
|
||||
this.selected = selected
|
||||
selectFromID(newId)
|
||||
viewPager.setCurrentItem(selected, false)
|
||||
val sel = model.loadSelected(media, isDownload)
|
||||
sel.window = selected
|
||||
model.saveSelected(media.id, sel)
|
||||
true
|
||||
}
|
||||
|
||||
|
||||
tabLayout.selectedItemId = idFromSelect()
|
||||
tabLayout.selectTab(selected)
|
||||
selectFromID(tabLayout.selected)
|
||||
viewPager.setCurrentItem(selected, false)
|
||||
|
||||
if (model.continueMedia == null && media.cameFromContinue) {
|
||||
|
@ -385,7 +399,6 @@ class MediaDetailsActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedLi
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private fun selectFromID(id: Int) {
|
||||
when (id) {
|
||||
R.id.info -> {
|
||||
|
@ -418,7 +431,7 @@ class MediaDetailsActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedLi
|
|||
|
||||
override fun onResume() {
|
||||
if (this::tabLayout.isInitialized) {
|
||||
tabLayout.selectedItemId = idFromSelect()
|
||||
tabLayout.selectTab(selected)
|
||||
}
|
||||
super.onResume()
|
||||
}
|
||||
|
@ -586,5 +599,4 @@ class MediaDetailsActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedLi
|
|||
companion object {
|
||||
var mediaSingleton: Media? = null
|
||||
}
|
||||
}
|
||||
|
||||
}
|
112
app/src/main/java/ani/dantotsu/media/TripleNavAdapter.kt
Normal file
112
app/src/main/java/ani/dantotsu/media/TripleNavAdapter.kt
Normal file
|
@ -0,0 +1,112 @@
|
|||
package ani.dantotsu.media
|
||||
|
||||
import android.graphics.Color
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import ani.dantotsu.R
|
||||
import ani.dantotsu.navBarHeight
|
||||
import nl.joery.animatedbottombar.AnimatedBottomBar
|
||||
|
||||
class TripleNavAdapter(
|
||||
private val nav1: AnimatedBottomBar,
|
||||
private val nav2: AnimatedBottomBar,
|
||||
private val nav3: AnimatedBottomBar,
|
||||
anime: Boolean,
|
||||
format: String,
|
||||
isVertical: Boolean = false
|
||||
) {
|
||||
var selected: Int = 0
|
||||
var selectionListener: ((Int, Int) -> Unit)? = null
|
||||
init {
|
||||
nav1.tabs.clear()
|
||||
nav2.tabs.clear()
|
||||
nav3.tabs.clear()
|
||||
val infoTab = nav1.createTab(R.drawable.ic_round_info_24, R.string.info, R.id.info)
|
||||
val watchTab = if (anime) {
|
||||
nav2.createTab(R.drawable.ic_round_movie_filter_24, R.string.watch, R.id.watch)
|
||||
} else if (format == "NOVEL") {
|
||||
nav2.createTab(R.drawable.ic_round_book_24, R.string.read, R.id.read)
|
||||
} else {
|
||||
nav2.createTab(R.drawable.ic_round_import_contacts_24, R.string.read, R.id.read)
|
||||
}
|
||||
val commentTab = nav3.createTab(R.drawable.ic_round_comment_24, R.string.comments, R.id.comment)
|
||||
nav1.addTab(infoTab)
|
||||
nav2.addTab(watchTab)
|
||||
nav3.addTab(commentTab)
|
||||
nav1.visibility = ViewGroup.VISIBLE
|
||||
nav2.visibility = ViewGroup.VISIBLE
|
||||
nav3.visibility = ViewGroup.VISIBLE
|
||||
if (!isVertical) {
|
||||
nav1.indicatorColor = Color.TRANSPARENT
|
||||
nav2.indicatorColor = Color.TRANSPARENT
|
||||
nav3.indicatorColor = Color.TRANSPARENT
|
||||
}
|
||||
nav1.setOnTabSelectListener(object : AnimatedBottomBar.OnTabSelectListener {
|
||||
override fun onTabSelected(
|
||||
lastIndex: Int,
|
||||
lastTab: AnimatedBottomBar.Tab?,
|
||||
newIndex: Int,
|
||||
newTab: AnimatedBottomBar.Tab
|
||||
) {
|
||||
selected = 0
|
||||
deselectOthers(selected)
|
||||
selectionListener?.invoke(selected, newTab.id)
|
||||
}
|
||||
})
|
||||
nav2.setOnTabSelectListener(object : AnimatedBottomBar.OnTabSelectListener {
|
||||
override fun onTabSelected(
|
||||
lastIndex: Int,
|
||||
lastTab: AnimatedBottomBar.Tab?,
|
||||
newIndex: Int,
|
||||
newTab: AnimatedBottomBar.Tab
|
||||
) {
|
||||
selected = 1
|
||||
deselectOthers(selected)
|
||||
selectionListener?.invoke(selected, newTab.id)
|
||||
}
|
||||
})
|
||||
nav3.setOnTabSelectListener(object : AnimatedBottomBar.OnTabSelectListener {
|
||||
override fun onTabSelected(
|
||||
lastIndex: Int,
|
||||
lastTab: AnimatedBottomBar.Tab?,
|
||||
newIndex: Int,
|
||||
newTab: AnimatedBottomBar.Tab
|
||||
) {
|
||||
selected = 2
|
||||
deselectOthers(selected)
|
||||
selectionListener?.invoke(selected, newTab.id)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun deselectOthers(selected: Int) {
|
||||
if (selected == 0) {
|
||||
nav2.clearSelection()
|
||||
nav3.clearSelection()
|
||||
}
|
||||
if (selected == 1) {
|
||||
nav1.clearSelection()
|
||||
nav3.clearSelection()
|
||||
}
|
||||
if (selected == 2) {
|
||||
nav1.clearSelection()
|
||||
nav2.clearSelection()
|
||||
}
|
||||
}
|
||||
|
||||
fun selectTab(tab: Int) {
|
||||
when (tab) {
|
||||
0 -> nav1.selectTabAt(0)
|
||||
1 -> nav2.selectTabAt(0)
|
||||
2 -> nav3.selectTabAt(0)
|
||||
}
|
||||
selected = tab
|
||||
deselectOthers(selected)
|
||||
}
|
||||
|
||||
fun setVisibility(visibility: Int) {
|
||||
nav1.visibility = visibility
|
||||
nav2.visibility = visibility
|
||||
nav3.visibility = visibility
|
||||
}
|
||||
}
|
|
@ -358,11 +358,9 @@ class AnimeWatchFragment : Fragment() {
|
|||
activity.findViewById<ViewPager2>(R.id.mediaViewPager).visibility = visibility
|
||||
activity.findViewById<CardView>(R.id.mediaCover).visibility = visibility
|
||||
activity.findViewById<CardView>(R.id.mediaClose).visibility = visibility
|
||||
try {
|
||||
activity.findViewById<CustomBottomNavBar>(R.id.mediaTab).visibility = visibility
|
||||
} catch (e: ClassCastException) {
|
||||
activity.findViewById<NavigationRailView>(R.id.mediaTab).visibility = visibility
|
||||
}
|
||||
|
||||
activity.tabLayout.setVisibility(visibility)
|
||||
|
||||
activity.findViewById<FrameLayout>(R.id.fragmentExtensionsContainer).visibility =
|
||||
if (show) View.GONE else View.VISIBLE
|
||||
}
|
||||
|
|
|
@ -262,10 +262,10 @@ class CommentItem(val comment: Comment,
|
|||
val minutes = diff / (60 * 1000) % 60
|
||||
|
||||
return when {
|
||||
days > 0 -> "$days days ago"
|
||||
hours > 0 -> "$hours hours ago"
|
||||
minutes > 0 -> "$minutes minutes ago"
|
||||
else -> "just now"
|
||||
days > 0 -> "${days}d"
|
||||
hours > 0 -> "${hours}h"
|
||||
minutes > 0 -> "${minutes}m"
|
||||
else -> "now"
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
"now"
|
||||
|
|
|
@ -11,6 +11,7 @@ import android.text.TextWatcher
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.WindowManager
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.EditText
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
@ -25,6 +26,7 @@ import ani.dantotsu.connections.anilist.Anilist
|
|||
import ani.dantotsu.connections.comments.Comment
|
||||
import ani.dantotsu.connections.comments.CommentResponse
|
||||
import ani.dantotsu.connections.comments.CommentsAPI
|
||||
import ani.dantotsu.copyToClipboard
|
||||
import ani.dantotsu.databinding.FragmentCommentsBinding
|
||||
import ani.dantotsu.loadImage
|
||||
import ani.dantotsu.media.MediaDetailsActivity
|
||||
|
@ -88,7 +90,6 @@ class CommentsFragment : Fragment() {
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
activity = requireActivity() as AppCompatActivity
|
||||
(activity as? MediaDetailsActivity)?.binding?.mediaAppBar?.setExpanded(false, true)
|
||||
//get the media id from the intent
|
||||
val mediaId = arguments?.getInt("mediaId") ?: -1
|
||||
mediaName = arguments?.getString("mediaName") ?: "unknown"
|
||||
|
@ -695,7 +696,7 @@ class CommentsFragment : Fragment() {
|
|||
.usePlugin(object : AbstractMarkwonPlugin() {
|
||||
override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
|
||||
builder.linkResolver { view, link ->
|
||||
// do nothing
|
||||
copyToClipboard(link, true)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -372,11 +372,7 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener {
|
|||
activity.findViewById<ViewPager2>(R.id.mediaViewPager).visibility = visibility
|
||||
activity.findViewById<CardView>(R.id.mediaCover).visibility = visibility
|
||||
activity.findViewById<CardView>(R.id.mediaClose).visibility = visibility
|
||||
try {
|
||||
activity.findViewById<CustomBottomNavBar>(R.id.mediaTab).visibility = visibility
|
||||
} catch (e: ClassCastException) {
|
||||
activity.findViewById<NavigationRailView>(R.id.mediaTab).visibility = visibility
|
||||
}
|
||||
activity.tabLayout.setVisibility(visibility)
|
||||
activity.findViewById<FrameLayout>(R.id.fragmentExtensionsContainer).visibility =
|
||||
if (show) View.GONE else View.VISIBLE
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package ani.dantotsu.others
|
||||
|
||||
import android.app.Activity
|
||||
import android.graphics.Rect
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
|
||||
class AndroidBug5497Workaround private constructor(activity: Activity, private val callback: (Boolean) -> Unit) {
|
||||
private val mChildOfContent: View
|
||||
private var usableHeightPrevious = 0
|
||||
private val frameLayoutParams: FrameLayout.LayoutParams
|
||||
|
||||
init {
|
||||
val content = activity.findViewById(android.R.id.content) as FrameLayout
|
||||
mChildOfContent = content.getChildAt(0)
|
||||
mChildOfContent.viewTreeObserver.addOnGlobalLayoutListener { possiblyResizeChildOfContent() }
|
||||
frameLayoutParams = mChildOfContent.layoutParams as FrameLayout.LayoutParams
|
||||
}
|
||||
|
||||
private fun possiblyResizeChildOfContent() {
|
||||
val usableHeightNow = computeUsableHeight()
|
||||
if (usableHeightNow != usableHeightPrevious) {
|
||||
val usableHeightSansKeyboard = mChildOfContent.rootView.height
|
||||
val heightDifference = usableHeightSansKeyboard - usableHeightNow
|
||||
if (heightDifference > usableHeightSansKeyboard / 4) {
|
||||
// keyboard probably just became visible
|
||||
callback.invoke(true)
|
||||
frameLayoutParams.height = usableHeightSansKeyboard - heightDifference
|
||||
} else {
|
||||
// keyboard probably just became hidden
|
||||
callback.invoke(false)
|
||||
frameLayoutParams.height = usableHeightSansKeyboard
|
||||
}
|
||||
mChildOfContent.requestLayout()
|
||||
usableHeightPrevious = usableHeightNow
|
||||
}
|
||||
}
|
||||
|
||||
private fun computeUsableHeight(): Int {
|
||||
val r = Rect()
|
||||
mChildOfContent.getWindowVisibleDisplayFrame(r)
|
||||
return r.bottom
|
||||
}
|
||||
|
||||
companion object {
|
||||
// For more information, see https://issuetracker.google.com/issues/36911528
|
||||
// To use this class, simply invoke assistActivity() on an Activity that already has its content view set.
|
||||
fun assistActivity(activity: Activity, callback: (Boolean) -> Unit) {
|
||||
AndroidBug5497Workaround(activity, callback)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ import android.text.Editable
|
|||
import android.text.TextWatcher
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.WindowManager
|
||||
import android.widget.AutoCompleteTextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.updateLayoutParams
|
||||
|
@ -17,6 +18,7 @@ import androidx.viewpager2.adapter.FragmentStateAdapter
|
|||
import androidx.viewpager2.widget.ViewPager2
|
||||
import ani.dantotsu.*
|
||||
import ani.dantotsu.databinding.ActivityExtensionsBinding
|
||||
import ani.dantotsu.others.AndroidBug5497Workaround
|
||||
import ani.dantotsu.others.LanguageMapper
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
|
@ -34,7 +36,22 @@ class ExtensionsActivity : AppCompatActivity() {
|
|||
ThemeManager(this).applyTheme()
|
||||
binding = ActivityExtensionsBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
initActivity(this)
|
||||
AndroidBug5497Workaround.assistActivity(this) {
|
||||
if (it) {
|
||||
binding.searchView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
bottomMargin = statusBarHeight
|
||||
}
|
||||
} else {
|
||||
binding.searchView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
bottomMargin = statusBarHeight + navBarHeight
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
binding.searchView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
bottomMargin = statusBarHeight + navBarHeight
|
||||
}
|
||||
|
||||
val tabLayout = findViewById<TabLayout>(R.id.tabLayout)
|
||||
val viewPager = findViewById<ViewPager2>(R.id.viewPager)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue