Search in sources :

Example 1 with ProfileController

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

use of com.cmput301w18t05.taskzilla.controller.ProfileController in project Taskzilla by CMPUT301W18T05.

the class ViewTaskActivity method setProviderField.

/**
 * setPoviderField
 * sets the provider text and picture accordingly
 * if the task status is bidded then the best bidder will appear on the field
 * else if the task status is assigned or completed then the provider will appear
 * @author myapplestory
 */
public void setProviderField() {
    if (task.getStatus().equals("requested")) {
        Photo defaultPhoto = new Photo("");
        ProviderPicture.setImageBitmap(defaultPhoto.StringToBitmap());
        ProviderName.setText("No bidders :'(");
    } else if (task.getStatus().equals("bidded")) {
        ProfileController profileController = new ProfileController(this.findViewById(android.R.id.content), this);
        profileController.setUserID(task.getBestBidder());
        profileController.getUserRequest();
        User tempUser = profileController.getUser();
        String text = "Best bidder: " + tempUser.getName() + "\nBid amount: " + "$" + String.format(Locale.CANADA, "%.2f", task.getBestBid());
        ProviderName.setText(text);
        try {
            ProviderPicture.setImageBitmap(tempUser.getPhoto().StringToBitmap());
        } catch (Exception e) {
            Photo defaultPhoto = new Photo("");
            ProviderPicture.setImageBitmap(defaultPhoto.StringToBitmap());
        }
    } else if (task.getStatus().equals("assigned") || task.isComplete()) {
        String text = "Provider: " + TaskProvider.getName();
        ProviderName.setText(text);
        try {
            ProviderPicture.setImageBitmap(TaskProvider.getPhoto().StringToBitmap());
        } catch (Exception e) {
            Photo defaultPhoto = new Photo("");
            ProviderPicture.setImageBitmap(defaultPhoto.StringToBitmap());
        }
    }
}
Also used : ProfileController(com.cmput301w18t05.taskzilla.controller.ProfileController) User(com.cmput301w18t05.taskzilla.User) com.cmput301w18t05.taskzilla.currentUser(com.cmput301w18t05.taskzilla.currentUser) Photo(com.cmput301w18t05.taskzilla.Photo)

Example 3 with ProfileController

use of com.cmput301w18t05.taskzilla.controller.ProfileController in project Taskzilla by CMPUT301W18T05.

the class ProfileActivity method setValues.

/**
 * retrieves id from previous activity and get the user from elastic search
 * setting up the views on the profile activity
 */
public void setValues() {
    userID = getIntent().getStringExtra("user id");
    this.profileController = new ProfileController(this.findViewById(android.R.id.content), this);
    profileController.setUserID(userID);
    profileController.getUserRequest();
    user = profileController.getUser();
    name = user.getName();
    try {
        email = user.getEmail().toString();
        phone = user.getPhone().toString();
    } catch (Exception e) {
        email = "No Email";
        phone = "No Number";
    }
    numRequests = profileController.getNumberOfRequests(user.getUsername());
    numTasksDone = profileController.getNumberOfTasksDone(user.getUsername());
    nameField.setText(name);
    emailField.setText(email);
    phoneField.setText(phone);
    numRequestsField.setText(numRequests);
    numTasksDoneField.setText(numTasksDone);
    providerRatingField.setText(String.format(Locale.CANADA, "%.1f", user.getProviderRating()));
    requesterRatingField.setText(String.format(Locale.CANADA, "%.1f", user.getRequesterRating()));
    try {
        profilePicture.setImageBitmap(user.getPhoto().StringToBitmap());
    } catch (Exception e) {
        Photo defaultPhoto = new Photo("");
        profilePicture.setImageBitmap(defaultPhoto.StringToBitmap());
    }
}
Also used : ProfileController(com.cmput301w18t05.taskzilla.controller.ProfileController) Photo(com.cmput301w18t05.taskzilla.Photo)

Example 4 with ProfileController

use of com.cmput301w18t05.taskzilla.controller.ProfileController in project Taskzilla by CMPUT301W18T05.

the class ViewTaskActivity method theYellowButton.

/**
 * theYellowButton
 * when the task is bidded or requested
 * the requester can accept an existing bid from the list of existing bids
 * onclick a dialog shows up with a list view of existing bids and a button to confirm acceptance
 *
 * @param view
 * @author myapplestory
 */
public void theYellowButton(android.view.View view) {
    final AlertDialog mBuilder = new AlertDialog.Builder(ViewTaskActivity.this).create();
    final View mView = getLayoutInflater().inflate(R.layout.dialog_accept_bid, null);
    final ListView acceptBidListView = mView.findViewById(R.id.AcceptBidList);
    final Button acceptBidButton = mView.findViewById(R.id.AcceptBidButton);
    ArrayList<String> tempBidList = new ArrayList<>();
    selectedBid = null;
    if (BidList.isEmpty()) {
        tempBidList.add("No bids :'(");
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, tempBidList);
        acceptBidListView.setAdapter(adapter);
        acceptBidButton.setText("SAD");
        acceptBidButton.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");
            tempBidList.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, tempBidList);
        acceptBidListView.setAdapter(adapter);
        acceptBidListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        acceptBidButton.setText("ACCEPT BID");
        acceptBidListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                selectedBid = BidList.get(i);
            }
        });
        // upon clicking accepting, take the bids that was selected and update task
        acceptBidButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (selectedBid == null) {
                    Toast.makeText(ViewTaskActivity.this, "Select one of the bids before accepting", Toast.LENGTH_SHORT).show();
                    return;
                }
                ProfileController controller = new ProfileController(mView, getBaseContext());
                controller.setUserID(selectedBid.getUserId());
                controller.getUserRequest();
                TaskProvider = controller.getUser();
                task.setTaskProvider(TaskProvider);
                task.setStatus("assigned");
                TaskStatus.setText("Assigned");
                updateBidsList();
                EditButton.setVisibility(View.INVISIBLE);
                setProviderField();
                mBuilder.dismiss();
                RedButton.setVisibility(View.VISIBLE);
                GreenButton.setVisibility(View.VISIBLE);
                PinkButton.setVisibility(View.INVISIBLE);
                YellowButton.setVisibility(View.INVISIBLE);
                BidslistView.setVisibility(View.INVISIBLE);
            }
        });
    }
    mBuilder.setView(mView);
    mBuilder.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ProfileController(com.cmput301w18t05.taskzilla.controller.ProfileController) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) 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) ListView(android.widget.ListView) ExpandableListView(android.widget.ExpandableListView) ImageButton(android.widget.ImageButton) Button(android.widget.Button) AdapterView(android.widget.AdapterView) Bid(com.cmput301w18t05.taskzilla.Bid) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

ProfileController (com.cmput301w18t05.taskzilla.controller.ProfileController)4 AlertDialog (android.support.v7.app.AlertDialog)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 ArrayAdapter (android.widget.ArrayAdapter)2 Button (android.widget.Button)2 ExpandableListView (android.widget.ExpandableListView)2 ImageButton (android.widget.ImageButton)2 ListView (android.widget.ListView)2 ScrollView (android.widget.ScrollView)2 TextView (android.widget.TextView)2 Bid (com.cmput301w18t05.taskzilla.Bid)2 Photo (com.cmput301w18t05.taskzilla.Photo)2 User (com.cmput301w18t05.taskzilla.User)2 com.cmput301w18t05.taskzilla.currentUser (com.cmput301w18t05.taskzilla.currentUser)2 DecimalFormat (java.text.DecimalFormat)2 ArrayList (java.util.ArrayList)2 Notification (com.cmput301w18t05.taskzilla.Notification)1 GetUserRequest (com.cmput301w18t05.taskzilla.request.command.GetUserRequest)1