android: bug fix ticket #1249 - notification regardless of preference

This commit is contained in:
Joachim Fritzsch 2013-05-17 19:23:03 +02:00
parent 8df34c4fbf
commit 6131a3c6bb
3 changed files with 16 additions and 19 deletions

View File

@ -172,7 +172,7 @@ public class PrefsActivity extends FragmentActivity {
case R.string.prefs_show_notification_header: //app pref
appPrefs.setShowNotification(isSet);
populateLayout(); // updates status text
ClientNotification.getInstance().enable(getApplicationContext(), isSet);
ClientNotification.getInstance().update(getApplicationContext());
break;
case R.string.prefs_show_advanced_header: //app pref
appPrefs.setShowAdvanced(isSet);

View File

@ -12,6 +12,8 @@ public class ClientNotification {
//private static final String TAG = "ClientNotification";
private static ClientNotification clientNotification = null;
public Notification notification;
private boolean mIsEnabled = true;
private int mOldComputingStatus = -1;
@ -34,7 +36,17 @@ public class ClientNotification {
* @param context
* @param updatedStatus new status
*/
public synchronized void update(Context context, ClientStatus updatedStatus) {
public synchronized void update(Context context) {
// check whether notification is allowed in preferences
if (!Monitor.getAppPrefs().getShowNotification()) {
hide(context);
return;
}
// get current client status
ClientStatus updatedStatus = Monitor.getClientStatus();
// update notification
if (clientNotification.mOldComputingStatus == -1
|| updatedStatus.computingStatus.intValue() != clientNotification.mOldComputingStatus
|| (updatedStatus.computingStatus == ClientStatus.COMPUTING_STATUS_SUSPENDED && updatedStatus.computingSuspendReason != clientNotification.mOldSuspendReason)) {
@ -45,21 +57,6 @@ public class ClientNotification {
}
}
/**
* Set notification enabled/disabled
* @param context
* @param enabled
*/
public synchronized void enable(Context context, boolean enabled) {
clientNotification.mIsEnabled = enabled;
if (clientNotification.mIsEnabled) {
if (clientNotification.mOldComputingStatus != -1)
updateNotification(context, clientNotification.mOldComputingStatus);
} else {
hide(context);
}
}
private void updateNotification(Context context, int status) {
switch(status) {
case ClientStatus.COMPUTING_STATUS_NEVER:
@ -85,7 +82,7 @@ public class ClientNotification {
Integer notificationId = context.getResources().getInteger(R.integer.autostart_notification_id);
// Set the icon, scrolling text and time-stamp
Notification notification = new Notification(
notification = new Notification(
icon,
statusText,
System.currentTimeMillis());

View File

@ -964,7 +964,7 @@ public class Monitor extends Service {
if( (status != null) && (state != null) && (state.results != null) && (state.projects != null) && (transfers != null)) {
Monitor.getClientStatus().setClientStatus(status, state.results, state.projects, transfers);
// Update status bar notification
ClientNotification.getInstance().update(getApplicationContext(), getClientStatus());
ClientNotification.getInstance().update(getApplicationContext());
} else {
Log.d(TAG, "client status connection problem");
}