package se.dat255.grupp12; import android.os.Parcel; import android.os.Parcelable; import java.io.Serializable; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; /** * A task * Created by ville unt oscar on 9/20/13. * A model representing a task and its attributes. */ public class Task implements Serializable{ private String title; private String content; private Priority priority; private Calendar date = Calendar.getInstance(); private ArrayList<User> users = new ArrayList<User>(); private boolean isDone = false; private boolean isAssigned = false; private long id; private static long nextLocalId = -1; private Task() {} // For serialization. /** * Creates a task with a title and a priority * @param title * @param priority */ public Task(String title, Priority priority) { this.title = title; this.priority = priority; this.id = nextLocalId--; } /** * Creates a task with id, content, title and a priority * @param id * @param title * @param content * @param priority */ public Task(long id, String title, String content, Priority priority) { this.id = id; this.title = title; this.content = content; this.priority = priority; } /** * Creates a task with a content, title and a priority which can be assigned to the user. * @param title * @param content * @param priority * @param assigned */ public Task(String title, String content, Priority priority, boolean assigned){ this.title = title; this.content = content; this.priority = priority; this.isAssigned = assigned; this.id = nextLocalId--; } /** * Getter for the title of the Task * @return the title */ public String getTitle() { return title; } /** * Getter for the content of the Task * @return the content */ public String getContent(){ return content; } /** * Getter for the priority of the Task * @return the priority */ public Priority getPriority() { return priority; } /** * Enum for the different levels of priority */ public Calendar getDate(){ return date; } public long getId() { return this.id; } public void setDate(Calendar calendar) { date=calendar; } public void setAssigned(boolean assigned) { if (isAssigned() && !assigned) { User userToRemove = null; for(User user : users) { if (User.getUserEmails().get(0).equals(user.getEmail())) { userToRemove=user; } } users.remove(userToRemove); } if (!isAssigned() && assigned) { users.add(new User("Placeholder",User.getUserEmails().get(0))); } } public static enum Priority { HIGH, MEDIUM, LOW } /** * To string that returns the title * @return A string with the title of the task */ @Override public String toString() { return title; } /** * Adds a user to a task * @param user */ public void addUser(User user){ users.add(user); } /** * Returns the number of users assigned to a task * @return number of users */ public int getNumberOfUsers(){ if (isAssigned()) { for (User user : users) { if (User.getUserEmails().contains(user.getEmail())) { return users.size(); } } return users.size()+1; } return users.size(); } /** * Returns the done-state of a task * @return If a task is marked as done */ public boolean isDone(){ return isDone; } /** * Marks a task as done */ public void setDone(boolean done){ isDone = done; } /** * @return whether or not the user is assigned to this task. */ public boolean isAssigned() { boolean existsInUsers = false; for(User user : users) { if (User.getUserEmails().get(0).equals(user.getEmail())) { existsInUsers = true; } } return existsInUsers; } /** * Resets the count of new local tasks */ public static void resetNextLocalId(){ nextLocalId = -1; } public void setTitle(String title){ this.title = title; } public void setContent(String content){ this.content = content; } public void setPriority(Priority prio){ this.priority = prio; } public Integer getPrioValue(){ if(this.isDone() == true){ return 4; } else if (this.priority == Priority.HIGH){ return 1; } else if (this.priority == Priority.MEDIUM){ return 2; } else if (this.priority == Priority.LOW){ return 3; } else { return 5; } } }