public ViewHolder(LayoutInflater inflater, ViewGroup parent) { super(inflater.inflate(R.layout.schedules_list, parent, false)); scheduleNameTextView = (TextView) itemView.findViewById(R.id.schedule_title); scheduleDeviceTextview = (TextView) itemView.findViewById(R.id.schedule_device_name); mondayTextView = (TextView) itemView.findViewById(R.id.schedule_monday); tuesdayTextView = (TextView) itemView.findViewById(R.id.schedule_tuesday); wednesdayTextView = (TextView) itemView.findViewById(R.id.schedule_wednesday); thursdayTextView = (TextView) itemView.findViewById(R.id.schedule_thursday); fridayTextView = (TextView) itemView.findViewById(R.id.schedule_friday); saturdayTextView = (TextView) itemView.findViewById(R.id.schedule_saturday); sundayTextView = (TextView) itemView.findViewById(R.id.schedule_sunday); timeTextView = (TextView) itemView.findViewById(R.id.schedule_time); scheduleSwitchCompat = (SwitchCompat) itemView.findViewById(R.id.schedule_switch); editImageButton = (ImageButton) itemView.findViewById(R.id.schedule_edit); deleteImageButton = (ImageButton) itemView.findViewById(R.id.schedule_delete); context = parent.getContext(); dbHelper = DatabaseHelper.getInstance(context.getApplicationContext()); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_schedules); // Add toolbar to Main screen Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle("Schedules"); setSupportActionBar(toolbar); // Create navigation drawer and inflate NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); drawerLayout = (DrawerLayout) findViewById(R.id.drawer); // Add menu icon to main toolbar ActionBar supportActionBar = getSupportActionBar(); if (supportActionBar != null) { supportActionBar.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp); supportActionBar.setDisplayHomeAsUpEnabled(true); } // Define behavior of navigation drawer navigationView.setNavigationItemSelectedListener( new NavigationView.OnNavigationItemSelectedListener() { // Triggered on navigation drawer item press @Override public boolean onNavigationItemSelected(MenuItem menuItem) { // Set item selected state if (menuItem.isChecked()) { menuItem.setChecked(false); } else { menuItem.setChecked(true); } // Set drawer to close on item press drawerLayout.closeDrawers(); // Respond to item selection Intent intent; switch (menuItem.getItemId()) { case R.id.nav_drawer_home: intent = new Intent(getApplicationContext(), MainActivity.class); startActivity(intent); return true; case R.id.nav_drawer_favourites: intent = new Intent(getApplicationContext(), FavouritesActivity.class); startActivity(intent); return true; case R.id.nav_drawer_settings: intent = new Intent(getApplicationContext(), SettingsActivity.class); startActivity(intent); return true; default: return true; } } }); recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view); db = DatabaseHelper.getInstance(getApplicationContext()); scheduleList = db.getAllSchedules(); socketList = db.getDevicesOfType("Power Socket"); recyclerView.setAdapter(new ContentAdapter()); recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(new LinearLayoutManager(this)); primaryColor = getResources().getColor(R.color.colorPrimary); // Add floating action button and define behavior FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(), AddScheduleActivity.class); startActivity(intent); } }); }