Skip to content

Commit

Permalink
Use server's default filter for group scenes (#452)
Browse files Browse the repository at this point in the history
If the server has set a server-side default filter for group scenes, the
app will now use it.

Most of the changes are refactoring to make sure server preferences can
be available before tabs are loaded. The view model now has
`currentServer` and `tabs`. The tabs are added based on the `tabs` view
model field. So if a page needs server preferences, it can observe the
`currentServer` before setting `tabs`.

Will need to follow up on various other default filters too.
  • Loading branch information
damontecres authored Nov 5, 2024
1 parent 36eb9da commit 2c0c31d
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import android.widget.TableLayout
import android.widget.TableRow
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.leanback.widget.ClassPresenterSelector
import androidx.lifecycle.lifecycleScope
import com.apollographql.apollo.api.Optional
Expand Down Expand Up @@ -52,15 +51,20 @@ class GalleryFragment : TabbedFragment(DataType.GALLERY.name) {
viewModel.title.value = gallery.name
}

override fun getPagerAdapter(fm: FragmentManager): StashFragmentPagerAdapter {
override fun onViewCreated(
view: View,
savedInstanceState: Bundle?,
) {
super.onViewCreated(view, savedInstanceState)

val galleries =
Optional.present(
MultiCriterionInput(
value = Optional.present(listOf(gallery.id)),
modifier = CriterionModifier.INCLUDES_ALL,
),
)
val items =
viewModel.tabs.value =
listOf(
StashFragmentPagerAdapter.PagerEntry(getString(R.string.stashapp_details)) {
GalleryDetailsFragment(gallery)
Expand Down Expand Up @@ -104,7 +108,6 @@ class GalleryFragment : TabbedFragment(DataType.GALLERY.name) {
)
},
).filter { it.title in getUiTabs(requireContext(), DataType.GALLERY) }
return StashFragmentPagerAdapter(items, fm)
}

class GalleryDetailsFragment() : Fragment(R.layout.gallery_view) {
Expand Down
158 changes: 77 additions & 81 deletions app/src/main/java/com/github/damontecres/stashapp/GroupFragment.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package com.github.damontecres.stashapp

import android.os.Bundle
import androidx.fragment.app.FragmentManager
import android.view.View
import com.apollographql.apollo.api.Optional
import com.github.damontecres.stashapp.api.type.CriterionModifier
import com.github.damontecres.stashapp.api.type.HierarchicalMultiCriterionInput
import com.github.damontecres.stashapp.api.type.SceneFilterType
import com.github.damontecres.stashapp.api.type.SceneMarkerFilterType
import com.github.damontecres.stashapp.api.type.SortDirectionEnum
import com.github.damontecres.stashapp.data.DataType
import com.github.damontecres.stashapp.data.Group
import com.github.damontecres.stashapp.data.GroupRelationshipType
import com.github.damontecres.stashapp.data.SortAndDirection
import com.github.damontecres.stashapp.data.SortOption
import com.github.damontecres.stashapp.data.StashFindFilter
import com.github.damontecres.stashapp.suppliers.DataSupplierOverride
import com.github.damontecres.stashapp.suppliers.FilterArgs
import com.github.damontecres.stashapp.util.StashFragmentPagerAdapter
Expand All @@ -28,88 +24,88 @@ class GroupFragment : TabbedFragment(DataType.GROUP.name) {
super.onCreate(savedInstanceState)
}

override fun getPagerAdapter(fm: FragmentManager): StashFragmentPagerAdapter {
val pages =
listOf(
StashFragmentPagerAdapter.PagerEntry(getString(R.string.stashapp_details)) {
GroupDetailsFragment()
},
StashFragmentPagerAdapter.PagerEntry(DataType.SCENE) {
StashGridFragment(
dataType = DataType.SCENE,
findFilter =
StashFindFilter(
SortAndDirection(
SortOption.GROUP_SCENE_NUMBER,
SortDirectionEnum.ASC,
override fun onViewCreated(
view: View,
savedInstanceState: Bundle?,
) {
super.onViewCreated(view, savedInstanceState)
viewModel.currentServer.observe(viewLifecycleOwner) { server ->
val groupSceneFilter = server.serverPreferences.defaultGroupSceneFilter
viewModel.tabs.value =
listOf(
StashFragmentPagerAdapter.PagerEntry(getString(R.string.stashapp_details)) {
GroupDetailsFragment()
},
StashFragmentPagerAdapter.PagerEntry(DataType.SCENE) {
StashGridFragment(
dataType = DataType.SCENE,
findFilter = groupSceneFilter.findFilter,
objectFilter =
(groupSceneFilter.objectFilter as SceneFilterType?)?.copy(
groups =
Optional.present(
HierarchicalMultiCriterionInput(
value = Optional.present(listOf(group.id)),
modifier = CriterionModifier.INCLUDES,
),
),
),
),
objectFilter =
SceneFilterType(
groups =
Optional.present(
HierarchicalMultiCriterionInput(
value = Optional.present(listOf(group.id)),
modifier = CriterionModifier.INCLUDES,
)
},
StashFragmentPagerAdapter.PagerEntry(DataType.MARKER) {
StashGridFragment(
dataType = DataType.MARKER,
objectFilter =
SceneMarkerFilterType(
scene_filter =
Optional.present(
SceneFilterType(
groups =
Optional.present(
HierarchicalMultiCriterionInput(
value = Optional.present(listOf(group.id)),
modifier = CriterionModifier.INCLUDES,
),
),
),
),
),
)
},
StashFragmentPagerAdapter.PagerEntry(DataType.TAG) {
StashGridFragment(
FilterArgs(
DataType.TAG,
override = DataSupplierOverride.GroupTags(group.id),
),
)
},
StashFragmentPagerAdapter.PagerEntry(getString(R.string.stashapp_containing_groups)) {
StashGridFragment(
FilterArgs(
DataType.GROUP,
override =
DataSupplierOverride.GroupRelationship(
group.id,
GroupRelationshipType.CONTAINING,
),
),
)
},
StashFragmentPagerAdapter.PagerEntry(DataType.MARKER) {
StashGridFragment(
dataType = DataType.MARKER,
objectFilter =
SceneMarkerFilterType(
scene_filter =
Optional.present(
SceneFilterType(
groups =
Optional.present(
HierarchicalMultiCriterionInput(
value = Optional.present(listOf(group.id)),
modifier = CriterionModifier.INCLUDES,
),
),
),
)
},
StashFragmentPagerAdapter.PagerEntry(getString(R.string.stashapp_sub_groups)) {
StashGridFragment(
FilterArgs(
DataType.GROUP,
override =
DataSupplierOverride.GroupRelationship(
group.id,
GroupRelationshipType.SUB,
),
),
)
},
StashFragmentPagerAdapter.PagerEntry(DataType.TAG) {
StashGridFragment(
FilterArgs(
DataType.TAG,
override = DataSupplierOverride.GroupTags(group.id),
),
)
},
StashFragmentPagerAdapter.PagerEntry(getString(R.string.stashapp_containing_groups)) {
StashGridFragment(
FilterArgs(
DataType.GROUP,
override =
DataSupplierOverride.GroupRelationship(
group.id,
GroupRelationshipType.CONTAINING,
),
),
)
},
StashFragmentPagerAdapter.PagerEntry(getString(R.string.stashapp_sub_groups)) {
StashGridFragment(
FilterArgs(
DataType.GROUP,
override =
DataSupplierOverride.GroupRelationship(
group.id,
GroupRelationshipType.SUB,
),
),
)
},
).filter { it.title in getUiTabs(requireContext(), DataType.GROUP) }
return StashFragmentPagerAdapter(pages, fm)
)
},
).filter { it.title in getUiTabs(requireContext(), DataType.GROUP) }
}
}

override fun getTitleText(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import android.os.Bundle
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.text.style.RelativeSizeSpan
import androidx.fragment.app.FragmentManager
import android.view.View
import androidx.leanback.widget.ClassPresenterSelector
import com.apollographql.apollo.api.Optional
import com.github.damontecres.stashapp.api.fragment.PerformerData
Expand Down Expand Up @@ -52,7 +52,12 @@ class PerformerFragment : TabbedFragment(DataType.PERFORMER.name) {
}
}

override fun getPagerAdapter(fm: FragmentManager): StashFragmentPagerAdapter {
override fun onViewCreated(
view: View,
savedInstanceState: Bundle?,
) {
super.onViewCreated(view, savedInstanceState)

val performers =
Optional.present(
MultiCriterionInput(
Expand All @@ -61,7 +66,7 @@ class PerformerFragment : TabbedFragment(DataType.PERFORMER.name) {
),
)

val items =
viewModel.tabs.value =
listOf(
StashFragmentPagerAdapter.PagerEntry(getString(R.string.stashapp_details)) {
PerformerDetailsFragment()
Expand Down Expand Up @@ -138,7 +143,6 @@ class PerformerFragment : TabbedFragment(DataType.PERFORMER.name) {
)
},
).filter { it.title in getUiTabs(requireContext(), DataType.PERFORMER) }
return StashFragmentPagerAdapter(items, fm)
}

private class PerformTogetherLongClickCallback(val performer: Performer) :
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.damontecres.stashapp

import android.os.Bundle
import androidx.fragment.app.FragmentManager
import android.view.View
import com.apollographql.apollo.api.Optional
import com.github.damontecres.stashapp.api.type.CriterionModifier
import com.github.damontecres.stashapp.api.type.GalleryFilterType
Expand Down Expand Up @@ -32,8 +32,14 @@ class StudioFragment : TabbedFragment(DataType.STUDIO.name) {
return requireActivity().intent.getStringExtra("studioName")
}

override fun getPagerAdapter(fm: FragmentManager): StashFragmentPagerAdapter {
val items =
override fun onViewCreated(
view: View,
savedInstanceState: Bundle?,
) {
super.onViewCreated(view, savedInstanceState)

val studioId = requireActivity().intent.getStringExtra("studioId")!!
viewModel.tabs.value =
listOf(
StashFragmentPagerAdapter.PagerEntry(getString(R.string.stashapp_details)) {
StudioDetailsFragment()
Expand Down Expand Up @@ -97,7 +103,6 @@ class StudioFragment : TabbedFragment(DataType.STUDIO.name) {
}
},
).filter { it.title in getUiTabs(requireContext(), DataType.STUDIO) }
return StashFragmentPagerAdapter(items, fm)
}

private fun createStashGridFragment(
Expand Down
Loading

0 comments on commit 2c0c31d

Please sign in to comment.