Beispiel #1
0
 @OnClick(R.id.fab_archive)
 public void onArchiveArticle() {
   if (mSaved) {
     mArticlePresenter.removeArticle(getFeedItem());
   } else {
     mArticlePresenter.archiveArticle(getFeedItem(), txtContent.getText().toString());
   }
 }
Beispiel #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // set theme
    setSystemTheme(getFeedThemeBgId());

    setContentView(R.layout.activity_article);

    ButterKnife.bind(this);

    // get Feed item from intent bundle
    FeedItem feedItem = getFeedItem();

    // set toolbar
    setToolbar(feedItem);

    // set default font sizes
    setFontSize();

    // set feed title
    txtFeedTitle.setText(feedItem.getItemTitle());

    // set feed category
    txtFeedCategory.setText(feedItem.getItemCategory());

    // set feed publish date
    txtFeedPubDate.setText(feedItem.getItemPubDate());

    // set feed image
    Glide.with(ArticleActivity.this)
        .load(feedItem.getItemImgUrl())
        .centerCrop()
        .crossFade()
        .into(imgArticle);

    // load article presenter
    if (mArticlePresenter == null) {
      mArticlePresenter = new ArticlePresenter(ArticleActivity.this, this);
    }

    // load feeds presenter
    if (mFeedsPresenter == null) {
      mFeedsPresenter = new FeedsPresenter(ArticleActivity.this, this);
    }

    // only load the data online if this activity was opened from FeedsFragment
    // , else if it was redirected from ArchiveFragment then load the saved article
    if (feedItem.getItemWebDesc().isEmpty()) {
      mSaved = false;
      if (NetworkConnectionUtil.isNetworkAvailable(ArticleActivity.this)) {
        mArticlePresenter.attemptArticleLoading(feedItem.getItemLink());
      } else {
        NetworkConnectionUtil.showNoNetworkDialog(ArticleActivity.this);
      }
    } else {
      mSaved = true;
      fabArchive.setImageResource(R.drawable.ic_archive_done_24dp);
      txtContent.setText(feedItem.getItemWebDesc());
    } /* else if(!feedItem.getItemWebDescSync().isEmpty()){
          txtContent.setText(feedItem.getItemWebDescSync());
      }*/
  }
Beispiel #3
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    // override default back button present on the toolbar
    if (id == android.R.id.home) {
      onBackPressed();
      return true;
    }

    if (id == R.id.action_refresh) {
      if (NetworkConnectionUtil.isNetworkAvailable(ArticleActivity.this)) {
        mArticlePresenter.attemptArticleLoading(getFeedItem().getItemLink());
      } else {
        NetworkConnectionUtil.showNoNetworkDialog(ArticleActivity.this);
      }
      return true;
    }

    if (id == R.id.action_share) {
      Intent intent = new Intent(Intent.ACTION_SEND);
      intent.putExtra(Intent.EXTRA_SUBJECT, getFeedItem().getItemTitle());
      intent.putExtra(
          Intent.EXTRA_TEXT,
          getFeedItem().getItemLink() + "\n\n" + txtContent.getText().toString());
      intent.setType("text/plain");
      startActivity(intent);
      return true;
    }

    if (id == R.id.action_open_in_browser) {
      // Use chrome custom tabs if user wants in-app browser, otherwise use user's own selected
      // browser for opening links
      if (SettingsPreferences.IN_APP_BROWSER) {
        new WebsiteIntentUtil(ArticleActivity.this)
            .loadCustomChromeTabs(getFeedItem().getItemLink());
      } else {
        new WebsiteIntentUtil(ArticleActivity.this).loadNormalBrowser(getFeedItem().getItemLink());
      }
      return true;
    }

    if (id == R.id.action_delete) {
      MaterialDialog confirmDeleteDialog =
          new MaterialDialog.Builder(this)
              .title(R.string.delete_this_feed)
              .content(R.string.delete_this_feed_desc)
              .iconRes(R.drawable.ic_delete_24dp)
              .positiveText(R.string.delete)
              .negativeText(R.string.cancel)
              .onPositive(
                  new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
                      mFeedsPresenter.deleteSelectedFeed(getFeedItem());
                      Intent intent = new Intent(ArticleActivity.this, HomeActivity.class);
                      startActivity(intent);
                      finish();
                    }
                  })
              .build();
      confirmDeleteDialog.show();
      return true;
    }

    return super.onOptionsItemSelected(item);
  }