|
|
@ -21,114 +21,223 @@ import eu.kanade.tachiyomi.data.source.base.Source;
|
|
|
|
import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment;
|
|
|
|
import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment;
|
|
|
|
import nucleus.factory.RequiresPresenter;
|
|
|
|
import nucleus.factory.RequiresPresenter;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Fragment that shows manga information.
|
|
|
|
|
|
|
|
* Uses R.layout.fragment_manga_info.
|
|
|
|
|
|
|
|
* UI related actions should be called from here.
|
|
|
|
|
|
|
|
*/
|
|
|
|
@RequiresPresenter(MangaInfoPresenter.class)
|
|
|
|
@RequiresPresenter(MangaInfoPresenter.class)
|
|
|
|
public class MangaInfoFragment extends BaseRxFragment<MangaInfoPresenter> {
|
|
|
|
public class MangaInfoFragment extends BaseRxFragment<MangaInfoPresenter> {
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* SwipeRefreshLayout showing refresh status
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Bind(R.id.swipe_refresh) SwipeRefreshLayout swipeRefresh;
|
|
|
|
@Bind(R.id.swipe_refresh) SwipeRefreshLayout swipeRefresh;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* TextView containing artist information.
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Bind(R.id.manga_artist) TextView artist;
|
|
|
|
@Bind(R.id.manga_artist) TextView artist;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* TextView containing author information.
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Bind(R.id.manga_author) TextView author;
|
|
|
|
@Bind(R.id.manga_author) TextView author;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* TextView containing chapter count.
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Bind(R.id.manga_chapters) TextView chapterCount;
|
|
|
|
@Bind(R.id.manga_chapters) TextView chapterCount;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* TextView containing genres.
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Bind(R.id.manga_genres) TextView genres;
|
|
|
|
@Bind(R.id.manga_genres) TextView genres;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* TextView containing status (ongoing, finished).
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Bind(R.id.manga_status) TextView status;
|
|
|
|
@Bind(R.id.manga_status) TextView status;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* TextView containing source.
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Bind(R.id.manga_source) TextView source;
|
|
|
|
@Bind(R.id.manga_source) TextView source;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* TextView containing manga summary.
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Bind(R.id.manga_summary) TextView description;
|
|
|
|
@Bind(R.id.manga_summary) TextView description;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* ImageView of cover.
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Bind(R.id.manga_cover) ImageView cover;
|
|
|
|
@Bind(R.id.manga_cover) ImageView cover;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* ImageView containing manga cover shown as blurred backdrop.
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Bind(R.id.backdrop) ImageView backdrop;
|
|
|
|
@Bind(R.id.backdrop) ImageView backdrop;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* FAB anchored to bottom of top view used to (add / remove) manga (to / from) library.
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Bind(R.id.fab_favorite) FloatingActionButton fabFavorite;
|
|
|
|
@Bind(R.id.fab_favorite) FloatingActionButton fabFavorite;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Create new instance of MangaInfoFragment.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return MangaInfoFragment.
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static MangaInfoFragment newInstance() {
|
|
|
|
public static MangaInfoFragment newInstance() {
|
|
|
|
return new MangaInfoFragment();
|
|
|
|
return new MangaInfoFragment();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onCreate(Bundle savedState) {
|
|
|
|
|
|
|
|
super.onCreate(savedState);
|
|
|
|
|
|
|
|
setHasOptionsMenu(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
|
Bundle savedInstanceState) {
|
|
|
|
Bundle savedInstanceState) {
|
|
|
|
// Inflate the layout for this fragment
|
|
|
|
// Inflate the layout for this fragment.
|
|
|
|
View view = inflater.inflate(R.layout.fragment_manga_info, container, false);
|
|
|
|
View view = inflater.inflate(R.layout.fragment_manga_info, container, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Bind layout objects.
|
|
|
|
ButterKnife.bind(this, view);
|
|
|
|
ButterKnife.bind(this, view);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set onclickListener to toggle favorite when FAB clicked.
|
|
|
|
fabFavorite.setOnClickListener(v -> getPresenter().toggleFavorite());
|
|
|
|
fabFavorite.setOnClickListener(v -> getPresenter().toggleFavorite());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set SwipeRefresh to refresh manga data.
|
|
|
|
swipeRefresh.setOnRefreshListener(this::fetchMangaFromSource);
|
|
|
|
swipeRefresh.setOnRefreshListener(this::fetchMangaFromSource);
|
|
|
|
|
|
|
|
|
|
|
|
return view;
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Check if manga is initialized.
|
|
|
|
|
|
|
|
* If true update view with manga information,
|
|
|
|
|
|
|
|
* if false fetch manga information
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param manga manga object containing information about manga.
|
|
|
|
|
|
|
|
* @param source the source of the manga.
|
|
|
|
|
|
|
|
*/
|
|
|
|
public void onNextManga(Manga manga, Source source) {
|
|
|
|
public void onNextManga(Manga manga, Source source) {
|
|
|
|
if (manga.initialized) {
|
|
|
|
if (manga.initialized) {
|
|
|
|
|
|
|
|
// Update view.
|
|
|
|
setMangaInfo(manga, source);
|
|
|
|
setMangaInfo(manga, source);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Initialize manga
|
|
|
|
// Initialize manga.
|
|
|
|
fetchMangaFromSource();
|
|
|
|
fetchMangaFromSource();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Set the info of the manga
|
|
|
|
* Update the view with manga information.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param manga manga object containing information about manga
|
|
|
|
* @param manga manga object containing information about manga.
|
|
|
|
* @param mangaSource the source of the manga
|
|
|
|
* @param mangaSource the source of the manga.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void setMangaInfo(Manga manga, Source mangaSource) {
|
|
|
|
private void setMangaInfo(Manga manga, Source mangaSource) {
|
|
|
|
|
|
|
|
// Update artist TextView.
|
|
|
|
artist.setText(manga.artist);
|
|
|
|
artist.setText(manga.artist);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update author TextView.
|
|
|
|
author.setText(manga.author);
|
|
|
|
author.setText(manga.author);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If manga source is known update source TextView.
|
|
|
|
if (mangaSource != null) {
|
|
|
|
if (mangaSource != null) {
|
|
|
|
source.setText(mangaSource.getName());
|
|
|
|
source.setText(mangaSource.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update genres TextView.
|
|
|
|
genres.setText(manga.genre);
|
|
|
|
genres.setText(manga.genre);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update status TextView.
|
|
|
|
status.setText(manga.getStatus(getActivity()));
|
|
|
|
status.setText(manga.getStatus(getActivity()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update description TextView.
|
|
|
|
description.setText(manga.description);
|
|
|
|
description.setText(manga.description);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set the favorite drawable to the correct one.
|
|
|
|
setFavoriteDrawable(manga.favorite);
|
|
|
|
setFavoriteDrawable(manga.favorite);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize CoverCache and Glide headers to retrieve cover information.
|
|
|
|
CoverCache coverCache = getPresenter().coverCache;
|
|
|
|
CoverCache coverCache = getPresenter().coverCache;
|
|
|
|
LazyHeaders headers = getPresenter().source.getGlideHeaders();
|
|
|
|
LazyHeaders headers = getPresenter().source.getGlideHeaders();
|
|
|
|
if (manga.thumbnail_url != null && cover.getDrawable() == null) {
|
|
|
|
|
|
|
|
if (manga.favorite) {
|
|
|
|
// Check if thumbnail_url is given.
|
|
|
|
coverCache.saveOrLoadFromCache(cover, manga.thumbnail_url, headers);
|
|
|
|
if (manga.thumbnail_url != null) {
|
|
|
|
} else {
|
|
|
|
// Check if cover is already drawn.
|
|
|
|
coverCache.loadFromNetwork(cover, manga.thumbnail_url, headers);
|
|
|
|
if (cover.getDrawable() == null) {
|
|
|
|
|
|
|
|
// If manga is in library then (download / save) (from / to) local cache if available,
|
|
|
|
|
|
|
|
// else download from network.
|
|
|
|
|
|
|
|
if (manga.favorite) {
|
|
|
|
|
|
|
|
coverCache.saveOrLoadFromCache(cover, manga.thumbnail_url, headers);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
coverCache.loadFromNetwork(cover, manga.thumbnail_url, headers);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check if backdrop is already drawn.
|
|
|
|
if (manga.thumbnail_url != null && backdrop.getDrawable() == null) {
|
|
|
|
if (backdrop.getDrawable() == null) {
|
|
|
|
if (manga.favorite) {
|
|
|
|
// If manga is in library then (download / save) (from / to) local cache if available,
|
|
|
|
coverCache.saveOrLoadFromCache(backdrop, manga.thumbnail_url, headers);
|
|
|
|
// else download from network.
|
|
|
|
} else {
|
|
|
|
if (manga.favorite) {
|
|
|
|
coverCache.loadFromNetwork(backdrop, manga.thumbnail_url, headers);
|
|
|
|
coverCache.saveOrLoadFromCache(backdrop, manga.thumbnail_url, headers);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
coverCache.loadFromNetwork(backdrop, manga.thumbnail_url, headers);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Update chapter count TextView.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param count number of chapters.
|
|
|
|
|
|
|
|
*/
|
|
|
|
public void setChapterCount(int count) {
|
|
|
|
public void setChapterCount(int count) {
|
|
|
|
chapterCount.setText(String.valueOf(count));
|
|
|
|
chapterCount.setText(String.valueOf(count));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Update FAB with correct drawable.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param isFavorite determines if manga is favorite or not.
|
|
|
|
|
|
|
|
*/
|
|
|
|
private void setFavoriteDrawable(boolean isFavorite) {
|
|
|
|
private void setFavoriteDrawable(boolean isFavorite) {
|
|
|
|
|
|
|
|
// Set the Favorite drawable to the correct one.
|
|
|
|
|
|
|
|
// Border drawable if false, filled drawable if true.
|
|
|
|
fabFavorite.setImageDrawable(ContextCompat.getDrawable(getContext(), isFavorite ?
|
|
|
|
fabFavorite.setImageDrawable(ContextCompat.getDrawable(getContext(), isFavorite ?
|
|
|
|
R.drawable.ic_bookmark_white_24dp :
|
|
|
|
R.drawable.ic_bookmark_white_24dp :
|
|
|
|
R.drawable.ic_bookmark_border_white_24dp));
|
|
|
|
R.drawable.ic_bookmark_border_white_24dp));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Start fetching manga information from source.
|
|
|
|
|
|
|
|
*/
|
|
|
|
private void fetchMangaFromSource() {
|
|
|
|
private void fetchMangaFromSource() {
|
|
|
|
setRefreshing(true);
|
|
|
|
setRefreshing(true);
|
|
|
|
|
|
|
|
// Call presenter and start fetching manga information
|
|
|
|
getPresenter().fetchMangaFromSource();
|
|
|
|
getPresenter().fetchMangaFromSource();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Update swipeRefresh to stop showing refresh in progress spinner.
|
|
|
|
|
|
|
|
*/
|
|
|
|
public void onFetchMangaDone() {
|
|
|
|
public void onFetchMangaDone() {
|
|
|
|
setRefreshing(false);
|
|
|
|
setRefreshing(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Update swipeRefresh to start showing refresh in progress spinner.
|
|
|
|
|
|
|
|
*/
|
|
|
|
public void onFetchMangaError() {
|
|
|
|
public void onFetchMangaError() {
|
|
|
|
setRefreshing(false);
|
|
|
|
setRefreshing(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Set swipeRefresh status.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param value status of manga fetch.
|
|
|
|
|
|
|
|
*/
|
|
|
|
private void setRefreshing(boolean value) {
|
|
|
|
private void setRefreshing(boolean value) {
|
|
|
|
swipeRefresh.setRefreshing(value);
|
|
|
|
swipeRefresh.setRefreshing(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|