Skip to content

Commit

Permalink
add tag grouping
Browse files Browse the repository at this point in the history
  • Loading branch information
LuftVerbot committed Jul 29, 2023
1 parent b8693c7 commit b8ea6da
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ private fun groupTypeDrawableRes(type: Int): Int {
AnimeLibraryGroup.BY_STATUS -> R.drawable.ic_progress_clock_24dp
AnimeLibraryGroup.BY_TRACK_STATUS -> R.drawable.ic_sync_24dp
AnimeLibraryGroup.BY_SOURCE -> R.drawable.ic_browse_filled_24dp
AnimeLibraryGroup.BY_TAG -> R.drawable.ic_tag_24dp
AnimeLibraryGroup.UNGROUPED -> R.drawable.ic_ungroup_24dp
else -> R.drawable.ic_label_24dp
}
Expand All @@ -320,6 +321,7 @@ private fun ColumnScope.GroupPage(
buildList {
add(AnimeLibraryGroup.BY_DEFAULT)
add(AnimeLibraryGroup.BY_SOURCE)
add(AnimeLibraryGroup.BY_TAG)
add(AnimeLibraryGroup.BY_STATUS)
if (screenModel.trackServices.isNotEmpty()) {
add(AnimeLibraryGroup.BY_TRACK_STATUS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ private fun groupTypeDrawableRes(type: Int): Int {
MangaLibraryGroup.BY_STATUS -> R.drawable.ic_progress_clock_24dp
MangaLibraryGroup.BY_TRACK_STATUS -> R.drawable.ic_sync_24dp
MangaLibraryGroup.BY_SOURCE -> R.drawable.ic_browse_filled_24dp
MangaLibraryGroup.BY_TAG -> R.drawable.ic_tag_24dp
MangaLibraryGroup.UNGROUPED -> R.drawable.ic_ungroup_24dp
else -> R.drawable.ic_label_24dp
}
Expand All @@ -319,6 +320,7 @@ private fun ColumnScope.GroupPage(
buildList {
add(MangaLibraryGroup.BY_DEFAULT)
add(MangaLibraryGroup.BY_SOURCE)
add(MangaLibraryGroup.BY_TAG)
add(MangaLibraryGroup.BY_STATUS)
if (screenModel.trackServices.isNotEmpty()) {
add(MangaLibraryGroup.BY_TRACK_STATUS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ class AnimeLibraryUpdateJob(private val context: Context, workerParams: WorkerPa

val categoryId = inputData.getLong(KEY_CATEGORY, -1L)
// SY -->
val group = inputData.getInt(AnimeLibraryUpdateJob.KEY_GROUP, AnimeLibraryGroup.BY_DEFAULT)
val groupExtra = inputData.getString(AnimeLibraryUpdateJob.KEY_GROUP_EXTRA)
val group = inputData.getInt(KEY_GROUP, AnimeLibraryGroup.BY_DEFAULT)
val groupExtra = inputData.getString(KEY_GROUP_EXTRA)
// SY <--
addAnimeToQueue(categoryId, group, groupExtra)

Expand Down Expand Up @@ -231,6 +231,14 @@ class AnimeLibraryUpdateJob(private val context: Context, workerParams: WorkerPa

if (source != null) libraryAnime.filter { it.anime.source == source } else emptyList()
}
AnimeLibraryGroup.BY_TAG -> {
val tagExtra = groupExtra?.nullIfBlank()?.toIntOrNull()
val tag = libraryAnime.map { it.anime.genre }
.distinct()
.getOrNull(tagExtra ?: -1)

if (tag != null) libraryAnime.filter { it.anime.genre == tag } else emptyList()
}
AnimeLibraryGroup.BY_STATUS -> {
val statusExtra = groupExtra?.toLongOrNull() ?: -1
libraryAnime.filter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ class MangaLibraryUpdateJob(private val context: Context, workerParams: WorkerPa

if (source != null) libraryManga.filter { it.manga.source == source } else emptyList()
}
MangaLibraryGroup.BY_TAG -> {
val tagExtra = groupExtra?.nullIfBlank()?.toIntOrNull()
val tag = libraryManga.map { it.manga.genre }
.distinct()
.getOrNull(tagExtra ?: -1)
if (tag != null) libraryManga.filter { it.manga.genre == tag } else emptyList()
}
MangaLibraryGroup.BY_STATUS -> {
val statusExtra = groupExtra?.toLongOrNull() ?: -1
libraryManga.filter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ class AnimeLibraryScreenModel(
mapOf(
Category(
0,
preferences.context.getString(eu.kanade.tachiyomi.R.string.ungrouped),
preferences.context.getString(R.string.ungrouped),
0,
0,
) to
Expand Down Expand Up @@ -784,6 +784,25 @@ class AnimeLibraryScreenModel(
)
}
}
AnimeLibraryGroup.BY_TAG -> {
val tags: List<String> = libraryAnime.flatMap { item ->
item.libraryAnime.anime.genre?.distinct() ?: emptyList()
}
libraryAnime.flatMap { item ->
item.libraryAnime.anime.genre?.distinct()?.map {
genre ->
Pair(genre, item)
} ?: emptyList()
}.groupBy({ it.first }, { it.second }).filterValues { it.size > 3 }
.mapKeys { (genre, _) ->
Category(
id = genre.hashCode().toLong(),
name = genre,
order = tags.indexOf(genre).takeUnless { it == -1 }?.toLong() ?: Long.MAX_VALUE,
flags = 0,
)
}
}
else -> {
libraryAnime.groupBy { item ->
item.libraryAnime.anime.status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ object AnimeLibraryTab : Tab {
group = state.groupType,
groupExtra = when (state.groupType) {
AnimeLibraryGroup.BY_DEFAULT -> null
AnimeLibraryGroup.BY_SOURCE, AnimeLibraryGroup.BY_TRACK_STATUS -> category?.id?.toString()
AnimeLibraryGroup.BY_SOURCE, AnimeLibraryGroup.BY_TRACK_STATUS, AnimeLibraryGroup.BY_TAG -> category?.id?.toString()
AnimeLibraryGroup.BY_STATUS -> category?.id?.minus(1)?.toString()
else -> null
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,25 @@ class MangaLibraryScreenModel(
)
}
}
MangaLibraryGroup.BY_TAG -> {
val tags: List<String> = libraryManga.flatMap { item ->
item.libraryManga.manga.genre?.distinct() ?: emptyList()
}
libraryManga.flatMap { item ->
item.libraryManga.manga.genre?.distinct()?.map {
genre ->
Pair(genre, item)
} ?: emptyList()
}.groupBy({ it.first }, { it.second }).filterValues { it.size > 3 }
.mapKeys { (genre, _) ->
Category(
id = genre.hashCode().toLong(),
name = genre,
order = tags.indexOf(genre).takeUnless { it == -1 }?.toLong() ?: Long.MAX_VALUE,
flags = 0,
)
}
}
else -> {
libraryManga.groupBy { item ->
item.libraryManga.manga.status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ object MangaLibraryTab : Tab {
group = state.groupType,
groupExtra = when (state.groupType) {
MangaLibraryGroup.BY_DEFAULT -> null
MangaLibraryGroup.BY_SOURCE, MangaLibraryGroup.BY_TRACK_STATUS -> category?.id?.toString()
MangaLibraryGroup.BY_SOURCE, MangaLibraryGroup.BY_TRACK_STATUS, MangaLibraryGroup.BY_TAG -> category?.id?.toString()
MangaLibraryGroup.BY_STATUS -> category?.id?.minus(1)?.toString()
else -> null
},
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/drawable/ic_tag_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- res/drawable/ic_tag_24dp.xml -->
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">

<path
android:fillColor="#000000"
android:pathData="M9,1h6v1h-6zM6,3C4.9,3 4,3.9 4,5v16c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2V5c0,-1.1 -0.9,-2 -2,-2h-3V2H9v1H6zM6,6h12v2H6zM6,10h12v2H6zM6,14h6v2H6z" />

</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ object AnimeLibraryGroup {
const val BY_SOURCE = 1
const val BY_STATUS = 2
const val BY_TRACK_STATUS = 3
const val UNGROUPED = 4
const val BY_TAG = 4
const val UNGROUPED = 5

fun groupTypeStringRes(type: Int, hasCategories: Boolean = true): Int {
return when (type) {
BY_STATUS -> R.string.status
BY_SOURCE -> R.string.label_sources
BY_TRACK_STATUS -> R.string.tracking_status
BY_TAG -> R.string.tag
UNGROUPED -> R.string.ungrouped
else -> if (hasCategories) R.string.categories else R.string.ungrouped
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ object MangaLibraryGroup {
const val BY_SOURCE = 1
const val BY_STATUS = 2
const val BY_TRACK_STATUS = 3
const val UNGROUPED = 4
const val BY_TAG = 4
const val UNGROUPED = 5

fun groupTypeStringRes(type: Int, hasCategories: Boolean = true): Int {
return when (type) {
BY_STATUS -> R.string.status
BY_SOURCE -> R.string.label_sources
BY_TRACK_STATUS -> R.string.tracking_status
BY_TAG -> R.string.tag
UNGROUPED -> R.string.ungrouped
else -> if (hasCategories) R.string.categories else R.string.ungrouped
}
Expand Down
1 change: 1 addition & 0 deletions i18n/src/main/res/values/strings-aniyomi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@
<!-- Library Grouping -->
<string name="tracking_status">Tracking status</string>
<string name="ungrouped">Ungrouped</string>
<string name="tag">Tag</string>
<string name="not_tracked">Not tracked</string>

<!-- More Info Menu -->
Expand Down

0 comments on commit b8ea6da

Please sign in to comment.