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