Moving collapse/expand categories button back to filter sheet

I just can't decide
This commit is contained in:
Jays2Kings 2021-04-19 00:31:28 -04:00
parent 4bb6dbf528
commit 17809d0493
6 changed files with 74 additions and 65 deletions

View File

@ -913,12 +913,12 @@ class LibraryController(
} }
binding.categoryHopperFrame.visibleIf(!singleCategory && !preferences.hideHopper().get()) binding.categoryHopperFrame.visibleIf(!singleCategory && !preferences.hideHopper().get())
binding.filterBottomSheet.filterBottomSheet.updateButtons(
groupType = presenter.groupType
)
adapter.isLongPressDragEnabled = canDrag() adapter.isLongPressDragEnabled = canDrag()
binding.categoryRecycler.setCategories(presenter.categories) binding.categoryRecycler.setCategories(presenter.categories)
displaySheet?.setExpandText(canCollapseOrExpandCategory()) with(binding.filterBottomSheet.root) {
updateGroupTypeButton(presenter.groupType)
setExpandText(canCollapseOrExpandCategory())
}
if (shouldScrollToTop) { if (shouldScrollToTop) {
binding.libraryGridRecycler.recycler.scrollToPosition(0) binding.libraryGridRecycler.recycler.scrollToPosition(0)
shouldScrollToTop = false shouldScrollToTop = false

View File

@ -1,12 +1,8 @@
package eu.kanade.tachiyomi.ui.library.display package eu.kanade.tachiyomi.ui.library.display
import android.content.Context import android.content.Context
import android.graphics.drawable.AnimatedVectorDrawable
import android.util.AttributeSet import android.util.AttributeSet
import androidx.core.view.isVisible
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.LibraryCategoryLayoutBinding import eu.kanade.tachiyomi.databinding.LibraryCategoryLayoutBinding
import eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet
import eu.kanade.tachiyomi.util.bindToPreference import eu.kanade.tachiyomi.util.bindToPreference
import eu.kanade.tachiyomi.util.system.toInt import eu.kanade.tachiyomi.util.system.toInt
import eu.kanade.tachiyomi.widget.BaseLibraryDisplayView import eu.kanade.tachiyomi.widget.BaseLibraryDisplayView
@ -41,41 +37,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
addCategoriesButton.setOnClickListener { addCategoriesButton.setOnClickListener {
controller?.showCategoriesController() controller?.showCategoriesController()
} }
expandCollapseCategories.setOnClickListener {
controller?.binding?.filterBottomSheet?.root
?.onGroupClicked?.invoke(FilterBottomSheet.ACTION_EXPAND_COLLAPSE_ALL)
}
hopperLongPress.bindToPreference(preferences.hopperLongPressAction()) hopperLongPress.bindToPreference(preferences.hopperLongPressAction())
} }
} }
fun setExpandText(allExpanded: Boolean?, animated: Boolean = true) {
binding.expandCollapseCategories.isVisible = allExpanded != null
allExpanded ?: return
binding.expandCollapseCategories.setText(
if (!allExpanded) {
R.string.expand_all_categories
} else {
R.string.collapse_all_categories
}
)
if (animated) {
binding.expandCollapseCategories.setIconResource(
if (!allExpanded) {
R.drawable.anim_expand_less_to_more
} else {
R.drawable.anim_expand_more_to_less
}
)
(binding.expandCollapseCategories.icon as? AnimatedVectorDrawable)?.start()
} else {
binding.expandCollapseCategories.setIconResource(
if (!allExpanded) {
R.drawable.ic_expand_more_24dp
} else {
R.drawable.ic_expand_less_24dp
}
)
}
}
} }

View File

@ -37,17 +37,8 @@ open class TabbedLibraryDisplaySheet(val controller: Controller) :
controller.router.pushController(SettingsLibraryController().withFadeTransaction()) controller.router.pushController(SettingsLibraryController().withFadeTransaction())
dismiss() dismiss()
} }
categoryView.binding.addCategoriesButton.isVisible = controller is LibraryController
if (controller is LibraryController) {
setExpandText(controller.canCollapseOrExpandCategory(), false)
} else {
setExpandText(null)
categoryView.binding.addCategoriesButton.isVisible = false
} }
}
fun setExpandText(allExpanded: Boolean?, animated: Boolean = true) =
categoryView.setExpandText(allExpanded, animated)
override fun dismiss() { override fun dismiss() {
super.dismiss() super.dismiss()

View File

@ -1,12 +1,14 @@
package eu.kanade.tachiyomi.ui.library.filter package eu.kanade.tachiyomi.ui.library.filter
import android.content.Context import android.content.Context
import android.graphics.drawable.AnimatedVectorDrawable
import android.os.Parcelable import android.os.Parcelable
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.View
import android.widget.ImageView import android.widget.ImageView
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.core.view.isVisible
import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.DatabaseHelper
@ -129,7 +131,22 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
} }
) )
post {
if (binding.secondLayout.width + binding.firstLayout.width + 20.dpToPx < width) {
binding.secondLayout.removeView(binding.viewOptions)
binding.firstLayout.addView(binding.viewOptions)
binding.secondLayout.isVisible = false
} else if (binding.viewOptions.parent == binding.firstLayout) {
binding.firstLayout.removeView(binding.viewOptions)
binding.secondLayout.addView(binding.viewOptions)
binding.secondLayout.isVisible = true
}
}
sheetBehavior?.hide() sheetBehavior?.hide()
binding.expandCategories.setOnClickListener {
onGroupClicked(ACTION_EXPAND_COLLAPSE_ALL)
}
binding.groupBy.setOnClickListener { binding.groupBy.setOnClickListener {
onGroupClicked(ACTION_GROUP_BY) onGroupClicked(ACTION_GROUP_BY)
} }
@ -157,6 +174,8 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
createTags() createTags()
clearButton.setOnClickListener { clearFilters() } clearButton.setOnClickListener { clearFilters() }
setExpandText(controller.canCollapseOrExpandCategory(), false)
clearButton.compatToolTipText = context.getString(R.string.clear_filters) clearButton.compatToolTipText = context.getString(R.string.clear_filters)
preferences.filterOrder().asFlow() preferences.filterOrder().asFlow()
.drop(1) .drop(1)
@ -205,6 +224,36 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
} }
} }
fun setExpandText(allExpanded: Boolean?, animated: Boolean = true) {
binding.expandCategories.isVisible = allExpanded != null
allExpanded ?: return
binding.expandCategories.setText(
if (!allExpanded) {
R.string.expand_all_categories
} else {
R.string.collapse_all_categories
}
)
if (animated) {
binding.expandCategories.setIconResource(
if (!allExpanded) {
R.drawable.anim_expand_less_to_more
} else {
R.drawable.anim_expand_more_to_less
}
)
(binding.expandCategories.icon as? AnimatedVectorDrawable)?.start()
} else {
binding.expandCategories.setIconResource(
if (!allExpanded) {
R.drawable.ic_expand_more_24dp
} else {
R.drawable.ic_expand_less_24dp
}
)
}
}
fun hasActiveFilters() = filterItems.any { it.isActivated } fun hasActiveFilters() = filterItems.any { it.isActivated }
private fun hasActiveFiltersFromPref(): Boolean { private fun hasActiveFiltersFromPref(): Boolean {
@ -400,7 +449,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
} }
} }
fun updateButtons(groupType: Int) { fun updateGroupTypeButton(groupType: Int) {
binding.groupBy.setIconResource(LibraryGroup.groupTypeDrawableRes(groupType)) binding.groupBy.setIconResource(LibraryGroup.groupTypeDrawableRes(groupType))
} }

View File

@ -93,6 +93,24 @@
app:icon="@drawable/ic_label_outline_24dp" app:icon="@drawable/ic_label_outline_24dp"
app:iconTint="?android:attr/textColorPrimary" /> app:iconTint="?android:attr/textColorPrimary" />
<com.google.android.material.button.MaterialButton
android:id="@+id/expand_categories"
style="@style/Theme.Widget.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
android:text="@string/expand_all_categories"
android:textColor="?android:attr/textColorPrimary"
app:icon="@drawable/ic_expand_more_24dp"
app:iconTint="?android:attr/textColorPrimary" />
</LinearLayout>
<LinearLayout
android:id="@+id/second_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/view_options" android:id="@+id/view_options"
style="@style/Theme.Widget.Button.TextButton" style="@style/Theme.Widget.Button.TextButton"
@ -104,6 +122,7 @@
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
app:icon="@drawable/ic_tune_24dp" app:icon="@drawable/ic_tune_24dp"
app:iconTint="?android:attr/textColorPrimary" /> app:iconTint="?android:attr/textColorPrimary" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -11,18 +11,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<com.google.android.material.button.MaterialButton
android:id="@+id/expand_collapse_categories"
style="@style/Theme.Widget.Button.TextButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="textStart"
app:icon="@drawable/ic_expand_more_24dp"
android:layout_marginStart="8dp"
android:textColor="?android:attr/textColorPrimary"
app:iconTint="?android:attr/textColorPrimary"
android:text="@string/expand_all_categories" />
<com.google.android.material.checkbox.MaterialCheckBox <com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/category_show" android:id="@+id/category_show"
android:layout_width="match_parent" android:layout_width="match_parent"