Minor changes

This commit is contained in:
inorichi 2015-12-02 10:32:16 +01:00
parent aa6dfddffa
commit 68f1e5f4bb
7 changed files with 24 additions and 12 deletions

View File

@ -10,10 +10,10 @@ import eu.kanade.mangafeed.util.UrlUtil;
public class Chapter { public class Chapter {
@StorIOSQLiteColumn(name = ChapterTable.COLUMN_ID, key = true) @StorIOSQLiteColumn(name = ChapterTable.COLUMN_ID, key = true)
public Long id; public long id;
@StorIOSQLiteColumn(name = ChapterTable.COLUMN_MANGA_ID) @StorIOSQLiteColumn(name = ChapterTable.COLUMN_MANGA_ID)
public Long manga_id; public long manga_id;
@StorIOSQLiteColumn(name = ChapterTable.COLUMN_URL) @StorIOSQLiteColumn(name = ChapterTable.COLUMN_URL)
public String url; public String url;

View File

@ -10,7 +10,7 @@ import eu.kanade.mangafeed.util.UrlUtil;
public class Manga { public class Manga {
@StorIOSQLiteColumn(name = MangaTable.COLUMN_ID, key = true) @StorIOSQLiteColumn(name = MangaTable.COLUMN_ID, key = true)
public Long id; public long id;
@StorIOSQLiteColumn(name = MangaTable.COLUMN_SOURCE) @StorIOSQLiteColumn(name = MangaTable.COLUMN_SOURCE)
public int source; public int source;

View File

@ -133,7 +133,7 @@ public class DownloadManager {
private boolean prepareDownload(Download download) { private boolean prepareDownload(Download download) {
// If the chapter is already queued, don't add it again // If the chapter is already queued, don't add it again
for (Download queuedDownload : queue.get()) { for (Download queuedDownload : queue.get()) {
if (download.chapter.id.equals(queuedDownload.chapter.id)) if (download.chapter.id == queuedDownload.chapter.id)
return true; return true;
} }

View File

@ -54,6 +54,6 @@ public class Download {
private void notifyStatus() { private void notifyStatus() {
if (statusSubject != null) if (statusSubject != null)
statusSubject.onNext(this); statusSubject.onNext(this);
EventBus.getDefault().post(new DownloadStatusEvent(chapter.id, status)); EventBus.getDefault().post(new DownloadStatusEvent(chapter, status));
} }
} }

View File

@ -1,17 +1,19 @@
package eu.kanade.mangafeed.event; package eu.kanade.mangafeed.event;
import eu.kanade.mangafeed.data.database.models.Chapter;
public class DownloadStatusEvent { public class DownloadStatusEvent {
private long chapterId; private Chapter chapter;
private int status; private int status;
public DownloadStatusEvent(long chapterId, int status) { public DownloadStatusEvent(Chapter chapter, int status) {
this.chapterId = chapterId; this.chapter = chapter;
this.status = status; this.status = status;
} }
public long getChapterId() { public Chapter getChapter() {
return chapterId; return chapter;
} }
public int getStatus() { public int getStatus() {

View File

@ -23,6 +23,7 @@ import butterknife.Bind;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import eu.kanade.mangafeed.R; import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.data.database.models.Chapter; import eu.kanade.mangafeed.data.database.models.Chapter;
import eu.kanade.mangafeed.data.database.models.Manga;
import eu.kanade.mangafeed.data.download.DownloadService; import eu.kanade.mangafeed.data.download.DownloadService;
import eu.kanade.mangafeed.event.DownloadStatusEvent; import eu.kanade.mangafeed.event.DownloadStatusEvent;
import eu.kanade.mangafeed.ui.base.activity.BaseActivity; import eu.kanade.mangafeed.ui.base.activity.BaseActivity;
@ -150,10 +151,15 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
@EventBusHook @EventBusHook
public void onEventMainThread(DownloadStatusEvent event) { public void onEventMainThread(DownloadStatusEvent event) {
Manga manga = getPresenter().getManga();
// If the download status is from another manga, don't bother
if (manga != null && event.getChapter().manga_id != manga.id)
return;
Chapter chapter; Chapter chapter;
for (int i = 0; i < adapter.getItemCount(); i++) { for (int i = 0; i < adapter.getItemCount(); i++) {
chapter = adapter.getItem(i); chapter = adapter.getItem(i);
if (event.getChapterId() == chapter.id) { if (event.getChapter().id == chapter.id) {
chapter.status = event.getStatus(); chapter.status = event.getStatus();
adapter.notifyItemChanged(i); adapter.notifyItemChanged(i);
break; break;

View File

@ -171,7 +171,7 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
public void checkIsChapterDownloaded(Chapter chapter) { public void checkIsChapterDownloaded(Chapter chapter) {
for (Download download : downloadManager.getQueue().get()) { for (Download download : downloadManager.getQueue().get()) {
if (chapter.id.equals(download.chapter.id)) { if (chapter.id == download.chapter.id) {
chapter.status = download.getStatus(); chapter.status = download.getStatus();
return; return;
} }
@ -207,4 +207,8 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
public boolean getReadFilter() { public boolean getReadFilter() {
return onlyUnread; return onlyUnread;
} }
public Manga getManga() {
return manga;
}
} }