multiple chapter download from manga view

This commit is contained in:
Kevin Richter 2016-02-09 16:01:11 +01:00
parent e69011ac5b
commit 6c069ad87b
3 changed files with 42 additions and 11 deletions

View File

@ -8,21 +8,12 @@ import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.view.ActionMode; import android.support.v7.view.ActionMode;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.*;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.ImageView; import android.widget.ImageView;
import com.afollestad.materialdialogs.MaterialDialog;
import java.util.List;
import butterknife.Bind; import butterknife.Bind;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import com.afollestad.materialdialogs.MaterialDialog;
import eu.kanade.tachiyomi.R; import eu.kanade.tachiyomi.R;
import eu.kanade.tachiyomi.data.database.models.Chapter; import eu.kanade.tachiyomi.data.database.models.Chapter;
import eu.kanade.tachiyomi.data.database.models.Manga; import eu.kanade.tachiyomi.data.database.models.Manga;
@ -40,6 +31,9 @@ import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers; import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers; import rx.schedulers.Schedulers;
import java.util.ArrayList;
import java.util.List;
@RequiresPresenter(ChaptersPresenter.class) @RequiresPresenter(ChaptersPresenter.class)
public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implements public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implements
ActionMode.Callback, FlexibleViewHolder.OnListItemClickListener { ActionMode.Callback, FlexibleViewHolder.OnListItemClickListener {
@ -110,6 +104,9 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
case R.id.action_display_mode: case R.id.action_display_mode:
showDisplayModeDialog(); showDisplayModeDialog();
return true; return true;
case R.id.manga_download:
showDownloadDialog();
return true;
} }
return false; return false;
} }
@ -202,6 +199,32 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
.show(); .show();
} }
private void showDownloadDialog() {
// Get available modes
String[] modes = {getString(R.string.download_all), getString(R.string.download_unread)};
new MaterialDialog.Builder(getActivity())
.title(R.string.manga_download)
.items(modes)
.itemsCallback((dialog, view, i, charSequence) -> {
List<Chapter> chapters = new ArrayList<>();
for(Chapter chapter : getPresenter().getChapters()) {
if(!chapter.isDownloaded()) {
if(i == 0 || (i == 1 && !chapter.read)) {
chapters.add(chapter);
}
}
}
if(chapters.size() > 0) {
onDownload(Observable.from(chapters));
}
})
.negativeText(R.string.button_cancel)
.show();
}
private void observeChapterDownloadProgress() { private void observeChapterDownloadProgress() {
downloadProgressSubscription = getPresenter().getDownloadProgressObs() downloadProgressSubscription = getPresenter().getDownloadProgressObs()
.subscribe(this::onDownloadProgressChange, .subscribe(this::onDownloadProgressChange,

View File

@ -6,4 +6,9 @@
android:title="@string/action_display_mode" android:title="@string/action_display_mode"
android:id="@+id/action_display_mode" android:id="@+id/action_display_mode"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:title="@string/manga_download"
android:id="@+id/manga_download"
app:showAsAction="never" />
</menu> </menu>

View File

@ -179,6 +179,9 @@
<string name="fetch_chapters_error">Error while fetching chapters</string> <string name="fetch_chapters_error">Error while fetching chapters</string>
<string name="show_title">Show title</string> <string name="show_title">Show title</string>
<string name="show_chapter_number">Show chapter number</string> <string name="show_chapter_number">Show chapter number</string>
<string name="manga_download">Download</string>
<string name="download_all">Download all</string>
<string name="download_unread">Download unread</string>
<!-- MyAnimeList fragment --> <!-- MyAnimeList fragment -->
<string name="reading">Reading</string> <string name="reading">Reading</string>