diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java index 61742c78e2..a919405508 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java @@ -23,16 +23,20 @@ import static android.app.Activity.RESULT_OK; import android.app.NotificationChannel; import android.app.NotificationManager; +import android.app.StatusBarManager; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.graphics.Paint; +import android.graphics.drawable.Icon; import android.media.RingtoneManager; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.provider.Settings; +import android.service.quicksettings.TileService; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -56,6 +60,8 @@ import androidx.lifecycle.Lifecycle; import androidx.preference.PreferenceManager; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.function.Consumer; public class FragmentOptionsNotifications extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { private ImageButton ibHelp; @@ -109,12 +115,18 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared private SwitchCompat swBiometricsNotify; private SwitchCompat swBackground; private SwitchCompat swAlertOnce; + private ImageButton ibTileSync; + private ImageButton ibTileUnseen; private TextView tvNoGrouping; private TextView tvNoChannels; private Group grpChannel; private Group grpProperties; private Group grpBackground; + private Group grpTiles; + + private static final ExecutorService executor = + Helper.getBackgroundExecutor(1, "notifications"); private final static String[] RESET_OPTIONS = new String[]{ "notify_newest_first", "notify_summary", @@ -192,12 +204,15 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared swBiometricsNotify = view.findViewById(R.id.swBiometricsNotify); swBackground = view.findViewById(R.id.swBackground); swAlertOnce = view.findViewById(R.id.swAlertOnce); + ibTileSync = view.findViewById(R.id.ibTileSync); + ibTileUnseen = view.findViewById(R.id.ibTileUnseen); tvNoGrouping = view.findViewById(R.id.tvNoGrouping); tvNoChannels = view.findViewById(R.id.tvNoChannels); grpChannel = view.findViewById(R.id.grpChannel); grpProperties = view.findViewById(R.id.grpProperties); grpBackground = view.findViewById(R.id.grpBackground); + grpTiles = view.findViewById(R.id.grpTiles); setOptions(); @@ -598,6 +613,22 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared } }); + ibTileSync.setOnClickListener(new View.OnClickListener() { + @Override + @RequiresApi(api = Build.VERSION_CODES.TIRAMISU) + public void onClick(View v) { + addTile(v.getContext(), ServiceTileSynchronize.class, R.string.tile_synchronize, R.drawable.twotone_sync_24); + } + }); + + ibTileUnseen.setOnClickListener(new View.OnClickListener() { + @Override + @RequiresApi(api = Build.VERSION_CODES.TIRAMISU) + public void onClick(View v) { + addTile(v.getContext(), ServiceTileUnseen.class, R.string.tile_unseen, R.drawable.twotone_mail_outline_24); + } + }); + // Initialize FragmentDialogTheme.setBackground(getContext(), view, false); @@ -618,6 +649,9 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared grpBackground.setVisibility( Build.VERSION.SDK_INT < Build.VERSION_CODES.O || BuildConfig.DEBUG ? View.VISIBLE : View.GONE); + grpTiles.setVisibility( + Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU || !BuildConfig.DEBUG + ? View.GONE : View.VISIBLE); PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this); @@ -775,4 +809,37 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared prefs.edit().remove("sound").apply(); } } + + @RequiresApi(api = 33) + private void addTile(Context context, Class cls, int title, int icon) { + StatusBarManager sbm = Helper.getSystemService(context, StatusBarManager.class); + sbm.requestAddTileService( + ComponentName.createRelative(context, cls.getName()), + context.getString(title), + Icon.createWithResource(context, icon), + executor, + new Consumer() { + @Override + public void accept(Integer result) { + Log.i("Tile result=" + result + " class=" + cls.getName()); + if (result == null) + return; + switch (result) { + case StatusBarManager.TILE_ADD_REQUEST_RESULT_TILE_ADDED: + case StatusBarManager.TILE_ADD_REQUEST_RESULT_TILE_NOT_ADDED: + break; + case StatusBarManager.TILE_ADD_REQUEST_RESULT_TILE_ALREADY_ADDED: + getMainHandler().post(new Runnable() { + @Override + public void run() { + ToastEx.makeText(context, R.string.tile_already_added, Toast.LENGTH_LONG).show(); + } + }); + break; + default: + Log.e("Tile result=" + result + " class=" + cls.getName()); + } + } + }); + } } diff --git a/app/src/main/res/layout/fragment_options_notifications.xml b/app/src/main/res/layout/fragment_options_notifications.xml index 1a1744375f..15ef06094c 100644 --- a/app/src/main/res/layout/fragment_options_notifications.xml +++ b/app/src/main/res/layout/fragment_options_notifications.xml @@ -837,6 +837,40 @@ app:layout_constraintTop_toBottomOf="@id/tvBackgroundHint" app:switchPadding="12dp" /> + + + + + + + app:layout_constraintTop_toBottomOf="@id/ibTileSync" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7286f0070a..e723e2f02e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -45,6 +45,7 @@ Synchronize New messages + Tile was already added Refresh Compose @@ -656,6 +657,7 @@ Use background service to synchronize messages A background service can be stopped by Android at any time, but doesn\'t require a status bar notification MIUI notification sound workaround + Add quick settings tiles PGP S/MIME