Search in sources :

Example 1 with RemoveBidRequest

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

the class ViewTaskActivity method thePinkButton.

/**
 * thePinkButton
 * when the task is requested or bidded
 * there will be a pink button where the requester can decline one of the existing bids
 * onclick it shows a dialog with a listview of existing bids and a button to confirm declination
 *
 * @param view the view this button is in
 * @author myapplestory
 */
public void thePinkButton(android.view.View view) {
    final AlertDialog mBuilder = new AlertDialog.Builder(ViewTaskActivity.this).create();
    final View mView = getLayoutInflater().inflate(R.layout.dialog_decline_bid, null);
    final ListView declineBidListView = mView.findViewById(R.id.DeclineBidList);
    final Button declineBidButton = mView.findViewById(R.id.DeclineBidButton);
    ArrayList<String> tempList = new ArrayList<>();
    selectedBid = null;
    if (BidList.isEmpty()) {
        tempList.add("No bids :'(");
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, tempList);
        declineBidListView.setAdapter(adapter);
        declineBidButton.setText("SAD");
        declineBidButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                mBuilder.dismiss();
            }
        });
    } else {
        for (Bid bid : BidList) {
            ProfileController controller = new ProfileController(mView, getBaseContext());
            controller.setUserID(bid.getUserId());
            controller.getUserRequest();
            DecimalFormat cents = new DecimalFormat("#0.00");
            tempList.add("Best bidder: " + controller.getUser().getName() + "\nBid Amount: $" + cents.format(bid.getBidAmount()));
        }
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_single_choice, tempList);
        declineBidListView.setAdapter(adapter);
        declineBidListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        declineBidButton.setText("DECLINE BID");
        declineBidListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                selectedBid = BidList.get(i);
            }
        });
        declineBidButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (selectedBid == null) {
                    Toast.makeText(ViewTaskActivity.this, "Select a bid before declining", Toast.LENGTH_SHORT).show();
                    return;
                }
                RemoveBidRequest removeRequest = new RemoveBidRequest(selectedBid);
                RequestManager.getInstance().invokeRequest(removeRequest);
                String temp = "Your bid has been declined!";
                Notification notification = new Notification("Bid Declined", task.getRequesterId(), selectedBid.getUserId(), taskID, taskName, temp, currentUser.getInstance());
                NotificationManager.getInstance().sendNotification(notification);
                BidList.remove(selectedBid);
                updateBidsList();
                if (BidList.size() == 1) {
                    EditButton.setVisibility(View.VISIBLE);
                    task.setStatus("requested");
                    TaskStatus.setText("requested");
                    updateBidsList();
                } else {
                    Float bestBidTemp = -1.0f;
                    String bestBidderIdTemp = "-1";
                    for (Bid bid : BidList) {
                        if (bestBidTemp == -1.0f) {
                            bestBidTemp = bid.getBidAmount();
                            GetUserRequest request = new GetUserRequest(bid.getUserId());
                            RequestManager.getInstance().invokeRequest(getApplicationContext(), request);
                            User tempBidder = request.getResult();
                            bestBidderIdTemp = tempBidder.getId();
                        }
                        if (bid.getBidAmount() < bestBidTemp && !task.getBestBidder().equals(bid.getUserId())) {
                            Log.i("CHANGE", bid.getBidAmount().toString());
                            bestBidTemp = bid.getBidAmount();
                            GetUserRequest request = new GetUserRequest(bid.getUserId());
                            RequestManager.getInstance().invokeRequest(getApplicationContext(), request);
                            User tempBidder = request.getResult();
                            bestBidderIdTemp = tempBidder.getId();
                        }
                    }
                    task.setBestBid(bestBidTemp);
                    task.setBestBidder(bestBidderIdTemp);
                    task.updateThis();
                }
                setProviderField();
                mBuilder.dismiss();
            }
        });
    }
    mBuilder.setView(mView);
    mBuilder.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ProfileController(com.cmput301w18t05.taskzilla.controller.ProfileController) GetUserRequest(com.cmput301w18t05.taskzilla.request.command.GetUserRequest) User(com.cmput301w18t05.taskzilla.User) com.cmput301w18t05.taskzilla.currentUser(com.cmput301w18t05.taskzilla.currentUser) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) Notification(com.cmput301w18t05.taskzilla.Notification) ListView(android.widget.ListView) ExpandableListView(android.widget.ExpandableListView) ImageButton(android.widget.ImageButton) Button(android.widget.Button) Bid(com.cmput301w18t05.taskzilla.Bid) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) ExpandableListView(android.widget.ExpandableListView) RemoveBidRequest(com.cmput301w18t05.taskzilla.request.command.RemoveBidRequest) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter)

Example 2 with RemoveBidRequest

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

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

the class Task method removeAllBids.

/**
 * removeAllBids
 * remove all bids under this task
 * @author myapplestory
 */
private void removeAllBids() {
    GetBidsByTaskIdRequest getbidrequest = new GetBidsByTaskIdRequest(this.Id);
    RequestManager.getInstance().invokeRequest(getbidrequest);
    ArrayList<Bid> bidlist = getbidrequest.getResult();
    for (Bid bid : bidlist) {
        RemoveBidRequest removerequest = new RemoveBidRequest(bid);
        RequestManager.getInstance().invokeRequest(removerequest);
        String temp = "Your bid has been declined!";
        Notification notification = new Notification("Bid Declined", this.requesterId, this.providerId, this.Id, this.getName(), temp, currentUser.getInstance());
        NotificationManager.getInstance().sendNotification(notification);
    }
}
Also used : RemoveBidRequest(com.cmput301w18t05.taskzilla.request.command.RemoveBidRequest) GetBidsByTaskIdRequest(com.cmput301w18t05.taskzilla.request.command.GetBidsByTaskIdRequest)

Aggregations

RemoveBidRequest (com.cmput301w18t05.taskzilla.request.command.RemoveBidRequest)3 AlertDialog (android.support.v7.app.AlertDialog)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 ListView (android.widget.ListView)2 Bid (com.cmput301w18t05.taskzilla.Bid)2 DialogInterface (android.content.DialogInterface)1 RecyclerView (android.support.v7.widget.RecyclerView)1 ArrayAdapter (android.widget.ArrayAdapter)1 Button (android.widget.Button)1 ExpandableListView (android.widget.ExpandableListView)1 ImageButton (android.widget.ImageButton)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1 Notification (com.cmput301w18t05.taskzilla.Notification)1 Task (com.cmput301w18t05.taskzilla.Task)1 User (com.cmput301w18t05.taskzilla.User)1 GetBidByUserIdController (com.cmput301w18t05.taskzilla.controller.GetBidByUserIdController)1 ProfileController (com.cmput301w18t05.taskzilla.controller.ProfileController)1 com.cmput301w18t05.taskzilla.currentUser (com.cmput301w18t05.taskzilla.currentUser)1