Moved edit cover to library | Updated manga info view | Updated catalogue
grid
This commit is contained in:
@@ -8,12 +8,22 @@ import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.view.ActionMode;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.*;
|
||||
import android.view.LayoutInflater;
|
||||
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.ImageView;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import eu.kanade.tachiyomi.R;
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter;
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga;
|
||||
@@ -31,9 +41,6 @@ import rx.Subscription;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RequiresPresenter(ChaptersPresenter.class)
|
||||
public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implements
|
||||
ActionMode.Callback, FlexibleViewHolder.OnListItemClickListener {
|
||||
|
||||
@@ -7,6 +7,12 @@ import android.view.View;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Date;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.kanade.tachiyomi.R;
|
||||
@@ -16,30 +22,21 @@ import eu.kanade.tachiyomi.data.download.model.Download;
|
||||
import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder;
|
||||
import rx.Observable;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Date;
|
||||
|
||||
public class ChaptersHolder extends FlexibleViewHolder {
|
||||
|
||||
private final ChaptersAdapter adapter;
|
||||
private final int readColor;
|
||||
private final int unreadColor;
|
||||
private final DecimalFormat decimalFormat;
|
||||
private final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||
@Bind(R.id.chapter_title) TextView title;
|
||||
@Bind(R.id.download_text) TextView downloadText;
|
||||
@Bind(R.id.chapter_menu) RelativeLayout chapterMenu;
|
||||
@Bind(R.id.chapter_pages) TextView pages;
|
||||
@Bind(R.id.chapter_date) TextView date;
|
||||
|
||||
private Context context;
|
||||
|
||||
private final ChaptersAdapter adapter;
|
||||
private Chapter item;
|
||||
|
||||
private final int readColor;
|
||||
private final int unreadColor;
|
||||
|
||||
private final DecimalFormat decimalFormat;
|
||||
private final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||
|
||||
public ChaptersHolder(View view, ChaptersAdapter adapter, OnListItemClickListener listener) {
|
||||
super(view, adapter, listener);
|
||||
this.adapter = adapter;
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package eu.kanade.tachiyomi.ui.manga.info;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
@@ -10,32 +7,22 @@ import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.load.model.LazyHeaders;
|
||||
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
|
||||
import com.mikepenz.iconics.IconicsDrawable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.kanade.tachiyomi.R;
|
||||
import eu.kanade.tachiyomi.data.cache.CoverCache;
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga;
|
||||
import eu.kanade.tachiyomi.data.io.IOHandler;
|
||||
import eu.kanade.tachiyomi.data.source.base.Source;
|
||||
import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment;
|
||||
import eu.kanade.tachiyomi.util.ToastUtil;
|
||||
import nucleus.factory.RequiresPresenter;
|
||||
|
||||
@RequiresPresenter(MangaInfoPresenter.class)
|
||||
public class MangaInfoFragment extends BaseRxFragment<MangaInfoPresenter> {
|
||||
|
||||
private static final int REQUEST_IMAGE_OPEN = 101;
|
||||
@Bind(R.id.swipe_refresh) SwipeRefreshLayout swipeRefresh;
|
||||
@Bind(R.id.manga_artist) TextView artist;
|
||||
@Bind(R.id.manga_author) TextView author;
|
||||
@@ -45,8 +32,8 @@ public class MangaInfoFragment extends BaseRxFragment<MangaInfoPresenter> {
|
||||
@Bind(R.id.manga_source) TextView source;
|
||||
@Bind(R.id.manga_summary) TextView description;
|
||||
@Bind(R.id.manga_cover) ImageView cover;
|
||||
@Bind(R.id.action_favorite) Button favoriteBtn;
|
||||
@Bind(R.id.fab_edit) FloatingActionButton fabEdit;
|
||||
@Bind(R.id.backdrop) ImageView backdrop;
|
||||
@Bind(R.id.fab_favorite) FloatingActionButton fabFavorite;
|
||||
|
||||
public static MangaInfoFragment newInstance() {
|
||||
return new MangaInfoFragment();
|
||||
@@ -65,10 +52,7 @@ public class MangaInfoFragment extends BaseRxFragment<MangaInfoPresenter> {
|
||||
View view = inflater.inflate(R.layout.fragment_manga_info, container, false);
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
// Set listener.
|
||||
fabEdit.setOnClickListener(v -> selectImage());
|
||||
|
||||
favoriteBtn.setOnClickListener(v -> getPresenter().toggleFavorite());
|
||||
fabFavorite.setOnClickListener(v -> getPresenter().toggleFavorite());
|
||||
|
||||
swipeRefresh.setOnRefreshListener(this::fetchMangaFromSource);
|
||||
|
||||
@@ -101,7 +85,7 @@ public class MangaInfoFragment extends BaseRxFragment<MangaInfoPresenter> {
|
||||
status.setText(manga.getStatus(getActivity()));
|
||||
description.setText(manga.description);
|
||||
|
||||
setFavoriteText(manga.favorite);
|
||||
setFavoriteDrawable(manga.favorite);
|
||||
|
||||
CoverCache coverCache = getPresenter().coverCache;
|
||||
LazyHeaders headers = getPresenter().source.getGlideHeaders();
|
||||
@@ -112,14 +96,23 @@ public class MangaInfoFragment extends BaseRxFragment<MangaInfoPresenter> {
|
||||
coverCache.loadFromNetwork(cover, manga.thumbnail_url, headers);
|
||||
}
|
||||
}
|
||||
if (manga.thumbnail_url != null && backdrop.getDrawable() == null) {
|
||||
if (manga.favorite) {
|
||||
coverCache.saveOrLoadFromCache(backdrop, manga.thumbnail_url, headers);
|
||||
} else {
|
||||
coverCache.loadFromNetwork(backdrop, manga.thumbnail_url, headers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setChapterCount(int count) {
|
||||
chapterCount.setText(String.valueOf(count));
|
||||
}
|
||||
|
||||
private void setFavoriteText(boolean isFavorite) {
|
||||
favoriteBtn.setText(!isFavorite ? R.string.add_to_library : R.string.remove_from_library);
|
||||
private void setFavoriteDrawable(boolean isFavorite) {
|
||||
fabFavorite.setImageDrawable(ContextCompat.getDrawable(getContext(), isFavorite ?
|
||||
R.drawable.ic_bookmark_white_24dp :
|
||||
R.drawable.ic_bookmark_border_white_24dp));
|
||||
}
|
||||
|
||||
private void fetchMangaFromSource() {
|
||||
@@ -127,43 +120,6 @@ public class MangaInfoFragment extends BaseRxFragment<MangaInfoPresenter> {
|
||||
getPresenter().fetchMangaFromSource();
|
||||
}
|
||||
|
||||
private void selectImage() {
|
||||
if (getPresenter().getManga().favorite) {
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.setType("image/*");
|
||||
intent.setAction(Intent.ACTION_GET_CONTENT);
|
||||
startActivityForResult(Intent.createChooser(intent,
|
||||
getString(R.string.file_select_cover)), REQUEST_IMAGE_OPEN);
|
||||
} else {
|
||||
ToastUtil.showShort(getContext(), R.string.notification_first_add_to_library);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_IMAGE_OPEN) {
|
||||
// Get the file's content URI from the incoming Intent
|
||||
Uri selectedImageUri = data.getData();
|
||||
|
||||
// Convert to absolute path to prevent FileNotFoundException
|
||||
String result = IOHandler.getFilePath(selectedImageUri,
|
||||
getContext().getContentResolver(), getContext());
|
||||
|
||||
// Get file from filepath
|
||||
File picture = new File(result != null ? result : "");
|
||||
|
||||
try {
|
||||
// Update cover to selected file, show error if something went wrong
|
||||
if (!getPresenter().editCoverWithLocalFile(picture, cover))
|
||||
ToastUtil.showShort(getContext(), R.string.notification_manga_update_failed);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onFetchMangaDone() {
|
||||
setRefreshing(false);
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
package eu.kanade.tachiyomi.ui.manga.info;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import eu.kanade.tachiyomi.data.cache.CoverCache;
|
||||
@@ -135,20 +131,7 @@ public class MangaInfoPresenter extends BasePresenter<MangaInfoFragment> {
|
||||
refreshManga();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update cover with local file
|
||||
*/
|
||||
public boolean editCoverWithLocalFile(File file, ImageView imageView) throws IOException {
|
||||
if (!manga.initialized)
|
||||
return false;
|
||||
|
||||
if (manga.favorite) {
|
||||
coverCache.copyToLocalCache(manga.thumbnail_url, file);
|
||||
coverCache.saveOrLoadFromCache(imageView, manga.thumbnail_url, source.getGlideHeaders());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void onMangaFavoriteChange(boolean isFavorite) {
|
||||
if (isFavorite) {
|
||||
|
||||
Reference in New Issue
Block a user