mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2025-01-11 23:49:10 +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 android.util.AttributeSet
|
||||||
import androidx.appcompat.graphics.drawable.DrawerArrowDrawable
|
import androidx.appcompat.graphics.drawable.DrawerArrowDrawable
|
||||||
import com.google.android.material.appbar.MaterialToolbar
|
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.*
|
import kotlinx.android.synthetic.main.main_activity.view.*
|
||||||
|
|
||||||
class CenteredToolbar@JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
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) {
|
if (navigationIcon is DrawerArrowDrawable) {
|
||||||
super.setTitle(resId)
|
super.setTitle(resId)
|
||||||
toolbar_title.text = null
|
toolbar_title.text = null
|
||||||
dropdown?.gone()
|
hideDropdown()
|
||||||
} else {
|
} else {
|
||||||
toolbar_title.text = context.getString(resId)
|
toolbar_title.text = context.getString(resId)
|
||||||
super.setTitle(null)
|
super.setTitle(null)
|
||||||
@ -25,10 +25,23 @@ class CenteredToolbar@JvmOverloads constructor(context: Context, attrs: Attribut
|
|||||||
if (navigationIcon is DrawerArrowDrawable) {
|
if (navigationIcon is DrawerArrowDrawable) {
|
||||||
super.setTitle(title)
|
super.setTitle(title)
|
||||||
toolbar_title.text = ""
|
toolbar_title.text = ""
|
||||||
dropdown?.gone()
|
hideDropdown()
|
||||||
} else {
|
} else {
|
||||||
toolbar_title.text = title
|
toolbar_title.text = title
|
||||||
super.setTitle(null)
|
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)
|
LibraryUpdateService.setListener(this)
|
||||||
recycler_cover.isClickable = false
|
recycler_cover.isClickable = false
|
||||||
recycler_cover.isFocusable = false
|
recycler_cover.isFocusable = false
|
||||||
if (onRoot) {
|
showDropdown()
|
||||||
activity?.dropdown?.visibleIf(!singleCategory)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
closeTip()
|
closeTip()
|
||||||
activity?.dropdown?.gone()
|
activity?.toolbar?.hideDropdown()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onChangeEnded(handler: ControllerChangeHandler, type: ControllerChangeType) {
|
override fun onChangeEnded(handler: ControllerChangeHandler, type: ControllerChangeType) {
|
||||||
super.onChangeEnded(handler, type)
|
super.onChangeEnded(handler, type)
|
||||||
if (!type.isEnter) {
|
if (!type.isEnter) {
|
||||||
activity?.dropdown?.gone()
|
activity?.toolbar?.hideDropdown()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -681,9 +679,7 @@ class LibraryController(
|
|||||||
recycler.itemAnimator = DefaultItemAnimator()
|
recycler.itemAnimator = DefaultItemAnimator()
|
||||||
}
|
}
|
||||||
singleCategory = presenter.categories.size <= 1
|
singleCategory = presenter.categories.size <= 1
|
||||||
if (onRoot) {
|
showDropdown()
|
||||||
activity?.dropdown?.visibleIf(!singleCategory)
|
|
||||||
}
|
|
||||||
progress.gone()
|
progress.gone()
|
||||||
if (!freshStart) {
|
if (!freshStart) {
|
||||||
justStarted = false
|
justStarted = false
|
||||||
@ -712,6 +708,15 @@ class LibraryController(
|
|||||||
}
|
}
|
||||||
if (!hasMovedHopper && isAnimatingHopper == null) {
|
if (!hasMovedHopper && isAnimatingHopper == null) {
|
||||||
showSlideAnimation()
|
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"
|
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:drawableTint="?actionBarTintColor"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:gravity="start"
|
android:gravity="start"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:textColor="?actionBarTintColor"
|
android:textColor="?actionBarTintColor"
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
|
tools:drawableEnd="@drawable/ic_arrow_drop_down_24dp"
|
||||||
|
tools:drawableStart="@drawable/ic_blank_24dp"
|
||||||
tools:text="Title Text" />
|
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>
|
</LinearLayout>
|
||||||
</eu.kanade.tachiyomi.ui.base.CenteredToolbar>
|
</eu.kanade.tachiyomi.ui.base.CenteredToolbar>
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user