Search in sources :

Example 6 with Notification

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

the class Task method addBid.

/**
 * addBid
 *
 * @author praharen
 */
public void addBid(Bid newbid) {
    System.out.println("Adding bid: " + newbid);
    AddBidRequest addBidRequest = new AddBidRequest(newbid);
    RequestManager.getInstance().invokeRequest(addBidRequest);
    String temp = "Your task '" + this.getName() + "' has been bidded on by " + currentUser.getInstance().getUsername() + " for $" + newbid.getBidAmount();
    Notification notification = new Notification("New Bid", newbid.getUserId(), this.getRequesterId(), this.Id, this.name, temp, currentUser.getInstance());
    NotificationManager.getInstance().sendNotification(notification);
}
Also used : AddBidRequest(com.cmput301w18t05.taskzilla.request.command.AddBidRequest)

Example 7 with Notification

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

the class Task method removeAllBids.

/**
 * removeAllBids
 * remove all bids under this task
 * @author myapplestory
 */
private void removeAllBids() {
    GetBidsByTaskIdRequest getbidrequest = new GetBidsByTaskIdRequest(this.Id);
    RequestManager.getInstance().invokeRequest(getbidrequest);
    ArrayList<Bid> bidlist = getbidrequest.getResult();
    for (Bid bid : bidlist) {
        RemoveBidRequest removerequest = new RemoveBidRequest(bid);
        RequestManager.getInstance().invokeRequest(removerequest);
        String temp = "Your bid has been declined!";
        Notification notification = new Notification("Bid Declined", this.requesterId, this.providerId, this.Id, this.getName(), temp, currentUser.getInstance());
        NotificationManager.getInstance().sendNotification(notification);
    }
}
Also used : RemoveBidRequest(com.cmput301w18t05.taskzilla.request.command.RemoveBidRequest) GetBidsByTaskIdRequest(com.cmput301w18t05.taskzilla.request.command.GetBidsByTaskIdRequest)

Example 8 with Notification

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

the class Notification method acknowledge.

/**
 *  If the notification is new, it is set to acknowledge to next time there wont be a
 *  heads up notification shown.
 *
 *  @see NotificationManager
 */
public void acknowledge() {
    if (id == null)
        return;
    this.acknowledged = true;
    AddNotificationRequest task = new AddNotificationRequest(this);
    RequestManager.getInstance().invokeRequest(task);
}
Also used : AddNotificationRequest(com.cmput301w18t05.taskzilla.request.command.AddNotificationRequest)

Example 9 with Notification

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

the class NotificationsFragment method onCreateView.

/**
 *  Initializes the fragment, and sets up listeners which checks if any notification
 *  on the listview has been clicked on.
 *
 * @param inflater              The current view
 * @param container
 * @param savedInstanceState    The state the fragment was in before switching to a new activity/fragment
 * @return                      Current view
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    final ConstraintLayout constraintLayout = (ConstraintLayout) inflater.inflate(R.layout.fragment_notifications, container, false);
    notificationList = new ArrayList<>();
    notificationListView = constraintLayout.findViewById(R.id.NotificationListView);
    notificationsController = new NotificationsController(this, getActivity(), currentUser.getInstance());
    adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, notificationList);
    notificationListView.setAdapter(adapter);
    notificationListView.setClickable(true);
    // get all notifications for the user currently available
    notificationsController.getNotificationsRequest();
    notificationListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            taskId = notificationList.get(i).getTaskID();
            if (notificationsController.checkTaskExistRequest(taskId))
                viewTask(taskId);
            else {
                AlertDialog.Builder deleteNotifcationAlert = new AlertDialog.Builder(getContext());
                deleteNotifcationAlert.setTitle("Task no longer exists!");
                deleteNotifcationAlert.setMessage("Do you want to remove this notification?");
                deleteNotifcationAlert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        notificationsController.removeNotificationRequest(taskId, i);
                        dialogInterface.dismiss();
                    }
                });
                deleteNotifcationAlert.setNegativeButton("No", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                    }
                });
                deleteNotifcationAlert.show();
            }
        }
    });
    notificationListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
            currentNotification = notificationList.get(position);
            notificationId = currentNotification.getId();
            AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
            alert.setTitle("Remove Notification?");
            alert.setMessage("Are you sure you want to delete this notification?");
            alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    // remove notification
                    notificationsController.removeNotificationRequest(notificationId, position);
                    dialogInterface.dismiss();
                }
            });
            alert.setNegativeButton("No", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                }
            });
            alert.show();
            return true;
        }
    });
    clear = constraintLayout.findViewById(R.id.clearButton);
    clear.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
            alert.setTitle("Remove Notification?");
            alert.setMessage("Are you sure you want to delete all notifications?");
            alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    // remove notification
                    notificationsController.removeAllNotificationRequest();
                    dialogInterface.dismiss();
                }
            });
            alert.setNegativeButton("No", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                }
            });
            alert.show();
        }
    });
    return constraintLayout;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) NotificationsController(com.cmput301w18t05.taskzilla.controller.NotificationsController) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ConstraintLayout(android.support.constraint.ConstraintLayout) AdapterView(android.widget.AdapterView)

Aggregations

View (android.view.View)2 AdapterView (android.widget.AdapterView)2 ListView (android.widget.ListView)2 Notification (com.cmput301w18t05.taskzilla.Notification)2 AddNotificationRequest (com.cmput301w18t05.taskzilla.request.command.AddNotificationRequest)2 GetNotificationsByUserIdRequest (com.cmput301w18t05.taskzilla.request.command.GetNotificationsByUserIdRequest)2 RemoveBidRequest (com.cmput301w18t05.taskzilla.request.command.RemoveBidRequest)2 RemoveNotificationRequest (com.cmput301w18t05.taskzilla.request.command.RemoveNotificationRequest)2 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 ConstraintLayout (android.support.constraint.ConstraintLayout)1 AlertDialog (android.support.v7.app.AlertDialog)1 RecyclerView (android.support.v7.widget.RecyclerView)1 ArrayAdapter (android.widget.ArrayAdapter)1 Button (android.widget.Button)1 ExpandableListView (android.widget.ExpandableListView)1 ImageButton (android.widget.ImageButton)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1 Bid (com.cmput301w18t05.taskzilla.Bid)1