Can accelerate notifications refresh in debug mode.

This commit is contained in:
Pierre HUBERT 2019-02-25 13:41:40 +01:00
parent a5c8b1825f
commit 6b3d46f04f
7 changed files with 65 additions and 2 deletions

View File

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

View File

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

View File

@ -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";
}
}

View File

@ -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);
}

View File

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_accelerate_notifications_refresh"
android:title="@string/action_accelerate_notifications_refresh"
android:checkable="true"/>
<item
android:id="@+id/action_clear_local_db"
android:title="@string/menu_clear_local_db"/>

View File

@ -324,4 +324,5 @@
<string name="notification_call_accept">Répondre</string>
<string name="notification_call_reject">Rejeter</string>
<string name="notification_call_content">%s vous appelle.</string>
<string name="action_accelerate_notifications_refresh">Accélérer le rafraîchissement des notifications</string>
</resources>

View File

@ -323,4 +323,5 @@
<string name="notification_call_accept">Respond</string>
<string name="notification_call_reject">Reject call</string>
<string name="notification_call_content">%s is calling you</string>
<string name="action_accelerate_notifications_refresh">Accelerate notifications refresh</string>
</resources>