Search in sources :

Example 26 with Task

use of com.cmput301w18t05.taskzilla.Task in project Taskzilla by CMPUT301W18T05.

the class ViewTaskController method getTaskRequest.

/**
 * getTaskRequest
 * get the task from elastic search using request manager
 * and set the task of the controller to be the result
 *
 * @author Micheal-Nguyen
 */
public void getTaskRequest() {
    GetTaskRequest request = new GetTaskRequest(taskID);
    RequestManager.getInstance().invokeRequest(ctx, request);
    this.task = request.getResult();
}
Also used : GetTaskRequest(com.cmput301w18t05.taskzilla.request.command.GetTaskRequest)

Example 27 with Task

use of com.cmput301w18t05.taskzilla.Task 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);
}
Also used : AddTaskRequest(com.cmput301w18t05.taskzilla.request.command.AddTaskRequest)

Example 28 with Task

use of com.cmput301w18t05.taskzilla.Task in project Taskzilla by CMPUT301W18T05.

the class GetAllTasksRequest method executeOffline.

/**
 * get all the tasks from the app cache
 */
@Override
public void executeOffline() {
    // return what is in app cache
    if (executedOfflineOnce) {
        // prevent infinite loop
        result = new ArrayList<Task>();
        return;
    }
    AppCache appCache = AppCache.getInstance();
    result = appCache.getCachedTasks();
    executedOfflineOnce = true;
}
Also used : Task(com.cmput301w18t05.taskzilla.Task) AppCache(com.cmput301w18t05.taskzilla.AppCache)

Example 29 with Task

use of com.cmput301w18t05.taskzilla.Task in project Taskzilla by CMPUT301W18T05.

the class GetTasksByProviderUsernameRequest method executeOffline.

/**
 * search through tasks in the app cache
 * Also add the found tasks to the app cache
 */
@Override
public void executeOffline() {
    if (executedOffline) {
        result = new ArrayList<>();
        return;
    }
    executedOffline = true;
    AppCache appCache = AppCache.getInstance();
    ArrayList<Task> cachedTasks = appCache.getCachedTasks();
    result = new ArrayList<>();
    for (Task t : cachedTasks) {
        if (t.getTaskProvider().getUsername() != null && t.getTaskProvider().equals(user)) {
            result.add(t);
        }
    }
}
Also used : Task(com.cmput301w18t05.taskzilla.Task) AppCache(com.cmput301w18t05.taskzilla.AppCache)

Example 30 with Task

use of com.cmput301w18t05.taskzilla.Task 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");
        }
    }
}
Also used : EditText(android.widget.EditText) Task(com.cmput301w18t05.taskzilla.Task) Intent(android.content.Intent) AddTaskRequest(com.cmput301w18t05.taskzilla.request.command.AddTaskRequest)

Aggregations

View (android.view.View)18 Task (com.cmput301w18t05.taskzilla.Task)16 MainActivity (com.cmput301w18t05.taskzilla.activity.MainActivity)10 AddTaskRequest (com.cmput301w18t05.taskzilla.request.command.AddTaskRequest)9 AlertDialog (android.support.v7.app.AlertDialog)6 AdapterView (android.widget.AdapterView)6 ListView (android.widget.ListView)6 GetTaskRequest (com.cmput301w18t05.taskzilla.request.command.GetTaskRequest)6 Intent (android.content.Intent)5 RecyclerView (android.support.v7.widget.RecyclerView)5 EditText (android.widget.EditText)5 ImageButton (android.widget.ImageButton)5 DecimalFormat (java.text.DecimalFormat)5 DialogInterface (android.content.DialogInterface)4 Button (android.widget.Button)4 TextView (android.widget.TextView)4 AppCache (com.cmput301w18t05.taskzilla.AppCache)4 Bid (com.cmput301w18t05.taskzilla.Bid)4 ColorDrawable (android.graphics.drawable.ColorDrawable)3 ActionBar (android.support.v7.app.ActionBar)3