Skip to content

Commit

Permalink
Use server provided page sorts for tabs if available (#457)
Browse files Browse the repository at this point in the history
Follow up to #452
Part of #453

If the user has saved a default sort on a data type page (eg a
performer's page scene list or a studio's page image list), the app will
now use that. The app will fallback to the standard default sort if
needed.

For now only sorting is used from the server. A follow up will include
other (object) filters.

The list is derived from
https://github.com/stashapp/stash/blob/v0.27.2/ui/v2.5/src/components/List/views.ts
  • Loading branch information
damontecres authored Nov 7, 2024
1 parent 45b584d commit 0ef9973
Show file tree
Hide file tree
Showing 8 changed files with 329 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.github.damontecres.stashapp.presenters.StashPresenter
import com.github.damontecres.stashapp.suppliers.DataSupplierOverride
import com.github.damontecres.stashapp.suppliers.FilterArgs
import com.github.damontecres.stashapp.util.MutationEngine
import com.github.damontecres.stashapp.util.PageFilterKey
import com.github.damontecres.stashapp.util.QueryEngine
import com.github.damontecres.stashapp.util.StashCoroutineExceptionHandler
import com.github.damontecres.stashapp.util.StashFragmentPagerAdapter
Expand Down Expand Up @@ -64,50 +65,53 @@ class GalleryFragment : TabbedFragment(DataType.GALLERY.name) {
modifier = CriterionModifier.INCLUDES_ALL,
),
)
viewModel.tabs.value =
listOf(
StashFragmentPagerAdapter.PagerEntry(getString(R.string.stashapp_details)) {
GalleryDetailsFragment(gallery)
},
StashFragmentPagerAdapter.PagerEntry(DataType.IMAGE) {
StashGridFragment(
dataType = DataType.IMAGE,
objectFilter = ImageFilterType(galleries = galleries),
).withImageGridClickListener()
},
StashFragmentPagerAdapter.PagerEntry(DataType.SCENE) {
StashGridFragment(
dataType = DataType.SCENE,
objectFilter = SceneFilterType(galleries = galleries),
)
},
StashFragmentPagerAdapter.PagerEntry(DataType.PERFORMER) {
val presenter =
ClassPresenterSelector().addClassPresenter(
PerformerData::class.java,
PerformerInScenePresenter(gallery.date),
viewModel.currentServer.observe(viewLifecycleOwner) { server ->
viewModel.tabs.value =
listOf(
StashFragmentPagerAdapter.PagerEntry(getString(R.string.stashapp_details)) {
GalleryDetailsFragment(gallery)
},
StashFragmentPagerAdapter.PagerEntry(DataType.IMAGE) {
StashGridFragment(
dataType = DataType.IMAGE,
findFilter = server.serverPreferences.getDefaultFilter(PageFilterKey.GALLERY_IMAGES).findFilter,
objectFilter = ImageFilterType(galleries = galleries),
).withImageGridClickListener()
},
StashFragmentPagerAdapter.PagerEntry(DataType.SCENE) {
StashGridFragment(
dataType = DataType.SCENE,
objectFilter = SceneFilterType(galleries = galleries),
)
val fragment =
},
StashFragmentPagerAdapter.PagerEntry(DataType.PERFORMER) {
val presenter =
ClassPresenterSelector().addClassPresenter(
PerformerData::class.java,
PerformerInScenePresenter(gallery.date),
)
val fragment =
StashGridFragment(
filterArgs =
FilterArgs(
DataType.PERFORMER,
override = DataSupplierOverride.GalleryPerformer(gallery.id),
),
)
fragment.presenterSelector = presenter
fragment
},
StashFragmentPagerAdapter.PagerEntry(DataType.TAG) {
StashGridFragment(
filterArgs =
FilterArgs(
DataType.PERFORMER,
override = DataSupplierOverride.GalleryPerformer(gallery.id),
DataType.TAG,
override = DataSupplierOverride.GalleryTag(gallery.id),
),
)
fragment.presenterSelector = presenter
fragment
},
StashFragmentPagerAdapter.PagerEntry(DataType.TAG) {
StashGridFragment(
filterArgs =
FilterArgs(
DataType.TAG,
override = DataSupplierOverride.GalleryTag(gallery.id),
),
)
},
).filter { it.title in getUiTabs(requireContext(), DataType.GALLERY) }
},
).filter { it.title in getUiTabs(requireContext(), DataType.GALLERY) }
}
}

class GalleryDetailsFragment() : Fragment(R.layout.gallery_view) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.github.damontecres.stashapp.data.Group
import com.github.damontecres.stashapp.data.GroupRelationshipType
import com.github.damontecres.stashapp.suppliers.DataSupplierOverride
import com.github.damontecres.stashapp.suppliers.FilterArgs
import com.github.damontecres.stashapp.util.PageFilterKey
import com.github.damontecres.stashapp.util.StashFragmentPagerAdapter
import com.github.damontecres.stashapp.util.getParcelable
import com.github.damontecres.stashapp.util.getUiTabs
Expand All @@ -30,7 +31,10 @@ class GroupFragment : TabbedFragment(DataType.GROUP.name) {
) {
super.onViewCreated(view, savedInstanceState)
viewModel.currentServer.observe(viewLifecycleOwner) { server ->
val groupSceneFilter = server.serverPreferences.defaultGroupSceneFilter
val groupSceneFilter =
server.serverPreferences.getDefaultFilter(PageFilterKey.GROUP_SCENES)
val subGroupFilter =
server.serverPreferences.getDefaultFilter(PageFilterKey.GROUP_SUB_GROUPS)
viewModel.tabs.value =
listOf(
StashFragmentPagerAdapter.PagerEntry(getString(R.string.stashapp_details)) {
Expand Down Expand Up @@ -92,6 +96,7 @@ class GroupFragment : TabbedFragment(DataType.GROUP.name) {
),
)
},
// TODO use subgroup filter
StashFragmentPagerAdapter.PagerEntry(getString(R.string.stashapp_sub_groups)) {
StashGridFragment(
FilterArgs(
Expand Down
152 changes: 80 additions & 72 deletions app/src/main/java/com/github/damontecres/stashapp/PerformerFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.github.damontecres.stashapp.presenters.StashPresenter
import com.github.damontecres.stashapp.presenters.TagPresenter
import com.github.damontecres.stashapp.suppliers.DataSupplierOverride
import com.github.damontecres.stashapp.suppliers.FilterArgs
import com.github.damontecres.stashapp.util.PageFilterKey
import com.github.damontecres.stashapp.util.StashFragmentPagerAdapter
import com.github.damontecres.stashapp.util.getParcelable
import com.github.damontecres.stashapp.util.getUiTabs
Expand Down Expand Up @@ -66,83 +67,90 @@ class PerformerFragment : TabbedFragment(DataType.PERFORMER.name) {
),
)

viewModel.tabs.value =
listOf(
StashFragmentPagerAdapter.PagerEntry(getString(R.string.stashapp_details)) {
PerformerDetailsFragment()
},
StashFragmentPagerAdapter.PagerEntry(DataType.SCENE) {
StashGridFragment(
dataType = DataType.SCENE,
objectFilter = SceneFilterType(performers = performers),
)
},
StashFragmentPagerAdapter.PagerEntry(DataType.GALLERY) {
StashGridFragment(
dataType = DataType.GALLERY,
objectFilter = GalleryFilterType(performers = performers),
)
},
StashFragmentPagerAdapter.PagerEntry(DataType.IMAGE) {
StashGridFragment(
dataType = DataType.IMAGE,
objectFilter = ImageFilterType(performers = performers),
).withImageGridClickListener()
},
StashFragmentPagerAdapter.PagerEntry(DataType.GROUP) {
StashGridFragment(
dataType = DataType.GROUP,
objectFilter = GroupFilterType(performers = performers),
)
},
StashFragmentPagerAdapter.PagerEntry(DataType.TAG) {
val presenter =
ClassPresenterSelector()
.addClassPresenter(
TagData::class.java,
TagPresenter(PerformersWithTagLongClickCallback()),
)
val fragment =
viewModel.currentServer.observe(viewLifecycleOwner) { server ->
viewModel.tabs.value =
listOf(
StashFragmentPagerAdapter.PagerEntry(getString(R.string.stashapp_details)) {
PerformerDetailsFragment()
},
StashFragmentPagerAdapter.PagerEntry(DataType.SCENE) {
StashGridFragment(
FilterArgs(
dataType = DataType.TAG,
override = DataSupplierOverride.PerformerTags(performer.id),
),
dataType = DataType.SCENE,
findFilter = server.serverPreferences.getDefaultFilter(PageFilterKey.PERFORMER_SCENES).findFilter,
objectFilter = SceneFilterType(performers = performers),
)
fragment.presenterSelector = presenter
fragment
},
StashFragmentPagerAdapter.PagerEntry(getString(R.string.stashapp_appears_with)) {
val presenter =
ClassPresenterSelector()
.addClassPresenter(
PerformerData::class.java,
PerformerPresenter(PerformTogetherLongClickCallback(performer)),
)
val fragment =
},
StashFragmentPagerAdapter.PagerEntry(DataType.GALLERY) {
StashGridFragment(
dataType = DataType.PERFORMER,
objectFilter =
PerformerFilterType(
performers =
Optional.present(
MultiCriterionInput(
value = Optional.present(listOf(performer.id)),
modifier = CriterionModifier.INCLUDES_ALL,
),
),
dataType = DataType.GALLERY,
findFilter = server.serverPreferences.getDefaultFilter(PageFilterKey.PERFORMER_GALLERIES).findFilter,
objectFilter = GalleryFilterType(performers = performers),
)
},
StashFragmentPagerAdapter.PagerEntry(DataType.IMAGE) {
StashGridFragment(
dataType = DataType.IMAGE,
findFilter = server.serverPreferences.getDefaultFilter(PageFilterKey.PERFORMER_IMAGES).findFilter,
objectFilter = ImageFilterType(performers = performers),
).withImageGridClickListener()
},
StashFragmentPagerAdapter.PagerEntry(DataType.GROUP) {
StashGridFragment(
dataType = DataType.GROUP,
findFilter = server.serverPreferences.getDefaultFilter(PageFilterKey.PERFORMER_GROUPS).findFilter,
objectFilter = GroupFilterType(performers = performers),
)
},
StashFragmentPagerAdapter.PagerEntry(DataType.TAG) {
val presenter =
ClassPresenterSelector()
.addClassPresenter(
TagData::class.java,
TagPresenter(PerformersWithTagLongClickCallback()),
)
val fragment =
StashGridFragment(
FilterArgs(
dataType = DataType.TAG,
override = DataSupplierOverride.PerformerTags(performer.id),
),
)
fragment.presenterSelector = presenter
fragment
},
StashFragmentPagerAdapter.PagerEntry(getString(R.string.stashapp_appears_with)) {
val presenter =
ClassPresenterSelector()
.addClassPresenter(
PerformerData::class.java,
PerformerPresenter(PerformTogetherLongClickCallback(performer)),
)
val fragment =
StashGridFragment(
dataType = DataType.PERFORMER,
findFilter = server.serverPreferences.getDefaultFilter(PageFilterKey.PERFORMER_APPEARS_WITH).findFilter,
objectFilter =
PerformerFilterType(
performers =
Optional.present(
MultiCriterionInput(
value = Optional.present(listOf(performer.id)),
modifier = CriterionModifier.INCLUDES_ALL,
),
),
),
)
fragment.presenterSelector = presenter
fragment
},
StashFragmentPagerAdapter.PagerEntry(DataType.MARKER) {
StashGridFragment(
dataType = DataType.MARKER,
objectFilter = SceneMarkerFilterType(performers = performers),
)
fragment.presenterSelector = presenter
fragment
},
StashFragmentPagerAdapter.PagerEntry(DataType.MARKER) {
StashGridFragment(
dataType = DataType.MARKER,
objectFilter = SceneMarkerFilterType(performers = performers),
)
},
).filter { it.title in getUiTabs(requireContext(), DataType.PERFORMER) }
},
).filter { it.title in getUiTabs(requireContext(), DataType.PERFORMER) }
}
}

private class PerformTogetherLongClickCallback(val performer: Performer) :
Expand Down
Loading

0 comments on commit 0ef9973

Please sign in to comment.