diff --git a/app/src/main/java/eu/kanade/mangafeed/presenter/BasePresenter.java b/app/src/main/java/eu/kanade/mangafeed/presenter/BasePresenter.java new file mode 100644 index 000000000..083a774c4 --- /dev/null +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/BasePresenter.java @@ -0,0 +1,18 @@ +package eu.kanade.mangafeed.presenter; + +import de.greenrobot.event.EventBus; + +public class BasePresenter { + + public void registerForStickyEvents() { + EventBus.getDefault().registerSticky(this); + } + + public void registerForEvents() { + EventBus.getDefault().register(this); + } + + public void unregisterForEvents() { + EventBus.getDefault().unregister(this); + } +} diff --git a/app/src/main/java/eu/kanade/mangafeed/presenter/LibraryPresenter.java b/app/src/main/java/eu/kanade/mangafeed/presenter/LibraryPresenter.java index ff21dab68..d292f2386 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/LibraryPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/LibraryPresenter.java @@ -10,11 +10,17 @@ import eu.kanade.mangafeed.data.helpers.PreferencesHelper; import eu.kanade.mangafeed.data.models.Manga; import eu.kanade.mangafeed.ui.activity.MangaDetailActivity; import eu.kanade.mangafeed.view.LibraryView; +import rx.Observable; +import rx.Subscription; +import rx.android.schedulers.AndroidSchedulers; +import rx.schedulers.Schedulers; +import rx.subjects.PublishSubject; +import timber.log.Timber; import uk.co.ribot.easyadapter.EasyAdapter; import static rx.android.schedulers.AndroidSchedulers.mainThread; -public class LibraryPresenter { +public class LibraryPresenter extends BasePresenter { private LibraryView view; @@ -24,6 +30,9 @@ public class LibraryPresenter { @Inject PreferencesHelper prefs; + private Subscription searchViewSubscription; + private PublishSubject> searchViewPublishSubject; + public LibraryPresenter(LibraryView view) { this.view = view; App.getComponent(view.getActivity()).inject(this); @@ -45,10 +54,24 @@ public class LibraryPresenter { view.getActivity().startActivity(intent); } + public void initializeSearch() { + searchViewPublishSubject = PublishSubject.create(); + searchViewSubscription = Observable.switchOnNext(searchViewPublishSubject) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(Timber::w); + } + public void initializeMangas() { db.manga.get() .observeOn(mainThread()) .subscribe(view::setMangas); } + public void onQueryTextChange(String query) { + if (searchViewPublishSubject != null) { + searchViewPublishSubject.onNext(Observable.just(query)); + } + } + } diff --git a/app/src/main/java/eu/kanade/mangafeed/presenter/MangaDetailPresenter.java b/app/src/main/java/eu/kanade/mangafeed/presenter/MangaDetailPresenter.java index 2d73cf004..77cff579f 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/MangaDetailPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/MangaDetailPresenter.java @@ -8,7 +8,7 @@ import eu.kanade.mangafeed.data.helpers.DatabaseHelper; import eu.kanade.mangafeed.data.models.Manga; import eu.kanade.mangafeed.view.MangaDetailView; -public class MangaDetailPresenter { +public class MangaDetailPresenter extends BasePresenter { private MangaDetailView view; @@ -20,14 +20,6 @@ public class MangaDetailPresenter { App.getComponent(view.getActivity()).inject(this); } - public void onStart() { - EventBus.getDefault().registerSticky(this); - } - - public void onStop() { - EventBus.getDefault().unregister(this); - } - public void onEventMainThread(Manga manga) { view.loadManga(manga); initializeChapters(manga); 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 66f972f70..5d09b5ef2 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 @@ -89,22 +89,6 @@ public class MainActivity extends BaseActivity { mSubscriptions.unsubscribe(); } - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.main, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.action_github: - return true; - default: - return super.onOptionsItemSelected(item); - } - } - private void setFragment(Fragment fragment) { try { if (fragment != null && getSupportFragmentManager() != null) { diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaDetailActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaDetailActivity.java index 519a9f761..69305263e 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaDetailActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaDetailActivity.java @@ -32,6 +32,12 @@ public class MangaDetailActivity extends BaseActivity implements MangaDetailView @Bind(R.id.manga_chapters_list) ListView list_chapters; + public static Intent newIntent(Context context, Manga manga) { + Intent intent = new Intent(context, MangaDetailActivity.class); + MangaDetailPresenter.newIntent(manga); + return intent; + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -42,44 +48,16 @@ public class MangaDetailActivity extends BaseActivity implements MangaDetailView setupToolbar(toolbar); } - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu_manga_detail, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); - - //noinspection SimplifiableIfStatement - if (id == R.id.action_settings) { - return true; - } - - return super.onOptionsItemSelected(item); - } - - public static Intent newIntent(Context context, Manga manga) { - Intent intent = new Intent(context, MangaDetailActivity.class); - MangaDetailPresenter.newIntent(manga); - return intent; - } - @Override public void onStart() { super.onStart(); - presenter.onStart(); + presenter.registerForStickyEvents(); } @Override public void onStop() { + presenter.unregisterForEvents(); super.onStop(); - presenter.onStop(); } public void loadManga(Manga manga) { 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 new file mode 100644 index 000000000..d2cf43adf --- /dev/null +++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/BaseFragment.java @@ -0,0 +1,6 @@ +package eu.kanade.mangafeed.ui.fragment; + +import android.app.Fragment; + +public class BaseFragment extends Fragment { +} diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/LibraryFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/LibraryFragment.java index a614fffbc..25b7610c3 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/LibraryFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/LibraryFragment.java @@ -1,8 +1,10 @@ package eu.kanade.mangafeed.ui.fragment; -import android.app.Fragment; import android.os.Bundle; +import android.support.v7.widget.SearchView; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; import android.widget.GridView; @@ -17,14 +19,16 @@ import eu.kanade.mangafeed.presenter.LibraryPresenter; import eu.kanade.mangafeed.ui.activity.MainActivity; import eu.kanade.mangafeed.ui.adapter.MangaLibraryHolder; import eu.kanade.mangafeed.view.LibraryView; +import timber.log.Timber; import uk.co.ribot.easyadapter.EasyAdapter; -public class LibraryFragment extends Fragment implements LibraryView { +public class LibraryFragment extends BaseFragment implements LibraryView { @Bind(R.id.gridView) GridView grid; LibraryPresenter presenter; EasyAdapter adapter; + MainActivity activity; public static LibraryFragment newInstance() { LibraryFragment fragment = new LibraryFragment(); @@ -36,8 +40,10 @@ public class LibraryFragment extends Fragment implements LibraryView { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setHasOptionsMenu(true); presenter = new LibraryPresenter(this); + activity = (MainActivity)getActivity(); } @Override @@ -45,18 +51,49 @@ public class LibraryFragment extends Fragment implements LibraryView { Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_library, container, false); - ((MainActivity)getActivity()).setToolbarTitle(getString(R.string.library_title)); + activity.setToolbarTitle(getString(R.string.library_title)); ButterKnife.bind(this, view); - presenter.initializeMangas(); - setMangaClickListener(); - return view; } + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + setupToolbar(); + setMangaClickListener(); + presenter.initializeMangas(); + presenter.initializeSearch(); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.library, menu); + initializeSearch(menu); + } + + private void initializeSearch(Menu menu) { + final SearchView sv = (SearchView) menu.findItem(R.id.action_search).getActionView(); + sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + @Override + public boolean onQueryTextSubmit(String query) { + return true; + } + + @Override + public boolean onQueryTextChange(String newText) { + presenter.onQueryTextChange(newText); + return true; + } + }); + } + + // LibraryView + public void setMangas(List mangas) { if (adapter == null) { - adapter = new EasyAdapter( + adapter = new EasyAdapter<>( getActivity(), MangaLibraryHolder.class, mangas @@ -71,8 +108,12 @@ public class LibraryFragment extends Fragment implements LibraryView { private void setMangaClickListener() { grid.setOnItemClickListener( (parent, view, position, id) -> - presenter.onMangaClick(adapter, position) + presenter.onMangaClick(adapter, position) ); } + private void setupToolbar() { + //activity.getSupportActionBar(). + } + } diff --git a/app/src/main/res/drawable-hdpi/ic_action_refresh.png b/app/src/main/res/drawable-hdpi/ic_action_refresh.png new file mode 100644 index 000000000..6d4481ff7 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_refresh.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_action_search.png b/app/src/main/res/drawable-hdpi/ic_action_search.png new file mode 100644 index 000000000..c53e3315c Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_search.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_refresh.png b/app/src/main/res/drawable-mdpi/ic_action_refresh.png new file mode 100644 index 000000000..ccca0127f Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_refresh.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_search.png b/app/src/main/res/drawable-mdpi/ic_action_search.png new file mode 100644 index 000000000..5feb851bd Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_search.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_refresh.png b/app/src/main/res/drawable-xhdpi/ic_action_refresh.png new file mode 100644 index 000000000..765ed43fc Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_refresh.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_search.png b/app/src/main/res/drawable-xhdpi/ic_action_search.png new file mode 100644 index 000000000..3b174553e Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_search.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_refresh.png b/app/src/main/res/drawable-xxhdpi/ic_action_refresh.png new file mode 100644 index 000000000..455000ed5 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_refresh.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_search.png b/app/src/main/res/drawable-xxhdpi/ic_action_search.png new file mode 100644 index 000000000..c635b4a53 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_search.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_action_refresh.png b/app/src/main/res/drawable-xxxhdpi/ic_action_refresh.png new file mode 100644 index 000000000..58b116e0d Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_action_refresh.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_action_search.png b/app/src/main/res/drawable-xxxhdpi/ic_action_search.png new file mode 100644 index 000000000..88f973d12 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_action_search.png differ diff --git a/app/src/main/res/menu/library.xml b/app/src/main/res/menu/library.xml new file mode 100644 index 000000000..dad70a02d --- /dev/null +++ b/app/src/main/res/menu/library.xml @@ -0,0 +1,17 @@ + + + + diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml deleted file mode 100644 index 537e37cfa..000000000 --- a/app/src/main/res/menu/main.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 400af76be..b4090eed2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -30,5 +30,8 @@ Hello world! Settings + Search + Refresh + Title or author...