コード例 #1
0
ファイル: Main.java プロジェクト: lucEvent/NewsUp
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    AppSettings.initialize(this, this);
    dataManager = new NewsManager(this);
    permissionHandler = new StoragePermissionHandler(this);

    if (AppSettings.firstStart()) {
      Intent intent = new Intent(this, SelectSitesActivity.class);
      intent.putExtra(AppCode.SEND_PURPOSE, SelectSitesActivity.For.APP_FIRST_START);
      startActivity(intent);
      finish();
      return;
    }

    setContentView(R.layout.a_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle =
        new ActionBarDrawerToggle(
            this,
            drawer,
            toolbar,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    assert navigationView != null : "Navigation view is null";
    navigationView.setNavigationItemSelectedListener(this);

    fragmentManager = new FragmentManager(this, navigationView, R.id.main_content);

    updateDrawer(true);

    Bundle extras = getIntent().getExtras();
    if (extras != null && extras.containsKey(AppCode.SEND_NEWS_IDS)) {
      int[] news_codes = extras.getIntArray(AppCode.SEND_NEWS_IDS);
      newsFragment = NewsListFragment.instanceForNotification(news_codes);
    } else newsFragment = NewsListFragment.instanceFor(-1);

    if (extras != null && extras.containsKey(AppCode.RESTART)) {
      ScheduledDownloadReceiver.scheduleDownloads(
          this, new ScheduleManager(this).getDownloadSchedules());
    }

    newsFragment.setRetainInstance(true);

    fragmentManager.addFragment(newsFragment, R.id.nav_my_news);
  }
コード例 #2
0
ファイル: Main.java プロジェクト: lucEvent/NewsUp
 @Override
 public void onMainistsChange() {
   if (newsFragment.lastLoadedSiteCode == -1) newsFragment.lastLoadedSiteCode = -9;
 }
コード例 #3
0
ファイル: Main.java プロジェクト: lucEvent/NewsUp
 @Override
 public void onLoadImagesPreferenceChanged() {
   newsFragment.onLoadImagesPreferenceChanged();
 }
コード例 #4
0
ファイル: Main.java プロジェクト: lucEvent/NewsUp
  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;
  }