-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from dmzz-yyhyy/word_count_filter
添加字数筛选器
- Loading branch information
Showing
14 changed files
with
261 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
...c/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/data/web/exploration/filter/FilterTypes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package indi.dmzz_yyhyy.lightnovelreader.data.web.exploration.filter | ||
|
||
enum class FilterTypes(name: String) { | ||
SWITCH("switch"), | ||
SINGLE_CHOICE("single_choice"), | ||
enum class FilterTypes { | ||
SWITCH, | ||
SINGLE_CHOICE, | ||
SLIDER | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
.../main/kotlin/indi/dmzz_yyhyy/lightnovelreader/data/web/exploration/filter/SliderFilter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package indi.dmzz_yyhyy.lightnovelreader.data.web.exploration.filter | ||
|
||
import androidx.annotation.IntRange | ||
|
||
abstract class SliderFilter( | ||
private val title: String, | ||
val description: String, | ||
defaultValue: Float, | ||
val valueRange: ClosedFloatingPointRange<Float>, | ||
@IntRange(from = 0) val steps: Int = 0, | ||
private val onChange: () -> Unit | ||
) : Filter() { | ||
abstract var enabled: Boolean | ||
abstract val displayValue: String | ||
open val displayTitle = title | ||
|
||
var value: Float = defaultValue | ||
set(value) { | ||
onChange() | ||
field = value | ||
} | ||
override fun getType(): FilterTypes = FilterTypes.SLIDER | ||
override fun getTitle(): String = title | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...in/kotlin/indi/dmzz_yyhyy/lightnovelreader/data/web/exploration/filter/WordCountFilter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package indi.dmzz_yyhyy.lightnovelreader.data.web.exploration.filter | ||
|
||
import indi.dmzz_yyhyy.lightnovelreader.data.book.BookInformation | ||
|
||
class WordCountFilter(onChange: () -> Unit) : SliderFilter( | ||
title = "字数限制", | ||
description = "仅显示字数大于该值的书本,若为0则显示全部书本。", | ||
defaultValue = 0f, | ||
valueRange = 0f..200_0000f, | ||
steps = 9, | ||
onChange = onChange | ||
), LocalFilter { | ||
override var enabled: Boolean | ||
get() = value != 0f | ||
set(value) { if (!value) this.value = 0f } | ||
override val displayValue: String | ||
get() = if (value == 0f) "无限制" else "${(value / 1000).toInt()}K" | ||
|
||
override val displayTitle: String | ||
get() = "字数" | ||
override fun filter(bookInformation: BookInformation): Boolean = | ||
!enabled || bookInformation.wordCount >= value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.