Convert catalogue to a fragment
This commit is contained in:
parent
4c786077a8
commit
4966f1e15f
@ -28,15 +28,6 @@
|
||||
android:label="@string/title_activity_manga_detail"
|
||||
android:parentActivityName=".ui.activity.MainActivity" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.activity.CatalogueActivity"
|
||||
android:label="@string/title_activity_catalogue_list"
|
||||
android:parentActivityName=".ui.activity.MainActivity"
|
||||
android:theme="@style/AppTheme" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="eu.kanade.mangafeed.ui.activity.MainActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.activity.ReaderActivity"
|
||||
android:label="@string/title_activity_viewer"
|
||||
|
@ -12,8 +12,8 @@ import eu.kanade.mangafeed.presenter.MainPresenter;
|
||||
import eu.kanade.mangafeed.presenter.MangaChaptersPresenter;
|
||||
import eu.kanade.mangafeed.presenter.MangaDetailPresenter;
|
||||
import eu.kanade.mangafeed.presenter.MangaInfoPresenter;
|
||||
import eu.kanade.mangafeed.presenter.SourcePresenter;
|
||||
import eu.kanade.mangafeed.presenter.ReaderPresenter;
|
||||
import eu.kanade.mangafeed.presenter.SourcePresenter;
|
||||
|
||||
@Singleton
|
||||
@Component(
|
||||
|
@ -14,7 +14,7 @@ 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.fragment.CatalogueFragment;
|
||||
import eu.kanade.mangafeed.util.PageBundle;
|
||||
import eu.kanade.mangafeed.util.RxPager;
|
||||
import icepick.State;
|
||||
@ -24,7 +24,7 @@ import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
import rx.subjects.PublishSubject;
|
||||
|
||||
public class CataloguePresenter extends BasePresenter<CatalogueActivity> {
|
||||
public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
|
||||
|
||||
@Inject SourceManager sourceManager;
|
||||
@Inject DatabaseHelper db;
|
||||
@ -67,7 +67,7 @@ public class CataloguePresenter extends BasePresenter<CatalogueActivity> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTakeView(CatalogueActivity view) {
|
||||
protected void onTakeView(CatalogueFragment view) {
|
||||
super.onTakeView(view);
|
||||
|
||||
view.setToolbarTitle(selectedSource.getName());
|
||||
|
@ -24,11 +24,18 @@ public class BaseActivity<P extends Presenter> extends NucleusAppCompatActivity<
|
||||
|
||||
protected void setupToolbar(Toolbar toolbar) {
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
if (getSupportActionBar() != null)
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
public void setToolbarTitle(String title) {
|
||||
getSupportActionBar().setTitle(title);
|
||||
if (getSupportActionBar() != null)
|
||||
getSupportActionBar().setTitle(title);
|
||||
}
|
||||
|
||||
public void setToolbarTitle(int titleResource) {
|
||||
if (getSupportActionBar() != null)
|
||||
getSupportActionBar().setTitle(getString(titleResource));
|
||||
}
|
||||
|
||||
public Context getActivity() {
|
||||
|
@ -82,7 +82,7 @@ public class MainActivity extends BaseActivity<MainPresenter> {
|
||||
drawer.setSelection(R.id.nav_drawer_library);
|
||||
}
|
||||
|
||||
private void setFragment(Fragment fragment) {
|
||||
public void setFragment(Fragment fragment) {
|
||||
try {
|
||||
if (fragment != null && getSupportFragmentManager() != null) {
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
@ -96,8 +96,4 @@ public class MainActivity extends BaseActivity<MainPresenter> {
|
||||
}
|
||||
}
|
||||
|
||||
public void setToolbarTitle(int titleResource) {
|
||||
getSupportActionBar().setTitle(getString(titleResource));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package eu.kanade.mangafeed.ui.fragment;
|
||||
import android.os.Bundle;
|
||||
|
||||
import eu.kanade.mangafeed.App;
|
||||
import eu.kanade.mangafeed.ui.activity.BaseActivity;
|
||||
import nucleus.factory.PresenterFactory;
|
||||
import nucleus.presenter.Presenter;
|
||||
import nucleus.view.NucleusSupportFragment;
|
||||
@ -20,4 +21,12 @@ public class BaseFragment<P extends Presenter> extends NucleusSupportFragment<P>
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
public void setToolbarTitle(String title) {
|
||||
((BaseActivity)getActivity()).setToolbarTitle(title);
|
||||
}
|
||||
|
||||
public void setToolbarTitle(int resourceId) {
|
||||
((BaseActivity)getActivity()).setToolbarTitle(getString(resourceId));
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +1,14 @@
|
||||
package eu.kanade.mangafeed.ui.activity;
|
||||
package eu.kanade.mangafeed.ui.fragment;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
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.GridView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
@ -22,6 +23,7 @@ import butterknife.OnItemClick;
|
||||
import eu.kanade.mangafeed.R;
|
||||
import eu.kanade.mangafeed.data.models.Manga;
|
||||
import eu.kanade.mangafeed.presenter.CataloguePresenter;
|
||||
import eu.kanade.mangafeed.ui.activity.MangaDetailActivity;
|
||||
import eu.kanade.mangafeed.ui.adapter.CatalogueHolder;
|
||||
import eu.kanade.mangafeed.util.PageBundle;
|
||||
import eu.kanade.mangafeed.widget.EndlessScrollListener;
|
||||
@ -29,10 +31,7 @@ import nucleus.factory.RequiresPresenter;
|
||||
import uk.co.ribot.easyadapter.EasyAdapter;
|
||||
|
||||
@RequiresPresenter(CataloguePresenter.class)
|
||||
public class CatalogueActivity extends BaseActivity<CataloguePresenter> {
|
||||
|
||||
@Bind(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
public class CatalogueFragment extends BaseFragment<CataloguePresenter> {
|
||||
|
||||
@Bind(R.id.gridView)
|
||||
GridView manga_list;
|
||||
@ -49,34 +48,44 @@ public class CatalogueActivity extends BaseActivity<CataloguePresenter> {
|
||||
|
||||
public final static String SOURCE_ID = "source_id";
|
||||
|
||||
public static Intent newIntent(Context context, int source_id) {
|
||||
Intent intent = new Intent(context, CatalogueActivity.class);
|
||||
intent.putExtra(SOURCE_ID, source_id);
|
||||
return intent;
|
||||
public static CatalogueFragment newInstance(int source_id) {
|
||||
CatalogueFragment fragment = new CatalogueFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(SOURCE_ID, source_id);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_catalogue);
|
||||
ButterKnife.bind(this);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
setupToolbar(toolbar);
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
View view = inflater.inflate(R.layout.fragment_catalogue, container, false);
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
initializeAdapter();
|
||||
initializeScrollListener();
|
||||
|
||||
int source_id = getIntent().getIntExtra(SOURCE_ID, -1);
|
||||
int source_id = getArguments().getInt(SOURCE_ID, -1);
|
||||
|
||||
showProgressBar();
|
||||
|
||||
if (savedInstanceState == null)
|
||||
getPresenter().startRequesting(source_id);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.catalogue_list, menu);
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.catalogue_list, menu);
|
||||
initializeSearch(menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
private void initializeSearch(Menu menu) {
|
||||
@ -107,7 +116,7 @@ public class CatalogueActivity extends BaseActivity<CataloguePresenter> {
|
||||
}
|
||||
|
||||
public void initializeAdapter() {
|
||||
adapter = new EasyAdapter<>(this, CatalogueHolder.class);
|
||||
adapter = new EasyAdapter<>(getActivity(), CatalogueHolder.class);
|
||||
manga_list.setAdapter(adapter);
|
||||
}
|
||||
|
||||
@ -115,7 +124,7 @@ public class CatalogueActivity extends BaseActivity<CataloguePresenter> {
|
||||
public void onMangaClick(int position) {
|
||||
Manga selectedManga = adapter.getItem(position);
|
||||
|
||||
Intent intent = MangaDetailActivity.newIntent(this, selectedManga);
|
||||
Intent intent = MangaDetailActivity.newIntent(getActivity(), selectedManga);
|
||||
intent.putExtra(MangaDetailActivity.MANGA_ONLINE, true);
|
||||
startActivity(intent);
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package eu.kanade.mangafeed.ui.fragment;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -15,7 +14,6 @@ import butterknife.OnItemClick;
|
||||
import eu.kanade.mangafeed.R;
|
||||
import eu.kanade.mangafeed.presenter.SourcePresenter;
|
||||
import eu.kanade.mangafeed.sources.Source;
|
||||
import eu.kanade.mangafeed.ui.activity.CatalogueActivity;
|
||||
import eu.kanade.mangafeed.ui.activity.MainActivity;
|
||||
import eu.kanade.mangafeed.ui.adapter.SourceHolder;
|
||||
import nucleus.factory.RequiresPresenter;
|
||||
@ -43,10 +41,10 @@ public class SourceFragment extends BaseFragment<SourcePresenter> {
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
View view = inflater.inflate(R.layout.fragment_catalogue, container, false);
|
||||
View view = inflater.inflate(R.layout.fragment_source, container, false);
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
activity.setToolbarTitle(R.string.catalogues_title);
|
||||
setToolbarTitle(R.string.catalogues_title);
|
||||
|
||||
createAdapter();
|
||||
|
||||
@ -57,8 +55,8 @@ public class SourceFragment extends BaseFragment<SourcePresenter> {
|
||||
public void onSourceClick(int position) {
|
||||
Source source = adapter.getItem(position);
|
||||
|
||||
Intent intent = CatalogueActivity.newIntent(activity, source.getSourceId());
|
||||
startActivity(intent);
|
||||
CatalogueFragment fragment = CatalogueFragment.newInstance(source.getSourceId());
|
||||
activity.setFragment(fragment);
|
||||
}
|
||||
|
||||
private void createAdapter() {
|
||||
|
@ -1,45 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" android:fitsSystemWindows="true"
|
||||
tools:context="eu.kanade.mangafeed.ui.activity.CatalogueActivity">
|
||||
|
||||
<include
|
||||
android:id="@+id/toolbar"
|
||||
layout="@layout/toolbar"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress"
|
||||
style="?android:attr/progressBarStyleLarge"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_gravity="center_vertical|center_horizontal"
|
||||
android:visibility="gone" />
|
||||
|
||||
<GridView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:id="@+id/gridView"
|
||||
android:padding="10dp"
|
||||
android:clipToPadding="false"
|
||||
android:verticalSpacing="8dp"
|
||||
android:horizontalSpacing="8dp"
|
||||
android:columnWidth="96dp"
|
||||
android:numColumns="auto_fit"
|
||||
android:stretchMode="columnWidth"
|
||||
android:fastScrollEnabled="true"
|
||||
tools:listitem="@layout/item_catalogue" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress_grid"
|
||||
style="?android:attr/progressBarStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical|center_horizontal"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
@ -1,13 +1,41 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="eu.kanade.mangafeed.ui.fragment.SourceFragment">
|
||||
android:layout_height="match_parent" android:fitsSystemWindows="true"
|
||||
tools:context="eu.kanade.mangafeed.ui.fragment.CatalogueFragment">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress"
|
||||
style="?android:attr/progressBarStyleLarge"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_gravity="center_vertical|center_horizontal"
|
||||
android:visibility="gone" />
|
||||
|
||||
<ListView
|
||||
<GridView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:id="@+id/gridView"
|
||||
android:padding="10dp"
|
||||
android:clipToPadding="false"
|
||||
android:verticalSpacing="8dp"
|
||||
android:horizontalSpacing="8dp"
|
||||
android:columnWidth="96dp"
|
||||
android:numColumns="auto_fit"
|
||||
android:stretchMode="columnWidth"
|
||||
android:fastScrollEnabled="true"
|
||||
tools:listitem="@layout/item_catalogue" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress_grid"
|
||||
style="?android:attr/progressBarStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/catalogue_list" />
|
||||
android:layout_gravity="center_vertical|center_horizontal"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -5,7 +5,7 @@
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" android:fitsSystemWindows="true"
|
||||
tools:context="eu.kanade.mangafeed.ui.activity.CatalogueActivity">
|
||||
tools:context="eu.kanade.mangafeed.ui.fragment.CatalogueFragment">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
13
app/src/main/res/layout/fragment_source.xml
Normal file
13
app/src/main/res/layout/fragment_source.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="eu.kanade.mangafeed.ui.fragment.SourceFragment">
|
||||
|
||||
|
||||
<ListView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/catalogue_list" />
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user