Search in sources :

Example 1 with Notification

use of com.abewy.android.apps.klyph.core.fql.Notification in project Klyph by jonathangerbaud.

the class Notifications method onActivityCreated.

/*
	 * @Override
	 * protected KlyphPullToRefreshListView onCreatePullToRefreshListView(LayoutInflater inflater, Bundle savedInstanceState)
	 * {
	 * return (KlyphPullToRefreshListView) inflater.inflate(R.layout.list_notifications, null);
	 * }
	 */
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    NotificationSwipeDismissAdapter swAdapter = new NotificationSwipeDismissAdapter(new MultiObjectAdapter(getListView()), new OnDismissCallback() {

        @Override
        public void onDismiss(AbsListView arg0, int[] positions) {
            for (int i : positions) {
                if (getAdapter().getItem(i) instanceof Notification) {
                    Notification notification = (Notification) getAdapter().getItem(i);
                    setNotificationRead(notification);
                }
            }
            List<GraphObject> list = new ArrayList<GraphObject>();
            for (GraphObject o : getAdapter().getItems()) {
                if (!(o instanceof Header)) {
                    list.add(o);
                }
            }
            populate(list);
        }
    });
    swAdapter.setAbsListView(getListView());
    setListAdapter(swAdapter);
    // setListAdapter(new MultiObjectAdapter(getListView()));
    defineEmptyText(R.string.empty_list_no_notification);
    setListVisible(false);
    setRequestType(Query.NOTIFICATIONS);
    loggedIn = true;
    new Handler().postDelayed(new Runnable() {

        public void run() {
            loadNotifications();
        }
    }, 2000);
}
Also used : MultiObjectAdapter(com.abewy.android.apps.klyph.adapter.MultiObjectAdapter) OnDismissCallback(com.haarman.listviewanimations.itemmanipulation.OnDismissCallback) AbsListView(android.widget.AbsListView) Handler(android.os.Handler) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject) Notification(com.abewy.android.apps.klyph.core.fql.Notification) KlyphNotification(com.abewy.android.apps.klyph.KlyphNotification) Header(com.abewy.klyph.items.Header) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with Notification

use of com.abewy.android.apps.klyph.core.fql.Notification in project Klyph by jonathangerbaud.

the class Notifications method getNewNotificationsCount.

public int getNewNotificationsCount() {
    List<Notification> list = new ArrayList<Notification>();
    for (GraphObject o : getAdapter().getItems()) {
        if (o instanceof Notification) {
            if (((Notification) o).getIs_unread() == true) {
                list.add((Notification) o);
            }
        }
    }
    long lastCheckedTime = KlyphPreferences.getLastCheckedNotificationTime();
    int count = 0;
    for (Notification notification : list) {
        long nTime = 0;
        try {
            nTime = Long.parseLong(notification.getUpdated_time());
        } catch (NumberFormatException e) {
        }
        if (nTime > lastCheckedTime)
            count++;
    }
    return count;
}
Also used : ArrayList(java.util.ArrayList) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject) Notification(com.abewy.android.apps.klyph.core.fql.Notification) KlyphNotification(com.abewy.android.apps.klyph.KlyphNotification)

Example 3 with Notification

use of com.abewy.android.apps.klyph.core.fql.Notification in project Klyph by jonathangerbaud.

the class Notifications method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.menu_dismiss) {
        List<GraphObject> list = new ArrayList<GraphObject>();
        List<List<AsyncRequest>> batchs = new ArrayList<List<AsyncRequest>>();
        List<AsyncRequest> requests = new ArrayList<AsyncRequest>();
        batchs.add(requests);
        for (GraphObject o : getAdapter().getItems()) {
            if (o instanceof Notification || o instanceof FriendRequest) {
                if (o instanceof Notification) {
                    Notification n = (Notification) o;
                    if (requests.size() == 40) {
                        requests = new ArrayList<AsyncRequest>();
                        batchs.add(requests);
                    }
                    requests.add(new AsyncRequest(Query.POST_READ_NOTIFICATION, n.getNotification_id(), "", null));
                    n.setIs_unread(false);
                }
                list.add(o);
            }
        }
        populate(list);
        unreadCount = 0;
        getActivity().invalidateOptionsMenu();
        for (List<AsyncRequest> batch : batchs) {
            if (batch.size() > 0)
                AsyncRequest.executeBatch(batch);
        }
        ((NotificationsListener) getActivity()).onNewNotifications();
        return true;
    } else if (item.getItemId() == R.id.menu_refresh) {
        onRefreshClicked();
        return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : AsyncRequest(com.abewy.android.apps.klyph.request.AsyncRequest) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) FriendRequest(com.abewy.android.apps.klyph.core.fql.FriendRequest) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject) Notification(com.abewy.android.apps.klyph.core.fql.Notification) KlyphNotification(com.abewy.android.apps.klyph.KlyphNotification)

Example 4 with Notification

use of com.abewy.android.apps.klyph.core.fql.Notification in project Klyph by jonathangerbaud.

the class Notifications method onResume.

@Override
public void onResume() {
    super.onResume();
    getActivity().registerReceiver(mMessageReceiver, new IntentFilter(KlyphBundleExtras.NOTIFICATION_EVENT));
    getActivity().registerReceiver(mMessageReceiver, new IntentFilter("com.abewy.android.apps.klyph.action.NOTIFICATION_STATUS_CHANGE"));
    // Update list in case some items have been read
    if (getAdapter() != null) {
        List<GraphObject> list = new ArrayList<GraphObject>();
        for (GraphObject o : getAdapter().getItems()) {
            if (o instanceof Notification || o instanceof FriendRequest)
                list.add(o);
        }
        populate(list);
    }
    // If last update greater than 1 min, do an update
    if ((new Date().getTime() - lastUpdateTime > 1 * 60 * 1000) || KlyphPreferences.hasNotificationReadStatusChanged()) {
        KlyphPreferences.setNotificationReadStatusChanged(false);
        if (hasPermissions() && loggedIn == true) {
            loadNotifications();
        }
    }
}
Also used : IntentFilter(android.content.IntentFilter) ArrayList(java.util.ArrayList) FriendRequest(com.abewy.android.apps.klyph.core.fql.FriendRequest) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject) Notification(com.abewy.android.apps.klyph.core.fql.Notification) KlyphNotification(com.abewy.android.apps.klyph.KlyphNotification) Date(java.util.Date)

Example 5 with Notification

use of com.abewy.android.apps.klyph.core.fql.Notification in project Klyph by jonathangerbaud.

the class Notifications method populate.

@Override
protected void populate(List<GraphObject> data) {
    getAdapter().clear(false);
    List<GraphObject> readNotifications = new ArrayList<GraphObject>();
    List<GraphObject> unreadNotifications = new ArrayList<GraphObject>();
    List<GraphObject> friendRequests = new ArrayList<GraphObject>();
    for (GraphObject graphObject : data) {
        if (graphObject instanceof Notification) {
            if (((Notification) graphObject).getIs_unread() == true) {
                unreadNotifications.add(graphObject);
            } else {
                readNotifications.add(graphObject);
            }
        } else {
            friendRequests.add(graphObject);
        }
    }
    List<GraphObject> list = new ArrayList<GraphObject>();
    unreadCount = unreadNotifications.size();
    if (unreadNotifications.size() > 0) {
        unreadNotifications.get(unreadNotifications.size() - 1).setShowDivider(false);
        Header nTitle = new Header();
        nTitle.setName(getString(R.string.notifications_unread_header_title, unreadNotifications.size()));
        list.add(nTitle);
        list.addAll(unreadNotifications);
    }
    if (readNotifications.size() > 0) {
        readNotifications.get(readNotifications.size() - 1).setShowDivider(false);
        Header nTitle = new Header();
        nTitle.setName(getString(R.string.notifications_read_header_title));
        list.add(nTitle);
        list.addAll(readNotifications);
    }
    if (friendRequests.size() > 0) {
        friendRequests.get(friendRequests.size() - 1).setShowDivider(false);
        Header fTitle = new Header();
        fTitle.setName(getString(R.string.notifications_friend_request_header_title));
        list.add(fTitle);
        list.addAll(friendRequests);
    }
    super.populate(list);
    lastUpdateTime = new Date().getTime();
    setActionBarRefreshItemLoading(false);
    ((NotificationsListener) getActivity()).onNewNotifications();
// getActivity().supportInvalidateOptionsMenu();
/*
		 * if (data.size() > 0)
		 * setOffset(((Notification) data.get(data.size() - 1)).getCreated_time());
		 */
}
Also used : Header(com.abewy.klyph.items.Header) ArrayList(java.util.ArrayList) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject) Notification(com.abewy.android.apps.klyph.core.fql.Notification) KlyphNotification(com.abewy.android.apps.klyph.KlyphNotification) Date(java.util.Date)

Aggregations

Notification (com.abewy.android.apps.klyph.core.fql.Notification)8 KlyphNotification (com.abewy.android.apps.klyph.KlyphNotification)6 GraphObject (com.abewy.android.apps.klyph.core.graph.GraphObject)6 ArrayList (java.util.ArrayList)5 FriendRequest (com.abewy.android.apps.klyph.core.fql.FriendRequest)3 Header (com.abewy.klyph.items.Header)2 Date (java.util.Date)2 List (java.util.List)2 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Handler (android.os.Handler)1 AbsListView (android.widget.AbsListView)1 MultiObjectAdapter (com.abewy.android.apps.klyph.adapter.MultiObjectAdapter)1 PicturePrimarySecondaryTextHolder (com.abewy.android.apps.klyph.adapter.holder.PicturePrimarySecondaryTextHolder)1 AsyncRequest (com.abewy.android.apps.klyph.request.AsyncRequest)1 ProfileImageView (com.abewy.android.apps.klyph.widget.ProfileImageView)1 OnDismissCallback (com.haarman.listviewanimations.itemmanipulation.OnDismissCallback)1