mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-10 04:37:25 +01:00
Set toolbar in BaseActivity. Show title in MangaDetailActivity
This commit is contained in:
parent
43439720db
commit
d3b6b8721e
@ -28,10 +28,24 @@ public class MangaManager extends BaseManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Observable<PutResult> insert(Manga manga) {
|
public Observable<PutResult> insert(Manga manga) {
|
||||||
|
|
||||||
return db.put()
|
return db.put()
|
||||||
.object(manga)
|
.object(manga)
|
||||||
.prepare()
|
.prepare()
|
||||||
.createObservable();
|
.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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,12 @@ package eu.kanade.mangafeed.presenter;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import de.greenrobot.event.EventBus;
|
import de.greenrobot.event.EventBus;
|
||||||
import eu.kanade.mangafeed.App;
|
import eu.kanade.mangafeed.App;
|
||||||
import eu.kanade.mangafeed.data.helpers.DatabaseHelper;
|
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.ui.activity.MangaDetailActivity;
|
||||||
import eu.kanade.mangafeed.view.LibraryView;
|
import eu.kanade.mangafeed.view.LibraryView;
|
||||||
import uk.co.ribot.easyadapter.EasyAdapter;
|
import uk.co.ribot.easyadapter.EasyAdapter;
|
||||||
@ -27,20 +26,18 @@ public class LibraryPresenter {
|
|||||||
App.getComponent(libraryView.getActivity()).inject(this);
|
App.getComponent(libraryView.getActivity()).inject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onMangaClick(EasyAdapter adapter, int position) {
|
public void onMangaClick(EasyAdapter<Manga> adapter, int position) {
|
||||||
Intent intent = new Intent(mLibraryView.getActivity(), MangaDetailActivity.class);
|
Intent intent = MangaDetailActivity.newIntent(
|
||||||
EventBus.getDefault().postSticky(adapter.getItem(position));
|
mLibraryView.getActivity(),
|
||||||
|
adapter.getItem(position)
|
||||||
|
);
|
||||||
mLibraryView.getActivity().startActivity(intent);
|
mLibraryView.getActivity().startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initializeMangas() {
|
public void initializeMangas() {
|
||||||
db.manga.get()
|
db.manga.get()
|
||||||
.observeOn(mainThread())
|
.observeOn(mainThread())
|
||||||
.subscribe(
|
.subscribe(mLibraryView::setMangas);
|
||||||
mangas -> {
|
|
||||||
mLibraryView.setMangas(new ArrayList<>(mangas));
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package eu.kanade.mangafeed.ui.activity;
|
|||||||
|
|
||||||
import android.app.FragmentManager;
|
import android.app.FragmentManager;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import eu.kanade.mangafeed.App;
|
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() {
|
protected AppComponent applicationComponent() {
|
||||||
return App.get(this).getComponent();
|
return App.get(this).getComponent();
|
||||||
}
|
}
|
||||||
|
@ -29,19 +29,17 @@ public class MainActivity extends BaseActivity {
|
|||||||
@Bind(R.id.drawer_container)
|
@Bind(R.id.drawer_container)
|
||||||
FrameLayout container;
|
FrameLayout container;
|
||||||
|
|
||||||
@Inject DatabaseHelper mDb;
|
|
||||||
private Drawer drawer;
|
private Drawer drawer;
|
||||||
private CompositeSubscription mSubscriptions;
|
private CompositeSubscription mSubscriptions;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
applicationComponent().inject(this);
|
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
mSubscriptions = new CompositeSubscription();
|
mSubscriptions = new CompositeSubscription();
|
||||||
|
|
||||||
setupToolbar();
|
setupToolbar(toolbar);
|
||||||
|
|
||||||
drawer = new DrawerBuilder()
|
drawer = new DrawerBuilder()
|
||||||
.withActivity(this)
|
.withActivity(this)
|
||||||
@ -107,10 +105,6 @@ public class MainActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupToolbar() {
|
|
||||||
setSupportActionBar(toolbar);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setFragment(Fragment fragment) {
|
private void setFragment(Fragment fragment) {
|
||||||
try {
|
try {
|
||||||
if (fragment != null && getSupportFragmentManager() != null) {
|
if (fragment != null && getSupportFragmentManager() != null) {
|
||||||
@ -125,4 +119,8 @@ public class MainActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setToolbarTitle(int titleResource) {
|
||||||
|
getSupportActionBar().setTitle(getString(titleResource));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,33 @@
|
|||||||
package eu.kanade.mangafeed.ui.activity;
|
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.os.Bundle;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
|
import butterknife.Bind;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
import de.greenrobot.event.EventBus;
|
import de.greenrobot.event.EventBus;
|
||||||
import eu.kanade.mangafeed.R;
|
import eu.kanade.mangafeed.R;
|
||||||
import eu.kanade.mangafeed.data.models.Manga;
|
import eu.kanade.mangafeed.data.models.Manga;
|
||||||
|
|
||||||
public class MangaDetailActivity extends AppCompatActivity {
|
public class MangaDetailActivity extends BaseActivity {
|
||||||
|
|
||||||
Manga manga;
|
Manga manga;
|
||||||
|
|
||||||
|
@Bind(R.id.toolbar)
|
||||||
|
Toolbar toolbar;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_manga_detail);
|
setContentView(R.layout.activity_manga_detail);
|
||||||
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
|
setupToolbar(toolbar);
|
||||||
|
|
||||||
EventBus.getDefault().registerSticky(this);
|
EventBus.getDefault().registerSticky(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,8 +60,19 @@ public class MangaDetailActivity extends AppCompatActivity {
|
|||||||
super.onDestroy();
|
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;
|
this.manga = manga;
|
||||||
|
loadManga();
|
||||||
//loadChapters();
|
//loadChapters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadManga() {
|
||||||
|
setToolbarTitle(manga.title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.GridView;
|
import android.widget.GridView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import butterknife.Bind;
|
import butterknife.Bind;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
@ -15,6 +16,7 @@ import eu.kanade.mangafeed.R;
|
|||||||
import eu.kanade.mangafeed.data.models.Manga;
|
import eu.kanade.mangafeed.data.models.Manga;
|
||||||
import eu.kanade.mangafeed.presenter.LibraryPresenter;
|
import eu.kanade.mangafeed.presenter.LibraryPresenter;
|
||||||
import eu.kanade.mangafeed.ui.activity.BaseActivity;
|
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.ui.adapter.MangaLibraryHolder;
|
||||||
import eu.kanade.mangafeed.view.LibraryView;
|
import eu.kanade.mangafeed.view.LibraryView;
|
||||||
import uk.co.ribot.easyadapter.EasyAdapter;
|
import uk.co.ribot.easyadapter.EasyAdapter;
|
||||||
@ -45,7 +47,7 @@ public class LibraryFragment extends Fragment implements LibraryView {
|
|||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
View view = inflater.inflate(R.layout.fragment_library, container, false);
|
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);
|
ButterKnife.bind(this, view);
|
||||||
|
|
||||||
mLibraryPresenter.initializeMangas();
|
mLibraryPresenter.initializeMangas();
|
||||||
@ -54,7 +56,7 @@ public class LibraryFragment extends Fragment implements LibraryView {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMangas(ArrayList<Manga> mangas) {
|
public void setMangas(List<Manga> mangas) {
|
||||||
if (mEasyAdapter == null) {
|
if (mEasyAdapter == null) {
|
||||||
mEasyAdapter = new EasyAdapter<Manga>(
|
mEasyAdapter = new EasyAdapter<Manga>(
|
||||||
getActivity(),
|
getActivity(),
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package eu.kanade.mangafeed.view;
|
package eu.kanade.mangafeed.view;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import eu.kanade.mangafeed.data.models.Manga;
|
import eu.kanade.mangafeed.data.models.Manga;
|
||||||
|
|
||||||
public interface LibraryView extends BaseView {
|
public interface LibraryView extends BaseView {
|
||||||
|
|
||||||
void setMangas(ArrayList<Manga> mangas);
|
void setMangas(List<Manga> mangas);
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,11 @@
|
|||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<android.support.v7.widget.Toolbar
|
<include
|
||||||
android:id="@+id/toolbar"
|
android:id="@+id/toolbar"
|
||||||
android:layout_width="match_parent"
|
layout="@layout/toolbar"/>
|
||||||
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" />
|
|
||||||
|
|
||||||
<!-- the layout which will contain (host) the drawerLayout -->
|
<!-- the layout which will contain (host) the drawerLayout -->
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="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">
|
tools:context="eu.kanade.mangafeed.ui.activity.MangaDetailActivity">
|
||||||
|
|
||||||
|
<include
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
layout="@layout/toolbar"/>
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
11
app/src/main/res/layout/toolbar.xml
Normal file
11
app/src/main/res/layout/toolbar.xml
Normal 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" />
|
@ -1,6 +1,6 @@
|
|||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<style name="AppTheme" parent="Theme.AppCompat.Light">
|
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||||
<item name="colorPrimary">@color/primary</item>
|
<item name="colorPrimary">@color/primary</item>
|
||||||
<item name="colorPrimaryDark">@color/primary_dark</item>
|
<item name="colorPrimaryDark">@color/primary_dark</item>
|
||||||
<item name="colorAccent">@color/accent</item>
|
<item name="colorAccent">@color/accent</item>
|
||||||
|
Loading…
Reference in New Issue
Block a user