Search in sources :

Example 1 with GetBidByUserIdController

use of com.cmput301w18t05.taskzilla.controller.GetBidByUserIdController 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)

Aggregations

DialogInterface (android.content.DialogInterface)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 Task (com.cmput301w18t05.taskzilla.Task)1 GetBidByUserIdController (com.cmput301w18t05.taskzilla.controller.GetBidByUserIdController)1 GetTaskRequest (com.cmput301w18t05.taskzilla.request.command.GetTaskRequest)1 RemoveBidRequest (com.cmput301w18t05.taskzilla.request.command.RemoveBidRequest)1