Power menu localization

pull/199/head
M66B 3 years ago
parent 10803280c3
commit 7428ca96e6

@ -1,5 +1,24 @@
package eu.faircode.email; 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 <http://www.gnu.org/licenses/>.
Copyright 2018-2021 by Marcel Bokhorst (M66B)
*/
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -28,23 +47,27 @@ import java.util.function.Consumer;
import io.reactivex.Flowable; import io.reactivex.Flowable;
import io.reactivex.processors.ReplayProcessor; import io.reactivex.processors.ReplayProcessor;
// https://developer.android.com/guide/topics/ui/device-control
@RequiresApi(api = Build.VERSION_CODES.R) @RequiresApi(api = Build.VERSION_CODES.R)
public class ServicePowerControl extends ControlsProviderService { public class ServicePowerControl extends ControlsProviderService {
private ReplayProcessor updatePublisher; private ReplayProcessor updatePublisher;
private static String DEVICE_SYNC = BuildConfig.APPLICATION_ID + ".sync"; private static String DEVICE_SYNC_TOGGLE = BuildConfig.APPLICATION_ID + ".sync_toggle";
@NonNull @NonNull
@Override @Override
public Flow.Publisher<Control> createPublisherForAllAvailable() { public Flow.Publisher<Control> createPublisherForAllAvailable() {
List controls = new ArrayList<>(); 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)) .setCustomIcon(Icon.createWithResource(this, R.drawable.twotone_sync_24))
.setTitle(getString(R.string.app_name)) .setTitle(getString(R.string.title_power_menu_sync))
.setSubtitle(getString(R.string.title_widget_title_sync)) .setSubtitle(getString(R.string.title_power_menu_on_off))
.setDeviceType(DeviceTypes.TYPE_GENERIC_ON_OFF) .setDeviceType(DeviceTypes.TYPE_GENERIC_ON_OFF)
.build(); .build();
controls.add(control); controls.add(controlSyncToggle);
return FlowAdapters.toFlowPublisher(Flowable.fromIterable(controls)); return FlowAdapters.toFlowPublisher(Flowable.fromIterable(controls));
} }
@ -53,27 +76,27 @@ public class ServicePowerControl extends ControlsProviderService {
public Flow.Publisher<Control> createPublisherFor(@NonNull List<String> controlIds) { public Flow.Publisher<Control> createPublisherFor(@NonNull List<String> controlIds) {
updatePublisher = ReplayProcessor.create(); updatePublisher = ReplayProcessor.create();
if (controlIds.contains(DEVICE_SYNC)) { if (controlIds.contains(DEVICE_SYNC_TOGGLE)) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean enabled = prefs.getBoolean("enabled", true); 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 .setCustomIcon(Icon.createWithResource(this, enabled
? R.drawable.twotone_sync_24 ? R.drawable.twotone_sync_24
: R.drawable.twotone_sync_disabled_24)) : R.drawable.twotone_sync_disabled_24))
.setTitle(getString(R.string.app_name)) .setTitle(getString(R.string.title_power_menu_sync))
.setSubtitle(getString(enabled .setSubtitle(getString(enabled
? R.string.title_legend_synchronize_on ? R.string.title_power_menu_on
: R.string.title_legend_synchronize_off)) : R.string.title_power_menu_off))
.setDeviceType(DeviceTypes.TYPE_GENERIC_ON_OFF) .setDeviceType(DeviceTypes.TYPE_GENERIC_ON_OFF)
.setStatus(Control.STATUS_OK) .setStatus(Control.STATUS_OK)
.setControlTemplate(new ToggleTemplate( .setControlTemplate(new ToggleTemplate(
DEVICE_SYNC, DEVICE_SYNC_TOGGLE,
new ControlButton(enabled, getString(R.string.title_widget_title_sync)) new ControlButton(enabled, getString(R.string.title_widget_title_sync))
)) ))
.build(); .build();
updatePublisher.onNext(control); updatePublisher.onNext(controlSyncToggle);
} }
return FlowAdapters.toFlowPublisher(updatePublisher); return FlowAdapters.toFlowPublisher(updatePublisher);
@ -88,23 +111,23 @@ public class ServicePowerControl extends ControlsProviderService {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
prefs.edit().putBoolean("enabled", enabled).apply(); 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 .setCustomIcon(Icon.createWithResource(this, enabled
? R.drawable.twotone_sync_24 ? R.drawable.twotone_sync_24
: R.drawable.twotone_sync_disabled_24)) : R.drawable.twotone_sync_disabled_24))
.setTitle(getString(R.string.app_name)) .setTitle(getString(R.string.title_power_menu_sync))
.setSubtitle(getString(enabled .setSubtitle(getString(enabled
? R.string.title_legend_synchronize_on ? R.string.title_power_menu_on
: R.string.title_legend_synchronize_off)) : R.string.title_power_menu_off))
.setDeviceType(DeviceTypes.TYPE_GENERIC_ON_OFF) .setDeviceType(DeviceTypes.TYPE_GENERIC_ON_OFF)
.setStatus(Control.STATUS_OK) .setStatus(Control.STATUS_OK)
.setControlTemplate(new ToggleTemplate( .setControlTemplate(new ToggleTemplate(
DEVICE_SYNC, DEVICE_SYNC_TOGGLE,
new ControlButton(enabled, getString(R.string.title_widget_title_sync)) new ControlButton(enabled, getString(R.string.title_power_menu_on_off))
)) ))
.build(); .build();
updatePublisher.onNext(control); updatePublisher.onNext(controlSyncToggle);
} }
} }

@ -536,7 +536,7 @@
</string> </string>
<string name="title_advanced_aes_key_size" translatable="false">Max AES key size: %1$d</string> <string name="title_advanced_aes_key_size" translatable="false">Max AES key size: %1$d</string>
<string name="title_advanced_power_menu">Add actions to the power menu</string> <string name="title_advanced_power_menu">Add actions to the Android power menu</string>
<string name="title_advanced_external_search">Allow other apps to search in messages</string> <string name="title_advanced_external_search">Allow other apps to search in messages</string>
<string name="title_advanced_shortcuts">Show frequently used contacts in Android share menu</string> <string name="title_advanced_shortcuts">Show frequently used contacts in Android share menu</string>
<string name="title_advanced_fts">Build search index</string> <string name="title_advanced_fts">Build search index</string>
@ -1581,6 +1581,11 @@
<string name="title_widget_title_list">Message list</string> <string name="title_widget_title_list">Message list</string>
<string name="title_widget_title_sync">Sync on/off</string> <string name="title_widget_title_sync">Sync on/off</string>
<string name="title_power_menu_sync">Synchronization</string>
<string name="title_power_menu_on">On</string>
<string name="title_power_menu_off">Off</string>
<string name="title_power_menu_on_off">On/Off</string>
<string name="title_widget_account">Account</string> <string name="title_widget_account">Account</string>
<string name="title_widget_account_all">All</string> <string name="title_widget_account_all">All</string>
<string name="title_widget_folder">Folder</string> <string name="title_widget_folder">Folder</string>

Loading…
Cancel
Save