Minor changes

This commit is contained in:
inorichi 2015-11-16 18:09:31 +01:00
parent b002a125fd
commit 75236559ca
5 changed files with 80 additions and 69 deletions

View file

@ -94,7 +94,7 @@ dependencies {
apt "com.pushtorefresh.storio:sqlite-annotations-processor:$STORIO_VERSION"
provided 'org.glassfish:javax.annotation:10.0-b28'
compile('com.mikepenz:materialdrawer:4.3.0@aar') {
compile('com.mikepenz:materialdrawer:4.4.8@aar') {
transitive = true
}

View file

@ -173,8 +173,9 @@ public class DatabaseHelper {
.withQuery(Query.builder()
.table(ChaptersTable.TABLE)
.where(ChaptersTable.COLUMN_MANGA_ID + "=? AND " +
ChaptersTable.COLUMN_CHAPTER_NUMBER + ">?")
.whereArgs(chapter.manga_id, chapter.chapter_number)
ChaptersTable.COLUMN_CHAPTER_NUMBER + ">? AND " +
ChaptersTable.COLUMN_CHAPTER_NUMBER + "<=?")
.whereArgs(chapter.manga_id, chapter.chapter_number, chapter.chapter_number + 1)
.orderBy(ChaptersTable.COLUMN_CHAPTER_NUMBER)
.limit(1)
.build())
@ -187,8 +188,9 @@ public class DatabaseHelper {
.withQuery(Query.builder()
.table(ChaptersTable.TABLE)
.where(ChaptersTable.COLUMN_MANGA_ID + "=? AND " +
ChaptersTable.COLUMN_CHAPTER_NUMBER + "<?")
.whereArgs(chapter.manga_id, chapter.chapter_number)
ChaptersTable.COLUMN_CHAPTER_NUMBER + "<? AND " +
ChaptersTable.COLUMN_CHAPTER_NUMBER + ">=?")
.whereArgs(chapter.manga_id, chapter.chapter_number, chapter.chapter_number - 1)
.orderBy(ChaptersTable.COLUMN_CHAPTER_NUMBER + " DESC")
.limit(1)
.build())

View file

@ -129,10 +129,15 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter> {
}
public void initializeScrollListener() {
scroll_listener = new EndlessScrollListener(getPresenter()::requestNext);
scroll_listener = new EndlessScrollListener(this::requestNext);
manga_list.setOnScrollListener(scroll_listener);
}
public void requestNext() {
if (getPresenter().requestNext())
showGridProgressBar();
}
public void showProgressBar() {
progress.setVisibility(ProgressBar.VISIBLE);
}
@ -147,6 +152,7 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter> {
}
public void onAddPage(PageBundle<List<Manga>> page) {
hideProgressBar();
if (page.page == 0) {
adapter.getItems().clear();
scroll_listener.resetScroll();
@ -155,7 +161,7 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter> {
}
private int getMangaIndex(Manga manga) {
for (int i = 0; i < adapter.getCount(); i++) {
for (int i = adapter.getCount() - 1; i >= 0; i--) {
if (manga.id == adapter.getItem(i).id) {
return i;
}
@ -164,6 +170,9 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter> {
}
private ImageView getImageView(int position) {
if (position == -1)
return null;
View v = manga_list.getChildAt(position -
manga_list.getFirstVisiblePosition());

View file

@ -23,6 +23,7 @@ import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import rx.subjects.PublishSubject;
import timber.log.Timber;
public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
@ -31,40 +32,55 @@ public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
private Source selectedSource;
@State protected String mSearchName;
@State protected boolean mSearchMode;
@State protected String searchName;
@State protected boolean searchMode;
private final int SEARCH_TIMEOUT = 1000;
private int mCurrentPage;
private int currentPage;
private RxPager pager;
private MangasPage lastMangasPage;
private Subscription mQueryDebouncerSubscription;
private Subscription mMangaDetailFetchSubscription;
private PublishSubject<String> mQueryDebouncerSubject;
private PublishSubject<List<Manga>> mMangaDetailPublishSubject;
private Subscription queryDebouncerSubscription;
private PublishSubject<String> queryDebouncerSubject;
private PublishSubject<List<Manga>> mangaDetailSubject;
private static final int GET_MANGA_LIST = 1;
private static final int GET_MANGA_DETAIL = 2;
@Override
protected void onCreate(Bundle savedState) {
super.onCreate(savedState);
mangaDetailSubject = PublishSubject.create();
restartableReplay(GET_MANGA_LIST,
() -> pager.pages().<PageBundle<List<Manga>>>concatMap(
page -> getMangaObs(page + 1)
.map(mangas -> new PageBundle<>(page, mangas))
.observeOn(AndroidSchedulers.mainThread())
),
.observeOn(AndroidSchedulers.mainThread())),
(view, page) -> {
view.hideProgressBar();
view.onAddPage(page);
if (mMangaDetailPublishSubject != null)
mMangaDetailPublishSubject.onNext(page.data);
});
if (mangaDetailSubject != null)
mangaDetailSubject.onNext(page.data);
},
(view, error) -> Timber.e(error.fillInStackTrace(), error.getMessage()));
restartableLatestCache(GET_MANGA_DETAIL,
() -> mangaDetailSubject
.subscribeOn(Schedulers.io())
.flatMap(Observable::from)
.filter(manga -> !manga.initialized)
.window(3)
.concatMap(pack -> pack.concatMap(this::getMangaDetails))
.filter(manga -> manga.initialized)
.onBackpressureBuffer()
.observeOn(AndroidSchedulers.mainThread()),
(view, manga) -> {
view.updateImage(manga);
},
(view, error) -> Timber.e(error.fillInStackTrace(), error.getMessage()));
initializeSearch();
initializeMangaDetailsLoader();
}
@Override
@ -73,8 +89,8 @@ public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
view.setToolbarTitle(selectedSource.getName());
if (mSearchMode)
view.restoreSearch(mSearchName);
if (searchMode)
view.restoreSearch(searchName);
}
public void startRequesting(int sourceId) {
@ -84,31 +100,32 @@ public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
private void restartRequest() {
stop(GET_MANGA_LIST);
mCurrentPage = 1;
currentPage = 1;
pager = new RxPager();
if (getView() != null)
getView().showProgressBar();
start(GET_MANGA_DETAIL);
start(GET_MANGA_LIST);
}
public void requestNext() {
pager.requestNext(++mCurrentPage);
public boolean requestNext() {
if (lastMangasPage.nextPageUrl == null)
return false;
pager.requestNext(++currentPage);
return true;
}
private Observable<List<Manga>> getMangaObs(int page) {
MangasPage nextMangasPage = new MangasPage(page);
if (page != 1) {
if (lastMangasPage.nextPageUrl == null)
return Observable.empty();
nextMangasPage.url = lastMangasPage.nextPageUrl;
}
if (getView() != null)
getView().showGridProgressBar();
Observable<MangasPage> obs;
if (mSearchMode)
obs = selectedSource.searchMangasFromNetwork(nextMangasPage, mSearchName);
if (searchMode)
obs = selectedSource.searchMangasFromNetwork(nextMangasPage, searchName);
else
obs = selectedSource.pullPopularMangasFromNetwork(nextMangasPage);
@ -131,41 +148,20 @@ public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
}
private void initializeSearch() {
if (mQueryDebouncerSubscription != null)
if (queryDebouncerSubscription != null)
return;
mSearchName = "";
mSearchMode = false;
mQueryDebouncerSubject = PublishSubject.create();
searchName = "";
searchMode = false;
queryDebouncerSubject = PublishSubject.create();
add(mQueryDebouncerSubscription = mQueryDebouncerSubject
add(queryDebouncerSubscription = queryDebouncerSubject
.debounce(SEARCH_TIMEOUT, TimeUnit.MILLISECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::queryFromSearch));
}
private void initializeMangaDetailsLoader() {
if (mMangaDetailFetchSubscription != null)
return;
mMangaDetailPublishSubject = PublishSubject.create();
add(mMangaDetailFetchSubscription = mMangaDetailPublishSubject
.subscribeOn(Schedulers.io())
.flatMap(Observable::from)
.filter(manga -> !manga.initialized)
.window(3)
.concatMap(pack -> pack.concatMap(this::getMangaDetails))
.filter(manga -> manga.initialized)
.onBackpressureBuffer()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(manga -> {
if (getView() != null)
getView().updateImage(manga);
}));
}
private Observable<Manga> getMangaDetails(final Manga manga) {
return selectedSource.pullMangaFromNetwork(manga.url)
.subscribeOn(Schedulers.io())
@ -173,6 +169,9 @@ public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
Manga.copyFromNetwork(manga, networkManga);
db.insertManga(manga).executeAsBlocking();
return Observable.just(manga);
})
.onErrorResumeNext(error -> {
return Observable.just(manga);
});
}
@ -180,25 +179,25 @@ public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
// If the query is empty or not debounced, resolve it instantly
if (now || query.equals(""))
queryFromSearch(query);
else if (mQueryDebouncerSubject != null)
mQueryDebouncerSubject.onNext(query);
else if (queryDebouncerSubject != null)
queryDebouncerSubject.onNext(query);
}
private void queryFromSearch(String query) {
// If text didn't change, do nothing
if (mSearchName.equals(query)) {
if (searchName.equals(query)) {
return;
}
// If going to search mode
else if (mSearchName.equals("") && !query.equals("")) {
mSearchMode = true;
else if (searchName.equals("") && !query.equals("")) {
searchMode = true;
}
// If going to normal mode
else if (!mSearchName.equals("") && query.equals("")) {
mSearchMode = false;
else if (!searchName.equals("") && query.equals("")) {
searchMode = false;
}
mSearchName = query;
searchName = query;
restartRequest();
}

View file

@ -14,11 +14,11 @@ import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
import butterknife.Bind;
import butterknife.ButterKnife;
import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.ui.setting.SettingsActivity;
import eu.kanade.mangafeed.ui.base.activity.BaseActivity;
import eu.kanade.mangafeed.ui.catalogue.SourceFragment;
import eu.kanade.mangafeed.ui.download.DownloadFragment;
import eu.kanade.mangafeed.ui.library.LibraryFragment;
import eu.kanade.mangafeed.ui.catalogue.SourceFragment;
import eu.kanade.mangafeed.ui.setting.SettingsActivity;
public class MainActivity extends BaseActivity {
@ -88,6 +88,7 @@ public class MainActivity extends BaseActivity {
)
.build();
if (savedInstanceState == null)
drawer.setSelection(R.id.nav_drawer_library);
}