mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07:57 +01:00 
			
		
		
		
	Show download status in chapters fragment
This commit is contained in:
		| @@ -119,7 +119,7 @@ public class DownloadManager { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // Public method to checks if a chapter is downloaded | ||||
|     // Public method to check if a chapter is downloaded | ||||
|     public boolean isChapterDownloaded(Source source, Manga manga, Chapter chapter) { | ||||
|         File directory = getAbsoluteChapterDirectory(source, manga, chapter); | ||||
|         if (!directory.exists()) | ||||
|   | ||||
| @@ -3,10 +3,12 @@ package eu.kanade.mangafeed.data.download.model; | ||||
| import java.io.File; | ||||
| import java.util.List; | ||||
|  | ||||
| import de.greenrobot.event.EventBus; | ||||
| import eu.kanade.mangafeed.data.database.models.Chapter; | ||||
| import eu.kanade.mangafeed.data.database.models.Manga; | ||||
| import eu.kanade.mangafeed.data.source.model.Page; | ||||
| import eu.kanade.mangafeed.data.source.base.Source; | ||||
| import eu.kanade.mangafeed.data.source.model.Page; | ||||
| import eu.kanade.mangafeed.event.DownloadStatusEvent; | ||||
| import rx.subjects.PublishSubject; | ||||
|  | ||||
| public class Download { | ||||
| @@ -52,5 +54,6 @@ public class Download { | ||||
|     private void notifyStatus() { | ||||
|         if (statusSubject != null) | ||||
|             statusSubject.onNext(this); | ||||
|         EventBus.getDefault().post(new DownloadStatusEvent(chapter.id, status)); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,21 @@ | ||||
| package eu.kanade.mangafeed.event; | ||||
|  | ||||
| public class DownloadStatusEvent { | ||||
|  | ||||
|     private long chapterId; | ||||
|     private int status; | ||||
|  | ||||
|     public DownloadStatusEvent(long chapterId, int status) { | ||||
|         this.chapterId = chapterId; | ||||
|         this.status = status; | ||||
|     } | ||||
|  | ||||
|     public long getChapterId() { | ||||
|         return chapterId; | ||||
|     } | ||||
|  | ||||
|     public int getStatus() { | ||||
|         return status; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -5,6 +5,8 @@ import android.support.v7.app.AppCompatActivity; | ||||
| import android.support.v7.widget.Toolbar; | ||||
| import android.view.MenuItem; | ||||
|  | ||||
| import de.greenrobot.event.EventBus; | ||||
|  | ||||
| public class BaseActivity extends AppCompatActivity { | ||||
|  | ||||
|     protected void setupToolbar(Toolbar toolbar) { | ||||
| @@ -47,4 +49,16 @@ public class BaseActivity extends AppCompatActivity { | ||||
|         return super.onOptionsItemSelected(item); | ||||
|     } | ||||
|  | ||||
|     public void registerForStickyEvents() { | ||||
|         EventBus.getDefault().registerSticky(this); | ||||
|     } | ||||
|  | ||||
|     public void registerForEvents() { | ||||
|         EventBus.getDefault().register(this); | ||||
|     } | ||||
|  | ||||
|     public void unregisterForEvents() { | ||||
|         EventBus.getDefault().unregister(this); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -2,6 +2,7 @@ package eu.kanade.mangafeed.ui.base.fragment; | ||||
|  | ||||
| import android.support.v4.app.Fragment; | ||||
|  | ||||
| import de.greenrobot.event.EventBus; | ||||
| import eu.kanade.mangafeed.ui.base.activity.BaseActivity; | ||||
|  | ||||
| public class BaseFragment extends Fragment { | ||||
| @@ -18,4 +19,16 @@ public class BaseFragment extends Fragment { | ||||
|         return (BaseActivity) getActivity(); | ||||
|     } | ||||
|  | ||||
|     public void registerForStickyEvents() { | ||||
|         EventBus.getDefault().registerSticky(this); | ||||
|     } | ||||
|  | ||||
|     public void registerForEvents() { | ||||
|         EventBus.getDefault().register(this); | ||||
|     } | ||||
|  | ||||
|     public void unregisterForEvents() { | ||||
|         EventBus.getDefault().unregister(this); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -24,11 +24,13 @@ import butterknife.ButterKnife; | ||||
| import eu.kanade.mangafeed.R; | ||||
| import eu.kanade.mangafeed.data.database.models.Chapter; | ||||
| import eu.kanade.mangafeed.data.download.DownloadService; | ||||
| import eu.kanade.mangafeed.event.DownloadStatusEvent; | ||||
| import eu.kanade.mangafeed.ui.base.activity.BaseActivity; | ||||
| import eu.kanade.mangafeed.ui.base.fragment.BaseRxFragment; | ||||
| import eu.kanade.mangafeed.ui.decoration.DividerItemDecoration; | ||||
| import eu.kanade.mangafeed.ui.manga.MangaActivity; | ||||
| import eu.kanade.mangafeed.ui.reader.ReaderActivity; | ||||
| import eu.kanade.mangafeed.util.EventBusHook; | ||||
| import eu.kanade.mangafeed.util.ToastUtil; | ||||
| import nucleus.factory.RequiresPresenter; | ||||
| import rx.Observable; | ||||
| @@ -94,6 +96,18 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen | ||||
|         return view; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onResume() { | ||||
|         super.onResume(); | ||||
|         registerForEvents(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onPause() { | ||||
|         unregisterForEvents(); | ||||
|         super.onPause(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { | ||||
|         inflater.inflate(R.menu.chapters, menu); | ||||
| @@ -134,6 +148,19 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen | ||||
|         startActivity(intent); | ||||
|     } | ||||
|  | ||||
|     @EventBusHook | ||||
|     public void onEventMainThread(DownloadStatusEvent event) { | ||||
|         Chapter chapter; | ||||
|         for (int i = 0; i < adapter.getItemCount(); i++) { | ||||
|             chapter = adapter.getItem(i); | ||||
|             if (event.getChapterId() == chapter.id) { | ||||
|                 chapter.status = event.getStatus(); | ||||
|                 adapter.notifyItemChanged(i); | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean onCreateActionMode(ActionMode mode, Menu menu) { | ||||
|         mode.getMenuInflater().inflate(R.menu.chapter_selection, menu); | ||||
|   | ||||
| @@ -62,10 +62,17 @@ public class ChaptersHolder extends RecyclerView.ViewHolder implements | ||||
|             pages.setText(""); | ||||
|         } | ||||
|  | ||||
|         if (chapter.status == Download.DOWNLOADED) { | ||||
|             downloadText.setVisibility(View.VISIBLE); | ||||
|         } else if (chapter.status == Download.NOT_DOWNLOADED) { | ||||
|             downloadText.setVisibility(View.INVISIBLE); | ||||
|         switch (chapter.status) { | ||||
|             case Download.QUEUE: | ||||
|                 downloadText.setText(R.string.chapter_queued); break; | ||||
|             case Download.DOWNLOADING: | ||||
|                 downloadText.setText(R.string.chapter_downloading); break; | ||||
|             case Download.DOWNLOADED: | ||||
|                 downloadText.setText(R.string.chapter_downloaded); break; | ||||
|             case Download.ERROR: | ||||
|                 downloadText.setText(R.string.chapter_error); break; | ||||
|             default: | ||||
|                 downloadText.setText(""); break; | ||||
|         } | ||||
|  | ||||
|         date.setText(sdf.format(new Date(chapter.date_upload))); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user