diff --git a/modules/features/podcasts/src/main/java/au/com/shiftyjelly/pocketcasts/podcasts/helper/search/BookmarkSearchHandler.kt b/modules/features/podcasts/src/main/java/au/com/shiftyjelly/pocketcasts/podcasts/helper/search/BookmarkSearchHandler.kt index 939b37bbf71..ddb7b0e7e5c 100644 --- a/modules/features/podcasts/src/main/java/au/com/shiftyjelly/pocketcasts/podcasts/helper/search/BookmarkSearchHandler.kt +++ b/modules/features/podcasts/src/main/java/au/com/shiftyjelly/pocketcasts/podcasts/helper/search/BookmarkSearchHandler.kt @@ -3,8 +3,7 @@ package au.com.shiftyjelly.pocketcasts.podcasts.helper.search import au.com.shiftyjelly.pocketcasts.models.entity.Bookmark import au.com.shiftyjelly.pocketcasts.repositories.bookmark.BookmarkManager import io.reactivex.Observable -import io.reactivex.Single -import java.util.concurrent.TimeUnit +import kotlinx.coroutines.rx2.rxSingle import javax.inject.Inject import javax.inject.Singleton @@ -12,22 +11,15 @@ import javax.inject.Singleton class BookmarkSearchHandler @Inject constructor( private val bookmarkManager: BookmarkManager, ) : SearchHandler() { - override val searchDebounce = 500L override fun getSearchResultsObservable(podcastUuid: String): Observable = - searchQueryRelay.debounce { // Only debounce when search has a value otherwise it slows down loading the pages - if (it.isEmpty()) { - Observable.empty() - } else { - Observable.timer(searchDebounce, TimeUnit.MILLISECONDS) - } - }.switchMapSingle { searchTerm -> + searchQueryRelay.switchMapSingle { searchTerm -> if (searchTerm.length > 1) { - Single.just(bookmarkManager.searchInPodcastByTitle(podcastUuid, searchTerm)) + rxSingle { bookmarkManager.searchInPodcastByTitle(podcastUuid, searchTerm) } .map { SearchResult(searchTerm, it) } .onErrorReturnItem(noSearchResult) } else { - Single.just(noSearchResult) + rxSingle { noSearchResult } } }.distinctUntilChanged() diff --git a/modules/features/podcasts/src/main/java/au/com/shiftyjelly/pocketcasts/podcasts/helper/search/EpisodeSearchHandler.kt b/modules/features/podcasts/src/main/java/au/com/shiftyjelly/pocketcasts/podcasts/helper/search/EpisodeSearchHandler.kt index faf9203d65f..02a12c7f3f2 100644 --- a/modules/features/podcasts/src/main/java/au/com/shiftyjelly/pocketcasts/podcasts/helper/search/EpisodeSearchHandler.kt +++ b/modules/features/podcasts/src/main/java/au/com/shiftyjelly/pocketcasts/podcasts/helper/search/EpisodeSearchHandler.kt @@ -17,7 +17,7 @@ class EpisodeSearchHandler @Inject constructor( private val cacheServerManager: PodcastCacheServerManagerImpl, private val analyticsTracker: AnalyticsTrackerWrapper, ) : SearchHandler() { - override val searchDebounce = settings.getEpisodeSearchDebounceMs() + private val searchDebounce = settings.getEpisodeSearchDebounceMs() override fun getSearchResultsObservable(podcastUuid: String): Observable = searchQueryRelay.debounce { // Only debounce when search has a value otherwise it slows down loading the pages diff --git a/modules/features/podcasts/src/main/java/au/com/shiftyjelly/pocketcasts/podcasts/helper/search/SearchHandler.kt b/modules/features/podcasts/src/main/java/au/com/shiftyjelly/pocketcasts/podcasts/helper/search/SearchHandler.kt index ac933625498..c4d7b4d0254 100644 --- a/modules/features/podcasts/src/main/java/au/com/shiftyjelly/pocketcasts/podcasts/helper/search/SearchHandler.kt +++ b/modules/features/podcasts/src/main/java/au/com/shiftyjelly/pocketcasts/podcasts/helper/search/SearchHandler.kt @@ -5,7 +5,6 @@ import io.reactivex.Observable abstract class SearchHandler { private var searchTerm = "" - abstract val searchDebounce: Long protected val searchQueryRelay = BehaviorRelay.create() .apply { accept("") } diff --git a/modules/services/model/src/main/java/au/com/shiftyjelly/pocketcasts/models/db/dao/BookmarkDao.kt b/modules/services/model/src/main/java/au/com/shiftyjelly/pocketcasts/models/db/dao/BookmarkDao.kt index 33fef128e92..9901228609c 100644 --- a/modules/services/model/src/main/java/au/com/shiftyjelly/pocketcasts/models/db/dao/BookmarkDao.kt +++ b/modules/services/model/src/main/java/au/com/shiftyjelly/pocketcasts/models/db/dao/BookmarkDao.kt @@ -71,7 +71,7 @@ abstract class BookmarkDao { AND (UPPER(bookmarks.title) LIKE UPPER(:title) OR UPPER(podcast_episodes.title) LIKE UPPER(:title)) AND deleted = :deleted""" ) - abstract fun searchInPodcastByTitle( + abstract suspend fun searchInPodcastByTitle( podcastUuid: String, title: String, deleted: Boolean = false, diff --git a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/bookmark/BookmarkManager.kt b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/bookmark/BookmarkManager.kt index 6b333c5b394..38bd60b695e 100644 --- a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/bookmark/BookmarkManager.kt +++ b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/bookmark/BookmarkManager.kt @@ -19,5 +19,5 @@ interface BookmarkManager { suspend fun deleteSynced(bookmarkUuid: String) suspend fun upsertSynced(bookmark: Bookmark): Bookmark fun findBookmarksToSync(): List - fun searchInPodcastByTitle(podcastUuid: String, title: String): List + suspend fun searchInPodcastByTitle(podcastUuid: String, title: String): List } diff --git a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/bookmark/BookmarkManagerImpl.kt b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/bookmark/BookmarkManagerImpl.kt index a966f712907..c4e4515249a 100644 --- a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/bookmark/BookmarkManagerImpl.kt +++ b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/bookmark/BookmarkManagerImpl.kt @@ -111,7 +111,7 @@ class BookmarkManagerImpl @Inject constructor( flowOf(helper.map { it.toBookmark() }) } - override fun searchInPodcastByTitle(podcastUuid: String, title: String) = + override suspend fun searchInPodcastByTitle(podcastUuid: String, title: String) = bookmarkDao.searchInPodcastByTitle(podcastUuid, "%$title%").map { it.uuid } /**