diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 957876e95..86e3a0b55 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -28,15 +28,6 @@ android:label="@string/title_activity_manga_detail" android:parentActivityName=".ui.activity.MainActivity" > - - - { +public class CataloguePresenter extends BasePresenter { @Inject SourceManager sourceManager; @Inject DatabaseHelper db; @@ -67,7 +67,7 @@ public class CataloguePresenter extends BasePresenter { } @Override - protected void onTakeView(CatalogueActivity view) { + protected void onTakeView(CatalogueFragment view) { super.onTakeView(view); view.setToolbarTitle(selectedSource.getName()); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/activity/BaseActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/activity/BaseActivity.java index e40afaef6..97ea61110 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/activity/BaseActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/activity/BaseActivity.java @@ -24,11 +24,18 @@ public class BaseActivity

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() { diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/activity/MainActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/activity/MainActivity.java index 13e46ab0c..208fe513c 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/activity/MainActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/activity/MainActivity.java @@ -82,7 +82,7 @@ public class MainActivity extends BaseActivity { 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 { } } - public void setToolbarTitle(int titleResource) { - getSupportActionBar().setTitle(getString(titleResource)); - } - } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/BaseFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/BaseFragment.java index b220bf513..25c91f457 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/BaseFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/BaseFragment.java @@ -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

extends NucleusSupportFragment

super.onCreate(savedInstanceState); } + public void setToolbarTitle(String title) { + ((BaseActivity)getActivity()).setToolbarTitle(title); + } + + public void setToolbarTitle(int resourceId) { + ((BaseActivity)getActivity()).setToolbarTitle(getString(resourceId)); + } + } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/activity/CatalogueActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/CatalogueFragment.java similarity index 77% rename from app/src/main/java/eu/kanade/mangafeed/ui/activity/CatalogueActivity.java rename to app/src/main/java/eu/kanade/mangafeed/ui/fragment/CatalogueFragment.java index 52a82422d..348a388ab 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/activity/CatalogueActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/CatalogueFragment.java @@ -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 { - - @Bind(R.id.toolbar) - Toolbar toolbar; +public class CatalogueFragment extends BaseFragment { @Bind(R.id.gridView) GridView manga_list; @@ -49,34 +48,44 @@ public class CatalogueActivity extends BaseActivity { 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 { } 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 { 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); } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/SourceFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/SourceFragment.java index 23a4b4e18..3cce7a2dc 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/SourceFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/SourceFragment.java @@ -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 { 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 { 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() { diff --git a/app/src/main/res/layout/activity_catalogue.xml b/app/src/main/res/layout/activity_catalogue.xml deleted file mode 100644 index 3d9d53f2e..000000000 --- a/app/src/main/res/layout/activity_catalogue.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - diff --git a/app/src/main/res/layout/fragment_catalogue.xml b/app/src/main/res/layout/fragment_catalogue.xml index 9d672fb29..d1adda782 100644 --- a/app/src/main/res/layout/fragment_catalogue.xml +++ b/app/src/main/res/layout/fragment_catalogue.xml @@ -1,13 +1,41 @@ - + + android:layout_height="match_parent" android:fitsSystemWindows="true" + tools:context="eu.kanade.mangafeed.ui.fragment.CatalogueFragment"> + - + + + android:layout_gravity="center_vertical|center_horizontal" + android:visibility="gone" /> diff --git a/app/src/main/res/layout/fragment_manga_info.xml b/app/src/main/res/layout/fragment_manga_info.xml index e637dbbca..6df249914 100644 --- a/app/src/main/res/layout/fragment_manga_info.xml +++ b/app/src/main/res/layout/fragment_manga_info.xml @@ -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"> + + + + +