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;
}
});
}
Aggregations