-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bookmarks - Add search on podcast page (#1211)
Co-authored-by: Philip Simpson <[email protected]>
- Loading branch information
1 parent
316be02
commit f12f256
Showing
12 changed files
with
387 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
.../main/java/au/com/shiftyjelly/pocketcasts/podcasts/helper/search/BookmarkSearchHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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 kotlinx.coroutines.rx2.rxSingle | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class BookmarkSearchHandler @Inject constructor( | ||
private val bookmarkManager: BookmarkManager, | ||
) : SearchHandler<Bookmark>() { | ||
|
||
override fun getSearchResultsObservable(podcastUuid: String): Observable<SearchResult> = | ||
searchQueryRelay.switchMapSingle { searchTerm -> | ||
if (searchTerm.length > 1) { | ||
rxSingle { bookmarkManager.searchInPodcastByTitle(podcastUuid, searchTerm) } | ||
.map { SearchResult(searchTerm, it) } | ||
.onErrorReturnItem(noSearchResult) | ||
} else { | ||
rxSingle { noSearchResult } | ||
} | ||
}.distinctUntilChanged() | ||
|
||
override fun trackSearchIfNeeded(oldValue: String, newValue: String) { | ||
// TODO: Bookmark search tracking | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...c/main/java/au/com/shiftyjelly/pocketcasts/podcasts/helper/search/EpisodeSearchHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package au.com.shiftyjelly.pocketcasts.podcasts.helper.search | ||
|
||
import au.com.shiftyjelly.pocketcasts.analytics.AnalyticsEvent | ||
import au.com.shiftyjelly.pocketcasts.analytics.AnalyticsTrackerWrapper | ||
import au.com.shiftyjelly.pocketcasts.models.entity.BaseEpisode | ||
import au.com.shiftyjelly.pocketcasts.preferences.Settings | ||
import au.com.shiftyjelly.pocketcasts.servers.podcast.PodcastCacheServerManagerImpl | ||
import io.reactivex.Observable | ||
import io.reactivex.Single | ||
import java.util.concurrent.TimeUnit | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class EpisodeSearchHandler @Inject constructor( | ||
settings: Settings, | ||
private val cacheServerManager: PodcastCacheServerManagerImpl, | ||
private val analyticsTracker: AnalyticsTrackerWrapper, | ||
) : SearchHandler<BaseEpisode>() { | ||
private val searchDebounce = settings.getEpisodeSearchDebounceMs() | ||
|
||
override fun getSearchResultsObservable(podcastUuid: String): Observable<SearchResult> = | ||
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 -> | ||
if (searchTerm.length > 2) { | ||
cacheServerManager.searchEpisodes(podcastUuid, searchTerm) | ||
.map { SearchResult(searchTerm, it) } | ||
.onErrorReturnItem(noSearchResult) | ||
} else { | ||
Single.just(noSearchResult) | ||
} | ||
}.distinctUntilChanged() | ||
|
||
override fun trackSearchIfNeeded(oldValue: String, newValue: String) { | ||
if (oldValue.isEmpty() && newValue.isNotEmpty()) { | ||
analyticsTracker.track(AnalyticsEvent.PODCAST_SCREEN_SEARCH_PERFORMED) | ||
} else if (oldValue.isNotEmpty() && newValue.isEmpty()) { | ||
analyticsTracker.track(AnalyticsEvent.PODCAST_SCREEN_SEARCH_CLEARED) | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...asts/src/main/java/au/com/shiftyjelly/pocketcasts/podcasts/helper/search/SearchHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package au.com.shiftyjelly.pocketcasts.podcasts.helper.search | ||
|
||
import com.jakewharton.rxrelay2.BehaviorRelay | ||
import io.reactivex.Observable | ||
|
||
abstract class SearchHandler<T> { | ||
private var searchTerm = "" | ||
protected val searchQueryRelay = BehaviorRelay.create<String>() | ||
.apply { accept("") } | ||
|
||
protected val noSearchResult = SearchResult("", null) | ||
|
||
abstract fun getSearchResultsObservable(podcastUuid: String): Observable<SearchResult> | ||
|
||
fun searchQueryUpdated(newValue: String) { | ||
val oldValue = searchQueryRelay.value ?: "" | ||
searchTerm = newValue | ||
searchQueryRelay.accept(newValue) | ||
trackSearchIfNeeded(oldValue, newValue) | ||
} | ||
|
||
abstract fun trackSearchIfNeeded(oldValue: String, newValue: String) | ||
|
||
data class SearchResult( | ||
val searchTerm: String, | ||
val searchUuids: List<String>?, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.