Search in sources :

Example 1 with SectionItem

use of it.niedermann.owncloud.notes.main.items.section.SectionItem in project nextcloud-notes by stefan-niedermann.

the class SlotterUtil method fillListByTime.

@NonNull
public static List<Item> fillListByTime(@NonNull Context context, @NonNull List<Note> noteList) {
    final var itemList = new ArrayList<Item>();
    final var timeslotter = new Timeslotter(context);
    String lastTimeslot = null;
    for (int i = 0; i < noteList.size(); i++) {
        final var currentNote = noteList.get(i);
        String timeslot = timeslotter.getTimeslot(currentNote);
        if (i > 0 && !timeslot.equals(lastTimeslot)) {
            itemList.add(new SectionItem(timeslot));
        }
        itemList.add(currentNote);
        lastTimeslot = timeslot;
    }
    return itemList;
}
Also used : SectionItem(it.niedermann.owncloud.notes.main.items.section.SectionItem) ArrayList(java.util.ArrayList) NonNull(androidx.annotation.NonNull)

Example 2 with SectionItem

use of it.niedermann.owncloud.notes.main.items.section.SectionItem in project nextcloud-notes by stefan-niedermann.

the class SlotterUtil method fillListByCategory.

@NonNull
public static List<Item> fillListByCategory(@NonNull List<Note> noteList, @Nullable String currentCategory) {
    final var itemList = new ArrayList<Item>();
    for (final var note : noteList) {
        if (currentCategory != null && !currentCategory.equals(note.getCategory())) {
            itemList.add(new SectionItem(NoteUtil.extendCategory(note.getCategory())));
        }
        itemList.add(note);
        currentCategory = note.getCategory();
    }
    return itemList;
}
Also used : SectionItem(it.niedermann.owncloud.notes.main.items.section.SectionItem) ArrayList(java.util.ArrayList) NonNull(androidx.annotation.NonNull)

Example 3 with SectionItem

use of it.niedermann.owncloud.notes.main.items.section.SectionItem in project nextcloud-notes by stefan-niedermann.

the class SlotterUtilTest method fillListByInitials_shouldAddSectionItems.

@Test
public void fillListByInitials_shouldAddSectionItems() {
    final var notes = List.of(new Note(1L, Calendar.getInstance(), "Aaa", "", "", false, ""), new Note(1L, Calendar.getInstance(), "Abc", "", "", false, ""), new Note(1L, Calendar.getInstance(), "Bbb", "", "", false, ""), new Note(1L, Calendar.getInstance(), "Bcd", "", "", false, ""), new Note(1L, Calendar.getInstance(), "Def", "", "", false, ""));
    final var items = SlotterUtil.fillListByInitials(ApplicationProvider.getApplicationContext(), notes);
    assertEquals(2, items.stream().filter(item -> item instanceof SectionItem).count());
    assertEquals(SectionItem.class, items.get(2).getClass());
    assertEquals(SectionItem.class, items.get(5).getClass());
}
Also used : SectionItem(it.niedermann.owncloud.notes.main.items.section.SectionItem) Note(it.niedermann.owncloud.notes.persistence.entity.Note) Test(org.junit.Test)

Example 4 with SectionItem

use of it.niedermann.owncloud.notes.main.items.section.SectionItem in project nextcloud-notes by stefan-niedermann.

the class SlotterUtil method fillListByInitials.

@NonNull
public static List<Item> fillListByInitials(@NonNull Context context, @NonNull List<Note> noteList) {
    final var itemList = new ArrayList<Item>();
    String lastInitials = null;
    for (int i = 0; i < noteList.size(); i++) {
        final var currentNote = noteList.get(i);
        final var title = currentNote.getTitle();
        String initials = "";
        if (!TextUtils.isEmpty(title)) {
            initials = title.substring(0, 1).toUpperCase();
            if (!initials.matches("[A-Z\\u00C0-\\u00DF]")) {
                initials = initials.matches("[\\u0250-\\uFFFF]") ? context.getString(R.string.simple_other) : "#";
            }
        }
        if (i > 0 && !initials.equals(lastInitials)) {
            itemList.add(new SectionItem(initials));
        }
        itemList.add(currentNote);
        lastInitials = initials;
    }
    return itemList;
}
Also used : SectionItem(it.niedermann.owncloud.notes.main.items.section.SectionItem) ArrayList(java.util.ArrayList) NonNull(androidx.annotation.NonNull)

Aggregations

SectionItem (it.niedermann.owncloud.notes.main.items.section.SectionItem)4 NonNull (androidx.annotation.NonNull)3 ArrayList (java.util.ArrayList)3 Note (it.niedermann.owncloud.notes.persistence.entity.Note)1 Test (org.junit.Test)1