mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-31 14:17:03 +02:00
Power menu localization
This commit is contained in:
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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<Control> 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<Control> createPublisherFor(@NonNull List<String> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user