Search in sources :

Example 6 with Task

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

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();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) DigitsKeyListener(android.text.method.DigitsKeyListener) Handler(android.os.Handler) InputMethodManager(android.view.inputmethod.InputMethodManager) 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) Spanned(android.text.Spanned) ImageButton(android.widget.ImageButton) Button(android.widget.Button) Bid(com.cmput301w18t05.taskzilla.Bid)

Example 8 with Task

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();
}
Also used : Task(com.cmput301w18t05.taskzilla.Task) GetAllTasksRequest(com.cmput301w18t05.taskzilla.request.command.GetAllTasksRequest)

Example 9 with Task

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;
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) GetTaskRequest(com.cmput301w18t05.taskzilla.request.command.GetTaskRequest) Task(com.cmput301w18t05.taskzilla.Task) GetBidByUserIdController(com.cmput301w18t05.taskzilla.controller.GetBidByUserIdController) DialogInterface(android.content.DialogInterface) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) RemoveBidRequest(com.cmput301w18t05.taskzilla.request.command.RemoveBidRequest) AdapterView(android.widget.AdapterView) Bid(com.cmput301w18t05.taskzilla.Bid)

Example 10 with Task

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;
}
Also used : GetTasksByRequesterUsernameRequest(com.cmput301w18t05.taskzilla.request.command.GetTasksByRequesterUsernameRequest) ArrayList(java.util.ArrayList)

Aggregations

View (android.view.View)18 Task (com.cmput301w18t05.taskzilla.Task)16 MainActivity (com.cmput301w18t05.taskzilla.activity.MainActivity)10 AddTaskRequest (com.cmput301w18t05.taskzilla.request.command.AddTaskRequest)9 AlertDialog (android.support.v7.app.AlertDialog)6 AdapterView (android.widget.AdapterView)6 ListView (android.widget.ListView)6 GetTaskRequest (com.cmput301w18t05.taskzilla.request.command.GetTaskRequest)6 Intent (android.content.Intent)5 RecyclerView (android.support.v7.widget.RecyclerView)5 EditText (android.widget.EditText)5 ImageButton (android.widget.ImageButton)5 DecimalFormat (java.text.DecimalFormat)5 DialogInterface (android.content.DialogInterface)4 Button (android.widget.Button)4 TextView (android.widget.TextView)4 AppCache (com.cmput301w18t05.taskzilla.AppCache)4 Bid (com.cmput301w18t05.taskzilla.Bid)4 ColorDrawable (android.graphics.drawable.ColorDrawable)3 ActionBar (android.support.v7.app.ActionBar)3