diff --git a/app/src/main/java/eu/faircode/email/ActivitySetup.java b/app/src/main/java/eu/faircode/email/ActivitySetup.java
index dd4bc8336c..b75ed2303e 100644
--- a/app/src/main/java/eu/faircode/email/ActivitySetup.java
+++ b/app/src/main/java/eu/faircode/email/ActivitySetup.java
@@ -40,10 +40,12 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On
static final int REQUEST_PERMISSION = 1;
static final int REQUEST_CHOOSE_ACCOUNT = 2;
- static final int REQUEST_EXPORT = 3;
- static final int REQUEST_IMPORT = 4;
+ static final int REQUEST_SOUND = 3;
- static final int REQUEST_ERROR = 5;
+ static final int REQUEST_EXPORT = 4;
+ static final int REQUEST_IMPORT = 5;
+
+ static final int REQUEST_ERROR = 6;
static final String ACTION_EDIT_ACCOUNT = BuildConfig.APPLICATION_ID + ".EDIT_ACCOUNT";
static final String ACTION_EDIT_IDENTITY = BuildConfig.APPLICATION_ID + ".EDIT_IDENTITY";
diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java
index ac29baee66..475f591ec7 100644
--- a/app/src/main/java/eu/faircode/email/FragmentOptions.java
+++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java
@@ -20,8 +20,12 @@ package eu.faircode.email;
*/
import android.content.Context;
+import android.content.Intent;
import android.content.SharedPreferences;
+import android.media.RingtoneManager;
import android.net.ConnectivityManager;
+import android.net.Uri;
+import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
@@ -29,6 +33,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
+import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.Spinner;
@@ -40,6 +45,8 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat;
+import static android.app.Activity.RESULT_OK;
+
public class FragmentOptions extends FragmentEx implements SharedPreferences.OnSharedPreferenceChangeListener {
private SwitchCompat swEnabled;
private SwitchCompat swMetered;
@@ -50,6 +57,7 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
private SwitchCompat swIdenticons;
private SwitchCompat swPreview;
private SwitchCompat swLight;
+ private Button btnSound;
private SwitchCompat swBrowse;
private SwitchCompat swSwipe;
private SwitchCompat swActionbar;
@@ -78,6 +86,7 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
swIdenticons = view.findViewById(R.id.swIdenticons);
swPreview = view.findViewById(R.id.swPreview);
swLight = view.findViewById(R.id.swLight);
+ btnSound = view.findViewById(R.id.btnSound);
swBrowse = view.findViewById(R.id.swBrowse);
swSwipe = view.findViewById(R.id.swSwipe);
swActionbar = view.findViewById(R.id.swActionbar);
@@ -200,6 +209,19 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
}
});
+ btnSound.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ String sound = prefs.getString("sound", null);
+ Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
+ intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
+ intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getString(R.string.title_advanced_sound));
+ intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
+ intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, sound == null ? null : Uri.parse(sound));
+ startActivityForResult(intent, ActivitySetup.REQUEST_SOUND);
+ }
+ });
+
swBrowse.setChecked(prefs.getBoolean("browse", true));
swBrowse.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
@@ -293,13 +315,32 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
}
});
- swLight.setVisibility(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ? View.VISIBLE : View.GONE);
+ swLight.setVisibility(BuildConfig.DEBUG || Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ? View.VISIBLE : View.GONE);
+ btnSound.setVisibility(BuildConfig.DEBUG || Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ? View.VISIBLE : View.GONE);
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
return view;
}
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ Log.i(Helper.TAG, "Result class=" + this.getClass().getSimpleName() +
+ " request=" + requestCode + " result=" + resultCode + " data=" + data);
+
+ if (requestCode == ActivitySetup.REQUEST_SOUND)
+ if (resultCode == RESULT_OK) {
+ Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
+ Log.i(Helper.TAG, "Selected ringtone=" + uri);
+
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
+ if (uri == null)
+ prefs.edit().remove("sound").apply();
+ else
+ prefs.edit().putString("sound", uri.toString()).apply();
+ }
+ }
+
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if ("enabled".equals(key))
diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java
index 047fa6940b..d79bdc77c8 100644
--- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java
+++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java
@@ -495,10 +495,22 @@ public class ServiceSynchronize extends LifecycleService {
else
builder.setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN);
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O &&
- prefs.getBoolean("light", false)) {
- builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS);
- builder.setLights(0xff00ff00, 1000, 1000);
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
+ int defaults = Notification.DEFAULT_VIBRATE;
+
+ if (prefs.getBoolean("light", false)) {
+ defaults |= Notification.FLAG_SHOW_LIGHTS;
+ builder.setLights(0xff00ff00, 1000, 1000);
+ } else
+ defaults += Notification.DEFAULT_LIGHTS;
+
+ String sound = prefs.getString("sound", null);
+ if (sound == null)
+ defaults |= Notification.DEFAULT_SOUND;
+ else
+ builder.setSound(Uri.parse(sound));
+
+ builder.setDefaults(defaults);
}
if (pro) {
diff --git a/app/src/main/res/layout/fragment_options.xml b/app/src/main/res/layout/fragment_options.xml
index 3a3b1ee835..44c1a891fe 100644
--- a/app/src/main/res/layout/fragment_options.xml
+++ b/app/src/main/res/layout/fragment_options.xml
@@ -92,6 +92,18 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swPreview" />
+
+
+ app:layout_constraintTop_toBottomOf="@id/btnSound" />
Show identicons
Show message preview
Use notification light
+ Select notification sound
Browse messages on the server
Swipe actions
Conversation action bar