Added "manga" to filter type

closes #381
This commit is contained in:
Jay 2020-05-19 20:55:01 -04:00
parent dd327bdb48
commit 0809a7b7ff
5 changed files with 80 additions and 57 deletions

View File

@ -108,7 +108,7 @@ interface Manga : SManga {
{ tag ->
tag == "chinese" || tag == "manhua" ||
tag.startsWith("english") || tag == "comic"
} == true || (isComicSource(sourceName) && !sourceName.contains("tapastic", true)) ||
} == true || (isComicSource(sourceName) && !sourceName.contains("tapas", true)) ||
sourceName.contains("manhua", true)
)
ReaderActivity.LEFT_TO_RIGHT
@ -142,7 +142,7 @@ interface Manga : SManga {
sourceName.contains("dilbert", true) ||
sourceName.contains("cyanide", true) ||
sourceName.contains("xkcd", true) ||
sourceName.contains("tapastic", true)
sourceName.contains("tapas", true)
}
fun key(): String {
@ -212,11 +212,11 @@ interface Manga : SManga {
const val DISPLAY_NUMBER = 0x00100000
const val DISPLAY_MASK = 0x00100000
const val TYPE_MANGA = 0
const val TYPE_MANHWA = 1
const val TYPE_MANHUA = 2
const val TYPE_COMIC = 3
const val TYPE_WEBTOON = 4
const val TYPE_MANGA = 1
const val TYPE_MANHWA = 2
const val TYPE_MANHUA = 3
const val TYPE_COMIC = 4
const val TYPE_WEBTOON = 5
fun create(source: Long): Manga = MangaImpl().apply {
this.source = source

View File

@ -242,8 +242,11 @@ class LibraryPresenter(
if (filterUnread == 4 && !(item.manga.unread > 0 && item.manga.hasRead)) return false
if (filterMangaType > 0) {
if (if (filterMangaType == Manga.TYPE_MANHWA) (filterMangaType != item.manga.mangaType() && filterMangaType != Manga.TYPE_WEBTOON)
else filterMangaType != item.manga.mangaType()
if (if (filterMangaType == Manga.TYPE_MANHWA) {
(filterMangaType != item.manga.mangaType() && filterMangaType != Manga.TYPE_WEBTOON)
} else {
filterMangaType != item.manga.mangaType()
}
) return false
}

View File

@ -57,7 +57,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
private val trackManager: TrackManager by injectLazy()
val hasTracking
private val hasTracking
get() = trackManager.hasLoggedServices()
private lateinit var downloaded: FilterTagGroup
@ -264,6 +264,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
val mangaType = inflate(R.layout.filter_buttons) as FilterTagGroup
mangaType.setup(
this@FilterBottomSheet,
R.string.manga,
types.first(),
types.getOrNull(1),
types.getOrNull(2)
@ -283,7 +284,13 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
unreadProgress.state = unreadP - 3
}
tracked?.setState(preferences.filterTracked())
mangaType?.setState(preferences.filterMangaType())
mangaType?.setState(when (preferences.filterMangaType().getOrDefault()) {
Manga.TYPE_MANGA -> context.getString(R.string.manga)
Manga.TYPE_MANHUA -> context.getString(R.string.manhua)
Manga.TYPE_MANHWA -> context.getString(R.string.manhwa)
Manga.TYPE_COMIC -> context.getString(R.string.comic)
else -> ""
})
reorderFilters()
reSortViews()
}
@ -409,7 +416,17 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri
downloaded -> preferences.filterDownloaded()
completed -> preferences.filterCompleted()
tracked -> preferences.filterTracked()
mangaType -> preferences.filterMangaType()
mangaType -> {
val newIndex = when (view.nameOf(index)) {
context.getString(R.string.manga) -> Manga.TYPE_MANGA
context.getString(R.string.manhua) -> Manga.TYPE_MANHUA
context.getString(R.string.manhwa) -> Manga.TYPE_MANHWA
context.getString(R.string.comic) -> Manga.TYPE_COMIC
else -> 0
}
preferences.filterMangaType().set(newIndex)
null
}
else -> null
}?.set(index + 1)
onGroupClicked(ACTION_FILTER)

View File

@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.visible
import eu.kanade.tachiyomi.util.view.visibleIf
import kotlinx.android.synthetic.main.filter_buttons.view.*
class FilterTagGroup@JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : LinearLayout
@ -24,8 +25,8 @@ class FilterTagGroup@JvmOverloads constructor(context: Context, attrs: Attribute
private var root: ViewGroup? = null
private val buttons by lazy { arrayOf(firstButton, secondButton, thirdButton) }
private val separators by lazy { arrayOf(separator1, separator2) }
private val buttons by lazy { arrayOf(firstButton, secondButton, thirdButton, fourthButton) }
private val separators by lazy { arrayOf(separator1, separator2, separator3) }
override fun isActivated(): Boolean {
return buttons.any { it.isActivated }
@ -33,45 +34,28 @@ class FilterTagGroup@JvmOverloads constructor(context: Context, attrs: Attribute
fun nameOf(index: Int): String? = buttons.getOrNull(index)?.text as? String
fun setup(root: ViewGroup, firstText: Int, secondText: Int? = null, thirdText: Int? = null) {
fun setup(root: ViewGroup, firstText: Int, vararg extra: Int?) {
val text1 = context.getString(firstText)
val text2 = if (secondText != null) context.getString(secondText) else null
val text3 = if (thirdText != null) context.getString(thirdText) else null
setup(root, text1, text2, text3)
val strings = extra.mapNotNull { if (it != null) context.getString(it) else null }
setup(root, text1, extra = *strings.toTypedArray())
}
fun setup(
root: ViewGroup,
firstText: String,
secondText: String? = null,
thirdText: String? =
null
) {
fun setup(root: ViewGroup, firstText: String, vararg extra: String?) {
listener = root as? FilterTagGroupListener
(layoutParams as? MarginLayoutParams)?.rightMargin = 5.dpToPx
(layoutParams as? MarginLayoutParams)?.leftMargin = 5.dpToPx
firstButton.text = firstText
if (secondText != null) {
secondButton.text = secondText
itemCount = 2
if (thirdText != null) {
thirdButton.text = thirdText
itemCount = 3
} else {
thirdButton.gone()
separator2.gone()
}
} else {
itemCount = 1
secondButton.gone()
separator1.gone()
thirdButton.gone()
separator2.gone()
val extras = (extra.toList() + listOf<String?>(null, null, null)).take(separators.size)
extras.forEachIndexed { index, text ->
buttons[index + 1].text = text
separators[index].visibleIf(text != null)
buttons[index + 1].visibleIf(text != null)
}
itemCount = buttons.count { !it.text.isNullOrBlank() }
this.root = root
firstButton.setOnClickListener { toggleButton(0) }
secondButton.setOnClickListener { toggleButton(1) }
thirdButton.setOnClickListener { toggleButton(2) }
buttons.forEachIndexed { index, textView ->
textView.setOnClickListener { toggleButton(index) }
}
}
var state: Int
@ -115,27 +99,24 @@ class FilterTagGroup@JvmOverloads constructor(context: Context, attrs: Attribute
listener?.onFilterClicked(this, if (firstButton.isActivated) index else -1, callBack)
return
}
val buttons = mutableListOf(firstButton, secondButton)
if (itemCount >= 3)
buttons.add(thirdButton)
val mainButton = buttons[index]
buttons.remove(mainButton)
if (mainButton.isActivated) {
mainButton.isActivated = false
separator1.visible()
listener?.onFilterClicked(this, -1, callBack)
if (itemCount >= 3)
separator2.visible()
buttons.forEach { it.visible() }
buttons.forEachIndexed { viewIndex, textView ->
if (!textView.text.isNullOrBlank()) {
textView.visible()
if (viewIndex > 0) {
separators[viewIndex - 1].visible()
}
}
}
} else {
mainButton.isActivated = true
listener?.onFilterClicked(this, index, callBack)
buttons.forEach { it.gone() }
separator1.gone()
if (itemCount >= 3) {
separator2.gone()
}
buttons.forEach { if (it != mainButton) it.gone() }
separators.forEach { it.gone() }
}
mainButton.setTextColor(if (mainButton.isActivated) Color.WHITE else context
.getResourceColor(android.R.attr.textColorPrimary))

View File

@ -64,4 +64,26 @@
tools:text="Item 3"
android:paddingStart="20dp"
android:paddingEnd="20dp"/>
<View
android:id="@+id/separator3"
android:layout_width="1dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:background="@color/strong_divider"/>
<TextView
android:id="@+id/fourthButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
android:textSize="15sp"
android:textColor="?android:attr/textColorPrimary"
android:background="@drawable/oval_ripple"
android:clickable="true"
android:focusable="true"
android:textStyle="normal"
tools:text="Item 4"
android:paddingStart="20dp"
android:paddingEnd="20dp"/>
</eu.kanade.tachiyomi.ui.library.filter.FilterTagGroup>