Skip to content

Commit

Permalink
Show account menu if there are notifications for more than one account
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelm committed Jan 23, 2013
1 parent 8b76617 commit 9841599
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/de/geeksfactory/opacclient/frontend/AccountActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public void onCreate(Bundle savedInstanceState) {
NotificationManager nMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nMgr.cancel(OpacClient.NOTIF_ID);
}
if (getIntent().getExtras().getBoolean("showmenu", false)) {
getSlidingMenu().showMenu(false);
}
}

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Expand Down
22 changes: 18 additions & 4 deletions src/de/geeksfactory/opacclient/reminder/ReminderCheckService.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ protected Long[] doInBackground(Object... params) {

long now = new Date().getTime();
long last = sp.getLong("notification_last", 0);
// long warning = Long.decode(sp.getString("notification_warning",
// "367200000"));
long warning = 1000 * 3600 * 24 * 90;
long warning = Long.decode(sp.getString("notification_warning",
"367200000"));
// long warning = 1000 * 3600 * 24 * 90;
long expired_new = 0;
long expired_total = 0;
long affected_accounts = 0;
long first = 0;

OpacClient app = (OpacClient) getApplication();
Expand All @@ -93,6 +94,8 @@ protected Long[] doInBackground(Object... params) {

data.storeCachedAccountData(account, res);

int this_account = 0;

for (ContentValues item : res.getLent()) {
if (item.containsKey(AccountData.KEY_LENT_DEADLINE_TIMESTAMP)) {
long expiring = item
Expand All @@ -102,6 +105,7 @@ protected Long[] doInBackground(Object... params) {
if (expiring >= last) {
expired_new++;
}
this_account++;
}
if (expiring > last) {
last = expiring;
Expand All @@ -112,6 +116,9 @@ protected Long[] doInBackground(Object... params) {
}
}

if (this_account > 0)
affected_accounts++;

} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (SocketException e) {
Expand All @@ -124,7 +131,8 @@ protected Long[] doInBackground(Object... params) {
}
}
data.close();
return new Long[] { expired_new, expired_total, last, first };
return new Long[] { expired_new, expired_total, last, first,
affected_accounts };
}

protected void onPostExecute(Long[] result) {
Expand All @@ -146,6 +154,7 @@ protected void onPostExecute(Long[] result) {
long expired_total = result[1];
long last = result[2];
long first = result[3];
long affected_accounts = result[4];
if (expired_new == 0)
return;

Expand All @@ -172,6 +181,11 @@ protected void onPostExecute(Long[] result) {
Intent notificationIntent = new Intent(ReminderCheckService.this,
AccountActivity.class);
notificationIntent.putExtra("notif_last", last);
if (affected_accounts > 1) {
// If there are notifications for more than one account, account
// menu should be opened
notificationIntent.putExtra("showmenu", true);
}
PendingIntent contentIntent = PendingIntent.getActivity(
ReminderCheckService.this, 0, notificationIntent, 0);
nb.setContentIntent(contentIntent);
Expand Down

0 comments on commit 9841599

Please sign in to comment.