public static void goTo(String code) { replaceFragment(sf); currentFragment = sf; assert (actionBar != null); actionBar.setDisplayShowTitleEnabled(false); actionBar.setTitle(R.string.title_activity_main); ScheduleFragment.user = Framework.MY_SCHEDULE; UpdateSchedule.dayOfWeek = DayPicker.toDayNumber(cal.get(Calendar.DAY_OF_WEEK)); ScheduleFragment.setWeekUnix((int) (System.currentTimeMillis() / 1000)); UpdateSchedule.scroll = true; ScheduleFragment.createList(); datePickerButton.setVisibility(View.VISIBLE); menu.findItem(R.id.menu_search).setVisible(true); navigationView.getMenu().getItem(0).setChecked(true); if (ScheduleFragment.classArrayList.size() == 0) { progressBar.setVisibility(View.VISIBLE); } ScheduleFragment.user = code; goToday(); actionBar.invalidateOptionsMenu(); }
public static void goToday() { cal.setTime(new Date(System.currentTimeMillis())); UpdateSchedule.dayOfWeek = DayPicker.toDayNumber(cal.get(Calendar.DAY_OF_WEEK)); ScheduleFragment.setWeekUnix((int) (System.currentTimeMillis() / 1000)); UpdateSchedule.scroll = true; ScheduleFragment.createList(); dialog = DatePickerDialog.newInstance( new DayPicker(), cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); }
@Override public void onBackPressed() { DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else { // moveTaskToBack(true); if (!ScheduleFragment.user.equals(Framework.MY_SCHEDULE) && sf.isVisible()) { ScheduleFragment.user = Framework.MY_SCHEDULE; UpdateSchedule.scroll = true; ScheduleFragment.createList(); } else { currentFragment = sf; finish(); } } }
private static void replaceFragment(Fragment fragment) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { sf.setEnterTransition(new Slide(Gravity.RIGHT)); } // TODO: Figure out a better transition system/speed up transition fragmentManager .beginTransaction() .setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out) .replace(R.id.schedule_fragment_container, fragment) .commit(); }
@Override protected void onNewIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); if (menu.findItem(R.id.menu_search).isActionViewExpanded()) { menu.findItem(R.id.menu_search).collapseActionView(); } Log.w("Search", query); ScheduleFragment.user = query.toLowerCase(); UpdateSchedule.scroll = true; ScheduleFragment.createList(); } }
public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.menu_refresh) { ScheduleFragment.createList(); } else if (id == R.id.menu_today) { goToday(); } else if (id == R.id.menu_star) { if (ScheduleFragment.user.equals(Framework.MY_SCHEDULE)) { Snackbar.make( findViewById(R.id.drawer_layout), getResources().getString(R.string.selfFriends), Snackbar.LENGTH_SHORT) .show(); return true; } if (FriendsFragment.friendArrayList.size() > 0) { for (int i = 0; i < FriendsFragment.friendArrayList.size(); i++) { if (FriendsFragment.friendArrayList.get(i).code != null && FriendsFragment.friendArrayList.get(i).code.equals(ScheduleFragment.user)) { Snackbar.make( findViewById(R.id.drawer_layout), getResources().getString(R.string.alreadyFriends), Snackbar.LENGTH_SHORT) .show(); return true; } } } MaterialDialog.Builder name = new MaterialDialog.Builder(this) .title(getText(R.string.addFriend)) .inputType(InputType.TYPE_CLASS_TEXT) .input( getString(R.string.name), "", new MaterialDialog.InputCallback() { @Override public void onInput( @NonNull MaterialDialog materialDialog, CharSequence charSequence) { FriendsFragment.friendArrayList.add( new FriendInfo(charSequence.toString(), ScheduleFragment.user)); Collections.sort(FriendsFragment.friendArrayList, nameSorter); FriendsFragment.fa.notifyDataSetChanged(); Gson gson = new Gson(); String jsonFriends = gson.toJson(FriendsFragment.friendArrayList); SharedPreferences settings = getSharedPreferences(StartActivity.PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); editor.putString("friends", jsonFriends); editor.apply(); } }); name.show(); } return true; }
// TODO: Move some off this stuff into seperate functions @SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); assert (actionBar != null); progressBar.setVisibility(View.GONE); if (id == R.id.nav_schedule) { actionBar.setDisplayShowTitleEnabled(false); actionBar.setTitle(R.string.title_activity_main); ScheduleFragment.user = Framework.MY_SCHEDULE; UpdateSchedule.dayOfWeek = DayPicker.toDayNumber(cal.get(Calendar.DAY_OF_WEEK)); ScheduleFragment.setWeekUnix((int) (System.currentTimeMillis() / 1000)); UpdateSchedule.scroll = true; ScheduleFragment.createList(); datePickerButton.setVisibility(View.VISIBLE); menu.findItem(R.id.menu_search).setVisible(true); navigationView.getMenu().getItem(0).setChecked(true); if (ScheduleFragment.classArrayList.size() == 0) { progressBar.setVisibility(View.VISIBLE); } replaceFragment(sf); currentFragment = sf; // } else if (id == R.id.nav_announcements) { // ab.setDisplayShowTitleEnabled(true); // ab.setTitle(R.string.title_fragment_announcements); // // datePickerButton.setVisibility(View.GONE); // menu.findItem(R.id.menu_search).setVisible(false); // // replaceFragment(af); } else if (id == R.id.nav_friends) { actionBar.setDisplayShowTitleEnabled(true); actionBar.setTitle(R.string.title_fragment_friends); datePickerButton.setVisibility(View.GONE); menu.findItem(R.id.menu_search).setVisible(false); replaceFragment(ff); currentFragment = ff; } else if (id == R.id.nav_info) { MaterialDialog.Builder about = new MaterialDialog.Builder(this) .title(R.string.about) .content(R.string.about_text) .positiveText(R.string.ok) .negativeText(R.string.contact) .onNegative( new MaterialDialog.SingleButtonCallback() { @Override public void onClick( @NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) { Uri uri = Uri.parse("mailto:[email protected]") .buildUpon() .build(); Intent intent = new Intent(Intent.ACTION_SENDTO, uri); startActivity(Intent.createChooser(intent, getString(R.string.send))); } }); about.show(); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); invalidateOptionsMenu(); return true; }