-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: simplify SessionFilter logic (#341)
- Loading branch information
Showing
6 changed files
with
73 additions
and
101 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
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
26 changes: 21 additions & 5 deletions
26
shared/ui/src/commonMain/kotlin/com/androidmakers/ui/common/SessionFilter.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,9 +1,25 @@ | ||
package com.androidmakers.ui.common | ||
|
||
data class SessionFilter(val type: FilterType, val value: Any) { | ||
enum class FilterType { | ||
BOOKMARK, | ||
LANGUAGE, | ||
ROOM | ||
import com.androidmakers.ui.model.UISession | ||
|
||
sealed interface SessionFilter { | ||
|
||
fun matches(session: UISession): Boolean | ||
|
||
data object Bookmark : SessionFilter { | ||
override fun matches(session: UISession) = session.isFavorite | ||
} | ||
|
||
data class Language(val value: String) : SessionFilter { | ||
override fun matches(session: UISession) = session.language == value | ||
|
||
companion object { | ||
const val FRENCH = "French" | ||
const val ENGLISH = "English" | ||
} | ||
} | ||
|
||
data class Room(val id: String) : SessionFilter { | ||
override fun matches(session: UISession): Boolean = session.roomId == id | ||
} | ||
} |
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