Skip to content

Commit

Permalink
draft Filter shows by watch provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Jan 25, 2024
1 parent 84b2249 commit 9833566
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Semaphore
import kotlinx.coroutines.sync.withPermit
import timber.log.Timber

class ShowsViewModel(application: Application) : AndroidViewModel(application) {

Expand All @@ -41,6 +42,9 @@ class ShowsViewModel(application: Application) : AndroidViewModel(application) {
// Use Semaphore with 1 permit to ensure results are delivered in order and never
// processed in parallel.
showItemsLiveDataSemaphore.withPermit {
// TODO Try filtering here instead


val mapped = sgShows?.mapTo(ArrayList(sgShows.size)) {
ShowsAdapter.ShowItem.map(it, getApplication())
}
Expand Down Expand Up @@ -169,7 +173,20 @@ class ShowsViewModel(application: Application) : AndroidViewModel(application) {
}

queryString.value = if (selection.isNotEmpty()) {
"SELECT * FROM ${Tables.SG_SHOW} WHERE $selection ORDER BY $orderClause"
// TODO filter by watch provider ID
// TODO Alternative: filter in code?
// Issues:
// - duplicate rows if multiple providers match
val query = "SELECT * FROM ${Tables.SG_SHOW}" +
" JOIN sg_watch_provider_show_mappings ON _id=sg_watch_provider_show_mappings.show_id" +
// " JOIN sg_genre_show_mappings ON _id=sg_genre_show_mappings.show_id" +
" WHERE (provider_id=9 OR provider_id=531) AND $selection" +
" GROUP BY _id" +
" ORDER BY $orderClause"

Timber.d(query)
// "SELECT * FROM ${Tables.SG_SHOW} WHERE $selection ORDER BY $orderClause"
query
} else {
"SELECT * FROM ${Tables.SG_SHOW} ORDER BY $orderClause"
}
Expand Down

0 comments on commit 9833566

Please sign in to comment.