Android Open Source - SimpleDo To Do Item Sorter






From Project

Back to project page SimpleDo.

License

The source code is released under:

GNU General Public License

If you think the Android project SimpleDo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package me.jamesfrost.simpledo;
// w  ww  .ja va 2  s.c  o m
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;

import java.util.ArrayList;

/**
 * Sorts ArrayLists of ToDoItems.
 *
 * Created by James Frost on 17/12/2014.
 */
public class ToDoItemSorter {


    /**
     * Sorts an ArrayList of ToDoItems by date using a bubble sort algorithm.
     *
     * @param toDoList List of items to sort
     */
    public ArrayList<ToDoItem> sortToDoList(ArrayList<ToDoItem> toDoList) {
        for (int i = toDoList.size() - 1; i >= 0; i--) {
            for (int j = 0; j < i; j++) {
                if (toDoList.get(j).getDate() != null && toDoList.get(j + 1).getDate() != null) {
                    if (toDoList.get(j).getDate() instanceof LocalDateTime && toDoList.get(j + 1).getDate() instanceof LocalDateTime) {
                        if (toDoList.get(j).getDate().isAfter(toDoList.get(j + 1).getDate())) {
                            ToDoItem temp = toDoList.get(j);
                            toDoList.set(j, toDoList.get(j + 1));
                            toDoList.set(j + 1, temp);
                        }
                    } else if (!(toDoList.get(j).getDate() instanceof LocalDateTime) && toDoList.get(j + 1).getDate() instanceof LocalDateTime) {
                        if (toDoList.get(j).getDate().isAfter(((LocalDateTime) toDoList.get(j + 1).getDate()).toLocalDate())) {
                            ToDoItem temp = toDoList.get(j);
                            toDoList.set(j, toDoList.get(j + 1));
                            toDoList.set(j + 1, temp);
                        } else if (toDoList.get(j).getDate().isEqual(((LocalDateTime) toDoList.get(j + 1).getDate()).toLocalDate())) {
                            ToDoItem temp = toDoList.get(j);
                            toDoList.set(j, toDoList.get(j + 1));
                            toDoList.set(j + 1, temp);
                        }
                    } else if (toDoList.get(j).getDate() instanceof LocalDate && toDoList.get(j + 1).getDate() instanceof LocalDate) {
                        if (toDoList.get(j).getDate().isAfter(toDoList.get(j + 1).getDate())) {
                            ToDoItem temp = toDoList.get(j);
                            toDoList.set(j, toDoList.get(j + 1));
                            toDoList.set(j + 1, temp);
                        }
                    }
                }
            }
        }
        return toDoList;
    }
}




Java Source Code List

me.jamesfrost.simpledo.AboutDialog.java
me.jamesfrost.simpledo.Constants.java
me.jamesfrost.simpledo.CreateItem.java
me.jamesfrost.simpledo.DataBaseOpenHelper.java
me.jamesfrost.simpledo.DateHelper.java
me.jamesfrost.simpledo.DeleteDialog.java
me.jamesfrost.simpledo.EditItem.java
me.jamesfrost.simpledo.ItemsDataSource.java
me.jamesfrost.simpledo.QuickReschedule.java
me.jamesfrost.simpledo.ReminderHelper.java
me.jamesfrost.simpledo.SettingsActivity.java
me.jamesfrost.simpledo.SimpleDo.java
me.jamesfrost.simpledo.SimpleEula.java
me.jamesfrost.simpledo.ToDoItemSorter.java
me.jamesfrost.simpledo.ToDoItem.java