示例#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);
  }
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
      adapter.notifyDataSetChanged();

      ScheduledDownloadReceiver.scheduleDownloads(
          getActivity(), dataManager.getDownloadSchedules());

      if (noDownloadsScreen.getVisibility() == View.VISIBLE)
        noDownloadsScreen.setVisibility(View.GONE);
    }
  }