Search for library (not working)
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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<Observable<String>> 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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package eu.kanade.mangafeed.ui.fragment;
|
||||
|
||||
import android.app.Fragment;
|
||||
|
||||
public class BaseFragment extends Fragment {
|
||||
}
|
|
@ -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<Manga> 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<Manga> mangas) {
|
||||
if (adapter == null) {
|
||||
adapter = new EasyAdapter<Manga>(
|
||||
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().
|
||||
}
|
||||
|
||||
}
|
||||
|
|
BIN
app/src/main/res/drawable-hdpi/ic_action_refresh.png
Normal file
After Width: | Height: | Size: 422 B |
BIN
app/src/main/res/drawable-hdpi/ic_action_search.png
Normal file
After Width: | Height: | Size: 448 B |
BIN
app/src/main/res/drawable-mdpi/ic_action_refresh.png
Normal file
After Width: | Height: | Size: 276 B |
BIN
app/src/main/res/drawable-mdpi/ic_action_search.png
Normal file
After Width: | Height: | Size: 265 B |
BIN
app/src/main/res/drawable-xhdpi/ic_action_refresh.png
Normal file
After Width: | Height: | Size: 557 B |
BIN
app/src/main/res/drawable-xhdpi/ic_action_search.png
Normal file
After Width: | Height: | Size: 492 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_action_refresh.png
Normal file
After Width: | Height: | Size: 787 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_action_search.png
Normal file
After Width: | Height: | Size: 744 B |
BIN
app/src/main/res/drawable-xxxhdpi/ic_action_refresh.png
Normal file
After Width: | Height: | Size: 1 KiB |
BIN
app/src/main/res/drawable-xxxhdpi/ic_action_search.png
Normal file
After Width: | Height: | Size: 967 B |
17
app/src/main/res/menu/library.xml
Normal file
|
@ -0,0 +1,17 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
|
||||
<item
|
||||
android:id="@+id/action_search"
|
||||
android:title="@string/action_search"
|
||||
android:icon="@drawable/ic_action_search"
|
||||
android:orderInCategory="100"
|
||||
app:showAsAction="collapseActionView|ifRoom"
|
||||
app:actionViewClass="android.support.v7.widget.SearchView"/>
|
||||
<item
|
||||
android:id="@+id/action_refresh"
|
||||
android:title="@string/action_refresh"
|
||||
android:icon="@drawable/ic_action_refresh"
|
||||
android:orderInCategory="1"
|
||||
app:showAsAction="ifRoom" />
|
||||
</menu>
|
|
@ -1,6 +0,0 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
|
||||
<item android:id="@+id/action_github" android:title="@string/action_github"
|
||||
android:orderInCategory="100" app:showAsAction="never" />
|
||||
</menu>
|
|
@ -30,5 +30,8 @@
|
|||
|
||||
<string name="hello_world">Hello world!</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="action_search">Search</string>
|
||||
<string name="action_refresh">Refresh</string>
|
||||
<string name="library_search_hint">Title or author...</string>
|
||||
|
||||
</resources>
|
||||
|
|