Set toolbar in BaseActivity. Show title in MangaDetailActivity

This commit is contained in:
inorichi 2015-09-28 12:42:16 +02:00
parent 43439720db
commit d3b6b8721e
11 changed files with 85 additions and 36 deletions

View File

@ -28,10 +28,24 @@ public class MangaManager extends BaseManager {
}
public Observable<PutResult> insert(Manga manga) {
return db.put()
.object(manga)
.prepare()
.createObservable();
}
public void createDummyManga() {
Manga m = new Manga();
m.url="http://example.com";
m.artist="Eiichiro Oda";
m.author="Eiichiro Oda";
m.description="...";
m.genre="Action, Drama";
m.status="Ongoing";
m.thumbnail_url="http://example.com/pic.png";
m.title="Berserk";
insert(m).subscribe();
}
}

View File

@ -2,13 +2,12 @@ package eu.kanade.mangafeed.presenter;
import android.content.Intent;
import java.util.ArrayList;
import javax.inject.Inject;
import de.greenrobot.event.EventBus;
import eu.kanade.mangafeed.App;
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.LibraryView;
import uk.co.ribot.easyadapter.EasyAdapter;
@ -27,20 +26,18 @@ public class LibraryPresenter {
App.getComponent(libraryView.getActivity()).inject(this);
}
public void onMangaClick(EasyAdapter adapter, int position) {
Intent intent = new Intent(mLibraryView.getActivity(), MangaDetailActivity.class);
EventBus.getDefault().postSticky(adapter.getItem(position));
public void onMangaClick(EasyAdapter<Manga> adapter, int position) {
Intent intent = MangaDetailActivity.newIntent(
mLibraryView.getActivity(),
adapter.getItem(position)
);
mLibraryView.getActivity().startActivity(intent);
}
public void initializeMangas() {
db.manga.get()
.observeOn(mainThread())
.subscribe(
mangas -> {
mLibraryView.setMangas(new ArrayList<>(mangas));
}
);
.subscribe(mLibraryView::setMangas);
}
}

View File

@ -2,6 +2,7 @@ package eu.kanade.mangafeed.ui.activity;
import android.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import eu.kanade.mangafeed.App;
@ -25,6 +26,15 @@ public class BaseActivity extends AppCompatActivity {
}
}
protected void setupToolbar(Toolbar toolbar) {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
public void setToolbarTitle(String title) {
getSupportActionBar().setTitle(title);
}
protected AppComponent applicationComponent() {
return App.get(this).getComponent();
}

View File

@ -29,19 +29,17 @@ public class MainActivity extends BaseActivity {
@Bind(R.id.drawer_container)
FrameLayout container;
@Inject DatabaseHelper mDb;
private Drawer drawer;
private CompositeSubscription mSubscriptions;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
applicationComponent().inject(this);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
mSubscriptions = new CompositeSubscription();
setupToolbar();
setupToolbar(toolbar);
drawer = new DrawerBuilder()
.withActivity(this)
@ -107,10 +105,6 @@ public class MainActivity extends BaseActivity {
}
}
private void setupToolbar() {
setSupportActionBar(toolbar);
}
private void setFragment(Fragment fragment) {
try {
if (fragment != null && getSupportFragmentManager() != null) {
@ -125,4 +119,8 @@ public class MainActivity extends BaseActivity {
}
}
public void setToolbarTitle(int titleResource) {
getSupportActionBar().setTitle(getString(titleResource));
}
}

View File

@ -1,22 +1,33 @@
package eu.kanade.mangafeed.ui.activity;
import android.support.v7.app.AppCompatActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import butterknife.Bind;
import butterknife.ButterKnife;
import de.greenrobot.event.EventBus;
import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.data.models.Manga;
public class MangaDetailActivity extends AppCompatActivity {
public class MangaDetailActivity extends BaseActivity {
Manga manga;
@Bind(R.id.toolbar)
Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_manga_detail);
ButterKnife.bind(this);
setupToolbar(toolbar);
EventBus.getDefault().registerSticky(this);
}
@ -49,8 +60,19 @@ public class MangaDetailActivity extends AppCompatActivity {
super.onDestroy();
}
public void onEvent(Manga manga) {
public static Intent newIntent(Context context, Manga manga) {
Intent intent = new Intent(context, MangaDetailActivity.class);
EventBus.getDefault().postSticky(manga);
return intent;
}
public void onEventMainThread(Manga manga) {
this.manga = manga;
loadManga();
//loadChapters();
}
private void loadManga() {
setToolbarTitle(manga.title);
}
}

View File

@ -8,6 +8,7 @@ import android.view.ViewGroup;
import android.widget.GridView;
import java.util.ArrayList;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
@ -15,6 +16,7 @@ import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.data.models.Manga;
import eu.kanade.mangafeed.presenter.LibraryPresenter;
import eu.kanade.mangafeed.ui.activity.BaseActivity;
import eu.kanade.mangafeed.ui.activity.MainActivity;
import eu.kanade.mangafeed.ui.adapter.MangaLibraryHolder;
import eu.kanade.mangafeed.view.LibraryView;
import uk.co.ribot.easyadapter.EasyAdapter;
@ -45,7 +47,7 @@ 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);
((BaseActivity) getActivity()).getSupportActionBar().setTitle(R.string.library_title);
((MainActivity)getActivity()).setToolbarTitle(getString(R.string.library_title));
ButterKnife.bind(this, view);
mLibraryPresenter.initializeMangas();
@ -54,7 +56,7 @@ public class LibraryFragment extends Fragment implements LibraryView {
return view;
}
public void setMangas(ArrayList<Manga> mangas) {
public void setMangas(List<Manga> mangas) {
if (mEasyAdapter == null) {
mEasyAdapter = new EasyAdapter<Manga>(
getActivity(),

View File

@ -1,10 +1,11 @@
package eu.kanade.mangafeed.view;
import java.util.ArrayList;
import java.util.List;
import eu.kanade.mangafeed.data.models.Manga;
public interface LibraryView extends BaseView {
void setMangas(ArrayList<Manga> mangas);
void setMangas(List<Manga> mangas);
}

View File

@ -1,17 +1,11 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
<include
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:elevation="4dp" />
layout="@layout/toolbar"/>
<!-- the layout which will contain (host) the drawerLayout -->
<FrameLayout

View File

@ -2,12 +2,12 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="eu.kanade.mangafeed.ui.activity.MangaDetailActivity">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"/>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:elevation="4dp" />

View File

@ -1,6 +1,6 @@
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>