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;
}
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);
}
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();
}
}
}
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);
}
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();
}
}
Aggregations