From 8ca0814affb478fbaf7b4ad911cd597e77dc0292 Mon Sep 17 00:00:00 2001 From: inorichi Date: Tue, 26 Jan 2016 16:33:19 +0100 Subject: [PATCH] Add a way to search in MAL only from the user's list --- .../myanimelist/MyAnimeListPresenter.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/myanimelist/MyAnimeListPresenter.java b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/myanimelist/MyAnimeListPresenter.java index db23a4e65..cf3a278d6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/myanimelist/MyAnimeListPresenter.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/myanimelist/MyAnimeListPresenter.java @@ -4,6 +4,8 @@ import android.content.Context; import android.os.Bundle; import android.text.TextUtils; +import java.util.List; + import javax.inject.Inject; import eu.kanade.tachiyomi.R; @@ -36,6 +38,8 @@ public class MyAnimeListPresenter extends BasePresenter { private static final int GET_SEARCH_RESULTS = 2; private static final int REFRESH = 3; + private static final String PREFIX_MY = "my:"; + @Override protected void onCreate(Bundle savedState) { super.onCreate(savedState); @@ -54,9 +58,7 @@ public class MyAnimeListPresenter extends BasePresenter { MyAnimeListFragment::setMangaSync); restartableLatestCache(GET_SEARCH_RESULTS, - () -> myAnimeList.search(query) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()), + this::getSearchResultsObservable, (view, results) -> { view.setSearchResults(results); }, (view, error) -> { @@ -108,6 +110,22 @@ public class MyAnimeListPresenter extends BasePresenter { start(GET_MANGA_SYNC); } + private Observable> getSearchResultsObservable() { + Observable> observable; + if (query.startsWith(PREFIX_MY)) { + String realQuery = query.substring(PREFIX_MY.length()).toLowerCase().trim(); + observable = myAnimeList.getList() + .flatMap(Observable::from) + .filter(manga -> manga.title.toLowerCase().contains(realQuery)) + .toList(); + } else { + observable = myAnimeList.search(query); + } + return observable + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()); + } + private void updateRemote() { add(myAnimeList.update(mangaSync) .flatMap(response -> db.insertMangaSync(mangaSync).asRxObservable())