mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-09 19:55:11 +01:00
Using compound drawables for centered toolbar
and making the library text centered even with the dropdown arrow showing
This commit is contained in:
parent
5bdd7dcea9
commit
83891c9b6b
@ -4,7 +4,7 @@ import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.appcompat.graphics.drawable.DrawerArrowDrawable
|
||||
import com.google.android.material.appbar.MaterialToolbar
|
||||
import eu.kanade.tachiyomi.util.view.gone
|
||||
import eu.kanade.tachiyomi.R
|
||||
import kotlinx.android.synthetic.main.main_activity.view.*
|
||||
|
||||
class CenteredToolbar@JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||
@ -14,7 +14,7 @@ class CenteredToolbar@JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
if (navigationIcon is DrawerArrowDrawable) {
|
||||
super.setTitle(resId)
|
||||
toolbar_title.text = null
|
||||
dropdown?.gone()
|
||||
hideDropdown()
|
||||
} else {
|
||||
toolbar_title.text = context.getString(resId)
|
||||
super.setTitle(null)
|
||||
@ -25,10 +25,23 @@ class CenteredToolbar@JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
if (navigationIcon is DrawerArrowDrawable) {
|
||||
super.setTitle(title)
|
||||
toolbar_title.text = ""
|
||||
dropdown?.gone()
|
||||
hideDropdown()
|
||||
} else {
|
||||
toolbar_title.text = title
|
||||
super.setTitle(null)
|
||||
}
|
||||
}
|
||||
|
||||
fun showDropdown(down: Boolean = true) {
|
||||
toolbar_title.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ic_blank_24dp, 0,
|
||||
if (down) {
|
||||
R.drawable.ic_arrow_drop_down_24dp
|
||||
} else {
|
||||
R.drawable.ic_arrow_drop_up_24dp
|
||||
}, 0)
|
||||
}
|
||||
|
||||
fun hideDropdown() {
|
||||
toolbar_title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0)
|
||||
}
|
||||
}
|
||||
|
@ -621,19 +621,17 @@ class LibraryController(
|
||||
LibraryUpdateService.setListener(this)
|
||||
recycler_cover.isClickable = false
|
||||
recycler_cover.isFocusable = false
|
||||
if (onRoot) {
|
||||
activity?.dropdown?.visibleIf(!singleCategory)
|
||||
}
|
||||
showDropdown()
|
||||
} else {
|
||||
closeTip()
|
||||
activity?.dropdown?.gone()
|
||||
activity?.toolbar?.hideDropdown()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onChangeEnded(handler: ControllerChangeHandler, type: ControllerChangeType) {
|
||||
super.onChangeEnded(handler, type)
|
||||
if (!type.isEnter) {
|
||||
activity?.dropdown?.gone()
|
||||
activity?.toolbar?.hideDropdown()
|
||||
}
|
||||
}
|
||||
|
||||
@ -681,9 +679,7 @@ class LibraryController(
|
||||
recycler.itemAnimator = DefaultItemAnimator()
|
||||
}
|
||||
singleCategory = presenter.categories.size <= 1
|
||||
if (onRoot) {
|
||||
activity?.dropdown?.visibleIf(!singleCategory)
|
||||
}
|
||||
showDropdown()
|
||||
progress.gone()
|
||||
if (!freshStart) {
|
||||
justStarted = false
|
||||
@ -712,6 +708,15 @@ class LibraryController(
|
||||
}
|
||||
if (!hasMovedHopper && isAnimatingHopper == null) {
|
||||
showSlideAnimation()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showDropdown() {
|
||||
if (onRoot) {
|
||||
if (!singleCategory) {
|
||||
activity?.toolbar?.showDropdown()
|
||||
} else {
|
||||
activity?.toolbar?.hideDropdown()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,22 +49,15 @@
|
||||
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableTint="?actionBarTintColor"
|
||||
android:ellipsize="end"
|
||||
android:gravity="start"
|
||||
android:maxLines="1"
|
||||
android:textColor="?actionBarTintColor"
|
||||
android:textSize="20sp"
|
||||
tools:drawableEnd="@drawable/ic_arrow_drop_down_24dp"
|
||||
tools:drawableStart="@drawable/ic_blank_24dp"
|
||||
tools:text="Title Text" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dropdown"
|
||||
android:visibility="gone"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="4dp"
|
||||
android:src="@drawable/ic_arrow_drop_down_24dp"
|
||||
android:tint="?actionBarTintColor" />
|
||||
</LinearLayout>
|
||||
</eu.kanade.tachiyomi.ui.base.CenteredToolbar>
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
Loading…
Reference in New Issue
Block a user