Search in sources :

Example 1 with Bid

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

the class BidTest method testSetBid.

/**
 * Test for setting the bid
 */
public void testSetBid() {
    User user = new User();
    Task task = new Task();
    AddUserRequest userRequest = new AddUserRequest(user);
    RequestManager.getInstance().invokeRequest(userRequest);
    userRequest.getResult();
    AddTaskRequest request = new AddTaskRequest(task);
    RequestManager.getInstance().invokeRequest(request);
    request.getResult();
    float bidAmount = 10.00f;
    Bid bid = new Bid(user.getId(), task.getId(), 10.00f);
    assertEquals(bid.getBidAmount(), bidAmount);
}
Also used : AddTaskRequest(com.cmput301w18t05.taskzilla.request.command.AddTaskRequest) AddUserRequest(com.cmput301w18t05.taskzilla.request.command.AddUserRequest)

Example 2 with Bid

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

the class ViewTaskActivity method thePinkButton.

/**
 * thePinkButton
 * when the task is requested or bidded
 * there will be a pink button where the requester can decline one of the existing bids
 * onclick it shows a dialog with a listview of existing bids and a button to confirm declination
 *
 * @param view the view this button is in
 * @author myapplestory
 */
public void thePinkButton(android.view.View view) {
    final AlertDialog mBuilder = new AlertDialog.Builder(ViewTaskActivity.this).create();
    final View mView = getLayoutInflater().inflate(R.layout.dialog_decline_bid, null);
    final ListView declineBidListView = mView.findViewById(R.id.DeclineBidList);
    final Button declineBidButton = mView.findViewById(R.id.DeclineBidButton);
    ArrayList<String> tempList = new ArrayList<>();
    selectedBid = null;
    if (BidList.isEmpty()) {
        tempList.add("No bids :'(");
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, tempList);
        declineBidListView.setAdapter(adapter);
        declineBidButton.setText("SAD");
        declineBidButton.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");
            tempList.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, tempList);
        declineBidListView.setAdapter(adapter);
        declineBidListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        declineBidButton.setText("DECLINE BID");
        declineBidListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                selectedBid = BidList.get(i);
            }
        });
        declineBidButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (selectedBid == null) {
                    Toast.makeText(ViewTaskActivity.this, "Select a bid before declining", Toast.LENGTH_SHORT).show();
                    return;
                }
                RemoveBidRequest removeRequest = new RemoveBidRequest(selectedBid);
                RequestManager.getInstance().invokeRequest(removeRequest);
                String temp = "Your bid has been declined!";
                Notification notification = new Notification("Bid Declined", task.getRequesterId(), selectedBid.getUserId(), taskID, taskName, temp, currentUser.getInstance());
                NotificationManager.getInstance().sendNotification(notification);
                BidList.remove(selectedBid);
                updateBidsList();
                if (BidList.size() == 1) {
                    EditButton.setVisibility(View.VISIBLE);
                    task.setStatus("requested");
                    TaskStatus.setText("requested");
                    updateBidsList();
                } else {
                    Float bestBidTemp = -1.0f;
                    String bestBidderIdTemp = "-1";
                    for (Bid bid : BidList) {
                        if (bestBidTemp == -1.0f) {
                            bestBidTemp = bid.getBidAmount();
                            GetUserRequest request = new GetUserRequest(bid.getUserId());
                            RequestManager.getInstance().invokeRequest(getApplicationContext(), request);
                            User tempBidder = request.getResult();
                            bestBidderIdTemp = tempBidder.getId();
                        }
                        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();
                }
                setProviderField();
                mBuilder.dismiss();
            }
        });
    }
    mBuilder.setView(mView);
    mBuilder.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ProfileController(com.cmput301w18t05.taskzilla.controller.ProfileController) GetUserRequest(com.cmput301w18t05.taskzilla.request.command.GetUserRequest) User(com.cmput301w18t05.taskzilla.User) com.cmput301w18t05.taskzilla.currentUser(com.cmput301w18t05.taskzilla.currentUser) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) Notification(com.cmput301w18t05.taskzilla.Notification) ListView(android.widget.ListView) ExpandableListView(android.widget.ExpandableListView) ImageButton(android.widget.ImageButton) Button(android.widget.Button) Bid(com.cmput301w18t05.taskzilla.Bid) 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) RemoveBidRequest(com.cmput301w18t05.taskzilla.request.command.RemoveBidRequest) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter)

Example 3 with Bid

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

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

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

the class MapActivity method onMapReady.

/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    getLocation();
    mMap = googleMap;
    if (getIntent().getStringExtra("drag") != null) {
        LatLng yourLocation = new LatLng(lat, lon);
        moveToCurrentLocation(yourLocation);
        final Marker locationMarker = mMap.addMarker(new MarkerOptions().position(new LatLng(lat, lon)).title("Hold and drag to pick your task location").draggable(true));
        locationMarker.showInfoWindow();
        mMap.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() {

            /**
             * Hide marker window when dragging
             * @param arg0
             */
            @Override
            public void onMarkerDragStart(Marker arg0) {
                // TODO Auto-generated method stub
                arg0.hideInfoWindow();
            }

            /**
             * Show LatLon of final location of their marker and prompt user to click
             * Switch back to previous activity returning the latitude and longitude
             * @param arg0
             */
            @SuppressWarnings("unchecked")
            @Override
            public void onMarkerDragEnd(Marker arg0) {
                // TODO Auto-generated method stub
                DecimalFormat df = new DecimalFormat("#.#####");
                mMap.animateCamera(CameraUpdateFactory.newLatLng(arg0.getPosition()));
                arg0.setTitle("Lat: " + Double.toString(Double.valueOf(df.format(arg0.getPosition().latitude))) + " Lon: " + Double.toString(Double.valueOf(df.format(arg0.getPosition().longitude))));
                arg0.setSnippet("Click here to confirm location");
                arg0.showInfoWindow();
                mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {

                    @Override
                    public void onInfoWindowClick(Marker marker) {
                        Intent intent = new Intent();
                        intent.putExtra("Lat", Double.toString(Double.valueOf(marker.getPosition().latitude)));
                        intent.putExtra("Lon", Double.toString(Double.valueOf(marker.getPosition().longitude)));
                        setResult(RESULT_OK, intent);
                        finish();
                    }
                });
            }

            /**
             * Hide window when dragging marker on map
             * @param arg0
             */
            @Override
            public void onMarkerDrag(Marker arg0) {
                // TODO Auto-generated method stub
                arg0.hideInfoWindow();
            }
        });
    } else if (getIntent().getStringExtra("lat") != null) {
        LatLng tLocation = new LatLng(Double.parseDouble(getIntent().getStringExtra("lat")), Double.parseDouble(getIntent().getStringExtra("lon")));
        mMap.addMarker(new MarkerOptions().position(tLocation).title(getIntent().getStringExtra("TaskName")).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))).showInfoWindow();
        mMap.moveCamera(CameraUpdateFactory.newLatLng(tLocation));
        moveToCurrentLocation(tLocation);
        LatLng yourLocation = new LatLng(lat, lon);
        mMap.addMarker(new MarkerOptions().position(yourLocation).title("Your Location").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN))).showInfoWindow();
    } else {
        myLocation = new Location("You");
        myLocation.setLatitude(lat);
        myLocation.setLongitude(lon);
        myLocation.setTime(new Date().getTime());
        // Add a marker to your location and move the camera
        LatLng yourLocation = new LatLng(lat, lon);
        mMap.addMarker(new MarkerOptions().position(yourLocation).title("Your Location").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN))).showInfoWindow();
        mMap.moveCamera(CameraUpdateFactory.newLatLng(yourLocation));
        moveToCurrentLocation(yourLocation);
        mMap.addCircle(new CircleOptions().center(yourLocation).radius(5000).strokeColor(Color.RED).strokeWidth((float) 5.0));
        Location taskLocation;
        // *Add locations of tasks*//
        for (Task t : tasks) {
            if (t.getLocation() != null) {
                taskLocation = new Location("Task");
                taskLocation.setLatitude(t.getLocation().latitude);
                taskLocation.setLongitude(t.getLocation().longitude);
                // Set time as current Date
                taskLocation.setTime(new Date().getTime());
                if (myLocation.distanceTo(taskLocation) <= 5000) {
                    LatLng taskslonlat = new LatLng(t.getLocation().latitude, t.getLocation().longitude);
                    if (t.getStatus().equalsIgnoreCase("requested")) {
                        mMap.addMarker(new MarkerOptions().position(taskslonlat).title(t.getName()).snippet("No Bids").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN))).setTag(t.getId());
                    }
                    if (t.getStatus().equalsIgnoreCase("bidded")) {
                        mMap.addMarker(new MarkerOptions().position(taskslonlat).title(t.getName()).snippet("Best Bid: $" + t.getBestBid().toString()).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE))).setTag(t.getId());
                    }
                }
            }
        }
        mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {

            @Override
            public void onInfoWindowClick(Marker marker) {
                if (marker.getTag() != null) {
                    Intent intent = new Intent(getApplicationContext(), ViewTaskActivity.class);
                    intent.putExtra("TaskId", marker.getTag().toString());
                    startActivity(intent);
                }
            }
        });
    }
}
Also used : Task(com.cmput301w18t05.taskzilla.Task) MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) DecimalFormat(java.text.DecimalFormat) Intent(android.content.Intent) Marker(com.google.android.gms.maps.model.Marker) Date(java.util.Date) CircleOptions(com.google.android.gms.maps.model.CircleOptions) GoogleMap(com.google.android.gms.maps.GoogleMap) LatLng(com.google.android.gms.maps.model.LatLng) Location(android.location.Location)

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