Search in sources :

Example 1 with GetTaskRequest

use of com.cmput301w18t05.taskzilla.request.command.GetTaskRequest 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 2 with GetTaskRequest

use of com.cmput301w18t05.taskzilla.request.command.GetTaskRequest in project Taskzilla by CMPUT301W18T05.

the class MyBidsFragment method onViewCreated.

/**
 * initialize variables as well as set up adapter and onlongclick
 * @param view states the current view
 * @param savedInstanceState idk what this does
 * @author myapplestory
 */
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    bidList = new ArrayList<>();
    bidController = new GetBidByUserIdController(getContext(), currentUser.getInstance());
    adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, bidList);
    taskListView.setAdapter(adapter);
    // goes to the respective task when a bid is tapped on
    taskListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        public void onItemClick(AdapterView<?> a, View v, int position, long id) {
            viewTask(bidList.get(position));
        }
    });
    // prompts to delete bid when held
    taskListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
            AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
            alert.setTitle("Delete");
            alert.setMessage("Are you sure you want to delete this bid?");
            alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    // remove bid
                    Bid targetBid = bidList.get(position);
                    RemoveBidRequest removeRequest = new RemoveBidRequest(targetBid);
                    RequestManager.getInstance().invokeRequest(removeRequest);
                    bidList.remove(position);
                    // change status of task
                    GetTaskRequest getTaskRequest = new GetTaskRequest(targetBid.getTaskId());
                    RequestManager.getInstance().invokeRequest(getTaskRequest);
                    Task temptask = getTaskRequest.getResult();
                    temptask.setStatus("requested");
                    adapter.notifyDataSetChanged();
                    dialogInterface.dismiss();
                }
            });
            alert.setNegativeButton("No", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                }
            });
            alert.show();
            return true;
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) GetTaskRequest(com.cmput301w18t05.taskzilla.request.command.GetTaskRequest) Task(com.cmput301w18t05.taskzilla.Task) GetBidByUserIdController(com.cmput301w18t05.taskzilla.controller.GetBidByUserIdController) DialogInterface(android.content.DialogInterface) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) RemoveBidRequest(com.cmput301w18t05.taskzilla.request.command.RemoveBidRequest) AdapterView(android.widget.AdapterView) Bid(com.cmput301w18t05.taskzilla.Bid)

Example 3 with GetTaskRequest

use of com.cmput301w18t05.taskzilla.request.command.GetTaskRequest in project Taskzilla by CMPUT301W18T05.

the class RequestManagerTest method testGetTaskRequest.

public void testGetTaskRequest() {
    GetTaskRequest getTaskRequest = new GetTaskRequest(task.getId());
    RequestManager.getInstance().invokeRequest(ctx, getTaskRequest);
    Task ret = getTaskRequest.getResult();
    Log.i("Event", "RETURNED TASK: " + ret.toString());
    assertEquals(task.getId(), ret.getId());
    assertEquals(task.getName(), ret.getName());
    assertEquals(task.getDescription(), ret.getDescription());
}
Also used : GetTaskRequest(com.cmput301w18t05.taskzilla.request.command.GetTaskRequest)

Example 4 with GetTaskRequest

use of com.cmput301w18t05.taskzilla.request.command.GetTaskRequest in project Taskzilla by CMPUT301W18T05.

the class RequestManagerTest method testRemoveTask.

public void testRemoveTask() {
    RemoveTaskRequest request = new RemoveTaskRequest(task.getId());
    RequestManager.getInstance().invokeRequest(ctx, request);
    GetTaskRequest getTaskRequest = new GetTaskRequest(task.getId());
    RequestManager.getInstance().invokeRequest(getTaskRequest);
    assertNull(getTaskRequest.getResult());
}
Also used : GetTaskRequest(com.cmput301w18t05.taskzilla.request.command.GetTaskRequest) RemoveTaskRequest(com.cmput301w18t05.taskzilla.request.command.RemoveTaskRequest)

Example 5 with GetTaskRequest

use of com.cmput301w18t05.taskzilla.request.command.GetTaskRequest in project Taskzilla by CMPUT301W18T05.

the class Bid method toString.

/**
 * Returns a string with the bid details
 * @return the string which is with the details of the bid
 */
public String toString() {
    GetTaskRequest taskRequest = new GetTaskRequest(this.taskId);
    RequestManager.getInstance().invokeRequest(taskRequest);
    return "Task: " + taskRequest.getResult().getName() + "\nBid amount: $" + Float.toString(this.bidAmount);
}
Also used : GetTaskRequest(com.cmput301w18t05.taskzilla.request.command.GetTaskRequest)

Aggregations

GetTaskRequest (com.cmput301w18t05.taskzilla.request.command.GetTaskRequest)6 Task (com.cmput301w18t05.taskzilla.Task)2 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 AlertDialog (android.support.v7.app.AlertDialog)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 Bid (com.cmput301w18t05.taskzilla.Bid)1 GetBidByUserIdController (com.cmput301w18t05.taskzilla.controller.GetBidByUserIdController)1 RemoveBidRequest (com.cmput301w18t05.taskzilla.request.command.RemoveBidRequest)1 RemoveTaskRequest (com.cmput301w18t05.taskzilla.request.command.RemoveTaskRequest)1