use of com.cmput301w18t05.taskzilla.Task in project Taskzilla by CMPUT301W18T05.
the class BidTest method testCompareTo.
/**
* Test for comparing a bid to another bid
* <p>
* greater than returns 1
* equality returns 0
* less than returns -1
*/
public void testCompareTo() {
User user1 = new User();
AddUserRequest addUserRequest = new AddUserRequest(user1);
RequestManager.getInstance().invokeRequest(getActivity(), addUserRequest);
Task task = new Task("Task name", user1, "Task description");
AddTaskRequest addTaskRequest = new AddTaskRequest(task);
RequestManager.getInstance().invokeRequest(getActivity(), addTaskRequest);
float bidAmount1 = 10.00f;
Bid bid1 = new Bid(user1.getId(), task.getId(), bidAmount1);
User user2 = new User();
AddUserRequest addUserRequest2 = new AddUserRequest(user2);
RequestManager.getInstance().invokeRequest(getActivity(), addUserRequest2);
float bidAmount2 = 1.00f;
Bid bid2 = new Bid(user2.getId(), task.getId(), bidAmount2);
assertEquals(bid1.compareTo(bid2), 1);
User user3 = new User();
AddUserRequest addUserRequest3 = new AddUserRequest(user3);
RequestManager.getInstance().invokeRequest(getActivity(), addUserRequest3);
float bidAmount3 = 10.00f;
Bid bid3 = new Bid(user3.getId(), task.getId(), bidAmount3);
assertEquals(bid1.compareTo(bid3), 0);
User user4 = new User();
AddUserRequest addUserRequest4 = new AddUserRequest(user4);
RequestManager.getInstance().invokeRequest(getActivity(), addUserRequest4);
float bidAmount4 = 20.00f;
Bid bid4 = new Bid(user4.getId(), task.getId(), bidAmount4);
assertEquals(bid1.compareTo(bid4), -1);
}
use of com.cmput301w18t05.taskzilla.Task 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.Task in project Taskzilla by CMPUT301W18T05.
the class ViewTaskActivity method onCreate.
/**
*onCreate
* Retrieve the task using the task id that was sent using
* intent into the activity updating the information on the
* activity_ViewTaskActivity while checking if the task has
* a provider, what the status is and if the user viewing
* is the owner of the task
*
* @param savedInstanceState
* @author Micheal-Nguyen, myapplestory
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_task);
appColors = AppColors.getInstance();
ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(appColors.getActionBarColor())));
actionBar.setTitle(Html.fromHtml("<font color='" + appColors.getActionBarTextColor() + "'>Taskzilla</font>"));
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.dragdropMap);
mapFragment.getMapAsync(this);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
findViews();
// starts the activity at the very top
scrollView.setFocusableInTouchMode(true);
scrollView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
// gets the task id
this.viewTaskController = new ViewTaskController(this.findViewById(android.R.id.content), this);
taskID = getIntent().getStringExtra("TaskId");
setValues();
setRequesterField();
setProviderField();
photos = task.getPhotos();
NoLocation = findViewById(R.id.NoLocationText);
NoLocation.setVisibility(View.INVISIBLE);
if (task.getLocation() == null) {
NoLocation.setVisibility(View.VISIBLE);
// mapFragment.s
}
linearLayout = findViewById(R.id.Photos);
recyclerPhotosView = findViewById(R.id.listOfPhotos);
layoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false);
recyclerPhotosView.setLayoutManager(layoutManager);
recyclerPhotosViewAdapter = new RecyclerViewAdapter(getApplicationContext(), photos, new CustomOnItemClick() {
@Override
public void onColumnClicked(int position) {
Intent intent = new Intent(getApplicationContext(), ZoomImageActivity.class);
intent.putExtra("Photo", photos.get(position).toString());
startActivity(intent);
}
});
recyclerPhotosView.setAdapter(recyclerPhotosViewAdapter);
setVisibility();
setUpBidsList();
}
use of com.cmput301w18t05.taskzilla.Task in project Taskzilla by CMPUT301W18T05.
the class NewTaskController method addTask.
/**
* Error checks the task name and description to enforce character limits.
* Then the task is added to Elastic Search
* @param name Task name
* @param user User that is making the task
* @param description Description of the task
*/
public void addTask(String name, User user, String description, LatLng taskLocation, ArrayList<Photo> photos) {
// Check field lengths and give error
EditText taskName = view.findViewById(R.id.TaskName);
EditText taskDescription = view.findViewById(R.id.Description);
if (TextUtils.getTrimmedLength(taskName.getText()) <= 55 && TextUtils.getTrimmedLength(taskName.getText()) > 0 && TextUtils.getTrimmedLength(taskDescription.getText()) <= 500 && TextUtils.getTrimmedLength(taskDescription.getText()) > 0) {
Task task = new Task(name, user, description, taskLocation, photos);
AddTaskRequest request = new AddTaskRequest(task);
RequestManager.getInstance().invokeRequest(ctx, request);
request.getResult();
taskId = task.getId();
Intent intent = new Intent();
intent.putExtra("result", taskId);
view.setResult(RESULT_OK, intent);
// Toast.makeText(view, "New task created, refresh page to see updated list", Toast.LENGTH_SHORT).show();
view.finish();
} else {
if (TextUtils.getTrimmedLength(taskName.getText()) > 55) {
taskName.setError("Name can not exceed 55 characters");
}
if (TextUtils.getTrimmedLength(taskName.getText()) == 0) {
taskName.setError("Name can not empty");
}
if (TextUtils.getTrimmedLength(taskDescription.getText()) > 500) {
taskDescription.setError("Description can not exceed 500 characters");
}
if (TextUtils.getTrimmedLength(taskDescription.getText()) == 0) {
taskDescription.setError("Description can not be empty");
}
}
}
use of com.cmput301w18t05.taskzilla.Task in project Taskzilla by CMPUT301W18T05.
the class SearchController method searchRequest.
/**
* This method invokes a search request using the given keywords, which is then sent
* to the request manager which determines if the app is online or offline, before doing
* the request.
*
* @param sentence string of keywords
* @see RequestManager
*/
public void searchRequest(String sentence) {
newRequest = new SearchTaskRequest(sentence);
RequestManager.getInstance().invokeRequest(ctx, newRequest);
ArrayList<Task> temp;
temp = newRequest.getTasks();
if (temp != null && temp.size() != 0) {
while (temp.size() > 0) {
for (Task t : temp) if (!t.getStatus().equalsIgnoreCase("assigned") && !t.getStatus().equalsIgnoreCase("completed")) {
this.searchResults.add(t);
}
RequestManager.getInstance().invokeRequest(ctx, newRequest);
temp = newRequest.getTasks();
}
} else if (temp == null) {
Toast.makeText(view.getActivity(), "Unable to search right now.", Toast.LENGTH_SHORT).show();
} else {
searchResults.clear();
}
view.notifyChange();
}
Aggregations