FairEmail/app/src/main/java/eu/faircode/email/FragmentOptionsNotification...

515 lines
22 KiB
Java
Raw Normal View History

2019-05-06 07:10:13 +00:00
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/>.
2020-01-05 17:32:53 +00:00
Copyright 2018-2020 by Marcel Bokhorst (M66B)
2019-05-06 07:10:13 +00:00
*/
import android.content.Intent;
import android.content.SharedPreferences;
2019-06-14 17:05:28 +00:00
import android.content.pm.PackageManager;
2019-05-06 07:10:13 +00:00
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
2019-06-14 17:05:28 +00:00
import android.provider.Settings;
2019-05-06 07:10:13 +00:00
import android.view.LayoutInflater;
2019-05-06 12:41:03 +00:00
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
2019-05-06 07:10:13 +00:00
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
2019-06-28 19:22:20 +00:00
import android.widget.TextView;
2019-07-14 10:32:32 +00:00
import android.widget.Toast;
2019-05-06 07:10:13 +00:00
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat;
import androidx.constraintlayout.widget.Group;
2019-09-10 06:53:07 +00:00
import androidx.lifecycle.Lifecycle;
2019-05-06 07:10:13 +00:00
import androidx.preference.PreferenceManager;
import static android.app.Activity.RESULT_OK;
2019-05-06 12:41:03 +00:00
public class FragmentOptionsNotifications extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
private Button btnManage;
private Button btnManageDefault;
private Button btnManageService;
private SwitchCompat swBackground;
2019-05-06 07:10:13 +00:00
private CheckBox cbNotifyActionTrash;
2019-09-26 19:28:05 +00:00
private CheckBox cbNotifyActionJunk;
private CheckBox cbNotifyActionBlockSender;
2019-05-06 07:10:13 +00:00
private CheckBox cbNotifyActionArchive;
2019-10-23 10:51:20 +00:00
private CheckBox cbNotifyActionMove;
2019-05-06 07:10:13 +00:00
private CheckBox cbNotifyActionReply;
2019-08-24 13:00:14 +00:00
private CheckBox cbNotifyActionReplyDirect;
2019-05-06 08:33:29 +00:00
private CheckBox cbNotifyActionFlag;
private CheckBox cbNotifyActionSeen;
2019-09-24 07:34:43 +00:00
private CheckBox cbNotifyActionSnooze;
2019-06-28 19:22:20 +00:00
private TextView tvNotifyActionsPro;
2019-05-06 07:10:13 +00:00
private SwitchCompat swLight;
private Button btnSound;
2020-03-15 10:50:49 +00:00
private SwitchCompat swBadge;
private SwitchCompat swUnseenIgnored;
private SwitchCompat swNotifyKnown;
2020-06-07 14:32:14 +00:00
private TextView tvNotifyKnownPro;
2020-03-15 10:50:49 +00:00
private SwitchCompat swNotifySummary;
private SwitchCompat swNotifyRemove;
private SwitchCompat swNotifyClear;
private SwitchCompat swNotifyPreview;
private SwitchCompat swNotifyPreviewAll;
private SwitchCompat swWearablePreview;
private SwitchCompat swBiometricsNotify;
private SwitchCompat swAlertOnce;
private TextView tvNoGrouping;
private TextView tvNoChannels;
2019-05-06 07:10:13 +00:00
private Group grpChannel;
2019-05-06 07:10:13 +00:00
private Group grpNotification;
2019-05-06 12:41:03 +00:00
private final static String[] RESET_OPTIONS = new String[]{
"notify_trash", "notify_junk", "notify_block_sender", "notify_archive", "notify_move",
2019-10-23 10:51:20 +00:00
"notify_reply", "notify_reply_direct",
2019-10-06 19:01:01 +00:00
"notify_flag", "notify_seen", "notify_snooze",
2020-03-15 10:50:49 +00:00
"light", "sound",
"badge", "unseen_ignored",
"notify_known", "notify_summary", "notify_remove", "notify_clear",
"notify_preview", "notify_preview_all", "wearable_preview",
"biometrics_notify",
2020-03-15 10:50:49 +00:00
"alert_once"
2019-05-06 12:41:03 +00:00
};
2019-05-06 07:10:13 +00:00
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
2019-06-12 14:15:46 +00:00
setSubtitle(R.string.title_setup);
2019-05-06 12:41:03 +00:00
setHasOptionsMenu(true);
2019-05-06 07:10:13 +00:00
View view = inflater.inflate(R.layout.fragment_options_notifications, container, false);
// Get controls
btnManage = view.findViewById(R.id.btnManage);
btnManageDefault = view.findViewById(R.id.btnManageDefault);
btnManageService = view.findViewById(R.id.btnManageService);
swBackground = view.findViewById(R.id.swBackground);
2019-05-06 07:10:13 +00:00
cbNotifyActionTrash = view.findViewById(R.id.cbNotifyActionTrash);
2019-09-26 19:28:05 +00:00
cbNotifyActionJunk = view.findViewById(R.id.cbNotifyActionJunk);
cbNotifyActionBlockSender = view.findViewById(R.id.cbNotifyActionBlockSender);
2019-05-06 07:10:13 +00:00
cbNotifyActionArchive = view.findViewById(R.id.cbNotifyActionArchive);
2019-10-23 10:51:20 +00:00
cbNotifyActionMove = view.findViewById(R.id.cbNotifyActionMove);
2019-05-06 07:10:13 +00:00
cbNotifyActionReply = view.findViewById(R.id.cbNotifyActionReply);
2019-08-24 13:00:14 +00:00
cbNotifyActionReplyDirect = view.findViewById(R.id.cbNotifyActionReplyDirect);
2019-05-06 08:33:29 +00:00
cbNotifyActionFlag = view.findViewById(R.id.cbNotifyActionFlag);
2019-05-06 07:10:13 +00:00
cbNotifyActionSeen = view.findViewById(R.id.cbNotifyActionSeen);
2019-09-24 07:34:43 +00:00
cbNotifyActionSnooze = view.findViewById(R.id.cbNotifyActionSnooze);
2019-06-28 19:22:20 +00:00
tvNotifyActionsPro = view.findViewById(R.id.tvNotifyActionsPro);
2019-05-06 07:10:13 +00:00
swLight = view.findViewById(R.id.swLight);
btnSound = view.findViewById(R.id.btnSound);
2020-03-15 10:50:49 +00:00
swBadge = view.findViewById(R.id.swBadge);
swUnseenIgnored = view.findViewById(R.id.swUnseenIgnored);
swNotifyKnown = view.findViewById(R.id.swNotifyKnown);
2020-06-07 14:32:14 +00:00
tvNotifyKnownPro = view.findViewById(R.id.tvNotifyKnownPro);
2020-03-15 10:50:49 +00:00
swNotifySummary = view.findViewById(R.id.swNotifySummary);
swNotifyRemove = view.findViewById(R.id.swNotifyRemove);
swNotifyClear = view.findViewById(R.id.swNotifyClear);
swNotifyPreview = view.findViewById(R.id.swNotifyPreview);
swNotifyPreviewAll = view.findViewById(R.id.swNotifyPreviewAll);
swWearablePreview = view.findViewById(R.id.swWearablePreview);
swBiometricsNotify = view.findViewById(R.id.swBiometricsNotify);
swAlertOnce = view.findViewById(R.id.swAlertOnce);
tvNoGrouping = view.findViewById(R.id.tvNoGrouping);
tvNoChannels = view.findViewById(R.id.tvNoChannels);
2019-05-06 07:10:13 +00:00
grpChannel = view.findViewById(R.id.grpChannel);
2019-05-06 07:10:13 +00:00
grpNotification = view.findViewById(R.id.grpNotification);
2019-05-06 13:30:30 +00:00
setOptions();
2019-05-06 07:10:13 +00:00
// Wire controls
PackageManager pm = getContext().getPackageManager();
2019-05-06 07:10:13 +00:00
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
final Intent manage = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
.putExtra("app_package", getContext().getPackageName())
.putExtra("app_uid", getContext().getApplicationInfo().uid)
.putExtra(Settings.EXTRA_APP_PACKAGE, getContext().getPackageName());
2020-06-14 16:34:13 +00:00
btnManage.setEnabled(manage.resolveActivity(pm) != null); // system whitelisted
btnManage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(manage);
}
});
final Intent channelNotification = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, getContext().getPackageName())
.putExtra(Settings.EXTRA_CHANNEL_ID, "notification");
2020-06-14 16:34:13 +00:00
btnManageDefault.setEnabled(channelNotification.resolveActivity(pm) != null); // system whitelisted
btnManageDefault.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(channelNotification);
}
});
final Intent channelService = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, getContext().getPackageName())
.putExtra(Settings.EXTRA_CHANNEL_ID, "service");
2020-06-14 16:34:13 +00:00
btnManageService.setEnabled(channelService.resolveActivity(pm) != null); // system whitelisted
btnManageService.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(channelService);
}
});
swBackground.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("background_service", checked).apply();
ServiceSynchronize.eval(getContext(), "background=" + checked);
}
});
2019-05-06 07:10:13 +00:00
cbNotifyActionTrash.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
2019-06-28 11:08:04 +00:00
prefs.edit().putBoolean("notify_trash", checked).apply();
2019-05-06 07:10:13 +00:00
}
});
2019-09-26 19:28:05 +00:00
cbNotifyActionJunk.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("notify_junk", checked).apply();
cbNotifyActionBlockSender.setEnabled(checked);
}
});
cbNotifyActionBlockSender.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("notify_block_sender", checked).apply();
2019-09-26 19:28:05 +00:00
}
});
2019-05-06 07:10:13 +00:00
cbNotifyActionArchive.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
2019-06-28 11:08:04 +00:00
prefs.edit().putBoolean("notify_archive", checked).apply();
2019-05-06 07:10:13 +00:00
}
});
2019-10-23 10:51:20 +00:00
cbNotifyActionMove.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("notify_move", checked).apply();
}
});
2019-05-06 07:10:13 +00:00
cbNotifyActionReply.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
2019-06-28 11:08:04 +00:00
prefs.edit().putBoolean("notify_reply", checked).apply();
2019-05-06 07:10:13 +00:00
}
});
2019-08-24 13:00:14 +00:00
cbNotifyActionReplyDirect.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("notify_reply_direct", checked).apply();
}
});
2019-05-06 08:33:29 +00:00
cbNotifyActionFlag.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
2019-06-28 11:08:04 +00:00
prefs.edit().putBoolean("notify_flag", checked).apply();
2019-05-06 08:33:29 +00:00
}
});
2019-05-06 07:10:13 +00:00
cbNotifyActionSeen.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
2019-06-28 11:08:04 +00:00
prefs.edit().putBoolean("notify_seen", checked).apply();
2019-05-06 07:10:13 +00:00
}
});
2019-09-24 07:34:43 +00:00
cbNotifyActionSnooze.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("notify_snooze", checked).apply();
}
});
2019-06-28 19:22:20 +00:00
Helper.linkPro(tvNotifyActionsPro);
2020-06-07 14:32:14 +00:00
Helper.linkPro(tvNotifyKnownPro);
2019-06-28 19:22:20 +00:00
2019-05-06 07:10:13 +00:00
swLight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("light", checked).apply();
}
});
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_SHOW_SILENT, true);
2019-05-06 07:10:13 +00:00
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, sound == null ? null : Uri.parse(sound));
startActivityForResult(Helper.getChooser(getContext(), intent), ActivitySetup.REQUEST_SOUND);
}
});
2020-03-15 10:50:49 +00:00
swBadge.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("badge", checked).apply();
}
});
swUnseenIgnored.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("unseen_ignored", checked).apply();
}
});
swNotifyKnown.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("notify_known", checked).apply();
enableOptions();
}
});
2020-03-15 10:50:49 +00:00
swNotifySummary.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("notify_summary", checked).apply();
enableOptions();
}
});
swNotifyRemove.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("notify_remove", checked).apply();
}
});
swNotifyClear.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("notify_clear", checked).apply();
}
});
swNotifyPreview.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("notify_preview", checked).apply();
enableOptions();
}
});
swNotifyPreviewAll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("notify_preview_all", checked).apply();
}
});
swWearablePreview.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("wearable_preview", checked).apply();
}
});
swBiometricsNotify.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("biometrics_notify", checked).apply();
}
});
swAlertOnce.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("alert_once", !checked).apply();
}
});
swAlertOnce.setVisibility(Log.isXiaomi() || BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
// https://developer.android.com/training/notify-user/group
tvNoGrouping.setVisibility(Build.VERSION.SDK_INT < Build.VERSION_CODES.N ? View.VISIBLE : View.GONE);
// https://developer.android.com/training/notify-user/channels
tvNoChannels.setVisibility(Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? View.VISIBLE : View.GONE);
grpChannel.setVisibility(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? View.VISIBLE : View.GONE);
grpNotification.setVisibility(
Build.VERSION.SDK_INT < Build.VERSION_CODES.O || BuildConfig.DEBUG
? View.VISIBLE : View.GONE);
2019-05-06 12:41:03 +00:00
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
2019-05-06 07:10:13 +00:00
return view;
}
2019-05-06 12:41:03 +00:00
@Override
public void onDestroyView() {
PreferenceManager.getDefaultSharedPreferences(getContext()).unregisterOnSharedPreferenceChangeListener(this);
super.onDestroyView();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
2019-09-10 06:53:07 +00:00
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
setOptions();
2019-05-06 12:41:03 +00:00
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_options, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_default:
onMenuDefault();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
2019-05-06 12:41:03 +00:00
private void onMenuDefault() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences.Editor editor = prefs.edit();
for (String option : RESET_OPTIONS)
editor.remove(option);
editor.apply();
2019-07-14 10:32:32 +00:00
ToastEx.makeText(getContext(), R.string.title_setup_done, Toast.LENGTH_LONG).show();
2019-05-06 12:41:03 +00:00
}
2019-05-06 07:10:13 +00:00
private void setOptions() {
2019-08-13 08:27:17 +00:00
boolean pro = ActivityBilling.isPro(getContext());
2019-05-06 07:10:13 +00:00
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
swBackground.setChecked(prefs.getBoolean("background_service", false));
2019-06-28 11:08:04 +00:00
cbNotifyActionTrash.setChecked(prefs.getBoolean("notify_trash", true) || !pro);
2019-09-26 19:28:05 +00:00
cbNotifyActionJunk.setChecked(prefs.getBoolean("notify_junk", false) && pro);
cbNotifyActionBlockSender.setChecked(prefs.getBoolean("notify_block_sender", false) && pro);
2019-06-28 11:08:04 +00:00
cbNotifyActionArchive.setChecked(prefs.getBoolean("notify_archive", true) || !pro);
2019-10-23 10:51:20 +00:00
cbNotifyActionMove.setChecked(prefs.getBoolean("notify_move", false) && pro);
cbNotifyActionReply.setChecked(prefs.getBoolean("notify_reply", false) && pro);
2019-08-24 13:00:14 +00:00
cbNotifyActionReplyDirect.setChecked(prefs.getBoolean("notify_reply_direct", false) && pro);
cbNotifyActionFlag.setChecked(prefs.getBoolean("notify_flag", false) && pro);
2019-06-28 11:08:04 +00:00
cbNotifyActionSeen.setChecked(prefs.getBoolean("notify_seen", true) || !pro);
2020-01-06 08:21:38 +00:00
cbNotifyActionSnooze.setChecked(prefs.getBoolean("notify_snooze", false) && pro);
2020-03-15 10:50:49 +00:00
swLight.setChecked(prefs.getBoolean("light", false));
2019-06-28 11:08:04 +00:00
2020-03-15 10:50:49 +00:00
swBadge.setChecked(prefs.getBoolean("badge", true));
swUnseenIgnored.setChecked(prefs.getBoolean("unseen_ignored", false));
swNotifyKnown.setChecked(prefs.getBoolean("notify_known", false));
2020-03-15 10:50:49 +00:00
swNotifySummary.setChecked(prefs.getBoolean("notify_summary", false));
swNotifyRemove.setChecked(prefs.getBoolean("notify_remove", true));
swNotifyClear.setChecked(prefs.getBoolean("notify_clear", false));
swNotifyPreview.setChecked(prefs.getBoolean("notify_preview", true));
swNotifyPreviewAll.setChecked(prefs.getBoolean("notify_preview_all", false));
swWearablePreview.setChecked(prefs.getBoolean("wearable_preview", false));
2019-08-21 17:39:06 +00:00
swBiometricsNotify.setChecked(prefs.getBoolean("biometrics_notify", false));
swAlertOnce.setChecked(!prefs.getBoolean("alert_once", true));
enableOptions();
}
private void enableOptions() {
boolean pro = ActivityBilling.isPro(getContext());
2019-10-23 10:51:20 +00:00
boolean summary = swNotifySummary.isChecked();
cbNotifyActionTrash.setEnabled(pro && !summary);
cbNotifyActionJunk.setEnabled(pro && !summary);
cbNotifyActionBlockSender.setEnabled(pro && !summary && cbNotifyActionJunk.isChecked());
2019-10-23 10:51:20 +00:00
cbNotifyActionArchive.setEnabled(pro && !summary);
cbNotifyActionMove.setEnabled(pro && !summary);
cbNotifyActionReply.setEnabled(pro && !summary);
cbNotifyActionReplyDirect.setEnabled(pro && !summary);
cbNotifyActionFlag.setEnabled(pro && !summary);
cbNotifyActionSeen.setEnabled(pro && !summary);
cbNotifyActionSnooze.setEnabled(pro && !summary);
2020-03-15 10:50:49 +00:00
swNotifyPreview.setEnabled(!summary);
swNotifyPreviewAll.setEnabled(!summary && swNotifyPreview.isChecked());
swWearablePreview.setEnabled(!summary && swNotifyPreview.isChecked());
2019-10-23 10:51:20 +00:00
swBiometricsNotify.setEnabled(!summary);
2019-05-06 07:10:13 +00:00
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
2019-06-30 14:55:15 +00:00
super.onActivityResult(requestCode, resultCode, data);
2019-05-06 07:10:13 +00:00
2019-07-15 12:11:55 +00:00
try {
switch (requestCode) {
case ActivitySetup.REQUEST_SOUND:
if (resultCode == RESULT_OK && data != null)
2019-12-31 08:47:01 +00:00
onSelectSound(data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI));
2019-07-15 12:11:55 +00:00
break;
2019-05-06 07:10:13 +00:00
}
2019-07-15 12:11:55 +00:00
} catch (Throwable ex) {
Log.e(ex);
}
}
private void onSelectSound(Uri uri) {
Log.i("Selected ringtone=" + uri);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
2019-12-31 08:47:01 +00:00
if (uri == null) // silent sound
prefs.edit().putString("sound", "").apply();
else {
if ("content".equals(uri.getScheme()))
prefs.edit().putString("sound", uri.toString()).apply();
else
prefs.edit().remove("sound").apply();
}
2019-05-06 07:10:13 +00:00
}
}