Search in sources :

Example 1 with Note

use of org.wordpress.android.models.Note in project WordPress-Android by wordpress-mobile.

the class NotesAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(NoteViewHolder noteViewHolder, int position) {
    final Note note = getNoteAtPosition(position);
    if (note == null) {
        return;
    }
    noteViewHolder.itemView.setTag(note.getId());
    // Display group header
    Note.NoteTimeGroup timeGroup = Note.getTimeGroupForTimestamp(note.getTimestamp());
    Note.NoteTimeGroup previousTimeGroup = null;
    if (position > 0) {
        Note previousNote = getNoteAtPosition(position - 1);
        previousTimeGroup = Note.getTimeGroupForTimestamp(previousNote.getTimestamp());
    }
    if (previousTimeGroup != null && previousTimeGroup == timeGroup) {
        noteViewHolder.headerView.setVisibility(View.GONE);
    } else {
        if (timeGroup == Note.NoteTimeGroup.GROUP_TODAY) {
            noteViewHolder.headerText.setText(R.string.stats_timeframe_today);
        } else if (timeGroup == Note.NoteTimeGroup.GROUP_YESTERDAY) {
            noteViewHolder.headerText.setText(R.string.stats_timeframe_yesterday);
        } else if (timeGroup == Note.NoteTimeGroup.GROUP_OLDER_TWO_DAYS) {
            noteViewHolder.headerText.setText(R.string.older_two_days);
        } else if (timeGroup == Note.NoteTimeGroup.GROUP_OLDER_WEEK) {
            noteViewHolder.headerText.setText(R.string.older_last_week);
        } else {
            noteViewHolder.headerText.setText(R.string.older_month);
        }
        noteViewHolder.headerView.setVisibility(View.VISIBLE);
    }
    if (mHiddenNoteIds.size() > 0 && mHiddenNoteIds.contains(note.getId())) {
        noteViewHolder.contentView.setVisibility(View.GONE);
        noteViewHolder.headerView.setVisibility(View.GONE);
    } else {
        noteViewHolder.contentView.setVisibility(View.VISIBLE);
    }
    CommentStatus commentStatus = CommentStatus.ALL;
    if (note.getCommentStatus() == CommentStatus.UNAPPROVED) {
        commentStatus = CommentStatus.UNAPPROVED;
    }
    if (!TextUtils.isEmpty(note.getLocalStatus())) {
        commentStatus = CommentStatus.fromString(note.getLocalStatus());
    }
    if (mModeratingNoteIds.size() > 0 && mModeratingNoteIds.contains(note.getId())) {
        noteViewHolder.progressBar.setVisibility(View.VISIBLE);
    } else {
        noteViewHolder.progressBar.setVisibility(View.GONE);
    }
    // Subject is stored in db as html to preserve text formatting
    CharSequence noteSubjectSpanned = note.getFormattedSubject();
    // Trim the '\n\n' added by Html.fromHtml()
    noteSubjectSpanned = noteSubjectSpanned.subSequence(0, TextUtils.getTrimmedLength(noteSubjectSpanned));
    noteViewHolder.txtSubject.setText(noteSubjectSpanned);
    String noteSubjectNoticon = note.getCommentSubjectNoticon();
    if (!TextUtils.isEmpty(noteSubjectNoticon)) {
        CommentUtils.indentTextViewFirstLine(noteViewHolder.txtSubject, mTextIndentSize);
        noteViewHolder.txtSubjectNoticon.setText(noteSubjectNoticon);
        noteViewHolder.txtSubjectNoticon.setVisibility(View.VISIBLE);
    } else {
        noteViewHolder.txtSubjectNoticon.setVisibility(View.GONE);
    }
    String noteSnippet = note.getCommentSubject();
    if (!TextUtils.isEmpty(noteSnippet)) {
        noteViewHolder.txtSubject.setMaxLines(2);
        noteViewHolder.txtDetail.setText(noteSnippet);
        noteViewHolder.txtDetail.setVisibility(View.VISIBLE);
    } else {
        noteViewHolder.txtSubject.setMaxLines(3);
        noteViewHolder.txtDetail.setVisibility(View.GONE);
    }
    String avatarUrl = GravatarUtils.fixGravatarUrl(note.getIconURL(), mAvatarSz);
    noteViewHolder.imgAvatar.setImageUrl(avatarUrl, WPNetworkImageView.ImageType.AVATAR);
    boolean isUnread = note.isUnread();
    String noticonCharacter = note.getNoticonCharacter();
    noteViewHolder.noteIcon.setText(noticonCharacter);
    if (commentStatus == CommentStatus.UNAPPROVED) {
        noteViewHolder.noteIcon.setBackgroundResource(R.drawable.shape_oval_orange);
    } else if (isUnread) {
        noteViewHolder.noteIcon.setBackgroundResource(R.drawable.shape_oval_blue_white_stroke);
    } else {
        noteViewHolder.noteIcon.setBackgroundResource(R.drawable.shape_oval_grey);
    }
    if (isUnread) {
        noteViewHolder.itemView.setBackgroundColor(mColorUnread);
    } else {
        noteViewHolder.itemView.setBackgroundColor(mColorRead);
    }
    // request to load more comments when we near the end
    if (mOnLoadMoreListener != null && position >= getItemCount() - 1) {
        mOnLoadMoreListener.onLoadMore(note.getTimestamp());
    }
}
Also used : Note(org.wordpress.android.models.Note) CommentStatus(org.wordpress.android.fluxc.model.CommentStatus)

Example 2 with Note

use of org.wordpress.android.models.Note in project WordPress-Android by wordpress-mobile.

the class NotificationsDetailActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ((WordPress) getApplication()).component().inject(this);
    AppLog.i(AppLog.T.NOTIFS, "Creating NotificationsDetailActivity");
    setContentView(R.layout.notifications_detail_activity);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    if (savedInstanceState == null) {
        mNoteId = getIntent().getStringExtra(NotificationsListFragment.NOTE_ID_EXTRA);
    } else {
        if (savedInstanceState.containsKey(ARG_TITLE) && getSupportActionBar() != null) {
            getSupportActionBar().setTitle(StringUtils.notNullStr(savedInstanceState.getString(ARG_TITLE)));
        }
        mNoteId = savedInstanceState.getString(NotificationsListFragment.NOTE_ID_EXTRA);
    }
    if (mNoteId == null) {
        showErrorToastAndFinish();
        return;
    }
    final Note note = NotificationsTable.getNoteById(mNoteId);
    if (note == null) {
        showErrorToastAndFinish();
        return;
    }
    // If `note.getTimestamp()` is not the most recent seen note, the server will discard the value.
    NotificationsActions.updateSeenTimestamp(note);
    Map<String, String> properties = new HashMap<>();
    properties.put("notification_type", note.getType());
    AnalyticsTracker.track(AnalyticsTracker.Stat.NOTIFICATIONS_OPENED_NOTIFICATION_DETAILS, properties);
    //set up the viewpager and adapter for lateral navigation
    mViewPager = (WPViewPager) findViewById(R.id.viewpager);
    mViewPager.setPageTransformer(false, new WPViewPagerTransformer(WPViewPagerTransformer.TransformType.SLIDE_OVER));
    NotesAdapter.FILTERS filter = NotesAdapter.FILTERS.FILTER_ALL;
    if (getIntent().hasExtra(NotificationsListFragment.NOTE_CURRENT_LIST_FILTER_EXTRA)) {
        filter = (NotesAdapter.FILTERS) getIntent().getSerializableExtra(NotificationsListFragment.NOTE_CURRENT_LIST_FILTER_EXTRA);
    }
    mAdapter = buildNoteListAdapterAndSetPosition(note, filter);
    //set title
    setActionBarTitleForNote(note);
    markNoteAsRead(note);
    mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            AnalyticsTracker.track(AnalyticsTracker.Stat.NOTIFICATION_SWIPE_PAGE_CHANGED);
            AppPrefs.setNotificationsSwipeToNavigateShown(true);
            //change the action bar title for the current note
            Note currentNote = mAdapter.getNoteAtPosition(position);
            if (currentNote != null) {
                setActionBarTitleForNote(currentNote);
                markNoteAsRead(currentNote);
            }
        }
    });
    // Hide the keyboard, unless we arrived here from the 'Reply' action in a push notification
    if (!getIntent().getBooleanExtra(NotificationsListFragment.NOTE_INSTANT_REPLY_EXTRA, false)) {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
    }
}
Also used : NotesAdapter(org.wordpress.android.ui.notifications.adapters.NotesAdapter) WPViewPagerTransformer(org.wordpress.android.widgets.WPViewPagerTransformer) HashMap(java.util.HashMap) Note(org.wordpress.android.models.Note) ViewPager(android.support.v4.view.ViewPager) WPViewPager(org.wordpress.android.widgets.WPViewPager) ActionBar(android.support.v7.app.ActionBar)

Example 3 with Note

use of org.wordpress.android.models.Note in project WordPress-Android by wordpress-mobile.

the class NotificationsDetailListFragment method setNote.

@Override
public void setNote(String noteId) {
    if (noteId == null) {
        showErrorToastAndFinish();
        return;
    }
    Note note = NotificationsTable.getNoteById(noteId);
    if (note == null) {
        showErrorToastAndFinish();
        return;
    }
    mNote = note;
}
Also used : Note(org.wordpress.android.models.Note)

Example 4 with Note

use of org.wordpress.android.models.Note in project WordPress-Android by wordpress-mobile.

the class NotificationsListFragment method updateNote.

private void updateNote(String noteId, CommentStatus status) {
    Note note = NotificationsTable.getNoteById(noteId);
    if (note == null)
        return;
    note.setLocalStatus(status.toString());
    NotificationsTable.saveNote(note);
    EventBus.getDefault().post(new NotificationEvents.NotificationsChanged());
}
Also used : Note(org.wordpress.android.models.Note)

Example 5 with Note

use of org.wordpress.android.models.Note in project WordPress-Android by wordpress-mobile.

the class CommentDetailFragment method setNote.

@Override
public void setNote(String noteId) {
    if (noteId == null) {
        showErrorToastAndFinish();
        return;
    }
    Note note = NotificationsTable.getNoteById(noteId);
    if (note == null) {
        showErrorToastAndFinish();
        return;
    }
    setNote(note);
}
Also used : Note(org.wordpress.android.models.Note)

Aggregations

Note (org.wordpress.android.models.Note)8 Cursor (android.database.Cursor)1 ViewPager (android.support.v4.view.ViewPager)1 ActionBar (android.support.v7.app.ActionBar)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 CommentStatus (org.wordpress.android.fluxc.model.CommentStatus)1 NotesAdapter (org.wordpress.android.ui.notifications.adapters.NotesAdapter)1 WPViewPager (org.wordpress.android.widgets.WPViewPager)1 WPViewPagerTransformer (org.wordpress.android.widgets.WPViewPagerTransformer)1