Use dialog for notification permisions

pull/213/head
M66B 1 year ago
parent f3b404e9c8
commit c5662d05d2

@ -0,0 +1,42 @@
package eu.faircode.email;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.preference.PreferenceManager;
public class FragmentDialogNotifications extends FragmentDialogBase {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
final Context context = getContext();
return new AlertDialog.Builder(context)
.setIcon(R.drawable.twotone_notifications_off_24)
.setTitle(R.string.title_hint_notifications)
.setMessage(R.string.title_hint_notifications_remark)
.setPositiveButton(R.string.title_fix, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(context, ActivitySetup.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(intent);
}
})
.setNegativeButton(R.string.title_dismiss, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putBoolean("notifications_reminder", false).apply();
}
})
.create();
}
}

@ -647,9 +647,7 @@ public class FragmentMessages extends FragmentBase
tvNotifications.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), ActivitySetup.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
v.getContext().startActivity(intent);
new FragmentDialogNotifications().show(getParentFragmentManager(), "notifications");
}
});
@ -5145,11 +5143,6 @@ public class FragmentMessages extends FragmentBase
updateAirplaneMode(ConnectionHelper.airplaneMode(context));
context.registerReceiver(airplanemode, new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED));
boolean canNotify =
(Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU ||
hasPermission(Manifest.permission.POST_NOTIFICATIONS));
grpNotifications.setVisibility(canNotify ? View.GONE : View.VISIBLE);
boolean isIgnoring = !Boolean.FALSE.equals(Helper.isIgnoringOptimizations(context));
//boolean canSchedule = AlarmManagerCompatEx.canScheduleExactAlarms(context);
boolean enabled = prefs.getBoolean("enabled", true);
@ -5174,6 +5167,7 @@ public class FragmentMessages extends FragmentBase
;
prefs.registerOnSharedPreferenceChangeListener(this);
onSharedPreferenceChanged(prefs, "notifications_reminder");
onSharedPreferenceChanged(prefs, "pro");
if (viewType == AdapterMessage.ViewType.UNIFIED || viewType == AdapterMessage.ViewType.FOLDER) {
@ -5229,6 +5223,16 @@ public class FragmentMessages extends FragmentBase
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if (grpNotifications != null && "notifications_reminder".equals(key)) {
boolean canNotify =
(Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU ||
hasPermission(Manifest.permission.POST_NOTIFICATIONS));
if (canNotify)
prefs.edit().remove("notifications_reminder").apply();
boolean notifications_reminder = prefs.getBoolean("notifications_reminder", true);
grpNotifications.setVisibility(canNotify || !notifications_reminder ? View.GONE : View.VISIBLE);
}
if (grpSupport != null &&
("pro".equals(key) || "banner_hidden".equals(key))) {
boolean pro = ActivityBilling.isPro(getContext());

@ -328,7 +328,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
"redmi_note",
"accept_space", "accept_unsupported",
"junk_hint",
"last_update_check", "last_announcement_check"
"last_update_check", "last_announcement_check",
"notifications_reminder"
};
@Override

@ -50,7 +50,7 @@
android:drawableStart="@drawable/twotone_notifications_off_24"
android:drawablePadding="6dp"
android:paddingHorizontal="12dp"
android:paddingTop="6dp"
android:paddingVertical="6dp"
android:text="@string/title_hint_notifications"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:drawableTint="?android:attr/textColorSecondary"
@ -58,25 +58,13 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/vSeparatorAirplane" />
<TextView
android:id="@+id/tvNotificationsRemark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="6dp"
android:text="@string/title_hint_notifications_remark"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvNotifications" />
<View
android:id="@+id/vSeparatorNotifications"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/colorSeparator"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvNotificationsRemark" />
app:layout_constraintTop_toBottomOf="@id/tvNotifications" />
<TextView
android:id="@+id/tvBatteryOptimizations"
@ -500,7 +488,7 @@
android:id="@+id/grpNotifications"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvNotifications,tvNotificationsRemark,vSeparatorNotifications" />
app:constraint_referenced_ids="tvNotifications,vSeparatorNotifications" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpBatteryOptimizations"

Loading…
Cancel
Save