diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/services/NotificationsService.java b/app/src/main/java/org/communiquons/android/comunic/client/data/services/NotificationsService.java index 2a33272..a24cd1d 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/services/NotificationsService.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/services/NotificationsService.java @@ -28,6 +28,7 @@ import static org.communiquons.android.comunic.client.ui.Constants.Notifications import static org.communiquons.android.comunic.client.ui.Constants.NotificationsChannels.GLOBAL_CHANNEL_DESCRIPTION; import static org.communiquons.android.comunic.client.ui.Constants.NotificationsChannels.GLOBAL_CHANNEL_ID; import static org.communiquons.android.comunic.client.ui.Constants.NotificationsChannels.GLOBAL_CHANNEL_NAME; +import static org.communiquons.android.comunic.client.ui.Constants.PreferencesKeys.PREFERENCE_ACCELERATE_NOTIFICATIONS_REFRESH; /** * Notifications service @@ -104,7 +105,10 @@ public class NotificationsService extends IntentService { try { //Make a pause - Thread.sleep(30000); + int secs = PreferencesUtils.getBoolean( + this, PREFERENCE_ACCELERATE_NOTIFICATIONS_REFRESH, false) ? + 2 /* high frequency */ : 30 /* low frequency */; + Thread.sleep(secs*1000); } catch (InterruptedException e){ Thread.currentThread().interrupt(); } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/utils/PreferencesUtils.java b/app/src/main/java/org/communiquons/android/comunic/client/data/utils/PreferencesUtils.java index f6db42c..7ff1c69 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/utils/PreferencesUtils.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/utils/PreferencesUtils.java @@ -27,4 +27,15 @@ public class PreferencesUtils { return sharedPrefs.getBoolean(key, def); } + /** + * Set (save) a new boolean preference + * + * @param context Application context + * @param key The name of the key to change + * @param value New value for the key + */ + public static void setBoolean(Context context, String key, boolean value){ + PreferenceManager.getDefaultSharedPreferences(context) + .edit().putBoolean(key, value).apply(); + } } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/Constants.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/Constants.java index 0d1d374..a8787fc 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/Constants.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/Constants.java @@ -112,4 +112,22 @@ public final class Constants { public static final int CALL_NOTIFICATION_ID = 1; } + + + /** + * Preferences keys + */ + public final class PreferencesKeys { + + /** + * Enable debug mode + */ + public static final String PREFERENCE_ENABLE_DEBUG_MODE = "enable_debug_mode"; + + /** + * Accelerate notifications refresh + */ + public static final String PREFERENCE_ACCELERATE_NOTIFICATIONS_REFRESH + = "accelerate_notifications_refresh"; + } } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java index 3419cb6..e1b8a7b 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java @@ -66,6 +66,8 @@ import java.util.Objects; import static org.communiquons.android.comunic.client.ui.Constants.IntentRequestCode.MAIN_ACTIVITY_GLOBAL_SEARCH_INTENT; import static org.communiquons.android.comunic.client.ui.Constants.IntentRequestCode.MAIN_ACTIVITY_SEARCH_USER_INTENT; +import static org.communiquons.android.comunic.client.ui.Constants.PreferencesKeys.PREFERENCE_ACCELERATE_NOTIFICATIONS_REFRESH; +import static org.communiquons.android.comunic.client.ui.Constants.PreferencesKeys.PREFERENCE_ENABLE_DEBUG_MODE; /** @@ -238,9 +240,17 @@ public class MainActivity extends BaseActivity implements getMenuInflater().inflate(R.menu.main_menu, menu); //Check if the debug menu has to be shown or not - if (PreferencesUtils.getBoolean(this, "enable_debug_mode", false)) { + if (PreferencesUtils.getBoolean(this, PREFERENCE_ENABLE_DEBUG_MODE, false)) { SubMenu debugMenu = menu.addSubMenu(R.string.menu_debug_title); getMenuInflater().inflate(R.menu.debug_menu, debugMenu); + + debugMenu.findItem(R.id.action_accelerate_notifications_refresh).setChecked( + PreferencesUtils.getBoolean( + this, + PREFERENCE_ACCELERATE_NOTIFICATIONS_REFRESH, + false + ) + ); } return true; @@ -293,6 +303,19 @@ public class MainActivity extends BaseActivity implements return true; } + //Check if we have to accelerate notifications refresh + if(id == R.id.action_accelerate_notifications_refresh){ + + boolean enable = !PreferencesUtils.getBoolean( + this, PREFERENCE_ACCELERATE_NOTIFICATIONS_REFRESH, false); + + PreferencesUtils.setBoolean( + this, + PREFERENCE_ACCELERATE_NOTIFICATIONS_REFRESH, + enable); + return true; + } + return super.onOptionsItemSelected(item); } diff --git a/app/src/main/res/menu/debug_menu.xml b/app/src/main/res/menu/debug_menu.xml index 79b228d..a7172b5 100644 --- a/app/src/main/res/menu/debug_menu.xml +++ b/app/src/main/res/menu/debug_menu.xml @@ -1,6 +1,11 @@ + + diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index a9ba16f..13ec0b6 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -324,4 +324,5 @@ Répondre Rejeter %s vous appelle. + Accélérer le rafraîchissement des notifications \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 08ccabf..5e97afd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -323,4 +323,5 @@ Respond Reject call %s is calling you + Accelerate notifications refresh