mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 07:41:51 +01:00
Initial support for read chapters
This commit is contained in:
parent
5e01937cce
commit
afebfec737
@ -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<PostResult> insertOrRemoveChapters(Manga manga, List<Chapter> chapters) {
|
||||
return mChapterManager.insertOrRemoveChapters(manga, chapters);
|
||||
|
@ -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<Response> getProgressResponse(final String url, final Headers headers, final Page page) {
|
||||
public Observable<Response> getProgressResponse(final String url, final Headers headers, final ProgressListener listener) {
|
||||
return Observable.<Response>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());
|
||||
|
@ -22,6 +22,8 @@ public interface ChapterManager {
|
||||
|
||||
Observable<PutResults<Chapter>> insertChapters(List<Chapter> chapters);
|
||||
|
||||
PutResult insertChapterBlock(Chapter chapter);
|
||||
|
||||
Observable<PostResult> insertOrRemoveChapters(Manga manga, List<Chapter> chapters);
|
||||
|
||||
Observable<DeleteResult> deleteChapter(Chapter chapter);
|
||||
|
@ -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<PostResult> insertOrRemoveChapters(Manga manga, List<Chapter> chapters) {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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 + ") "
|
||||
|
@ -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<ReaderActivity> {
|
||||
|
||||
@Inject PreferencesHelper prefs;
|
||||
@Inject DatabaseHelper db;
|
||||
|
||||
private Source source;
|
||||
private Chapter chapter;
|
||||
private List<Page> 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<ReaderActivity> {
|
||||
.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<ReaderActivity> {
|
||||
@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<ReaderActivity> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
|
||||
|
||||
@Inject PreferencesHelper prefs;
|
||||
|
||||
private int currentPage;
|
||||
private BaseViewer viewer;
|
||||
|
||||
private static final int LEFT_TO_RIGHT = 1;
|
||||
@ -61,18 +60,13 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
|
||||
enableHardwareAcceleration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
getPresenter().setCurrentPage(currentPage);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
public void onPageListReady(List<Page> 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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package eu.kanade.mangafeed.ui.adapter;
|
||||
package eu.kanade.mangafeed.ui.holder;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
@ -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<Chapter> {
|
||||
|
||||
@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<Chapter> {
|
||||
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
|
@ -1,4 +1,4 @@
|
||||
package eu.kanade.mangafeed.ui.adapter;
|
||||
package eu.kanade.mangafeed.ui.holder;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
@ -1,4 +1,4 @@
|
||||
package eu.kanade.mangafeed.ui.adapter;
|
||||
package eu.kanade.mangafeed.ui.holder;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -15,4 +15,5 @@
|
||||
<color name="bg_light_grey">#E9E9E9</color>
|
||||
<color name="black_87pc">#DD000000</color>
|
||||
<color name="library_text_background">#E8E8E8</color>
|
||||
<color name="chapter_read_text">#909090</color>
|
||||
</resources>
|
@ -75,5 +75,6 @@
|
||||
<string name="action_favorite">Favorite</string>
|
||||
<string name="downloading">Downloading…</string>
|
||||
<string name="download_progress">Downloaded %1$d%%</string>
|
||||
<string name="chapter_progress">Page: %1$d</string>
|
||||
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user