| 27 | import static android.widget.Toast.LENGTH_SHORT; |
| 28 | |
| 29 | public final class MainActivity extends Activity { |
| 30 | @BindView(R.id.main_drawer_layout) DrawerLayout drawerLayout; |
| 31 | @BindView(R.id.main_navigation) NavigationView drawer; |
| 32 | @BindView(R.id.main_content) ViewGroup content; |
| 33 | |
| 34 | @BindColor(R.color.status_bar) int statusBarColor; |
| 35 | |
| 36 | @Inject ViewContainer viewContainer; |
| 37 | |
| 38 | private ObjectGraph activityGraph; |
| 39 | |
| 40 | @Override protected void onCreate(Bundle savedInstanceState) { |
| 41 | super.onCreate(savedInstanceState); |
| 42 | LayoutInflater inflater = getLayoutInflater(); |
| 43 | |
| 44 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
| 45 | // Remove the status bar color. The DrawerLayout is responsible for drawing it from now on. |
| 46 | setStatusBarColor(getWindow()); |
| 47 | } |
| 48 | |
| 49 | // Explicitly reference the application object since we don't want to match our own injector. |
| 50 | ObjectGraph appGraph = Injector.obtain(getApplication()); |
| 51 | appGraph.inject(this); |
| 52 | activityGraph = appGraph.plus(new MainActivityModule(this)); |
| 53 | |
| 54 | ViewGroup container = viewContainer.forActivity(this); |
| 55 | |
| 56 | inflater.inflate(R.layout.main_activity, container); |
| 57 | ButterKnife.bind(this, container); |
| 58 | |
| 59 | drawerLayout.setStatusBarBackgroundColor(statusBarColor); |
| 60 | drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); |
| 61 | |
| 62 | drawer.setNavigationItemSelectedListener(item -> { |
| 63 | switch (item.getItemId()) { |
| 64 | case R.id.nav_search: |
| 65 | Toast.makeText(MainActivity.this, "Search!", LENGTH_SHORT).show(); |
| 66 | break; |
| 67 | case R.id.nav_trending: |
| 68 | Toast.makeText(MainActivity.this, "Trending!", LENGTH_SHORT).show(); |
| 69 | break; |
| 70 | default: |
| 71 | throw new IllegalStateException("Unknown navigation item: " + item.getTitle()); |
| 72 | } |
| 73 | |
| 74 | drawerLayout.closeDrawers(); |
| 75 | // If we supported actual navigation, we would change what was checked and navigate there. |
| 76 | //item.setChecked(true); |
| 77 | |
| 78 | return true; |
| 79 | }); |
| 80 | |
| 81 | inflater.inflate(R.layout.trending_view, content); |
| 82 | } |
| 83 | |
| 84 | @Override public Object getSystemService(@NonNull String name) { |
| 85 | if (Injector.matchesService(name)) { |
| 86 | return activityGraph; |
nothing calls this directly
no outgoing calls
no test coverage detected