Search in sources :

Example 46 with Task

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

Example 47 with Task

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();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ProfileController(com.cmput301w18t05.taskzilla.controller.ProfileController) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) 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) ListView(android.widget.ListView) ExpandableListView(android.widget.ExpandableListView) ImageButton(android.widget.ImageButton) Button(android.widget.Button) AdapterView(android.widget.AdapterView) Bid(com.cmput301w18t05.taskzilla.Bid) ArrayAdapter(android.widget.ArrayAdapter)

Example 48 with Task

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();
}
Also used : SupportMapFragment(com.google.android.gms.maps.SupportMapFragment) ColorDrawable(android.graphics.drawable.ColorDrawable) Intent(android.content.Intent) RecyclerViewAdapter(com.cmput301w18t05.taskzilla.RecyclerViewAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) CustomOnItemClick(com.cmput301w18t05.taskzilla.CustomOnItemClick) ActionBar(android.support.v7.app.ActionBar) ViewTaskController(com.cmput301w18t05.taskzilla.controller.ViewTaskController)

Example 49 with Task

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");
        }
    }
}
Also used : EditText(android.widget.EditText) Task(com.cmput301w18t05.taskzilla.Task) Intent(android.content.Intent) AddTaskRequest(com.cmput301w18t05.taskzilla.request.command.AddTaskRequest)

Example 50 with Task

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

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