Search in sources :

Example 16 with OrgDateTime

use of com.orgzly.org.datetime.OrgDateTime in project orgzly-android by orgzly.

the class TitleGenerator method generateTitle.

public CharSequence generateTitle(Note note, OrgHead head) {
    SpannableStringBuilder builder = new SpannableStringBuilder();
    /* State. */
    if (head.getState() != null) {
        builder.append(generateState(head));
    }
    /* Priority. */
    if (head.getPriority() != null) {
        if (builder.length() > 0) {
            builder.append(TITLE_SEPARATOR);
        }
        builder.append(generatePriority(head));
    }
    /* Bold everything up until now. */
    if (builder.length() > 0) {
        builder.setSpan(new StyleSpan(Typeface.BOLD), 0, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    /* Space before title, unless there's nothing added. */
    if (builder.length() > 0) {
        builder.append(TITLE_SEPARATOR);
    }
    /* Title. */
    builder.append(OrgFormatter.INSTANCE.parse(head.getTitle(), mContext));
    /* Append note ID. */
    // builder.append(TITLE_SEPARATOR).append("#").append(String.valueOf(note.getId()));
    int mark = builder.length();
    boolean hasPostTitleText = false;
    /* Tags. */
    if (head.hasTags()) {
        builder.append(TITLE_SEPARATOR).append(generateTags(head.getTags()));
        hasPostTitleText = true;
    }
    /* Inherited tags in search results. */
    if (!inBook && note.hasInheritedTags() && AppPreferences.inheritedTagsInSearchResults(mContext)) {
        if (head.hasTags()) {
            builder.append(INHERITED_TAGS_SEPARATOR);
        } else {
            builder.append(TITLE_SEPARATOR);
        }
        builder.append(generateTags(note.getInheritedTags()));
        hasPostTitleText = true;
    }
    /* Content line number. */
    if (head.hasContent() && AppPreferences.contentLineCountDisplayed(mContext)) {
        if (!shouldDisplayContent(note)) {
            builder.append(TITLE_SEPARATOR).append(String.valueOf(note.getContentLines()));
            hasPostTitleText = true;
        }
    }
    if (false) {
        String times = note.getCreatedAt() > 0 ? new OrgDateTime(note.getCreatedAt(), false).toString() : "N/A";
        builder.append("  ").append(times);
        hasPostTitleText = true;
    }
    /* Change font style of text after title. */
    if (hasPostTitleText) {
        builder.setSpan(attributes.postTitleTextSize, mark, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.setSpan(attributes.postTitleTextColor, mark, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    return builder;
}
Also used : StyleSpan(android.text.style.StyleSpan) OrgDateTime(com.orgzly.org.datetime.OrgDateTime) SpannableString(android.text.SpannableString) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

OrgDateTime (com.orgzly.org.datetime.OrgDateTime)16 ArrayList (java.util.ArrayList)4 Cursor (android.database.Cursor)3 Calendar (java.util.Calendar)3 DateTime (org.joda.time.DateTime)3 ContentValues (android.content.ContentValues)2 DbNote (com.orgzly.android.provider.models.DbNote)2 OrgRepeater (com.orgzly.org.datetime.OrgRepeater)2 SuppressLint (android.annotation.SuppressLint)1 AlertDialog (android.app.AlertDialog)1 DatePickerDialog (android.app.DatePickerDialog)1 Dialog (android.app.Dialog)1 TimePickerDialog (android.app.TimePickerDialog)1 ContentProviderOperation (android.content.ContentProviderOperation)1 Context (android.content.Context)1 OperationApplicationException (android.content.OperationApplicationException)1 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)1 Bundle (android.os.Bundle)1 RemoteException (android.os.RemoteException)1 DialogFragment (android.support.v4.app.DialogFragment)1