Search in sources :

Example 36 with GraphObject

use of com.abewy.android.apps.klyph.core.graph.GraphObject 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 37 with GraphObject

use of com.abewy.android.apps.klyph.core.graph.GraphObject 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 38 with GraphObject

use of com.abewy.android.apps.klyph.core.graph.GraphObject 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 39 with GraphObject

use of com.abewy.android.apps.klyph.core.graph.GraphObject in project Klyph by jonathangerbaud.

the class PostPhotos method setImages.

public void setImages(List<String> uris) {
    MultiObjectAdapter adapter = new MultiObjectAdapter(getListView()) {

        @Override
        protected TypeAdapter<GraphObject> getAdapter(GraphObject object, int layoutType) {
            TypeAdapter<GraphObject> adapter = BaseAdapterSelector.getAdapter(object, layoutType);
            if (adapter != null)
                return adapter;
            if (object instanceof Picture)
                return new GalleryAdapter();
            return null;
        }
    };
    for (String uri : uris) {
        adapter.add(new Picture(uri));
    }
    getGridView().setAdapter(adapter);
    adapter.notifyDataSetChanged();
    setListVisible(true);
}
Also used : MultiObjectAdapter(com.abewy.android.apps.klyph.adapter.MultiObjectAdapter) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject)

Example 40 with GraphObject

use of com.abewy.android.apps.klyph.core.graph.GraphObject in project Klyph by jonathangerbaud.

the class StreamListFragment method populateNewest.

@Override
protected void populateNewest(List<GraphObject> data) {
    int n = data.size();
    if (n > 0) {
        int index = getListView().getFirstVisiblePosition();
        View v = getListView().getChildAt(index);
        int top = v == null ? 0 : v.getTop();
        int lastIndex = -1;
        if (KlyphPreferences.getNewsfeedGoToTop() == false) {
            List<GraphObject> list = new ArrayList<GraphObject>();
            list.addAll(getAdapter().getItems());
            // Looking for a matching post
            outer: for (int i = 0; i < n; i++) {
                Stream stream = (Stream) data.get(i);
                for (int j = 0, m = list.size(); j < m; j++) {
                    if (list.get(j) instanceof Stream) {
                        Stream s = (Stream) list.get(j);
                        Log.d("StreamListFragment", "populateNewest: " + stream.getPost_id() + " " + s.getPost_id());
                        if (stream.getPost_id().equals(s.getPost_id())) {
                            lastIndex = i;
                            // list.add(stream);
                            break outer;
                        }
                    }
                }
            }
            Log.d("StreamListFragment", "populateNewest: " + lastIndex);
            // If no match, then insert all the data
            if (lastIndex == -1)
                lastIndex = data.size();
            // Insert filtered data
            for (int i = lastIndex - 1; i >= 0; i--) {
                list.add(0, data.get(i));
            }
            getAdapter().clear(false);
            getAdapter().addAll(list);
        } else {
            getAdapter().clear(false);
            getAdapter().addAll(data);
            setOffset(((Stream) data.get(data.size() - 1)).getCreated_time());
        }
        if (getListAdapter() instanceof KlyphAnimationAdapter) {
            int firstVisiblePosition = getListView().getFirstVisiblePosition();
            int lastVisiblePosition = getListView().getLastVisiblePosition();
            if (firstVisiblePosition != lastVisiblePosition)
                ((KlyphAnimationAdapter) getListAdapter()).deactivateNext(lastVisiblePosition - firstVisiblePosition);
            else
                ((KlyphAnimationAdapter) getListAdapter()).deactivateNext(1);
        }
        getAdapter().notifyDataSetChanged();
        if (KlyphPreferences.getNewsfeedGoToTop() == false) {
            getListView().setSelectionFromTop(lastIndex, top);
        }
    }
    setNewestLoading(false);
    setPullToRefreshRefreshing(false);
    if (data.size() > 0) {
        storeSessionStreams();
        storeData();
    }
}
Also used : KlyphAnimationAdapter(com.abewy.android.apps.klyph.adapter.animation.KlyphAnimationAdapter) ArrayList(java.util.ArrayList) Stream(com.abewy.android.apps.klyph.core.fql.Stream) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject) View(android.view.View) ListView(android.widget.ListView)

Aggregations

GraphObject (com.abewy.android.apps.klyph.core.graph.GraphObject)101 ArrayList (java.util.ArrayList)71 JSONArray (org.json.JSONArray)41 JSONObject (org.json.JSONObject)16 FriendDeserializer (com.abewy.android.apps.klyph.core.fql.serializer.FriendDeserializer)11 PhotoDeserializer (com.abewy.android.apps.klyph.core.fql.serializer.PhotoDeserializer)9 MultiObjectAdapter (com.abewy.android.apps.klyph.adapter.MultiObjectAdapter)7 Stream (com.abewy.android.apps.klyph.core.fql.Stream)7 View (android.view.View)6 KlyphNotification (com.abewy.android.apps.klyph.KlyphNotification)6 Notification (com.abewy.android.apps.klyph.core.fql.Notification)6 Photo (com.abewy.android.apps.klyph.core.fql.Photo)6 JSONException (org.json.JSONException)6 StreamDeserializer (com.abewy.android.apps.klyph.core.fql.serializer.StreamDeserializer)5 Intent (android.content.Intent)4 ListView (android.widget.ListView)4 Event (com.abewy.android.apps.klyph.core.fql.Event)4 AsyncRequest (com.abewy.android.apps.klyph.request.AsyncRequest)4 TextButtonItem (com.abewy.klyph.items.TextButtonItem)4 AbsListView (android.widget.AbsListView)3