mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07:57 +01:00 
			
		
		
		
	Set toolbar in BaseActivity. Show title in MangaDetailActivity
This commit is contained in:
		| @@ -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(); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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(); | ||||
|     } | ||||
|   | ||||
| @@ -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)); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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(), | ||||
|   | ||||
| @@ -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); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user