예제 #1
0
  static void populateEntryView(
      final View view,
      final Entry entry,
      final EntryManager entryManager,
      final UIHelper uiHelper) {
    final Resources resources = entryManager.getContext().getResources();

    // swipe
    final SwipeRelativeLayout swipeContainer =
        (SwipeRelativeLayout) view.findViewById(R.id.swipe_container);

    final View outterContainer = view.findViewById(R.id.outter_container);
    outterContainer.setPadding(0, 0, 0, 0);

    swipeContainer.setSwipeListener(
        new SwipeRelativeLayout.ISwipeListener() {

          private final int selectionFeedbackColor = resources.getColor(R.color.selection_feedback);

          public boolean swipeTopToBottom(final View v) {
            return false;
          }

          public boolean swipeRightToLeft(final View v) {

            view.setBackgroundColor(selectionFeedbackColor);
            entryManager.increaseUnreadLevel(entry);
            return true;
          }

          public boolean swipeLeftToRight(final View v) {

            view.setBackgroundColor(selectionFeedbackColor);
            entryManager.increaseReadLevel(entry);
            return true;
          }

          public boolean swipeBottomToTop(final View v) {
            return false;
          }

          public boolean onLongClick(final View v, final MotionEvent e) {
            return view.performLongClick();
          }

          public boolean onClick(final View v, final MotionEvent e) {
            return view.performClick();
          }
        });

    swipeContainer.setSwipeEnabeld(entryManager.isSwipeOnArticleDetailViewEnabled());
    swipeContainer.setBackgroundResource(R.drawable.article_header_background_thin);

    final TextView entryTitleView = (TextView) view.findViewById(R.id.entry_title);
    final TextView feedTitleView = (TextView) view.findViewById(R.id.feed_title);

    if (feedTitleView == null || entryTitleView == null) {
      Log.e(TAG, "feedTitleView or entryTitleView were null.");
      return;
    }

    if (entry == null) {
      Log.d(TAG, "entry was null");
      return;
    }

    if (entry.getFeedTitle() == null) {
      Log.e(TAG, "entry.getFeedTitle() was null.");
      return;
    }

    feedTitleView.setText(entry.getFeedTitle());
    entryTitleView.setText(entry.getTitle());

    if (entryManager.shouldTitlesBeEllipsized()) {
      entryTitleView.setEllipsize(TruncateAt.MIDDLE);
      entryTitleView.setLines(2);
    }

    // final int backgroundColor = resources.getColor(entry.isRead() ?
    // R.color.article_read_background
    // : R.color.article_unread_background);
    // final int textColor = resources.getColor(entry.isRead() ?
    // R.color.article_read_text
    // : R.color.article_unread_text);

    final TextView readIndicator = (TextView) view.findViewById(R.id.read_status_indicator);
    final int readIndicatorBackground =
        entryManager.isLightColorSchemeSelected()
            ? R.drawable.read_indicator
            : R.drawable.read_indicator_dark;
    final int pinnedIndicatorBackground =
        entryManager.isLightColorSchemeSelected()
            ? R.drawable.pinned_indicator
            : R.drawable.pinned_indicator_dark;

    int bgReadIndicator = -1;

    switch (entry.getReadState()) {
      case READ:
        bgReadIndicator = R.drawable.read_indicator_invisible;
        break;
      case UNREAD:
        bgReadIndicator = readIndicatorBackground;
        break;
      default:
        bgReadIndicator = pinnedIndicatorBackground;
    }

    readIndicator.setBackgroundResource(bgReadIndicator);

    // view.setBackgroundColor(backgroundColor);
    View container = view.findViewById(R.id.outter_container);
    if (entryManager.isLightColorSchemeSelected())
      container.setBackgroundColor(resources.getColor(R.color.article_read_background));
    else
      container.setBackgroundDrawable(
          resources.getDrawable(R.drawable.article_header_background_dark));

    // entryTitleView.setTextColor(textColor);
    // feedTitleView.setTextColor(textColor);

    //
    feedTitleView.setCompoundDrawablePadding(3);
    feedTitleView.setCompoundDrawablesWithIntrinsicBounds(
        resources.getDrawable(
            uiHelper.getArticleDownloadIndicatorDrawable(
                entry.getDownloaded(), entry.getDownloadPref(), resources)),
        null,
        null,
        null);

    // star check box
    final CheckBox starCheckBox = (CheckBox) view.findViewById(R.id.star_checkbox);
    starCheckBox.setVisibility(View.VISIBLE);
    starCheckBox.setChecked(entry.isStarred());
    starCheckBox.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(final View v) {
            entryManager.updateStarredState(entry, starCheckBox.isChecked());
          }
        });
    starCheckBox.requestFocus();

    if (false) {
      // changed
      final TextView changedView = (TextView) view.findViewById(R.id.article_changed);

      final boolean stateChanged = entry.isReadStatePending() || entry.isStarredStatePending();
      changedView.setText(stateChanged ? "*" : "");
    }
  }
예제 #2
0
  static boolean articleActionSelected(
      final Activity owningActivity,
      final MenuItem item,
      final EntryManager entryManager,
      final Entry selectedEntry) {

    if (selectedEntry == null) return false;

    switch (item.getItemId()) {
      case ArticleViewHelper.MENU_ITEM_PIN_ARTICLE_ID:
        new Thread(
                new Runnable() {
                  public void run() {
                    PL.log("AVH:Submitting PIN", owningActivity);
                    entryManager.updateReadState(selectedEntry, ReadState.PINNED);
                  }
                })
            .start();

        return true;

      case ArticleViewHelper.MENU_ITEM_MARK_ENTRY_READ_ID:
        new Thread(
                new Runnable() {
                  public void run() {
                    PL.log("AVH:Submitting READ", owningActivity);
                    entryManager.updateReadState(selectedEntry, ReadState.READ);
                  }
                })
            .start();

        return true;

      case ArticleViewHelper.MENU_ITEM_MARK_ENTRY_UNREAD_ID:
        new Thread(
                new Runnable() {

                  @Override
                  public void run() {
                    PL.log("AVH:Submitting UNREAD", owningActivity);
                    entryManager.updateReadState(selectedEntry, ReadState.UNREAD);
                  }
                })
            .start();
        return true;

      case ArticleViewHelper.MENU_ITEM_STAR_ID:
        new Thread(
                new Runnable() {

                  @Override
                  public void run() {
                    PL.log("AVH:Submitting STAR", owningActivity);
                    entryManager.updateStarredState(selectedEntry, true);
                  }
                })
            .start();
        return true;

      case ArticleViewHelper.MENU_ITEM_UNSTAR_ID:
        new Thread(
                new Runnable() {

                  @Override
                  public void run() {
                    PL.log("AVH:Submitting UNSTAR", owningActivity);
                    entryManager.updateStarredState(selectedEntry, false);
                  }
                })
            .start();
        return true;

      case ArticleViewHelper.MENU_ITEM_SHOW_ARTICLE_INFO_ID:
        owningActivity.startActivity(
            new Intent(entryManager.getContext(), ShowArticleInfoActivity.class)
                .putExtra(ShowArticleInfoActivity.EXTRA_ATOM_ID, selectedEntry.getAtomId()));
        return true;
      case ArticleViewHelper.MENU_ITEM_MANAGE_FEED_ID:
        owningActivity.startActivity(
            new Intent(entryManager.getContext(), ManageFeedActivity.class)
                .putExtra(ManageFeedActivity.EXTRA_FEED_ID, selectedEntry.getFeedId()));
        return true;
      case ArticleViewHelper.MENU_ITEM_REFRESH_CONTENT_ID:
        Toast.makeText(
                owningActivity,
                "The article's content is being removed. NewsRob will try to re-download it during the next sync.",
                Toast.LENGTH_LONG)
            .show();
        new Thread(
                new Runnable() {
                  @Override
                  public void run() {
                    if (selectedEntry.isRead())
                      entryManager.updateReadState(selectedEntry, ReadState.UNREAD);
                    entryManager.removeArticleContent(selectedEntry);
                  }
                })
            .start();
        return true;

      case MENU_ITEM_BOOM_ID:
        // throw new OutOfMemoryError("Just testing!");
        throw new RuntimeException("Just testing!");
    }
    return false;
  }