mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-12-23 19:31:30 +00:00
Added option to show normal priority notification (fixes #366).
This commit is contained in:
parent
cb6a3fc884
commit
54820d20f4
4 changed files with 34 additions and 16 deletions
|
@ -92,7 +92,7 @@ public class SyncthingService extends Service implements
|
|||
public static final String PREF_SYNC_ONLY_WIFI = "sync_only_wifi";
|
||||
public static final String PREF_SYNC_ONLY_CHARGING = "sync_only_charging";
|
||||
public static final String PREF_USE_ROOT = "use_root";
|
||||
private static final String PREF_PERSISTENT_NOTIFICATION = "persistent_notification";
|
||||
private static final String PREF_NOTIFICATION_TYPE = "notification_type";
|
||||
|
||||
private static final int NOTIFICATION_ACTIVE = 1;
|
||||
|
||||
|
@ -242,22 +242,24 @@ public class SyncthingService extends Service implements
|
|||
|
||||
/**
|
||||
* Shows or hides the persistent notification based on running state and
|
||||
* {@link #PREF_PERSISTENT_NOTIFICATION}.
|
||||
* {@link #PREF_NOTIFICATION_TYPE}.
|
||||
*/
|
||||
private void updateNotification() {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String type = sp.getString(PREF_NOTIFICATION_TYPE, "low_priority");
|
||||
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
if ((mCurrentState == State.ACTIVE || mCurrentState == State.STARTING) &&
|
||||
sp.getBoolean(PREF_PERSISTENT_NOTIFICATION, true)) {
|
||||
Notification n = new NotificationCompat.Builder(this)
|
||||
!type.equals("none")) {
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
|
||||
.setContentTitle(getString(R.string.syncthing_active))
|
||||
.setSmallIcon(R.drawable.ic_stat_notify)
|
||||
.setOngoing(true)
|
||||
.setPriority(NotificationCompat.PRIORITY_MIN)
|
||||
.setContentIntent(PendingIntent.getActivity(this, 0,
|
||||
new Intent(this, MainActivity.class), 0))
|
||||
.build();
|
||||
nm.notify(NOTIFICATION_ACTIVE, n);
|
||||
new Intent(this, MainActivity.class), 0));
|
||||
if (type.equals("low_priority"))
|
||||
builder.setPriority(NotificationCompat.PRIORITY_MIN);
|
||||
|
||||
nm.notify(NOTIFICATION_ACTIVE, builder.build());
|
||||
} else {
|
||||
nm.cancel(NOTIFICATION_ACTIVE);
|
||||
}
|
||||
|
@ -265,7 +267,7 @@ public class SyncthingService extends Service implements
|
|||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (key.equals(PREF_PERSISTENT_NOTIFICATION))
|
||||
if (key.equals(PREF_NOTIFICATION_TYPE))
|
||||
updateNotification();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources translatable="false">
|
||||
|
||||
<string-array name="compress_values">
|
||||
<item>never</item>
|
||||
<item>metadata</item>
|
||||
<item>always</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="notification_type_entry_values">
|
||||
<item>normal</item>
|
||||
<item>low_priority</item>
|
||||
<item>none</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -237,9 +237,15 @@ Please report any problems you encounter via Github.</string>
|
|||
|
||||
<string name="use_root_summary">Run Syncthing as Superuser</string>
|
||||
|
||||
<string name="persistent_notification_title">Persistent Notification</string>
|
||||
<string name="notification_type_title">Notification</string>
|
||||
|
||||
<string name="persistent_notification_summary">Show Notification while Syncthing is running</string>
|
||||
<string name="notification_type_summary">Choose the notification type</string>
|
||||
|
||||
<string-array name="notification_type_entries">
|
||||
<item>Normal</item>
|
||||
<item>Low Priority</item>
|
||||
<item>None</item>
|
||||
</string-array>
|
||||
|
||||
<string name="category_syncthing">Syncthing</string>
|
||||
|
||||
|
|
|
@ -32,11 +32,13 @@
|
|||
android:defaultValue="false"
|
||||
android:enabled="false" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="persistent_notification"
|
||||
android:title="@string/persistent_notification_title"
|
||||
android:summary="@string/persistent_notification_summary"
|
||||
android:defaultValue="true" />
|
||||
<ListPreference
|
||||
android:key="notification_type"
|
||||
android:title="@string/notification_type_title"
|
||||
android:entryValues="@array/notification_type_entry_values"
|
||||
android:entries="@array/notification_type_entries"
|
||||
android:summary="@string/notification_type_summary"
|
||||
android:defaultValue="low_priority" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
|
|
Loading…
Reference in a new issue