mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-11 10:20:47 +01:00
Can now delete manga from recent + added missing res files #118
This commit is contained in:
parent
dec9442a65
commit
aac6b242a0
6 changed files with 154 additions and 15 deletions
|
@ -10,6 +10,8 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.Bind;
|
||||
|
@ -26,6 +28,8 @@ import eu.kanade.tachiyomi.ui.decoration.DividerItemDecoration;
|
|||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity;
|
||||
import nucleus.factory.RequiresPresenter;
|
||||
import rx.Observable;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
@RequiresPresenter(RecentChaptersPresenter.class)
|
||||
public class RecentChaptersFragment extends BaseRxFragment<RecentChaptersPresenter> implements FlexibleViewHolder.OnListItemClickListener {
|
||||
|
@ -103,4 +107,38 @@ public class RecentChaptersFragment extends BaseRxFragment<RecentChaptersPresent
|
|||
return true;
|
||||
}
|
||||
|
||||
protected boolean onDelete(Observable<Chapter> chapters, Manga manga) {
|
||||
int size = adapter.getSelectedItemCount();
|
||||
|
||||
MaterialDialog dialog = new MaterialDialog.Builder(getActivity())
|
||||
.title(R.string.deleting)
|
||||
.progress(false, size, true)
|
||||
.cancelable(false)
|
||||
.show();
|
||||
|
||||
Observable<Chapter> observable = chapters
|
||||
.concatMap(chapter -> {
|
||||
getPresenter().deleteChapter(chapter, manga);
|
||||
return Observable.just(chapter);
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnNext(chapter -> {
|
||||
dialog.incrementProgress(1);
|
||||
chapter.status = Download.NOT_DOWNLOADED;
|
||||
})
|
||||
.doOnCompleted(adapter::notifyDataSetChanged)
|
||||
.finallyDo(dialog::dismiss);
|
||||
|
||||
getPresenter().deleteChapters(observable);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean onMarkAsRead(Observable<Chapter> chapters) {
|
||||
getPresenter().markChaptersRead(chapters, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -133,11 +133,6 @@ public class RecentChaptersHolder extends FlexibleViewHolder {
|
|||
}
|
||||
}
|
||||
|
||||
public void onProgressChange(Context context, int downloaded, int total) {
|
||||
downloadText.setText(context.getString(
|
||||
R.string.chapter_downloading_progress, downloaded, total));
|
||||
}
|
||||
|
||||
private void showPopupMenu(View view) {
|
||||
// Create a PopupMenu, giving it the clicked view for an anchor
|
||||
PopupMenu popup = new PopupMenu(adapter.getFragment().getActivity(), view);
|
||||
|
@ -170,13 +165,10 @@ public class RecentChaptersHolder extends FlexibleViewHolder {
|
|||
case R.id.action_download:
|
||||
return adapter.getFragment().onDownload(chapterObservable, mangaChapter.manga);
|
||||
case R.id.action_delete:
|
||||
ToastUtil.showShort(context, "Delete does not work, yet....");
|
||||
return true;
|
||||
// return adapter.getFragment().onDelete(chapterObservable);
|
||||
return adapter.getFragment().onDelete(chapterObservable, mangaChapter.manga);
|
||||
case R.id.action_mark_as_read:
|
||||
ToastUtil.showShort(context, "Mark as read does not work, yet....");
|
||||
return true;
|
||||
// return adapter.getFragment().onMarkAsRead(chapterObservable);
|
||||
ToastUtil.showShort(context, "Mark as read");
|
||||
return adapter.getFragment().onMarkAsRead(chapterObservable);
|
||||
case R.id.action_mark_as_unread:
|
||||
ToastUtil.showShort(context, "Mark as unread does not work, yet....");
|
||||
return true;
|
||||
|
|
|
@ -27,6 +27,7 @@ import eu.kanade.tachiyomi.event.ReaderEvent;
|
|||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter;
|
||||
import rx.Observable;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class RecentChaptersPresenter extends BasePresenter<RecentChaptersFragment> {
|
||||
|
@ -109,6 +110,7 @@ public class RecentChaptersPresenter extends BasePresenter<RecentChaptersFragmen
|
|||
}
|
||||
|
||||
|
||||
|
||||
private Observable<List<Object>> getRecentChaptersObservable() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(new Date());
|
||||
|
@ -171,4 +173,32 @@ public class RecentChaptersPresenter extends BasePresenter<RecentChaptersFragmen
|
|||
EventBus.getDefault().postSticky(new DownloadChaptersEvent(manga, chapters));
|
||||
}));
|
||||
}
|
||||
|
||||
public void deleteChapter(Chapter chapter, Manga manga) {
|
||||
Source source = sourceManager.get(manga.source);
|
||||
downloadManager.deleteChapter(source, manga, chapter);
|
||||
}
|
||||
|
||||
public void deleteChapters(Observable<Chapter> selectedChapters) {
|
||||
add(selectedChapters
|
||||
.subscribe(chapter -> {
|
||||
downloadManager.getQueue().remove(chapter);
|
||||
}, error -> {
|
||||
Timber.e(error.getMessage());
|
||||
}));
|
||||
}
|
||||
|
||||
public void markChaptersRead(Observable<Chapter> selectedChapters, boolean read) {
|
||||
add(selectedChapters
|
||||
.subscribeOn(Schedulers.io())
|
||||
.map(chapter -> {
|
||||
chapter.read = read;
|
||||
if (!read) chapter.last_page_read = 0;
|
||||
return chapter;
|
||||
})
|
||||
.toList()
|
||||
.flatMap(chapters -> db.insertChapters(chapters).asRxObservable())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
android:layout_height="?android:attr/listPreferredItemHeight"
|
||||
android:background="@drawable/selector_chapter_light">
|
||||
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
@ -13,13 +14,34 @@
|
|||
android:paddingRight="?android:attr/listPreferredItemPaddingRight"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/relativeLayout"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="18dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/download_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:textAllCaps="true"
|
||||
android:textColor="@color/accent_text"
|
||||
android:textSize="12sp"/>
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginRight="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
|
@ -27,8 +49,8 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
tools:text="My manga"/>
|
||||
|
||||
<TextView
|
||||
|
@ -36,12 +58,37 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:maxLines="1"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
tools:text="Title"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/chapter_menu"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:gravity="center|end"
|
||||
android:paddingBottom="18dp"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:paddingRight="?android:attr/listPreferredItemPaddingRight">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_alignParentEnd="false"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:background="?android:selectableItemBackground"
|
||||
android:src="@drawable/ic_more_horiz_black_24dp"
|
||||
/>
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
</RelativeLayout>
|
32
app/src/main/res/menu/chapter_recent.xml
Normal file
32
app/src/main/res/menu/chapter_recent.xml
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_download"
|
||||
android:title="@string/action_download"
|
||||
android:icon="@drawable/ic_file_download"
|
||||
android:visible="true"
|
||||
app:showAsAction="ifRoom"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_delete"
|
||||
android:title="@string/action_delete"
|
||||
android:icon="@drawable/ic_action_delete"
|
||||
android:visible="false"
|
||||
app:showAsAction="ifRoom"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_mark_as_read"
|
||||
android:title="@string/action_mark_as_read"
|
||||
android:icon="@drawable/ic_action_done_all"
|
||||
app:showAsAction="ifRoom"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_mark_as_unread"
|
||||
android:title="@string/action_mark_as_unread"
|
||||
android:icon="@drawable/ic_action_undone_all"
|
||||
app:showAsAction="ifRoom"/>
|
||||
|
||||
</menu>
|
|
@ -6,7 +6,7 @@ buildscript {
|
|||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.0.0-beta2'
|
||||
classpath 'com.android.tools.build:gradle:2.0.0-beta4'
|
||||
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
|
||||
classpath 'me.tatarka:gradle-retrolambda:3.2.4'
|
||||
classpath 'com.github.ben-manes:gradle-versions-plugin:0.12.0'
|
||||
|
|
Loading…
Reference in a new issue