Skip to content

Commit

Permalink
New filter sheet draft implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Koitharu committed Dec 5, 2023
1 parent 64dc646 commit 6c07abe
Show file tree
Hide file tree
Showing 18 changed files with 512 additions and 234 deletions.
10 changes: 10 additions & 0 deletions app/src/main/kotlin/org/koitharu/kotatsu/core/model/Manga.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.koitharu.kotatsu.core.model

import android.net.Uri
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.core.os.LocaleListCompat
import org.koitharu.kotatsu.R
Expand Down Expand Up @@ -43,6 +44,15 @@ val MangaState.titleResId: Int
MangaState.PAUSED -> R.string.state_paused
}

@get:DrawableRes
val MangaState.iconResId: Int
get() = when (this) {
MangaState.ONGOING -> R.drawable.ic_state_ongoing
MangaState.FINISHED -> R.drawable.ic_state_finished
MangaState.ABANDONED -> R.drawable.ic_state_abandoned
MangaState.PAUSED -> R.drawable.ic_action_pause
}

fun Manga.findChapter(id: Long): MangaChapter? {
return chapters?.findById(id)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ class ChipsView @JvmOverloads constructor(
defaultChipTextColor = a.getColorStateListOrThrow(materialR.styleable.Chip_android_textColor)
defaultChipIconTint = a.getColorStateListOrThrow(materialR.styleable.Chip_chipIconTint)
a.recycle()

if (isInEditMode) {
setChips(
List(5) {
ChipModel(0, "Chip $it", 0, false, false)
},
)
}
}

override fun requestLayout() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import org.koitharu.kotatsu.core.exceptions.SyncApiException
import org.koitharu.kotatsu.core.exceptions.TooManyRequestExceptions
import org.koitharu.kotatsu.core.exceptions.UnsupportedFileException
import org.koitharu.kotatsu.core.exceptions.WrongPasswordException
import org.koitharu.kotatsu.parsers.ErrorMessages.FILTER_BOTH_LOCALE_GENRES_NOT_SUPPORTED
import org.koitharu.kotatsu.parsers.ErrorMessages.FILTER_BOTH_STATES_GENRES_NOT_SUPPORTED
import org.koitharu.kotatsu.parsers.ErrorMessages.FILTER_MULTIPLE_GENRES_NOT_SUPPORTED
import org.koitharu.kotatsu.parsers.ErrorMessages.FILTER_MULTIPLE_STATES_NOT_SUPPORTED
import org.koitharu.kotatsu.parsers.ErrorMessages.SEARCH_NOT_SUPPORTED
import org.koitharu.kotatsu.parsers.exception.AuthRequiredException
import org.koitharu.kotatsu.parsers.exception.ContentUnavailableException
import org.koitharu.kotatsu.parsers.exception.NotFoundException
Expand All @@ -28,9 +33,6 @@ import java.net.UnknownHostException

private const val MSG_NO_SPACE_LEFT = "No space left on device"
private const val IMAGE_FORMAT_NOT_SUPPORTED = "Image format not supported"
private const val MULTIPLE_GENRES_NOT_SUPPORTED = "Multiple genres are not supported by this source"
private const val MULTIPLE_STATES_NOT_SUPPORTED = "Multiple states are not supported by this source"
private const val SEARCH_NOT_SUPPORTED = "Search is not supported by this source"

fun Throwable.getDisplayMessage(resources: Resources): String = when (this) {
is AuthRequiredException -> resources.getString(R.string.auth_required)
Expand Down Expand Up @@ -85,9 +87,11 @@ private fun getDisplayMessage(msg: String?, resources: Resources): String? = whe
msg.isNullOrEmpty() -> null
msg.contains(MSG_NO_SPACE_LEFT) -> resources.getString(R.string.error_no_space_left)
msg.contains(IMAGE_FORMAT_NOT_SUPPORTED) -> resources.getString(R.string.error_corrupted_file)
msg == MULTIPLE_GENRES_NOT_SUPPORTED -> resources.getString(R.string.error_multiple_genres_not_supported)
msg == MULTIPLE_STATES_NOT_SUPPORTED -> resources.getString(R.string.error_multiple_states_not_supported)
msg == FILTER_MULTIPLE_GENRES_NOT_SUPPORTED -> resources.getString(R.string.error_multiple_genres_not_supported)
msg == FILTER_MULTIPLE_STATES_NOT_SUPPORTED -> resources.getString(R.string.error_multiple_states_not_supported)
msg == SEARCH_NOT_SUPPORTED -> resources.getString(R.string.error_search_not_supported)
msg == FILTER_BOTH_LOCALE_GENRES_NOT_SUPPORTED -> resources.getString(R.string.error_filter_locale_genre_not_supported)
msg == FILTER_BOTH_STATES_GENRES_NOT_SUPPORTED -> resources.getString(R.string.error_filter_states_genre_not_supported)
else -> null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fun filterSortDelegate(
) {

itemView.setOnClickListener {
listener.onSortItemClick(item)
listener.setSortOrder(item.order)
}

bind { payloads ->
Expand All @@ -35,7 +35,7 @@ fun filterStateDelegate(
) {

itemView.setOnClickListener {
listener.onStateItemClick(item)
listener.setState(item.state, !item.isChecked)
}

bind { payloads ->
Expand All @@ -52,7 +52,7 @@ fun filterLanguageDelegate(
) {

itemView.setOnClickListener {
listener.onLanguageItemClick(item)
listener.setLanguage(item.locale)
}

bind { payloads ->
Expand All @@ -69,7 +69,7 @@ fun filterTagDelegate(
) {

itemView.setOnClickListener {
listener.onTagItemClick(item, isFromChip = false)
listener.setTag(item.tag, !item.isChecked)
}

bind { payloads ->
Expand All @@ -86,7 +86,7 @@ fun filterTagMultipleDelegate(
) {

itemView.setOnClickListener {
listener.onTagItemClick(item, isFromChip = false)
listener.setTag(item.tag, !item.isChecked)
}

bind { payloads ->
Expand Down
Loading

0 comments on commit 6c07abe

Please sign in to comment.