Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for subscribing to search queries #463

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
246 changes: 246 additions & 0 deletions app/schemas/de.christinecoenen.code.zapp.persistence.Database/5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
{
"formatVersion": 1,
"database": {
"version": 5,
"identityHash": "f1c3bab7699a6783b71aa0a4c5edaa60",
"entities": [
{
"tableName": "PersistedMediathekShow",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `createdAt` INTEGER NOT NULL, `showUpdatedAt` INTEGER, `downloadId` INTEGER NOT NULL, `downloadedAt` INTEGER, `downloadedVideoPath` TEXT, `downloadStatus` INTEGER NOT NULL, `downloadProgress` INTEGER NOT NULL, `bookmarked` INTEGER NOT NULL, `bookmarkedAt` INTEGER, `lastPlayedBackAt` INTEGER, `playbackPosition` INTEGER NOT NULL, `videoDuration` INTEGER NOT NULL, `apiId` TEXT NOT NULL, `topic` TEXT NOT NULL, `title` TEXT NOT NULL, `description` TEXT, `channel` TEXT NOT NULL, `timestamp` INTEGER NOT NULL, `size` INTEGER NOT NULL, `duration` TEXT, `filmlisteTimestamp` INTEGER NOT NULL, `websiteUrl` TEXT, `subtitleUrl` TEXT, `videoUrl` TEXT NOT NULL, `videoUrlLow` TEXT, `videoUrlHd` TEXT)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "createdAt",
"columnName": "createdAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "showUpdatedAt",
"columnName": "showUpdatedAt",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "downloadId",
"columnName": "downloadId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "downloadedAt",
"columnName": "downloadedAt",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "downloadedVideoPath",
"columnName": "downloadedVideoPath",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "downloadStatus",
"columnName": "downloadStatus",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "downloadProgress",
"columnName": "downloadProgress",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isBookmarked",
"columnName": "bookmarked",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "bookmarkedAt",
"columnName": "bookmarkedAt",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "lastPlayedBackAt",
"columnName": "lastPlayedBackAt",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "playbackPosition",
"columnName": "playbackPosition",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "videoDuration",
"columnName": "videoDuration",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "mediathekShow.apiId",
"columnName": "apiId",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "mediathekShow.topic",
"columnName": "topic",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "mediathekShow.title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "mediathekShow.description",
"columnName": "description",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "mediathekShow.channel",
"columnName": "channel",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "mediathekShow.timestamp",
"columnName": "timestamp",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "mediathekShow.size",
"columnName": "size",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "mediathekShow.duration",
"columnName": "duration",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "mediathekShow.filmlisteTimestamp",
"columnName": "filmlisteTimestamp",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "mediathekShow.websiteUrl",
"columnName": "websiteUrl",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "mediathekShow.subtitleUrl",
"columnName": "subtitleUrl",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "mediathekShow.videoUrl",
"columnName": "videoUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "mediathekShow.videoUrlLow",
"columnName": "videoUrlLow",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "mediathekShow.videoUrlHd",
"columnName": "videoUrlHd",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [
{
"name": "index_PersistedMediathekShow_apiId",
"unique": true,
"columnNames": [
"apiId"
],
"orders": [],
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_PersistedMediathekShow_apiId` ON `${TABLE_NAME}` (`apiId`)"
}
],
"foreignKeys": []
},
{
"tableName": "SearchQuery",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`query` TEXT NOT NULL, `date` INTEGER NOT NULL, PRIMARY KEY(`query`))",
"fields": [
{
"fieldPath": "query",
"columnName": "query",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "date",
"columnName": "date",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"query"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "QuerySubscription",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`query` TEXT NOT NULL, PRIMARY KEY(`query`))",
"fields": [
{
"fieldPath": "query",
"columnName": "query",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"query"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'f1c3bab7699a6783b71aa0a4c5edaa60')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import de.christinecoenen.code.zapp.models.channels.json.JsonChannelList
import de.christinecoenen.code.zapp.persistence.Database
import de.christinecoenen.code.zapp.repositories.ChannelRepository
import de.christinecoenen.code.zapp.repositories.MediathekRepository
import de.christinecoenen.code.zapp.repositories.QuerySubscriptionRepository
import de.christinecoenen.code.zapp.repositories.SearchRepository
import de.christinecoenen.code.zapp.utils.api.UserAgentInterceptor
import io.noties.markwon.Markwon
Expand Down Expand Up @@ -57,6 +58,7 @@ class KoinModules {
single { Database.getInstance(androidContext()) }
single { MediathekRepository(get()) }
single { SearchRepository(get()) }
single { QuerySubscriptionRepository(get()) }
single { PersistedPlaybackPositionRepository(get()) } bind IPlaybackPositionRepository::class
single {
WorkManagerDownloadController(
Expand Down Expand Up @@ -87,10 +89,10 @@ class KoinModules {
viewModel { ContinueWatchingViewModel(get()) }
viewModel { DownloadsViewModel(get()) }
viewModel { ProgramInfoViewModel(androidApplication(), get()) }
viewModel { parameters -> MediathekListFragmentViewModel(get(), parameters.get()) }
viewModel { MediathekListFragmentViewModel(get(), get()) }
viewModel { MediathekFilterViewModel() }
viewModel { ShowMenuHelperViewModel(get(), get()) }
viewModel { SearchViewModel(get(), get(), get()) }
viewModel { SearchViewModel(get(), get(), get(), get()) }
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class MainActivity : AppCompatActivity(), MenuProvider {
appBarConfiguration = AppBarConfiguration(
setOf(
R.id.channelListFragment,
R.id.mediathekListFragment,
R.id.mediathekListBaseFragment,
R.id.personalFragment,
),
fallbackOnNavigateUpListener = ::onSupportNavigateUp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import java.io.IOException
class MediathekPagingSource(
private val mediathekApi: IMediathekApiService,
private val query: QueryRequest,
private val queryInfoResultPublisher: MutableStateFlow<QueryInfoResult?>
private val queryInfoResultPublisher: MutableStateFlow<QueryInfoResult?>,
private val emptyIfNoQueries: Boolean = false
) : PagingSource<Int, MediathekShow>() {

override fun getRefreshKey(state: PagingState<Int, MediathekShow>): Int? {
Expand All @@ -23,6 +24,9 @@ class MediathekPagingSource(
}

override suspend fun load(params: LoadParams<Int>): LoadResult<Int, MediathekShow> {
if (query.isEmpty() && emptyIfNoQueries) {
return LoadResult.Page(emptyList(), null, null)
}

queryInfoResultPublisher.emit(null)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.christinecoenen.code.zapp.app.mediathek.api.request

import android.text.TextUtils
import androidx.annotation.Keep
import com.google.gson.annotations.SerializedName
import java.io.Serializable
Expand All @@ -27,36 +26,40 @@ class QueryRequest : Serializable {
private val channels: MutableSet<MediathekChannel> = mutableSetOf()

@Transient
private var queryString: String = ""
private var queryStrings: MutableSet<String> = mutableSetOf()

init {
resetQueries()
}

fun setChannels(channels: List<MediathekChannel>): QueryRequest {
fun setChannels(channels: List<MediathekChannel>): QueryRequest = apply {
this.channels.clear()
this.channels.addAll(channels)

resetQueries()

return this
}

fun setQueryString(queryString: String): QueryRequest {
this.queryString = queryString
fun setQueryString(queryString: String): QueryRequest = apply {
this.queryStrings.clear()
this.queryStrings.add(queryString)

resetQueries()
}

fun setQueryStrings(queryStrings: List<String>): QueryRequest = apply {
this.queryStrings.clear()
this.queryStrings.addAll(queryStrings)

return this
resetQueries()
}

private fun resetQueries() {
queries.clear()

// set search query
if (!TextUtils.isEmpty(this.queryString)) {
queries.add(Query(this.queryString, "title", "topic"))
}
queries.addAll(queryStrings.filter { it.isNotEmpty() }.map { queryString ->
Query(queryString, "title", "topic")
})

// We do not allow an empty channel Filter as the result would always be empty.
// Instead we filter for all available channels. This also excludes all channels
Expand All @@ -72,6 +75,8 @@ class QueryRequest : Serializable {
}
}

fun isEmpty() = queries.isEmpty()

override fun toString(): String {
return "QueryRequest(sortBy='$sortBy', sortOrder='$sortOrder', future=$future, offset=$offset, size=$size, queries=$queries)"
}
Expand Down
Loading
Loading