Пример #1
0
  private void doWork(Context context, Intent intent) {
    DownloadSchedule job =
        (DownloadSchedule) intent.getExtras().getSerializable(AppCode.SEND_DOWNLOAD_SCHEDULE);
    assert job != null : "DownloadSchedule received is null";

    AppSettings.initialize(context);
    ScheduleManager dataManager = new ScheduleManager(context);
    if (!job.repeat) {
      Calendar calendar = Calendar.getInstance();
      int day = (calendar.get(Calendar.DAY_OF_WEEK) - Calendar.MONDAY + 7) % 7;

      job.days[day] = false;

      boolean maintain = false;
      for (boolean b : job.days)
        if (b) {
          maintain = true;
          dataManager.updateDownloadSchedule(job);
          break;
        }

      if (!maintain) dataManager.deleteDownloadSchedule(job);
    }
    ScheduledDownloadReceiver.scheduleDownloads(context, dataManager.getDownloadSchedules());

    NewsArray news = dataManager.getScheduledNews(job.sites_codes);

    if (job.notify && news != null && !news.isEmpty()) {
      int[] extras = new int[news.size()];
      String[] headlines = new String[job.sites_codes.length];

      int headlineIndex = 0;
      int currentSiteCode = -1;
      for (int index = 0; index < news.size(); index++) {
        News N = news.get(index);

        extras[index] = N.id;

        if (N.site_code != currentSiteCode) {
          Site site = AppData.getSiteByCode(N.site_code);

          headlines[headlineIndex++] = site.name + ": " + N.title;
          currentSiteCode = N.site_code;
        }
      }

      // build notification
      Intent notificationIntent = new Intent(this, Main.class);
      notificationIntent.putExtra(AppCode.SEND_NEWS_IDS, extras);

      NotificationBuilder.notifyUser(
          this, NotificationBuilder.build(this, notificationIntent, headlines));
    }
    if (news == null) {
      // todo
    }
  }
Пример #2
0
  private void setUpColors(int colorCode) {
    int barColor, textColor, statusBarColor;
    boolean navBlack = false;

    Toolbar ab = (Toolbar) findViewById(R.id.toolbar);
    if (colorCode < 0) {
      barColor = ContextCompat.getColor(this, R.color.colorPrimary);
      textColor = Color.WHITE;
      statusBarColor = ContextCompat.getColor(this, R.color.colorPrimaryDark);
    } else {
      Site site = AppData.getSiteByCode(colorCode);

      barColor = site.color;
      textColor = site.hasDarkColor() ? Color.WHITE : Color.BLACK;
      statusBarColor = barColor == 0xffffffff ? 0xffcccccc : barColor;
      navBlack = !site.hasDarkColor();
    }
    //noinspection ConstantConditions
    ab.setBackgroundColor(barColor);
    ab.setTitleTextColor(textColor);

    if (!navBlack)
      //noinspection ConstantConditions
      ab.getNavigationIcon().clearColorFilter();
    else
      //noinspection ConstantConditions
      ab.getNavigationIcon().setColorFilter(Color.BLACK, PorterDuff.Mode.MULTIPLY);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
      if (statusBarColor == 0xffcccccc) {
        drawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        statusBarColor = barColor;
      } else drawer.setSystemUiVisibility(0);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      Window window = getWindow();
      window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
      window.setStatusBarColor(statusBarColor);
    }
  }
Пример #3
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;
  }