Skip to content

Commit

Permalink
Support new backwards-compatible features in server v0.26.x (#284)
Browse files Browse the repository at this point in the history
Closes #265

Add support for various new features in the future Stash server version
`v0.26.x`. Only ones that are backwards compatible are added.
  • Loading branch information
damontecres authored Jun 12, 2024
1 parent bd92e02 commit e83f78f
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,22 @@ class FilterListActivity : FragmentActivity() {
null,
android.R.attr.listPopupWindowStyle,
)
val serverVersion = ServerPreferences(this).serverVersion
// Resolve the strings, then sort
val sortOptions =
dataType.sortOptions
.filter { serverVersion.isAtLeast(it.requiresVersion) }
.map {
Pair(
it.key,
this@FilterListActivity.getString(it.nameStringId),
)
}.sortedBy { it.second }
val resolvedNames = sortOptions.map { it.second }

val currentDirection = filterData?.find_filter?.direction
val currentKey = filterData?.find_filter?.sort
val isRandom = currentKey?.startsWith("random_") ?: false
val isRandom = currentKey?.startsWith("random") ?: false
val index =
if (isRandom) {
sortOptions.map { it.first }.indexOf("random")
Expand Down
108 changes: 55 additions & 53 deletions app/src/main/java/com/github/damontecres/stashapp/data/SortOptions.kt
Original file line number Diff line number Diff line change
@@ -1,131 +1,133 @@
package com.github.damontecres.stashapp.data

import com.github.damontecres.stashapp.R
import com.github.damontecres.stashapp.util.Version

data class SortOption(val key: String, val nameStringId: Int)
data class SortOption(
val key: String,
val nameStringId: Int,
val requiresVersion: Version = Version.MINIMUM_STASH_VERSION,
)

val COMMON_SORT_OPTIONS =
arrayOf(
SortOption("created_at", R.string.stashapp_created_at),
SortOption("updated_at", R.string.stashapp_updated_at),
SortOption("random", R.string.stashapp_random),
)

val SCENE_SORT_OPTIONS =
listOf(
*COMMON_SORT_OPTIONS,
SortOption("title", R.string.stashapp_title),
SortOption("path", R.string.stashapp_path),
SortOption("rating", R.string.stashapp_rating),
SortOption("file_mod_time", R.string.stashapp_file_mod_time),
SortOption("tag_count", R.string.stashapp_tag_count),
SortOption("performer_count", R.string.stashapp_performer_count),
SortOption("random", R.string.stashapp_random),
SortOption("organized", R.string.stashapp_organized),
SortOption("o_counter", R.string.stashapp_o_counter),
SortOption("bitrate", R.string.stashapp_bitrate),
SortOption("date", R.string.stashapp_date),
SortOption("duration", R.string.stashapp_duration),
SortOption("file_count", R.string.stashapp_file_count),
SortOption("file_mod_time", R.string.stashapp_file_mod_time),
SortOption("filesize", R.string.stashapp_filesize),
SortOption("duration", R.string.stashapp_duration),
SortOption("framerate", R.string.stashapp_framerate),
SortOption("bitrate", R.string.stashapp_bitrate),
SortOption("last_played_at", R.string.stashapp_last_played_at),
SortOption("resume_time", R.string.stashapp_resume_time),
SortOption("play_duration", R.string.stashapp_play_duration),
SortOption("play_count", R.string.stashapp_play_count),
SortOption("movie_scene_number", R.string.stashapp_movie_scene_number),
SortOption("interactive", R.string.stashapp_interactive),
SortOption("interactive_speed", R.string.stashapp_interactive_speed),
SortOption("last_o_at", R.string.stashapp_last_o_at, Version.V0_26_0),
SortOption("last_played_at", R.string.stashapp_last_played_at),
SortOption("movie_scene_number", R.string.stashapp_movie_scene_number),
SortOption("o_counter", R.string.stashapp_o_count),
SortOption("organized", R.string.stashapp_organized),
SortOption("path", R.string.stashapp_path),
SortOption("perceptual_similarity", R.string.stashapp_perceptual_similarity),
SortOption("performer_count", R.string.stashapp_performer_count),
SortOption("play_count", R.string.stashapp_play_count),
SortOption("play_duration", R.string.stashapp_play_duration),
SortOption("rating", R.string.stashapp_rating),
SortOption("resume_time", R.string.stashapp_resume_time),
SortOption("tag_count", R.string.stashapp_tag_count),
SortOption("title", R.string.stashapp_title),
)

val GALLERY_SORT_OPTIONS =
listOf(
*COMMON_SORT_OPTIONS,
SortOption("title", R.string.stashapp_title),
SortOption("date", R.string.stashapp_date),
SortOption("file_count", R.string.stashapp_zip_file_count),
SortOption("file_mod_time", R.string.stashapp_file_mod_time),
SortOption("images_count", R.string.stashapp_image_count),
SortOption("path", R.string.stashapp_path),
SortOption("performer_count", R.string.stashapp_performer_count),
SortOption("rating", R.string.stashapp_rating),
SortOption("file_mod_time", R.string.stashapp_file_mod_time),
SortOption("tag_count", R.string.stashapp_tag_count),
SortOption("performer_count", R.string.stashapp_performer_count),
SortOption("random", R.string.stashapp_random),
SortOption("date", R.string.stashapp_date),
SortOption("images_count", R.string.stashapp_image_count),
SortOption("file_count", R.string.stashapp_zip_file_count),
SortOption("title", R.string.stashapp_title),
)

val IMAGE_SORT_OPTIONS =
listOf(
*COMMON_SORT_OPTIONS,
SortOption("title", R.string.stashapp_title),
SortOption("date", R.string.stashapp_date),
SortOption("file_count", R.string.stashapp_file_count),
SortOption("file_mod_time", R.string.stashapp_file_mod_time),
SortOption("filesize", R.string.stashapp_filesize),
SortOption("o_counter", R.string.stashapp_o_count),
SortOption("path", R.string.stashapp_path),
SortOption("performer_count", R.string.stashapp_performer_count),
SortOption("rating", R.string.stashapp_rating),
SortOption("file_mod_time", R.string.stashapp_file_mod_time),
SortOption("tag_count", R.string.stashapp_tag_count),
SortOption("performer_count", R.string.stashapp_performer_count),
SortOption("random", R.string.stashapp_random),
SortOption("o_counter", R.string.stashapp_o_counter),
SortOption("filesize", R.string.stashapp_filesize),
SortOption("file_count", R.string.stashapp_file_count),
SortOption("date", R.string.stashapp_date),
SortOption("title", R.string.stashapp_title),
)

val MOVIE_SORT_OPTIONS =
listOf(
*COMMON_SORT_OPTIONS,
SortOption("name", R.string.stashapp_name),
SortOption("random", R.string.stashapp_random),
SortOption("date", R.string.stashapp_date),
SortOption("duration", R.string.stashapp_duration),
SortOption("name", R.string.stashapp_name),
SortOption("rating", R.string.stashapp_rating),
SortOption("scenes_count", R.string.stashapp_scene_count),
)

val PERFORMER_SORT_OPTIONS =
listOf(
*COMMON_SORT_OPTIONS,
SortOption("name", R.string.stashapp_name),
SortOption("height", R.string.stashapp_height),
SortOption("birthdate", R.string.stashapp_birthdate),
SortOption("tag_count", R.string.stashapp_tag_count),
SortOption("random", R.string.stashapp_random),
SortOption("rating", R.string.stashapp_rating),
SortOption("galleries_count", R.string.stashapp_gallery_count),
SortOption("height", R.string.stashapp_height),
SortOption("images_count", R.string.stashapp_image_count),
SortOption("last_o_at", R.string.stashapp_last_o_at, Version.V0_26_0),
SortOption("last_played_at", R.string.stashapp_last_played_at, Version.V0_26_0),
SortOption("name", R.string.stashapp_name),
SortOption("o_counter", R.string.stashapp_o_count),
SortOption("penis_length", R.string.stashapp_penis_length),
SortOption("play_count", R.string.stashapp_play_count, Version.V0_26_0),
SortOption("rating", R.string.stashapp_rating),
SortOption("scenes_count", R.string.stashapp_scene_count),
SortOption("images_count", R.string.stashapp_image_count),
SortOption("galleries_count", R.string.stashapp_gallery_count),
SortOption("o_counter", R.string.stashapp_o_counter),
SortOption("tag_count", R.string.stashapp_tag_count),
)

val MARKER_SORT_OPTIONS =
listOf(
*COMMON_SORT_OPTIONS,
SortOption("title", R.string.stashapp_title),
SortOption("seconds", R.string.stashapp_seconds),
SortOption("scene_id", R.string.stashapp_scene_id),
SortOption("random", R.string.stashapp_random),
SortOption("scenes_updated_at", R.string.stashapp_scenes_updated_at),
SortOption("seconds", R.string.stashapp_seconds),
SortOption("title", R.string.stashapp_title),
)

val STUDIO_SORT_OPTIONS =
listOf(
*COMMON_SORT_OPTIONS,
SortOption("child_count", R.string.stashapp_subsidiary_studio_count),
SortOption("galleries_count", R.string.stashapp_gallery_count),
SortOption("images_count", R.string.stashapp_image_count),
SortOption("name", R.string.stashapp_name),
SortOption("random", R.string.stashapp_random),
SortOption("rating", R.string.stashapp_rating),
SortOption("scenes_count", R.string.stashapp_scene_count),
SortOption("images_count", R.string.stashapp_image_count),
SortOption("galleries_count", R.string.stashapp_gallery_count),
SortOption("child_count", R.string.stashapp_subsidiary_studio_count),
)

val TAG_SORT_OPTIONS =
listOf(
*COMMON_SORT_OPTIONS,
SortOption("name", R.string.stashapp_name),
SortOption("random", R.string.stashapp_random),
SortOption("scenes_count", R.string.stashapp_scene_count),
SortOption("images_count", R.string.stashapp_image_count),
SortOption("galleries_count", R.string.stashapp_gallery_count),
SortOption("images_count", R.string.stashapp_image_count),
SortOption("name", R.string.stashapp_name),
SortOption("performers_count", R.string.stashapp_performer_count),
SortOption("scene_markers_count", R.string.stashapp_marker_count),
SortOption("scenes_count", R.string.stashapp_scene_count),
)
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ class FilterParser(private val serverVersion: Version) {
scene_count = Optional.presentIfNotNull(convertIntCriterionInput(filter["scene_count"])),
image_count = Optional.presentIfNotNull(convertIntCriterionInput(filter["image_count"])),
gallery_count = Optional.presentIfNotNull(convertIntCriterionInput(filter["gallery_count"])),
play_count = Optional.presentIfNotNull(convertIntCriterionInput(filter["play_count"])),
o_counter = Optional.presentIfNotNull(convertIntCriterionInput(filter["o_counter"])),
stash_id_endpoint = Optional.presentIfNotNull(convertStashIDCriterionInput(filter["stash_id_endpoint"])),
rating100 = Optional.presentIfNotNull(convertIntCriterionInput(filter["rating100"])),
Expand Down Expand Up @@ -376,13 +377,15 @@ class FilterParser(private val serverVersion: Version) {
resolution = Optional.presentIfNotNull(convertResolutionCriterionInput(filter["resolution"])),
orientation = Optional.presentIfNotNull(convertOrientationCriterionInput(filter["orientation"])),
framerate = Optional.presentIfNotNull(convertIntCriterionInput(filter["framerate"])),
bitrate = Optional.presentIfNotNull(convertIntCriterionInput(filter["bitrate"])),
video_codec = Optional.presentIfNotNull(convertStringCriterionInput(filter["video_codec"])),
audio_codec = Optional.presentIfNotNull(convertStringCriterionInput(filter["audio_codec"])),
duration = Optional.presentIfNotNull(convertIntCriterionInput(filter["duration"])),
has_markers = Optional.presentIfNotNull(convertString(filter["has_markers"])),
is_missing = Optional.presentIfNotNull(convertString(filter["is_missing"])),
studios = Optional.presentIfNotNull(convertHierarchicalMultiCriterionInput(filter["studios"])),
movies = Optional.presentIfNotNull(convertMultiCriterionInput(filter["movies"])),
galleries = Optional.presentIfNotNull(convertMultiCriterionInput(filter["galleries"])),
tags = Optional.presentIfNotNull(convertHierarchicalMultiCriterionInput(filter["tags"])),
tag_count = Optional.presentIfNotNull(convertIntCriterionInput(filter["tag_count"])),
performer_tags =
Expand All @@ -403,6 +406,7 @@ class FilterParser(private val serverVersion: Version) {
resume_time = Optional.presentIfNotNull(convertIntCriterionInput(filter["resume_time"])),
play_count = Optional.presentIfNotNull(convertIntCriterionInput(filter["play_count"])),
play_duration = Optional.presentIfNotNull(convertIntCriterionInput(filter["play_duration"])),
last_played_at = Optional.presentIfNotNull(convertTimestampCriterionInput(filter["last_played_at"])),
date = Optional.presentIfNotNull(convertDateCriterionInput(filter["date"])),
created_at = Optional.presentIfNotNull(convertTimestampCriterionInput(filter["created_at"])),
updated_at = Optional.presentIfNotNull(convertTimestampCriterionInput(filter["updated_at"])),
Expand Down Expand Up @@ -433,6 +437,7 @@ class FilterParser(private val serverVersion: Version) {
),
is_missing = Optional.presentIfNotNull(convertString(filter["is_missing"])),
rating100 = Optional.presentIfNotNull(convertIntCriterionInput(filter["rating100"])),
favorite = Optional.presentIfNotNull(convertBoolean(filter["favorite"])),
scene_count = Optional.presentIfNotNull(convertIntCriterionInput(filter["scene_count"])),
image_count = Optional.presentIfNotNull(convertIntCriterionInput(filter["image_count"])),
gallery_count = Optional.presentIfNotNull(convertIntCriterionInput(filter["gallery_count"])),
Expand Down Expand Up @@ -466,6 +471,7 @@ class FilterParser(private val serverVersion: Version) {
NOT = Optional.presentIfNotNull(convertTagObjectFilter(filter["NOT"])),
name = Optional.presentIfNotNull(convertStringCriterionInput(filter["name"])),
aliases = Optional.presentIfNotNull(convertStringCriterionInput(filter["aliases"])),
favorite = Optional.presentIfNotNull(convertBoolean(filter["favorite"])),
description = Optional.presentIfNotNull(convertStringCriterionInput(filter["description"])),
is_missing = Optional.presentIfNotNull(convertString(filter["is_missing"])),
scene_count = Optional.presentIfNotNull(convertIntCriterionInput(filter["scene_count"])),
Expand Down Expand Up @@ -603,6 +609,7 @@ class FilterParser(private val serverVersion: Version) {
),
),
has_chapters = Optional.presentIfNotNull(convertString(filter["has_chapters"])),
scenes = Optional.presentIfNotNull(convertMultiCriterionInput(filter["scenes"])),
studios = Optional.presentIfNotNull(convertHierarchicalMultiCriterionInput(filter["studios"])),
tags = Optional.presentIfNotNull(convertHierarchicalMultiCriterionInput(filter["tags"])),
tag_count = Optional.presentIfNotNull(convertIntCriterionInput(filter["tag_count"])),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ServerPreferences(private val context: Context) {
),
)

val trackActivity get() = preferences.getBoolean(PREF_TRACK_ACTIVITY, false)
val trackActivity get() = preferences.getBoolean(PREF_TRACK_ACTIVITY, true)

val showStudioAsText get() = preferences.getBoolean(PREF_INTERFACE_STUDIOS_AS_TEXT, false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ data class Version(
val MINIMUM_STASH_VERSION = fromString("0.23.0")
val V0_24_3 = fromString("v0.24.3")
val V0_25_0 = fromString("v0.25.0")
val V0_26_0 = fromString("v0.26.0")

fun fromString(version: String): Version {
val v = tryFromString(version)
Expand Down
2 changes: 1 addition & 1 deletion stash-server
Submodule stash-server updated 287 files

0 comments on commit e83f78f

Please sign in to comment.