예제 #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    List<City> cityList = City.listAll(City.class);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    adapter = new WeatherRecyclerAdapter(this, cityList);

    recyclerView.setHasFixedSize(true);
    final LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setAdapter(adapter);

    layoutContent = (CoordinatorLayout) findViewById(R.id.layoutContent);

    FloatingActionButton fabAdd = (FloatingActionButton) findViewById(R.id.btnAdd);

    fabAdd.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            new FragmentCreate().show(getSupportFragmentManager(), FragmentCreate.TAG);
          }
        });

    drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);

    NavigationView navigationView = (NavigationView) findViewById(R.id.navigationView);
    navigationView.setNavigationItemSelectedListener(
        new NavigationView.OnNavigationItemSelectedListener() {
          @Override
          public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(true);
            switch (menuItem.getItemId()) {
              case R.id.action_about:
                showSnackBarMessage(getString(R.string.snkbr_about));
                drawerLayout.closeDrawer(GravityCompat.START);
                break;
              case R.id.action_add:
                new FragmentCreate().show(getSupportFragmentManager(), FragmentCreate.TAG);
                showSnackBarMessage(getString(R.string.snkbr_add));
                drawerLayout.closeDrawer(GravityCompat.START);
                break;
            }
            return false;
          }
        });
    setUpToolBar();
  }
예제 #2
0
 public void showDetailActivity(City city) {
   Intent details = new Intent(MainActivity.this, WeatherDetailsActivity.class);
   details.putExtra(PASS_DETAILS, city.getCity());
   startActivity(details);
 }