mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 07:41:51 +01:00
Add filter by downloaded chapter. When searching manga by URL, also check the source
This commit is contained in:
parent
d6257cf52e
commit
6b8ccbe01b
@ -85,7 +85,7 @@ dependencies {
|
||||
compile "frankiesardo:icepick:$ICEPICK_VERSION"
|
||||
provided "frankiesardo:icepick-processor:$ICEPICK_VERSION"
|
||||
compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.4'
|
||||
compile 'eu.davidea:flexible-adapter:4.0.1@aar'
|
||||
compile 'eu.davidea:flexible-adapter:4.1.0@aar'
|
||||
|
||||
compile "com.google.dagger:dagger:$DAGGER_VERSION"
|
||||
apt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
|
||||
|
@ -108,13 +108,13 @@ public class DatabaseHelper {
|
||||
.prepare();
|
||||
}
|
||||
|
||||
public PreparedGetListOfObjects<Manga> getManga(String url) {
|
||||
public PreparedGetListOfObjects<Manga> getManga(String url, int sourceId) {
|
||||
return db.get()
|
||||
.listOfObjects(Manga.class)
|
||||
.withQuery(Query.builder()
|
||||
.table(MangaTable.TABLE)
|
||||
.where(MangaTable.COLUMN_URL + "=?")
|
||||
.whereArgs(url)
|
||||
.where(MangaTable.COLUMN_URL + "=? AND " + MangaTable.COLUMN_SOURCE + "=?")
|
||||
.whereArgs(url, sourceId)
|
||||
.build())
|
||||
.prepare();
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
|
||||
}
|
||||
|
||||
private Manga networkToLocalManga(Manga networkManga) {
|
||||
List<Manga> dbResult = db.getManga(networkManga.url).executeAsBlocking();
|
||||
List<Manga> dbResult = db.getManga(networkManga.url, selectedSource.getSourceId()).executeAsBlocking();
|
||||
Manga localManga = !dbResult.isEmpty() ? dbResult.get(0) : null;
|
||||
if (localManga == null) {
|
||||
PutResult result = db.insertManga(networkManga).executeAsBlocking();
|
||||
|
@ -79,11 +79,15 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
|
||||
|
||||
// Set initial values
|
||||
setReadFilter();
|
||||
setDownloadedFilter();
|
||||
setSortIcon();
|
||||
|
||||
// Init listeners
|
||||
swipeRefresh.setOnRefreshListener(this::onFetchChapters);
|
||||
readCb.setOnCheckedChangeListener((arg, isChecked) -> getPresenter().setReadFilter(isChecked));
|
||||
readCb.setOnCheckedChangeListener((arg, isChecked) ->
|
||||
getPresenter().setReadFilter(isChecked));
|
||||
downloadedCb.setOnCheckedChangeListener((v, isChecked) ->
|
||||
getPresenter().setDownloadedFilter(isChecked));
|
||||
sortBtn.setOnClickListener(v -> {
|
||||
getPresenter().revertSortOrder();
|
||||
setSortIcon();
|
||||
@ -294,4 +298,11 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
|
||||
readCb.setChecked(getPresenter().getReadFilter());
|
||||
}
|
||||
}
|
||||
|
||||
public void setDownloadedFilter() {
|
||||
if (downloadedCb != null) {
|
||||
downloadedCb.setChecked(getPresenter().getDownloadedFilter());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
||||
private boolean isCatalogueManga;
|
||||
private boolean sortOrderAToZ = true;
|
||||
private boolean onlyUnread = true;
|
||||
private boolean onlyDownloaded;
|
||||
|
||||
private static final int DB_CHAPTERS = 1;
|
||||
private static final int FETCH_CHAPTERS = 2;
|
||||
@ -98,6 +99,7 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
||||
private Observable<List<Chapter>> getDbChaptersObs() {
|
||||
return db.getChapters(manga.id, sortOrderAToZ, onlyUnread).createObservable()
|
||||
.doOnNext(this::checkChaptersStatus)
|
||||
.flatMap(this::applyDownloadedFilter)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
@ -152,7 +154,6 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
private void checkChaptersStatus(List<Chapter> chapters) {
|
||||
for (Chapter chapter : chapters) {
|
||||
checkIsChapterDownloaded(chapter);
|
||||
@ -174,6 +175,15 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
||||
}
|
||||
}
|
||||
|
||||
private Observable<List<Chapter>> applyDownloadedFilter(List<Chapter> chapters) {
|
||||
if (onlyDownloaded)
|
||||
return Observable.from(chapters)
|
||||
.filter(chapter -> chapter.status == Download.DOWNLOADED)
|
||||
.toList();
|
||||
|
||||
return Observable.just(chapters);
|
||||
}
|
||||
|
||||
public void revertSortOrder() {
|
||||
//TODO manga.chapter_order
|
||||
sortOrderAToZ = !sortOrderAToZ;
|
||||
@ -186,6 +196,11 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
||||
start(DB_CHAPTERS);
|
||||
}
|
||||
|
||||
public void setDownloadedFilter(boolean onlyDownloaded) {
|
||||
this.onlyDownloaded = onlyDownloaded;
|
||||
start(DB_CHAPTERS);
|
||||
}
|
||||
|
||||
public void setIsCatalogueManga(boolean value) {
|
||||
isCatalogueManga = value;
|
||||
}
|
||||
@ -198,7 +213,12 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
||||
return onlyUnread;
|
||||
}
|
||||
|
||||
public boolean getDownloadedFilter() {
|
||||
return onlyDownloaded;
|
||||
}
|
||||
|
||||
public Manga getManga() {
|
||||
return manga;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user