use of com.cmput301w18t05.taskzilla.Task 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());
}
}
}
use of com.cmput301w18t05.taskzilla.Task in project Taskzilla by CMPUT301W18T05.
the class ViewTaskActivity method theBlueButton.
/**
* @param view pretty much the page it's on
* @author myapplestory
* theBlueButton
* upon pressing place button on task page
* prompts user to enter in a bid amount
* if valid input, will add bid to task
*/
public void theBlueButton(android.view.View view) {
final AlertDialog mBuilder = new AlertDialog.Builder(ViewTaskActivity.this).create();
final View mView = getLayoutInflater().inflate(R.layout.dialog_place_bid, null);
final EditText incomingBidText = mView.findViewById(R.id.place_bid_edittext);
// Taken from https://gist.github.com/gaara87/3607765
// 2018-03-19
// Limits the number of decimals allowed in input
incomingBidText.setFilters(new InputFilter[] { new DigitsKeyListener(Boolean.FALSE, Boolean.TRUE) {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
StringBuilder builder = new StringBuilder(dest);
builder.insert(dstart, source);
String temp = builder.toString();
if (temp.contains(".")) {
temp = temp.substring(temp.indexOf(".") + 1);
if (temp.length() > 2) {
return "";
}
}
return super.filter(source, start, end, dest, dstart, dend);
}
} });
// bring up keyboard when user taps place bid
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
final Button submitBidButton = mView.findViewById(R.id.submit_bid_button);
submitBidButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Float incomingBidFloat;
try {
incomingBidFloat = Float.parseFloat(incomingBidText.getText().toString());
incomingBidFloat = (float) (Math.round(incomingBidFloat * 100.0) / 100.0);
} catch (Exception exception) {
Toast.makeText(ViewTaskActivity.this, "Please enter in a valid bid amount", Toast.LENGTH_SHORT).show();
return;
}
// do stuff here to actually add bid
if (updateBestBid(incomingBidFloat) == -1) {
return;
} else {
task.addBid(new Bid(currentUserId, taskID, incomingBidFloat));
task.setStatus("bidded");
TaskStatus.setText("Bidded");
}
setProviderField();
Toast.makeText(ViewTaskActivity.this, "Bid placed", Toast.LENGTH_SHORT).show();
// hide keyboard upon pressing button
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(submitBidButton.getWindowToken(), 0);
mBuilder.dismiss();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
updateBidsList();
}
}, 1500);
}
});
mBuilder.setView(mView);
mBuilder.show();
}
use of com.cmput301w18t05.taskzilla.Task in project Taskzilla by CMPUT301W18T05.
the class SearchController method getAllRequest.
/**
* This method invokes a get all request, which is then sent
* to the request manager which determines if the app is online or offline,
* before doing the request.
*
* @see RequestManager
*/
public void getAllRequest() {
GetAllTasksRequest request = new GetAllTasksRequest();
RequestManager.getInstance().invokeRequest(ctx, request);
searchResults.clear();
ArrayList<Task> temp;
temp = request.getResult();
System.out.println("Search result is: " + temp);
while (temp != null && temp.size() > 0) {
for (Task t : temp) {
if (!t.getStatus().equalsIgnoreCase("assigned") && !t.getStatus().equalsIgnoreCase("completed")) {
this.searchResults.add(t);
}
}
RequestManager.getInstance().invokeRequest(ctx, request);
temp = request.getResult();
}
view.notifyChange();
}
use of com.cmput301w18t05.taskzilla.Task 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;
}
});
}
use of com.cmput301w18t05.taskzilla.Task in project Taskzilla by CMPUT301W18T05.
the class User method getTasksRequested.
/**
* Get a list of tasks that this user has requested.
* @return ArrayList
*/
public ArrayList<Task> getTasksRequested() {
ArrayList<Task> res = new ArrayList<>();
ArrayList<Task> temp;
GetTasksByRequesterUsernameRequest requestTasks = new GetTasksByRequesterUsernameRequest(this.getUsername());
RequestManager.getInstance().invokeRequest(requestTasks);
temp = requestTasks.getResult();
while (temp != null && !temp.isEmpty()) {
res.addAll(temp);
RequestManager.getInstance().invokeRequest(requestTasks);
temp = requestTasks.getResult();
}
return res;
}
Aggregations