diff --git a/app/src/main/java/eu/faircode/email/ServicePowerControl.java b/app/src/main/java/eu/faircode/email/ServicePowerControl.java
index f6fdbe08ce..56fa0763d1 100644
--- a/app/src/main/java/eu/faircode/email/ServicePowerControl.java
+++ b/app/src/main/java/eu/faircode/email/ServicePowerControl.java
@@ -1,5 +1,24 @@
package eu.faircode.email;
+/*
+ This file is part of FairEmail.
+
+ FairEmail is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ FairEmail is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with FairEmail. If not, see .
+
+ Copyright 2018-2021 by Marcel Bokhorst (M66B)
+*/
+
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@@ -28,23 +47,27 @@ import java.util.function.Consumer;
import io.reactivex.Flowable;
import io.reactivex.processors.ReplayProcessor;
+// https://developer.android.com/guide/topics/ui/device-control
+
@RequiresApi(api = Build.VERSION_CODES.R)
public class ServicePowerControl extends ControlsProviderService {
private ReplayProcessor updatePublisher;
- private static String DEVICE_SYNC = BuildConfig.APPLICATION_ID + ".sync";
+ private static String DEVICE_SYNC_TOGGLE = BuildConfig.APPLICATION_ID + ".sync_toggle";
@NonNull
@Override
public Flow.Publisher createPublisherForAllAvailable() {
List controls = new ArrayList<>();
- Control control = new Control.StatelessBuilder(DEVICE_SYNC, getPendingIntent())
+
+ Control controlSyncToggle = new Control.StatelessBuilder(DEVICE_SYNC_TOGGLE, getPendingIntent())
.setCustomIcon(Icon.createWithResource(this, R.drawable.twotone_sync_24))
- .setTitle(getString(R.string.app_name))
- .setSubtitle(getString(R.string.title_widget_title_sync))
+ .setTitle(getString(R.string.title_power_menu_sync))
+ .setSubtitle(getString(R.string.title_power_menu_on_off))
.setDeviceType(DeviceTypes.TYPE_GENERIC_ON_OFF)
.build();
- controls.add(control);
+ controls.add(controlSyncToggle);
+
return FlowAdapters.toFlowPublisher(Flowable.fromIterable(controls));
}
@@ -53,27 +76,27 @@ public class ServicePowerControl extends ControlsProviderService {
public Flow.Publisher createPublisherFor(@NonNull List controlIds) {
updatePublisher = ReplayProcessor.create();
- if (controlIds.contains(DEVICE_SYNC)) {
+ if (controlIds.contains(DEVICE_SYNC_TOGGLE)) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean enabled = prefs.getBoolean("enabled", true);
- Control control = new Control.StatefulBuilder(DEVICE_SYNC, getPendingIntent())
+ Control controlSyncToggle = new Control.StatefulBuilder(DEVICE_SYNC_TOGGLE, getPendingIntent())
.setCustomIcon(Icon.createWithResource(this, enabled
? R.drawable.twotone_sync_24
: R.drawable.twotone_sync_disabled_24))
- .setTitle(getString(R.string.app_name))
+ .setTitle(getString(R.string.title_power_menu_sync))
.setSubtitle(getString(enabled
- ? R.string.title_legend_synchronize_on
- : R.string.title_legend_synchronize_off))
+ ? R.string.title_power_menu_on
+ : R.string.title_power_menu_off))
.setDeviceType(DeviceTypes.TYPE_GENERIC_ON_OFF)
.setStatus(Control.STATUS_OK)
.setControlTemplate(new ToggleTemplate(
- DEVICE_SYNC,
+ DEVICE_SYNC_TOGGLE,
new ControlButton(enabled, getString(R.string.title_widget_title_sync))
))
.build();
- updatePublisher.onNext(control);
+ updatePublisher.onNext(controlSyncToggle);
}
return FlowAdapters.toFlowPublisher(updatePublisher);
@@ -88,23 +111,23 @@ public class ServicePowerControl extends ControlsProviderService {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
prefs.edit().putBoolean("enabled", enabled).apply();
- Control control = new Control.StatefulBuilder(DEVICE_SYNC, getPendingIntent())
+ Control controlSyncToggle = new Control.StatefulBuilder(DEVICE_SYNC_TOGGLE, getPendingIntent())
.setCustomIcon(Icon.createWithResource(this, enabled
? R.drawable.twotone_sync_24
: R.drawable.twotone_sync_disabled_24))
- .setTitle(getString(R.string.app_name))
+ .setTitle(getString(R.string.title_power_menu_sync))
.setSubtitle(getString(enabled
- ? R.string.title_legend_synchronize_on
- : R.string.title_legend_synchronize_off))
+ ? R.string.title_power_menu_on
+ : R.string.title_power_menu_off))
.setDeviceType(DeviceTypes.TYPE_GENERIC_ON_OFF)
.setStatus(Control.STATUS_OK)
.setControlTemplate(new ToggleTemplate(
- DEVICE_SYNC,
- new ControlButton(enabled, getString(R.string.title_widget_title_sync))
+ DEVICE_SYNC_TOGGLE,
+ new ControlButton(enabled, getString(R.string.title_power_menu_on_off))
))
.build();
- updatePublisher.onNext(control);
+ updatePublisher.onNext(controlSyncToggle);
}
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 0ab5e6c940..ed94fdf112 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -536,7 +536,7 @@
Max AES key size: %1$d
- Add actions to the power menu
+ Add actions to the Android power menu
Allow other apps to search in messages
Show frequently used contacts in Android share menu
Build search index
@@ -1581,6 +1581,11 @@
Message list
Sync on/off
+ Synchronization
+ On
+ Off
+ On/Off
+
Account
All
Folder