Beispiel #1
0
  public GenericEntity<List<com.near.senders.Notification>> getNotifications(int userId) {
    NotificationDAO notificationDAO = new NotificationDAO();
    List<Integer> notificationIds = notificationDAO.getNotifications(userId);
    List<com.near.senders.Notification> notifications =
        new ArrayList<com.near.senders.Notification>();
    for (Integer notificationId : notificationIds) {
      com.near.senders.Notification notification = new com.near.senders.Notification();
      UserDAO userDAO = new UserDAO();
      if (userDAO.getUser(userId).getNotify() == 1) {
        UserProfileDAO userProfileDAO = new UserProfileDAO();

        Notification notificationDB = notificationDAO.getNotification(notificationId);

        notification.setId(notificationDB.getId());
        notification.setNotification(notificationDB.getNotification());
        notification.setNotifierName(userDAO.getUser(notificationDB.getUserId()).getName());
        notification.setNotifierPhoto(
            userProfileDAO.getUserProfile(notificationDB.getRecieverId()).getAvatar());
        notification.setUserId(notificationDB.getUserId());

        String posted = "";
        java.util.Date date = new java.util.Date();
        int days =
            (int)
                ((date.getTime() - notificationDB.getDateNotified().getTime())
                    / (1000 * 60 * 60 * 24));

        if (days == 0) posted += "Today";
        else if (days == 1) posted += "Yesterday";
        else posted += days + " days ago";
        notification.setDateNotified(posted);

        notifications.add(notification);
        notificationDAO.delete(notificationId);
      }
    }
    return new GenericEntity<List<com.near.senders.Notification>>(notifications) {};
  }
Beispiel #2
0
  public GenericEntity<List<Person>> getPeopleNearMe(int user, int lastId) {
    ArrayList<Person> list = new ArrayList<Person>();

    UserDAO userDAO = new UserDAO();
    List<Integer> users = userDAO.getUserIds();

    UserInfoDAO userInfoDAO = new UserInfoDAO();
    UserInfo userInfo = userInfoDAO.getUserInfo(user);
    int i = 0;
    for (Integer userId : users) {
      if (i < 40) {
        UserInfo otherInfo = userInfoDAO.getUserInfo(userId);
        if ((userId < lastId || lastId == 0) && otherInfo.getCanLocate() == 1) {

          double distance =
              Feed.distance(
                  userInfo.getCurrentLat(),
                  userInfo.getCurrentLng(),
                  otherInfo.getCurrentLat(),
                  otherInfo.getCurrentLng(),
                  'M');

          if (isInsideCircle((long) distance)) {
            UserProfileDAO userProfileDAO = new UserProfileDAO();
            Person person = new Person();
            person.setName(userDAO.getUser(userId).getName());
            person.setDistance((int) distance);
            person.setUserId(userId);
            person.setAvatar(userProfileDAO.getUserProfile(userId).getAvatar());
            list.add(person);
          }
          i++;
        }
      }
    }
    return new GenericEntity<List<Person>>(list) {};
  }