mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-06 18:57:26 +01:00
Use same activity for manga details on catalague and library. Move some methos to view.
This commit is contained in:
parent
c768b4de3b
commit
161a4b17a6
@ -41,15 +41,6 @@
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="eu.kanade.mangafeed.ui.activity.MainActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.activity.MangaCatalogueActivity"
|
||||
android:label="@string/title_activity_manga_catalogue"
|
||||
android:parentActivityName=".ui.activity.CatalogueActivity"
|
||||
android:theme="@style/AppTheme" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="eu.kanade.mangafeed.ui.activity.CatalogueActivity" />
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
@ -8,7 +8,6 @@ import dagger.Component;
|
||||
import eu.kanade.mangafeed.data.DataModule;
|
||||
import eu.kanade.mangafeed.presenter.CataloguePresenter;
|
||||
import eu.kanade.mangafeed.presenter.LibraryPresenter;
|
||||
import eu.kanade.mangafeed.presenter.MangaCataloguePresenter;
|
||||
import eu.kanade.mangafeed.presenter.MangaChaptersPresenter;
|
||||
import eu.kanade.mangafeed.presenter.MangaDetailPresenter;
|
||||
import eu.kanade.mangafeed.presenter.MangaInfoPresenter;
|
||||
@ -27,7 +26,6 @@ public interface AppComponent {
|
||||
void inject(MangaDetailPresenter mangaDetailPresenter);
|
||||
void inject(SourcePresenter sourcePresenter);
|
||||
void inject(CataloguePresenter cataloguePresenter);
|
||||
void inject(MangaCataloguePresenter mangaCataloguePresenter);
|
||||
void inject(MangaInfoPresenter mangaInfoPresenter);
|
||||
void inject(MangaChaptersPresenter mangaChaptersPresenter);
|
||||
|
||||
|
@ -1,11 +1,7 @@
|
||||
package eu.kanade.mangafeed.presenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -13,13 +9,11 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
import eu.kanade.mangafeed.data.helpers.DatabaseHelper;
|
||||
import eu.kanade.mangafeed.data.helpers.SourceManager;
|
||||
import eu.kanade.mangafeed.data.models.Manga;
|
||||
import eu.kanade.mangafeed.sources.Source;
|
||||
import eu.kanade.mangafeed.ui.activity.CatalogueActivity;
|
||||
import eu.kanade.mangafeed.ui.activity.MangaCatalogueActivity;
|
||||
import nucleus.presenter.RxPresenter;
|
||||
import rx.Observable;
|
||||
import rx.Subscription;
|
||||
@ -135,16 +129,7 @@ public class CataloguePresenter extends RxPresenter<CatalogueActivity> {
|
||||
.onBackpressureBuffer()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.compose(deliverReplay())
|
||||
.subscribe(this.split((view, manga) -> {
|
||||
// Get manga index in the adapter
|
||||
int index = getMangaIndex(manga);
|
||||
// Get the image view associated with the manga.
|
||||
// If it's null (not visible in the screen) there's no need to update the image.
|
||||
ImageView imageView = view.getImageView(index);
|
||||
if (imageView != null) {
|
||||
updateImage(imageView, manga.thumbnail_url);
|
||||
}
|
||||
}));
|
||||
.subscribe(this.split(CatalogueActivity::updateImage));
|
||||
|
||||
add(mMangaDetailFetchSubscription);
|
||||
}
|
||||
@ -188,13 +173,6 @@ public class CataloguePresenter extends RxPresenter<CatalogueActivity> {
|
||||
return localManga;
|
||||
}
|
||||
|
||||
public void onMangaClick(int position) {
|
||||
Intent intent = new Intent(getView().getActivity(), MangaCatalogueActivity.class);
|
||||
Manga selectedManga = getView().getAdapter().getItem(position);
|
||||
EventBus.getDefault().postSticky(selectedManga);
|
||||
getView().getActivity().startActivity(intent);
|
||||
}
|
||||
|
||||
public void onQueryTextChange(String query) {
|
||||
if (mSearchViewPublishSubject != null)
|
||||
mSearchViewPublishSubject.onNext(Observable.just(query));
|
||||
@ -235,20 +213,4 @@ public class CataloguePresenter extends RxPresenter<CatalogueActivity> {
|
||||
mCurrentPage = page;
|
||||
}
|
||||
|
||||
private int getMangaIndex(Manga manga) {
|
||||
for (int i = 0; i < getView().getAdapter().getCount(); i++) {
|
||||
if (manga.id == getView().getAdapter().getItem(i).id) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void updateImage(ImageView imageView, String thumbnail) {
|
||||
Glide.with(getView().getActivity())
|
||||
.load(thumbnail)
|
||||
.centerCrop()
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +0,0 @@
|
||||
package eu.kanade.mangafeed.presenter;
|
||||
|
||||
import eu.kanade.mangafeed.ui.activity.MangaCatalogueActivity;
|
||||
|
||||
public class MangaCataloguePresenter extends BasePresenter<MangaCatalogueActivity> {
|
||||
|
||||
}
|
@ -1,26 +1,7 @@
|
||||
package eu.kanade.mangafeed.presenter;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import eu.kanade.mangafeed.data.helpers.DatabaseHelper;
|
||||
import eu.kanade.mangafeed.data.models.Manga;
|
||||
import eu.kanade.mangafeed.ui.activity.MangaDetailActivity;
|
||||
import eu.kanade.mangafeed.view.MangaDetailView;
|
||||
|
||||
public class MangaDetailPresenter extends BasePresenter<MangaDetailActivity> {
|
||||
|
||||
private MangaDetailView view;
|
||||
|
||||
@Inject
|
||||
DatabaseHelper db;
|
||||
|
||||
public void onEventMainThread(Manga manga) {
|
||||
view.loadManga(manga);
|
||||
initializeChapters(manga);
|
||||
}
|
||||
|
||||
public void initializeChapters(Manga manga) {
|
||||
db.getChapters(manga)
|
||||
.subscribe(view::setChapters);
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,13 @@ import android.widget.GridView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnItemClick;
|
||||
import eu.kanade.mangafeed.R;
|
||||
import eu.kanade.mangafeed.data.models.Manga;
|
||||
import eu.kanade.mangafeed.presenter.CataloguePresenter;
|
||||
@ -58,7 +61,6 @@ public class CatalogueActivity extends BaseActivity<CataloguePresenter> {
|
||||
setupToolbar(toolbar);
|
||||
|
||||
initializeAdapter();
|
||||
initializeClickListener();
|
||||
initializeScrollListener();
|
||||
}
|
||||
|
||||
@ -95,11 +97,12 @@ public class CatalogueActivity extends BaseActivity<CataloguePresenter> {
|
||||
manga_list.setAdapter(adapter);
|
||||
}
|
||||
|
||||
public void initializeClickListener() {
|
||||
manga_list.setOnItemClickListener(
|
||||
(parent, view, position, id) ->
|
||||
getPresenter().onMangaClick(position)
|
||||
);
|
||||
@OnItemClick(R.id.gridView)
|
||||
public void onMangaClick(int position) {
|
||||
Manga selectedManga = adapter.getItem(position);
|
||||
|
||||
Intent intent = MangaDetailActivity.newIntent(this, selectedManga);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
public void initializeScrollListener() {
|
||||
@ -139,7 +142,20 @@ public class CatalogueActivity extends BaseActivity<CataloguePresenter> {
|
||||
progress_grid.setVisibility(ProgressBar.GONE);
|
||||
}
|
||||
|
||||
public ImageView getImageView(int position) {
|
||||
public void onMangasNext(List<Manga> newMangas) {
|
||||
adapter.addItems(newMangas);
|
||||
}
|
||||
|
||||
private int getMangaIndex(Manga manga) {
|
||||
for (int i = 0; i < adapter.getCount(); i++) {
|
||||
if (manga.id == adapter.getItem(i).id) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private ImageView getImageView(int position) {
|
||||
View v = manga_list.getChildAt(position -
|
||||
manga_list.getFirstVisiblePosition());
|
||||
|
||||
@ -149,7 +165,13 @@ public class CatalogueActivity extends BaseActivity<CataloguePresenter> {
|
||||
return (ImageView) v.findViewById(R.id.catalogue_thumbnail);
|
||||
}
|
||||
|
||||
public void onMangasNext(List<Manga> newMangas) {
|
||||
adapter.addItems(newMangas);
|
||||
public void updateImage(Manga manga) {
|
||||
ImageView imageView = getImageView(getMangaIndex(manga));
|
||||
if (imageView != null) {
|
||||
Glide.with(this)
|
||||
.load(manga.thumbnail_url)
|
||||
.centerCrop()
|
||||
.into(imageView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,56 +0,0 @@
|
||||
package eu.kanade.mangafeed.ui.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.kanade.mangafeed.R;
|
||||
import eu.kanade.mangafeed.data.models.Manga;
|
||||
import eu.kanade.mangafeed.presenter.MangaCataloguePresenter;
|
||||
import nucleus.factory.RequiresPresenter;
|
||||
|
||||
@RequiresPresenter(MangaCataloguePresenter.class)
|
||||
public class MangaCatalogueActivity extends BaseActivity<MangaCataloguePresenter> {
|
||||
|
||||
@Bind(R.id.toolbar) Toolbar toolbar;
|
||||
|
||||
@Bind(R.id.manga_artist) TextView mArtist;
|
||||
@Bind(R.id.manga_author) TextView mAuthor;
|
||||
@Bind(R.id.manga_chapters) TextView mChapters;
|
||||
@Bind(R.id.manga_genres) TextView mGenres;
|
||||
@Bind(R.id.manga_status) TextView mStatus;
|
||||
@Bind(R.id.manga_summary) TextView mDescription;
|
||||
@Bind(R.id.manga_cover) ImageView mCover;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_manga_catalogue);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
setupToolbar(toolbar);
|
||||
}
|
||||
|
||||
public void setMangaInfo(Manga manga) {
|
||||
mArtist.setText(manga.artist);
|
||||
mAuthor.setText(manga.author);
|
||||
mChapters.setText("0"); // TODO
|
||||
mGenres.setText(manga.genre);
|
||||
mStatus.setText("Ongoing"); //TODO
|
||||
mDescription.setText(manga.description);
|
||||
|
||||
Glide.with(getActivity())
|
||||
.load(manga.thumbnail_url)
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESULT)
|
||||
.centerCrop()
|
||||
.into(mCover);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user