Search in sources :

Example 6 with Bid

use of com.cmput301w18t05.taskzilla.Bid in project Taskzilla by CMPUT301W18T05.

the class BidActivityTest method testBid.

public void testBid() {
    // Set up for Test
    MainActivity activity = (MainActivity) solo.getCurrentActivity();
    solo.assertCurrentActivity("Wrong Activity", MainActivity.class);
    solo.clickOnText("Sign Up");
    solo.assertCurrentActivity("Wrong Activity", SignUpActivity.class);
    solo.enterText((EditText) solo.getView(R.id.usernameField), "TestUser");
    solo.enterText((EditText) solo.getView(R.id.nameField), "TestName");
    solo.enterText((EditText) solo.getView(R.id.emailField), "Test@Email.com");
    solo.enterText((EditText) solo.getView(R.id.phoneField), "1234567890");
    solo.clickOnButton("Sign Up");
    // Correct Log in Info
    solo.clearEditText((EditText) solo.getView(R.id.usernameText));
    solo.enterText((EditText) solo.getView(R.id.usernameText), "TestUser");
    solo.clickOnButton("Log In");
    solo.assertCurrentActivity("Wrong Activity", WelcomeActivity.class);
    solo.waitForText("Tasks");
    View fab = solo.getCurrentActivity().findViewById(R.id.fab);
    solo.clickOnView(fab);
    solo.waitForActivity(NewTaskActivity.class);
    solo.assertCurrentActivity("Wrong Activity", NewTaskActivity.class);
    // Valid Information
    solo.clearEditText((EditText) solo.getView(R.id.Description));
    solo.enterText((EditText) solo.getView(R.id.TaskName), "Test Task Name");
    solo.clearEditText((EditText) solo.getView(R.id.Description));
    solo.enterText((EditText) solo.getView(R.id.Description), "Test Description");
    solo.clickOnButton("Add Task");
    solo.waitForActivity(WelcomeActivity.class);
    solo.assertCurrentActivity("Wrong Activity", WelcomeActivity.class);
    View fab2 = solo.getCurrentActivity().findViewById(R.id.fab2);
    solo.clickOnView(fab2);
    assertTrue(solo.waitForText("Test Task Name"));
    solo.waitForText("Profile");
    solo.clickOnText("Profile");
    solo.clickOnView(solo.getView(R.id.LogOutButton));
    solo.waitForActivity(MainActivity.class);
    solo.assertCurrentActivity("Wrong Activity", MainActivity.class);
    solo.clickOnText("Sign Up");
    solo.assertCurrentActivity("Wrong Activity", SignUpActivity.class);
    solo.enterText((EditText) solo.getView(R.id.usernameField), "TestUserOne");
    solo.enterText((EditText) solo.getView(R.id.nameField), "TestNameOne");
    solo.enterText((EditText) solo.getView(R.id.emailField), "Test1@Email.com");
    solo.enterText((EditText) solo.getView(R.id.phoneField), "1234567890");
    solo.clickOnButton("Sign Up");
    // Correct Log in Info
    solo.clearEditText((EditText) solo.getView(R.id.usernameText));
    solo.enterText((EditText) solo.getView(R.id.usernameText), "TestUserOne");
    solo.clickOnButton("Log In");
    solo.assertCurrentActivity("Wrong Activity", WelcomeActivity.class);
    // Test Bid on task
    solo.waitForText("Search");
    solo.clickOnText("Search");
    solo.clickOnText("Status: ");
    solo.assertCurrentActivity("Wrong Activity", ViewTaskActivity.class);
    solo.clickOnButton("PLACE BID");
    solo.enterText((EditText) solo.getView(R.id.place_bid_edittext), "25.22");
    solo.clickOnButton("Place Bid");
    solo.goBack();
    // Test Bid in bid list
    solo.waitForText("My Bids");
    solo.assertCurrentActivity("Wrong Activity", WelcomeActivity.class);
    solo.clickOnText("My Bids");
    solo.waitForText("Bid amount: ");
    solo.clickOnText("25.22");
    solo.assertCurrentActivity("Wrong Activity", ViewTaskActivity.class);
    // Test update bid
    solo.clickOnButton("PLACE BID");
    solo.enterText((EditText) solo.getView(R.id.place_bid_edittext), "29.22");
    solo.clickOnButton("Place Bid");
    solo.goBack();
    solo.clickLongOnText("29.22");
    // Test Delete bid
    solo.sleep(1000);
    solo.clickOnButton("Yes");
    assertFalse(solo.waitForText("25.22", 1, 1000));
}
Also used : MainActivity(com.cmput301w18t05.taskzilla.activity.MainActivity) View(android.view.View)

Example 7 with Bid

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

Example 8 with Bid

use of com.cmput301w18t05.taskzilla.Bid in project Taskzilla by CMPUT301W18T05.

the class ViewTaskActivity method updateBestBid.

/**
 * updateBestBid
 * updates best bidder field if new bid has value less than the current best bid
 *
 * @param incomingBidFloat the bid amount the new bid will be
 * @return 0 if best bidder needs update, -1 if not
 * @author myapplestory, Micheal-Nguyen
 */
public Integer updateBestBid(Float incomingBidFloat) {
    Log.i("CURRENTBESTBIDDER", task.getBestBidder());
    Log.i("CURRENTUSER", currentUserId);
    if (task.getBestBid() > incomingBidFloat || task.getBestBid() == -1.0f) {
        Log.i("in", "1");
        task.setBestBidder(currentUserId);
        task.setBestBid(incomingBidFloat);
        task.updateThis();
    } else if (task.getBestBid().equals(incomingBidFloat)) {
        Toast.makeText(ViewTaskActivity.this, "A similar bid already exists. Please bid another value", Toast.LENGTH_SHORT).show();
        return -1;
    } else if (task.getBestBidder().equals(currentUserId)) {
        Float bestBidTemp = incomingBidFloat;
        String bestBidderIdTemp = currentUserId;
        for (Bid bid : BidList) {
            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();
    return 0;
}
Also used : GetUserRequest(com.cmput301w18t05.taskzilla.request.command.GetUserRequest) User(com.cmput301w18t05.taskzilla.User) com.cmput301w18t05.taskzilla.currentUser(com.cmput301w18t05.taskzilla.currentUser) Bid(com.cmput301w18t05.taskzilla.Bid)

Example 9 with Bid

use of com.cmput301w18t05.taskzilla.Bid in project Taskzilla by CMPUT301W18T05.

the class ExpandableBidListAdapter method getChildView.

/**
 * @param groupPosition which group was clicked
 * @param childPosition which child was clicked
 * @param isLastChild if it the last element in the list
 * @param view the listview parent in context
 * @param parent the parent group this group belongs to
 * @return the textview to be displayed
 * @author myapplestory
 *
 * gets bids on this task as well as the bid amount and big owner name
 * and displays it
 */
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, ViewGroup parent) {
    Bid currentBid = this.bidList.get(childPosition);
    GetUserRequest getUserRequest = new GetUserRequest(currentBid.getUserId());
    RequestManager.getInstance().invokeRequest(getUserRequest);
    User BidOwner = getUserRequest.getResult();
    TextView textView = new TextView(context);
    String output = "$" + String.format(Locale.CANADA, "%.2f", currentBid.getBidAmount()) + "    By user: " + BidOwner.getName();
    textView.setText(output);
    textView.setTextColor(0xffff88ff);
    textView.setTextSize(18);
    textView.setPadding(144, 0, 0, 0);
    textView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast.makeText(context, "Secret developer settings enabled", Toast.LENGTH_SHORT).show();
        }
    });
    return textView;
}
Also used : GetUserRequest(com.cmput301w18t05.taskzilla.request.command.GetUserRequest) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View)

Example 10 with Bid

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

View (android.view.View)7 Bid (com.cmput301w18t05.taskzilla.Bid)5 AlertDialog (android.support.v7.app.AlertDialog)4 AdapterView (android.widget.AdapterView)4 ListView (android.widget.ListView)4 TextView (android.widget.TextView)4 DecimalFormat (java.text.DecimalFormat)4 RecyclerView (android.support.v7.widget.RecyclerView)3 Button (android.widget.Button)3 ExpandableListView (android.widget.ExpandableListView)3 ImageButton (android.widget.ImageButton)3 ScrollView (android.widget.ScrollView)3 GetUserRequest (com.cmput301w18t05.taskzilla.request.command.GetUserRequest)3 RemoveBidRequest (com.cmput301w18t05.taskzilla.request.command.RemoveBidRequest)3 ArrayAdapter (android.widget.ArrayAdapter)2 Task (com.cmput301w18t05.taskzilla.Task)2 User (com.cmput301w18t05.taskzilla.User)2 MainActivity (com.cmput301w18t05.taskzilla.activity.MainActivity)2 ProfileController (com.cmput301w18t05.taskzilla.controller.ProfileController)2 com.cmput301w18t05.taskzilla.currentUser (com.cmput301w18t05.taskzilla.currentUser)2