Search in sources :

Example 1 with GetBidsByTaskIdRequest

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

the class ViewTaskActivity method onCreate.

/**
 *onCreate
 * Retrieve the task using the task id that was sent using
 * intent into the activity updating the information on the
 * activity_ViewTaskActivity while checking if the task has
 * a provider, what the status is and if the user viewing
 * is the owner of the task
 *
 * @param savedInstanceState
 * @author Micheal-Nguyen
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_task);
    EditButton = findViewById(R.id.EditButton);
    DeleteButton = findViewById(R.id.DeleteButton);
    ProviderPicture = findViewById(R.id.ProviderPicture);
    RequesterPicture = findViewById(R.id.RequesterPicture);
    ProviderName = findViewById(R.id.ProviderName);
    DescriptionView = findViewById(R.id.Description);
    RequesterName = findViewById(R.id.RequesterName);
    TaskName = findViewById(R.id.TaskName);
    TaskStatus = findViewById(R.id.TaskStatus);
    BidslistView = findViewById(R.id.BidsListView);
    PinkButton = findViewById(R.id.PinkButton);
    this.viewTaskController = new ViewTaskController(this.findViewById(android.R.id.content), this);
    taskID = getIntent().getStringExtra("TaskId");
    viewTaskController.setTaskID(taskID);
    viewTaskController.getTaskRequest();
    task = viewTaskController.getTask();
    currentUserId = currentUser.getInstance().getId();
    taskUserId = task.getTaskRequester().getId();
    taskName = task.getName();
    taskStatus = task.getStatus();
    description = task.getDescription();
    TaskRequester = task.getTaskRequester();
    try {
        TaskProvider = task.getTaskProvider();
    } catch (Exception e) {
        TaskProvider = new User();
    }
    RequesterName.setText(TaskRequester.getName());
    DescriptionView.setText(description);
    TaskName.setText(taskName);
    TaskStatus.setText(taskStatus);
    // 2018-03-14
    if (currentUserId.equals(taskUserId)) {
        DeleteButton.setVisibility(View.VISIBLE);
        PinkButton.setVisibility(View.INVISIBLE);
        if (taskStatus.equals("requested") || taskStatus.equals("bidded")) {
            EditButton.setVisibility(View.VISIBLE);
        } else {
            EditButton.setVisibility(View.INVISIBLE);
        }
    } else {
        DeleteButton.setVisibility(View.INVISIBLE);
        EditButton.setVisibility(View.INVISIBLE);
    }
    if (taskStatus.equals("assigned")) {
        ProviderPicture.setVisibility(View.VISIBLE);
        ProviderName.setVisibility(View.VISIBLE);
        ProviderName.setText(TaskProvider.getName());
    // LinearLayout.LayoutParams detailsLayout =
    // new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
    // LinearLayout.LayoutParams.WRAP_CONTENT);
    // detailsLayout.setMargins(0,999,0,0);
    // DescriptionView.setLayoutParams(detailsLayout);
    }
    /*
         * ProviderPicture and RequesterPicture
         * when provider or requester picture clicked in
         * activity_view_task.xml pass user id through intent
         * and start the ProfileActivity
         *
         * @author Micheal-Nguyen
         */
    ProviderPicture.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            try {
                Intent intent = new Intent(view.getContext(), ProfileActivity.class);
                intent.putExtra("user id", TaskProvider.getId());
                startActivity(intent);
            } catch (Exception e) {
            }
        }
    });
    RequesterPicture.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            try {
                Intent intent = new Intent(view.getContext(), ProfileActivity.class);
                intent.putExtra("user id", TaskRequester.getId());
                startActivity(intent);
            } catch (Exception e) {
            }
        }
    });
    // Edit Task Button
    EditButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = new Intent(view.getContext(), EditTaskActivity.class);
            intent.putExtra("task Name", taskName);
            intent.putExtra("Description", description);
            startActivityForResult(intent, 1);
        }
    });
    /*
         * DeleteButton
         * in the activity_view_taskxml, when the delete button is pressed
         * prompt user with a confirmation dialog.
         * upon confirmation call vieTaskController to remove
         * the task through elastic search
         *
         * @author Micheal-Nguyen
         */
    DeleteButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // taken from https://stackoverflow.com/questions/2115758/how-do-i-display-an-alert-dialog-on-android
            // 2018-03-16
            AlertDialog.Builder alert = new AlertDialog.Builder(ViewTaskActivity.this);
            alert.setTitle("Delete");
            alert.setMessage("Are you sure you want to delete?");
            // DELETE CODE
            alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    viewTaskController.RemoveTaskRequest(task);
                    dialogInterface.dismiss();
                    Intent intent = new Intent();
                    intent.putExtra("result", true);
                    setResult(RESULT_OK, intent);
                    finish();
                }
            });
            // DELETE CANCEL CODE
            alert.setNegativeButton("No", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                }
            });
            alert.show();
        }
    });
    // get all of this task's bids and pass it into expandable list to display
    // @author myapplestory
    BidList = new ArrayList<>();
    GetBidsByTaskIdRequest getBidsByTaskIdRequest = new GetBidsByTaskIdRequest(this.taskID);
    RequestManager.getInstance().invokeRequest(getBidsByTaskIdRequest);
    BidList.addAll(getBidsByTaskIdRequest.getResult());
    ExpandableListAdapter expandableListAdapter = new ExpandableBidListAdapter(this, BidList);
    BidslistView.setAdapter(expandableListAdapter);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) User(com.cmput301w18t05.taskzilla.User) com.cmput301w18t05.taskzilla.currentUser(com.cmput301w18t05.taskzilla.currentUser) DialogInterface(android.content.DialogInterface) GetBidsByTaskIdRequest(com.cmput301w18t05.taskzilla.request.command.GetBidsByTaskIdRequest) Intent(android.content.Intent) ExpandableListAdapter(android.widget.ExpandableListAdapter) ExpandableBidListAdapter(com.cmput301w18t05.taskzilla.ExpandableBidListAdapter) View(android.view.View) TextView(android.widget.TextView) ExpandableListView(android.widget.ExpandableListView) ViewTaskController(com.cmput301w18t05.taskzilla.controller.ViewTaskController)

Example 2 with GetBidsByTaskIdRequest

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

the class Task method addBid.

/**
 * addBid
 * Insert into sorted bid list
 *
 * @author praharen
 */
public void addBid(Bid newbid) {
    GetBidsByTaskIdRequest getbidrequest = new GetBidsByTaskIdRequest(this.Id);
    RequestManager.getInstance().invokeRequest(getbidrequest);
    ArrayList<Bid> bidlist = getbidrequest.getResult();
    for (Bid bid : bidlist) {
        if (bid.getUserId().equals(newbid.getUserId())) {
            RemoveBidRequest removerequest = new RemoveBidRequest(bid);
            RequestManager.getInstance().invokeRequest(removerequest);
            break;
        }
    }
    AddBidRequest addBidRequest = new AddBidRequest(newbid);
    RequestManager.getInstance().invokeRequest(addBidRequest);
}
Also used : RemoveBidRequest(com.cmput301w18t05.taskzilla.request.command.RemoveBidRequest) GetBidsByTaskIdRequest(com.cmput301w18t05.taskzilla.request.command.GetBidsByTaskIdRequest) AddBidRequest(com.cmput301w18t05.taskzilla.request.command.AddBidRequest)

Example 3 with GetBidsByTaskIdRequest

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

the class Task method retrieveBids.

/**
 * get bids from elastic search
 *
 * @return a list of bids
 */
private ArrayList<Bid> retrieveBids() {
    GetBidsByTaskIdRequest getBids = new GetBidsByTaskIdRequest(this.getId());
    RequestManager.getInstance().invokeRequest(getBids);
    return getBids.getResult();
}
Also used : GetBidsByTaskIdRequest(com.cmput301w18t05.taskzilla.request.command.GetBidsByTaskIdRequest)

Aggregations

GetBidsByTaskIdRequest (com.cmput301w18t05.taskzilla.request.command.GetBidsByTaskIdRequest)3 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 AlertDialog (android.support.v7.app.AlertDialog)1 View (android.view.View)1 ExpandableListAdapter (android.widget.ExpandableListAdapter)1 ExpandableListView (android.widget.ExpandableListView)1 TextView (android.widget.TextView)1 ExpandableBidListAdapter (com.cmput301w18t05.taskzilla.ExpandableBidListAdapter)1 User (com.cmput301w18t05.taskzilla.User)1 ViewTaskController (com.cmput301w18t05.taskzilla.controller.ViewTaskController)1 com.cmput301w18t05.taskzilla.currentUser (com.cmput301w18t05.taskzilla.currentUser)1 AddBidRequest (com.cmput301w18t05.taskzilla.request.command.AddBidRequest)1 RemoveBidRequest (com.cmput301w18t05.taskzilla.request.command.RemoveBidRequest)1