diff --git a/app/src/main/java/eu/kanade/mangafeed/data/helpers/DatabaseHelper.java b/app/src/main/java/eu/kanade/mangafeed/data/helpers/DatabaseHelper.java index c0975d92e..beb7ad8f5 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/helpers/DatabaseHelper.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/helpers/DatabaseHelper.java @@ -73,6 +73,11 @@ public class DatabaseHelper implements MangaManager, ChapterManager { return mChapterManager.insertChapters(chapters); } + @Override + public PutResult insertChapterBlock(Chapter chapter) { + return mChapterManager.insertChapterBlock(chapter); + } + @Override public Observable insertOrRemoveChapters(Manga manga, List chapters) { return mChapterManager.insertOrRemoveChapters(manga, chapters); diff --git a/app/src/main/java/eu/kanade/mangafeed/data/helpers/NetworkHelper.java b/app/src/main/java/eu/kanade/mangafeed/data/helpers/NetworkHelper.java index f3a5ef4d7..30242c9c1 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/helpers/NetworkHelper.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/helpers/NetworkHelper.java @@ -15,7 +15,6 @@ import java.net.CookieManager; import java.net.CookiePolicy; import java.net.CookieStore; -import eu.kanade.mangafeed.data.models.Page; import okio.Buffer; import okio.BufferedSource; import okio.ForwardingSource; @@ -91,7 +90,7 @@ public final class NetworkHelper { }); } - public Observable getProgressResponse(final String url, final Headers headers, final Page page) { + public Observable getProgressResponse(final String url, final Headers headers, final ProgressListener listener) { return Observable.create(subscriber -> { try { if (!subscriber.isUnsubscribed()) { @@ -106,7 +105,7 @@ public final class NetworkHelper { progressClient.networkInterceptors().add(chain -> { Response originalResponse = chain.proceed(chain.request()); return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), page)) + .body(new ProgressResponseBody(originalResponse.body(), listener)) .build(); }); subscriber.onNext(progressClient.newCall(request).execute()); diff --git a/app/src/main/java/eu/kanade/mangafeed/data/managers/ChapterManager.java b/app/src/main/java/eu/kanade/mangafeed/data/managers/ChapterManager.java index c692a9d92..28a388195 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/managers/ChapterManager.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/managers/ChapterManager.java @@ -22,6 +22,8 @@ public interface ChapterManager { Observable> insertChapters(List chapters); + PutResult insertChapterBlock(Chapter chapter); + Observable insertOrRemoveChapters(Manga manga, List chapters); Observable deleteChapter(Chapter chapter); diff --git a/app/src/main/java/eu/kanade/mangafeed/data/managers/ChapterManagerImpl.java b/app/src/main/java/eu/kanade/mangafeed/data/managers/ChapterManagerImpl.java index ffe87e175..3d6a7b487 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/managers/ChapterManagerImpl.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/managers/ChapterManagerImpl.java @@ -67,6 +67,14 @@ public class ChapterManagerImpl extends BaseManager implements ChapterManager { .createObservable(); } + @Override + public PutResult insertChapterBlock(Chapter chapter) { + return db.put() + .object(chapter) + .prepare() + .executeAsBlocking(); + } + // Add new chapters or delete if the source deletes them @Override public Observable insertOrRemoveChapters(Manga manga, List chapters) { diff --git a/app/src/main/java/eu/kanade/mangafeed/data/models/Chapter.java b/app/src/main/java/eu/kanade/mangafeed/data/models/Chapter.java index 5b3ad3655..86dd0d101 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/models/Chapter.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/models/Chapter.java @@ -1,8 +1,5 @@ package eu.kanade.mangafeed.data.models; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; - import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn; import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType; @@ -11,31 +8,27 @@ import eu.kanade.mangafeed.data.tables.ChaptersTable; @StorIOSQLiteType(table = ChaptersTable.TABLE) public class Chapter { - @Nullable @StorIOSQLiteColumn(name = ChaptersTable.COLUMN_ID, key = true) public Long id; - @NonNull @StorIOSQLiteColumn(name = ChaptersTable.COLUMN_MANGA_ID) public Long manga_id; - @NonNull @StorIOSQLiteColumn(name = ChaptersTable.COLUMN_URL) public String url; - @NonNull @StorIOSQLiteColumn(name = ChaptersTable.COLUMN_NAME) public String name; - @NonNull @StorIOSQLiteColumn(name = ChaptersTable.COLUMN_READ) - public int read; + public boolean read; + + @StorIOSQLiteColumn(name = ChaptersTable.COLUMN_LAST_PAGE_READ) + public int last_page_read; - @NonNull @StorIOSQLiteColumn(name = ChaptersTable.COLUMN_DATE_FETCH) public long date_fetch; - @NonNull @StorIOSQLiteColumn(name = ChaptersTable.COLUMN_DATE_UPLOAD) public long date_upload; diff --git a/app/src/main/java/eu/kanade/mangafeed/data/tables/ChaptersTable.java b/app/src/main/java/eu/kanade/mangafeed/data/tables/ChaptersTable.java index f8fe05993..394c27360 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/tables/ChaptersTable.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/tables/ChaptersTable.java @@ -28,6 +28,9 @@ public class ChaptersTable { @NonNull public static final String COLUMN_DATE_UPLOAD = "date_upload"; + @NonNull + public static final String COLUMN_LAST_PAGE_READ = "last_page_read"; + @NonNull public static String getCreateTableQuery() { return "CREATE TABLE " + TABLE + "(" @@ -36,6 +39,7 @@ public class ChaptersTable { + COLUMN_URL + " TEXT NOT NULL, " + COLUMN_NAME + " TEXT NOT NULL, " + COLUMN_READ + " BOOLEAN NOT NULL, " + + COLUMN_LAST_PAGE_READ + " INT NOT NULL, " + COLUMN_DATE_FETCH + " LONG NOT NULL, " + COLUMN_DATE_UPLOAD + " LONG NOT NULL, " + "FOREIGN KEY(" + COLUMN_MANGA_ID + ") REFERENCES " + MangasTable.TABLE + "(" + MangasTable.COLUMN_ID + ") " diff --git a/app/src/main/java/eu/kanade/mangafeed/presenter/ReaderPresenter.java b/app/src/main/java/eu/kanade/mangafeed/presenter/ReaderPresenter.java index 2e688eb2d..9efee111b 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/ReaderPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/ReaderPresenter.java @@ -7,6 +7,7 @@ import java.util.List; import javax.inject.Inject; import de.greenrobot.event.EventBus; +import eu.kanade.mangafeed.data.helpers.DatabaseHelper; import eu.kanade.mangafeed.data.helpers.PreferencesHelper; import eu.kanade.mangafeed.data.models.Chapter; import eu.kanade.mangafeed.data.models.Page; @@ -23,11 +24,13 @@ import timber.log.Timber; public class ReaderPresenter extends BasePresenter { @Inject PreferencesHelper prefs; + @Inject DatabaseHelper db; private Source source; private Chapter chapter; private List pageList; - @State int savedSelectedPage = 0; + private boolean initialStart = true; + @State int currentPage = 0; private static final int GET_PAGE_LIST = 1; private static final int GET_PAGE_IMAGES = 2; @@ -42,9 +45,10 @@ public class ReaderPresenter extends BasePresenter { .doOnCompleted(() -> start(GET_PAGE_IMAGES)), (view, pages) -> { view.onPageListReady(pages); - if (savedSelectedPage != 0) { - view.setSelectedPage(savedSelectedPage); - } + if (initialStart && !chapter.read) + view.setSelectedPage(chapter.last_page_read - 1); + else if (currentPage != 0) + view.setSelectedPage(currentPage); }, (view, error) -> Timber.e("An error occurred while downloading page list") ); @@ -69,14 +73,16 @@ public class ReaderPresenter extends BasePresenter { @Override protected void onDropView() { unregisterForEvents(); + initialStart = false; super.onDropView(); } @Override protected void onDestroy() { - super.onDestroy(); EventBus.getDefault().removeStickyEvent(SourceChapterEvent.class); source.savePageList(chapter.url, pageList); + saveChapter(); + super.onDestroy(); } @EventBusHook @@ -99,23 +105,22 @@ public class ReaderPresenter extends BasePresenter { return Observable.merge( Observable.from(pageList).filter(page -> page.getImageUrl() != null), source.getRemainingImageUrlsFromPageList(pageList) - .doOnNext(this::replacePageUrl) ) .flatMap(source::getCachedImage) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); } - private void replacePageUrl(Page page) { - for (int i = 0; i < pageList.size(); i++) { - if (pageList.get(i).getPageNumber() == page.getPageNumber()) { - pageList.set(i, page); - return; - } - } + public void setCurrentPage(int currentPage) { + this.currentPage = currentPage; } - public void setCurrentPage(int savedPage) { - this.savedSelectedPage = savedPage; + private void saveChapter() { + chapter.last_page_read = currentPage + 1; + if (currentPage == pageList.size() - 1) { + chapter.read = true; + + } + db.insertChapterBlock(chapter); } } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/activity/ReaderActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/activity/ReaderActivity.java index 5c8ada458..856b9a10d 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/activity/ReaderActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/activity/ReaderActivity.java @@ -36,7 +36,6 @@ public class ReaderActivity extends BaseRxActivity { @Inject PreferencesHelper prefs; - private int currentPage; private BaseViewer viewer; private static final int LEFT_TO_RIGHT = 1; @@ -60,19 +59,14 @@ public class ReaderActivity extends BaseRxActivity { enableHardwareAcceleration(); } - - @Override - public void onDestroy() { - getPresenter().setCurrentPage(currentPage); - super.onDestroy(); - } - + public void onPageListReady(List pages) { viewer.onPageListReady(pages); } public void onPageChanged(int currentPageIndex, int totalPages) { - currentPage = currentPageIndex; + if (currentPageIndex != 0) + getPresenter().setCurrentPage(currentPageIndex); String page = (currentPageIndex + 1) + "/" + totalPages; pageNumber.setText(page); } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/LibraryAdapter.java b/app/src/main/java/eu/kanade/mangafeed/ui/adapter/LibraryAdapter.java index dc42d0558..77bd90a9f 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/LibraryAdapter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/adapter/LibraryAdapter.java @@ -7,6 +7,7 @@ import android.widget.Filterable; import java.util.List; import eu.kanade.mangafeed.data.models.Manga; +import eu.kanade.mangafeed.ui.holder.LibraryHolder; import rx.Observable; import uk.co.ribot.easyadapter.EasyAdapter; diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/CatalogueFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/CatalogueFragment.java index fbfbc3730..93c0c27b6 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/CatalogueFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/CatalogueFragment.java @@ -24,7 +24,7 @@ import eu.kanade.mangafeed.R; import eu.kanade.mangafeed.data.models.Manga; import eu.kanade.mangafeed.presenter.CataloguePresenter; import eu.kanade.mangafeed.ui.activity.MangaDetailActivity; -import eu.kanade.mangafeed.ui.adapter.CatalogueHolder; +import eu.kanade.mangafeed.ui.holder.CatalogueHolder; import eu.kanade.mangafeed.ui.fragment.base.BaseRxFragment; import eu.kanade.mangafeed.util.PageBundle; import eu.kanade.mangafeed.widget.EndlessScrollListener; diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/MangaChaptersFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/MangaChaptersFragment.java index c18f7fcb5..b58153cde 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/MangaChaptersFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/MangaChaptersFragment.java @@ -22,7 +22,7 @@ import eu.kanade.mangafeed.data.models.Chapter; import eu.kanade.mangafeed.presenter.MangaChaptersPresenter; import eu.kanade.mangafeed.ui.activity.MangaDetailActivity; import eu.kanade.mangafeed.ui.activity.ReaderActivity; -import eu.kanade.mangafeed.ui.adapter.ChapterListHolder; +import eu.kanade.mangafeed.ui.holder.ChapterListHolder; import eu.kanade.mangafeed.ui.fragment.base.BaseRxFragment; import nucleus.factory.RequiresPresenter; import uk.co.ribot.easyadapter.EasyRecyclerAdapter; diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/SourceFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/SourceFragment.java index 3d661fe10..d35e5e6cd 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/SourceFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/SourceFragment.java @@ -15,7 +15,7 @@ import eu.kanade.mangafeed.R; import eu.kanade.mangafeed.presenter.SourcePresenter; import eu.kanade.mangafeed.sources.base.Source; import eu.kanade.mangafeed.ui.activity.MainActivity; -import eu.kanade.mangafeed.ui.adapter.SourceHolder; +import eu.kanade.mangafeed.ui.holder.SourceHolder; import eu.kanade.mangafeed.ui.fragment.base.BaseRxFragment; import nucleus.factory.RequiresPresenter; import uk.co.ribot.easyadapter.EasyAdapter; diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/CatalogueHolder.java b/app/src/main/java/eu/kanade/mangafeed/ui/holder/CatalogueHolder.java similarity index 96% rename from app/src/main/java/eu/kanade/mangafeed/ui/adapter/CatalogueHolder.java rename to app/src/main/java/eu/kanade/mangafeed/ui/holder/CatalogueHolder.java index a95a20116..c1850a491 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/CatalogueHolder.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/holder/CatalogueHolder.java @@ -1,4 +1,4 @@ -package eu.kanade.mangafeed.ui.adapter; +package eu.kanade.mangafeed.ui.holder; import android.view.View; import android.widget.ImageView; diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/ChapterListHolder.java b/app/src/main/java/eu/kanade/mangafeed/ui/holder/ChapterListHolder.java similarity index 62% rename from app/src/main/java/eu/kanade/mangafeed/ui/adapter/ChapterListHolder.java rename to app/src/main/java/eu/kanade/mangafeed/ui/holder/ChapterListHolder.java index ee18a9c39..ffa40386c 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/ChapterListHolder.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/holder/ChapterListHolder.java @@ -1,5 +1,7 @@ -package eu.kanade.mangafeed.ui.adapter; +package eu.kanade.mangafeed.ui.holder; +import android.graphics.Color; +import android.support.v4.content.ContextCompat; import android.view.View; import android.widget.ImageView; import android.widget.TextView; @@ -14,11 +16,9 @@ import uk.co.ribot.easyadapter.annotations.ViewId; @LayoutId(R.layout.item_chapter) public class ChapterListHolder extends ItemViewHolder { - @ViewId(R.id.chapter_title) - TextView title; - - @ViewId(R.id.chapter_download_image) - ImageView download_icon; + @ViewId(R.id.chapter_title) TextView title; + @ViewId(R.id.chapter_download_image) ImageView download_icon; + @ViewId(R.id.chapter_pages) TextView pages; View view; @@ -30,6 +30,18 @@ public class ChapterListHolder extends ItemViewHolder { public void onSetValues(Chapter chapter, PositionInfo positionInfo) { title.setText(chapter.name); download_icon.setImageResource(R.drawable.ic_file_download_black_48dp); + + if (chapter.read) { + title.setTextColor(ContextCompat.getColor(getContext(), R.color.chapter_read_text)); + } else { + title.setTextColor(Color.BLACK); + } + + if (chapter.last_page_read > 0 && !chapter.read) { + pages.setText(getContext().getString(R.string.chapter_progress, chapter.last_page_read)); + } else { + pages.setText(""); + } } @Override diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/LibraryHolder.java b/app/src/main/java/eu/kanade/mangafeed/ui/holder/LibraryHolder.java similarity index 97% rename from app/src/main/java/eu/kanade/mangafeed/ui/adapter/LibraryHolder.java rename to app/src/main/java/eu/kanade/mangafeed/ui/holder/LibraryHolder.java index 42c540db5..6cf11ad9e 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/LibraryHolder.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/holder/LibraryHolder.java @@ -1,4 +1,4 @@ -package eu.kanade.mangafeed.ui.adapter; +package eu.kanade.mangafeed.ui.holder; import android.view.View; import android.widget.ImageView; diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/SourceHolder.java b/app/src/main/java/eu/kanade/mangafeed/ui/holder/SourceHolder.java similarity index 94% rename from app/src/main/java/eu/kanade/mangafeed/ui/adapter/SourceHolder.java rename to app/src/main/java/eu/kanade/mangafeed/ui/holder/SourceHolder.java index 4bdf927fe..de0a65641 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/SourceHolder.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/holder/SourceHolder.java @@ -1,4 +1,4 @@ -package eu.kanade.mangafeed.ui.adapter; +package eu.kanade.mangafeed.ui.holder; import android.view.View; import android.widget.TextView; diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/viewer/VerticalViewer.java b/app/src/main/java/eu/kanade/mangafeed/ui/viewer/VerticalViewer.java index 02e65ddd9..28842cc65 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/viewer/VerticalViewer.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/viewer/VerticalViewer.java @@ -54,8 +54,7 @@ public class VerticalViewer extends BaseViewer { @Override public void setSelectedPage(int pageNumber) { - // TODO - return; + viewPager.setCurrentItem(getCurrentPageIndex(pageNumber)); } @Override @@ -66,6 +65,6 @@ public class VerticalViewer extends BaseViewer { @Override public boolean onImageTouch(MotionEvent motionEvent) { - return false; + return true; } } diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 503bec0f0..7aa1362cc 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -15,4 +15,5 @@ #E9E9E9 #DD000000 #E8E8E8 + #909090 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dd7f19e38..9123594de 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -75,5 +75,6 @@ Favorite Downloading… Downloaded %1$d%% + Page: %1$d