Ejemplo n.º 1
0
 @Override
 public void onRequestPermissionsResult(
     int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
   if (permissionHandler.onRequestPermissionsResult(requestCode, permissions, grantResults)) {
     navigateTo(R.id.nav_saved_news);
     ((NavigationView) findViewById(R.id.nav_view)).setCheckedItem(R.id.nav_saved_news);
   }
 }
Ejemplo n.º 2
0
  private boolean navigateTo(int where) {
    Fragment fragment = null;
    String title;
    int colorCode = -1;
    boolean isNewsFragment = false;

    switch (where) {
      case R.id.nav_my_news:
        newsFragment.setSite(-1);
        title = getString(R.string.my_news);
        isNewsFragment = true;
        break;
      case R.id.nav_saved_news:
        if (permissionHandler.checkAndAsk(this)) {
          fragment = new BookmarksFragment();
          title = getString(R.string.bookmarks);
          break;
        }
        return false;
      case R.id.nav_read_news:
        fragment = new HistorialFragment();
        title = getString(R.string.read_news);
        break;
      case R.id.nav_stats:
        fragment = new StatisticsFragment();
        title = getString(R.string.statistics);
        break;
      case R.id.nav_more_publications:
        Intent intent = new Intent(this, SelectSitesActivity.class);
        intent.putExtra(AppCode.SEND_PURPOSE, SelectSitesActivity.For.SELECT_ONE);
        startActivityForResult(intent, AppCode.REQUEST_ADD_CONTENT);
        return true;
      case R.id.nav_notes:
        fragment = new NotesFragment();
        title = getString(R.string.notes);
        break;
      case R.id.nav_settings:
        fragment = new AppSettingsFragment();
        title = getString(R.string.settings);
        break;
      case R.id.nav_contact:
        startActivity(new Intent(this, ContactActivity.class));
        return false;
      case R.id.nav_about:
        fragment = new AboutFragment();
        title = getString(R.string.about);
        break;
      default:
        colorCode = where;
        newsFragment.setSite(where);
        title = AppData.getSiteByCode(where).name;
        isNewsFragment = true;
    }
    drawer.closeDrawer(GravityCompat.START);

    if (isNewsFragment) {

      if (!(fragmentManager.currentFragment instanceof NewsListFragment))
        fragmentManager.popToFirst();
      else newsFragment.setUp();

      fragmentManager.setNavigationItemId(0, where);

    } else
      fragmentManager.replaceFragment(
          fragment, where, fragmentManager.currentFragment instanceof NewsListFragment);

    setTitle(title);
    setUpColors(colorCode);
    return true;
  }