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"
|
compile "frankiesardo:icepick:$ICEPICK_VERSION"
|
||||||
provided "frankiesardo:icepick-processor:$ICEPICK_VERSION"
|
provided "frankiesardo:icepick-processor:$ICEPICK_VERSION"
|
||||||
compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.4'
|
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"
|
compile "com.google.dagger:dagger:$DAGGER_VERSION"
|
||||||
apt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
|
apt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
|
||||||
|
@ -108,13 +108,13 @@ public class DatabaseHelper {
|
|||||||
.prepare();
|
.prepare();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PreparedGetListOfObjects<Manga> getManga(String url) {
|
public PreparedGetListOfObjects<Manga> getManga(String url, int sourceId) {
|
||||||
return db.get()
|
return db.get()
|
||||||
.listOfObjects(Manga.class)
|
.listOfObjects(Manga.class)
|
||||||
.withQuery(Query.builder()
|
.withQuery(Query.builder()
|
||||||
.table(MangaTable.TABLE)
|
.table(MangaTable.TABLE)
|
||||||
.where(MangaTable.COLUMN_URL + "=?")
|
.where(MangaTable.COLUMN_URL + "=? AND " + MangaTable.COLUMN_SOURCE + "=?")
|
||||||
.whereArgs(url)
|
.whereArgs(url, sourceId)
|
||||||
.build())
|
.build())
|
||||||
.prepare();
|
.prepare();
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Manga networkToLocalManga(Manga networkManga) {
|
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;
|
Manga localManga = !dbResult.isEmpty() ? dbResult.get(0) : null;
|
||||||
if (localManga == null) {
|
if (localManga == null) {
|
||||||
PutResult result = db.insertManga(networkManga).executeAsBlocking();
|
PutResult result = db.insertManga(networkManga).executeAsBlocking();
|
||||||
|
@ -79,11 +79,15 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
|
|||||||
|
|
||||||
// Set initial values
|
// Set initial values
|
||||||
setReadFilter();
|
setReadFilter();
|
||||||
|
setDownloadedFilter();
|
||||||
setSortIcon();
|
setSortIcon();
|
||||||
|
|
||||||
// Init listeners
|
// Init listeners
|
||||||
swipeRefresh.setOnRefreshListener(this::onFetchChapters);
|
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 -> {
|
sortBtn.setOnClickListener(v -> {
|
||||||
getPresenter().revertSortOrder();
|
getPresenter().revertSortOrder();
|
||||||
setSortIcon();
|
setSortIcon();
|
||||||
@ -294,4 +298,11 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
|
|||||||
readCb.setChecked(getPresenter().getReadFilter());
|
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 isCatalogueManga;
|
||||||
private boolean sortOrderAToZ = true;
|
private boolean sortOrderAToZ = true;
|
||||||
private boolean onlyUnread = true;
|
private boolean onlyUnread = true;
|
||||||
|
private boolean onlyDownloaded;
|
||||||
|
|
||||||
private static final int DB_CHAPTERS = 1;
|
private static final int DB_CHAPTERS = 1;
|
||||||
private static final int FETCH_CHAPTERS = 2;
|
private static final int FETCH_CHAPTERS = 2;
|
||||||
@ -98,6 +99,7 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
|||||||
private Observable<List<Chapter>> getDbChaptersObs() {
|
private Observable<List<Chapter>> getDbChaptersObs() {
|
||||||
return db.getChapters(manga.id, sortOrderAToZ, onlyUnread).createObservable()
|
return db.getChapters(manga.id, sortOrderAToZ, onlyUnread).createObservable()
|
||||||
.doOnNext(this::checkChaptersStatus)
|
.doOnNext(this::checkChaptersStatus)
|
||||||
|
.flatMap(this::applyDownloadedFilter)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread());
|
.observeOn(AndroidSchedulers.mainThread());
|
||||||
}
|
}
|
||||||
@ -152,7 +154,6 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void checkChaptersStatus(List<Chapter> chapters) {
|
private void checkChaptersStatus(List<Chapter> chapters) {
|
||||||
for (Chapter chapter : chapters) {
|
for (Chapter chapter : chapters) {
|
||||||
checkIsChapterDownloaded(chapter);
|
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() {
|
public void revertSortOrder() {
|
||||||
//TODO manga.chapter_order
|
//TODO manga.chapter_order
|
||||||
sortOrderAToZ = !sortOrderAToZ;
|
sortOrderAToZ = !sortOrderAToZ;
|
||||||
@ -186,6 +196,11 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
|||||||
start(DB_CHAPTERS);
|
start(DB_CHAPTERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDownloadedFilter(boolean onlyDownloaded) {
|
||||||
|
this.onlyDownloaded = onlyDownloaded;
|
||||||
|
start(DB_CHAPTERS);
|
||||||
|
}
|
||||||
|
|
||||||
public void setIsCatalogueManga(boolean value) {
|
public void setIsCatalogueManga(boolean value) {
|
||||||
isCatalogueManga = value;
|
isCatalogueManga = value;
|
||||||
}
|
}
|
||||||
@ -198,7 +213,12 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
|||||||
return onlyUnread;
|
return onlyUnread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getDownloadedFilter() {
|
||||||
|
return onlyDownloaded;
|
||||||
|
}
|
||||||
|
|
||||||
public Manga getManga() {
|
public Manga getManga() {
|
||||||
return manga;
|
return manga;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user