use of com.cmput301w18t05.taskzilla.request.command.AddTaskRequest in project Taskzilla by CMPUT301W18T05.
the class ViewTaskController method updateTaskRequest.
public void updateTaskRequest(Task task) {
AddTaskRequest request = new AddTaskRequest(task);
request.setUpdate(true);
RequestManager.getInstance().invokeRequest(ctx, request);
}
use of com.cmput301w18t05.taskzilla.request.command.AddTaskRequest in project Taskzilla by CMPUT301W18T05.
the class NewTaskController method addTask.
/**
* Error checks the task name and description to enforce character limits.
* Then the task is added to Elastic Search
* @param name Task name
* @param user User that is making the task
* @param description Description of the task
*/
public void addTask(String name, User user, String description) {
// Check field lengths and give error
EditText taskName = view.findViewById(R.id.TaskName);
EditText taskDescription = view.findViewById(R.id.Description);
if (TextUtils.getTrimmedLength(taskName.getText()) <= 25 && TextUtils.getTrimmedLength(taskName.getText()) > 0 && TextUtils.getTrimmedLength(taskDescription.getText()) <= 25 && TextUtils.getTrimmedLength(taskDescription.getText()) > 0) {
Task task = new Task(name, user, description);
AddTaskRequest request = new AddTaskRequest(task);
RequestManager.getInstance().invokeRequest(ctx, request);
request.getResult();
taskId = task.getId();
Intent intent = new Intent();
intent.putExtra("result", taskId);
view.setResult(RESULT_OK, intent);
Toast.makeText(view, "New task created, refresh page to see updated list", Toast.LENGTH_SHORT).show();
view.finish();
} else {
if (TextUtils.getTrimmedLength(taskName.getText()) > 25) {
taskName.setError("Name can not exceed 25 characters");
}
if (TextUtils.getTrimmedLength(taskName.getText()) == 0) {
taskName.setError("Name can not empty");
}
if (TextUtils.getTrimmedLength(taskDescription.getText()) > 280) {
taskDescription.setError("Description can not exceed 280 characters");
}
if (TextUtils.getTrimmedLength(taskDescription.getText()) == 0) {
taskDescription.setError("Description can not be empty");
}
}
}
use of com.cmput301w18t05.taskzilla.request.command.AddTaskRequest in project Taskzilla by CMPUT301W18T05.
the class RequestManagerTest method addTask.
public void addTask() {
AddTaskRequest addTaskRequest = new AddTaskRequest(task);
RequestManager.getInstance().invokeRequest(addTaskRequest);
assertTrue(addTaskRequest.getResult());
}
use of com.cmput301w18t05.taskzilla.request.command.AddTaskRequest in project Taskzilla by CMPUT301W18T05.
the class BidTest method testCompareTo.
/**
* Test for comparing a bid to another bid
* <p>
* greater than returns 1
* equality returns 0
* less than returns -1
*/
public void testCompareTo() {
User user1 = new User();
AddUserRequest addUserRequest = new AddUserRequest(user1);
RequestManager.getInstance().invokeRequest(getActivity(), addUserRequest);
Task task = new Task("Task name", user1, "Task description");
AddTaskRequest addTaskRequest = new AddTaskRequest(task);
RequestManager.getInstance().invokeRequest(getActivity(), addTaskRequest);
float bidAmount1 = 10.00f;
Bid bid1 = new Bid(user1.getId(), task.getId(), bidAmount1);
User user2 = new User();
AddUserRequest addUserRequest2 = new AddUserRequest(user2);
RequestManager.getInstance().invokeRequest(getActivity(), addUserRequest2);
float bidAmount2 = 1.00f;
Bid bid2 = new Bid(user2.getId(), task.getId(), bidAmount2);
assertEquals(bid1.compareTo(bid2), 1);
User user3 = new User();
AddUserRequest addUserRequest3 = new AddUserRequest(user3);
RequestManager.getInstance().invokeRequest(getActivity(), addUserRequest3);
float bidAmount3 = 10.00f;
Bid bid3 = new Bid(user3.getId(), task.getId(), bidAmount3);
assertEquals(bid1.compareTo(bid3), 0);
User user4 = new User();
AddUserRequest addUserRequest4 = new AddUserRequest(user4);
RequestManager.getInstance().invokeRequest(getActivity(), addUserRequest4);
float bidAmount4 = 20.00f;
Bid bid4 = new Bid(user4.getId(), task.getId(), bidAmount4);
assertEquals(bid1.compareTo(bid4), -1);
}
use of com.cmput301w18t05.taskzilla.request.command.AddTaskRequest in project Taskzilla by CMPUT301W18T05.
the class NewTaskController method addTask.
/**
* Error checks the task name and description to enforce character limits.
* Then the task is added to Elastic Search
* @param name Task name
* @param user User that is making the task
* @param description Description of the task
*/
public void addTask(String name, User user, String description, LatLng taskLocation, ArrayList<Photo> photos) {
// Check field lengths and give error
EditText taskName = view.findViewById(R.id.TaskName);
EditText taskDescription = view.findViewById(R.id.Description);
if (TextUtils.getTrimmedLength(taskName.getText()) <= 55 && TextUtils.getTrimmedLength(taskName.getText()) > 0 && TextUtils.getTrimmedLength(taskDescription.getText()) <= 500 && TextUtils.getTrimmedLength(taskDescription.getText()) > 0) {
Task task = new Task(name, user, description, taskLocation, photos);
AddTaskRequest request = new AddTaskRequest(task);
RequestManager.getInstance().invokeRequest(ctx, request);
request.getResult();
taskId = task.getId();
Intent intent = new Intent();
intent.putExtra("result", taskId);
view.setResult(RESULT_OK, intent);
// Toast.makeText(view, "New task created, refresh page to see updated list", Toast.LENGTH_SHORT).show();
view.finish();
} else {
if (TextUtils.getTrimmedLength(taskName.getText()) > 55) {
taskName.setError("Name can not exceed 55 characters");
}
if (TextUtils.getTrimmedLength(taskName.getText()) == 0) {
taskName.setError("Name can not empty");
}
if (TextUtils.getTrimmedLength(taskDescription.getText()) > 500) {
taskDescription.setError("Description can not exceed 500 characters");
}
if (TextUtils.getTrimmedLength(taskDescription.getText()) == 0) {
taskDescription.setError("Description can not be empty");
}
}
}
Aggregations