Skip to content

Commit

Permalink
Fix a few crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
c99koder committed Sep 25, 2015
1 parent 09dcbd2 commit f61d741
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/com/irccloud/android/NetworkConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -1794,7 +1794,8 @@ public void parse(IRCCloudJSONObject object) throws JSONException {
put("set_ignores", new Parser() {
@Override
public void parse(IRCCloudJSONObject object) throws JSONException {
mServers.getServer(object.cid()).updateIgnores(object.getJsonNode("masks"));
if(mServers.getServer(object.cid()) != null)
mServers.getServer(object.cid()).updateIgnores(object.getJsonNode("masks"));
if (!backlog)
notifyHandlers(EVENT_SETIGNORES, object);
}
Expand Down Expand Up @@ -2452,7 +2453,8 @@ public void parse(IRCCloudJSONObject object) throws JSONException {
public void parse(IRCCloudJSONObject object) throws JSONException {
if (!backlog) {
mUsers.updateAwayMsg(object.bid(), object.getString("nick"), 1, object.getString("away_msg"));
mServers.getServer(object.cid()).setAway(object.getString("away_msg"));
if(mServers.getServer(object.cid()) != null)
mServers.getServer(object.cid()).setAway(object.getString("away_msg"));
notifyHandlers(EVENT_AWAY, object);
}
}
Expand Down Expand Up @@ -2606,11 +2608,11 @@ private synchronized void parse_object(IRCCloudJSONObject object) throws JSONExc
}
if((!backlog || numbuffers > 0) && object.eid() > highest_eid) {
highest_eid = object.eid();
if(!backlog) {
/*if(!backlog) {
SharedPreferences.Editor editor = IRCCloudApplication.getInstance().getApplicationContext().getSharedPreferences("prefs", 0).edit();
editor.putLong("highest_eid", highest_eid);
editor.apply();
}
}*/
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/com/irccloud/android/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3199,7 +3199,8 @@ public void onClick(DialogInterface dialogInterface, int item) {
BuffersListFragment blf = (BuffersListFragment) getSupportFragmentManager().findFragmentById(R.id.BuffersList);
if (blf != null)
blf.refresh();
conn.heartbeat(buffer.getBid(), cids.toArray(new Integer[cids.size()]), bids.toArray(new Integer[bids.size()]), eids.toArray(new Long[eids.size()]));
if(conn != null && buffer != null)
conn.heartbeat(buffer.getBid(), cids.toArray(new Integer[cids.size()]), bids.toArray(new Integer[bids.size()]), eids.toArray(new Long[eids.size()]));
} else if (items[item].equals("Delete")) {
builder = new AlertDialog.Builder(MainActivity.this);
builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB);
Expand Down
13 changes: 11 additions & 2 deletions src/com/irccloud/android/data/collection/NotificationsList.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ public void clearLastSeenEIDs() {
}

public long getLastSeenEid(int bid) {
Buffer b = BuffersList.getInstance().getBuffer(bid);
if(b != null)
return b.getLast_seen_eid();
synchronized (dbLock) {
Notification_LastSeenEID eid = new Select().from(Notification_LastSeenEID.class).where(Condition.column(Notification_LastSeenEID$Table.BID).is(bid)).querySingle();
if (eid != null)
Expand Down Expand Up @@ -178,8 +181,11 @@ public void deleteOldNotifications() {

if (notifications.size() > 0) {
for (Notification n : notifications) {
long last_seen_eid = getLastSeenEid(n.bid);
Buffer b = BuffersList.getInstance().getBuffer(n.bid);
if (n.bid == b.getBid() && n.eid <= b.getLast_seen_eid()) {
if(b != null)
last_seen_eid = b.getLast_seen_eid();
if (n.eid <= last_seen_eid) {
NotificationManagerCompat.from(IRCCloudApplication.getInstance().getApplicationContext()).cancel((int) (n.eid / 1000));
changed = true;
try {
Expand All @@ -194,8 +200,11 @@ public void deleteOldNotifications() {
notifications = getNotifications();

for (Notification n : notifications) {
long last_seen_eid = getLastSeenEid(n.bid);
Buffer b = BuffersList.getInstance().getBuffer(n.bid);
if (b != null && n.bid == b.getBid() && n.eid <= b.getLast_seen_eid()) {
if(b != null)
last_seen_eid = b.getLast_seen_eid();
if (n.eid <= last_seen_eid) {
n.delete();
NotificationManagerCompat.from(IRCCloudApplication.getInstance().getApplicationContext()).cancel(n.bid);
NotificationManagerCompat.from(IRCCloudApplication.getInstance().getApplicationContext()).cancel((int) (n.eid / 1000));
Expand Down

0 comments on commit f61d741

Please sign in to comment.