From 4ba48781c023ab4c4ca31c2da66234258fe5d3ad Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 20 Aug 2024 20:23:32 +0200 Subject: [PATCH] Fetch more messages as setting --- .../eu/faircode/email/FragmentDialogSync.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentDialogSync.java b/app/src/main/java/eu/faircode/email/FragmentDialogSync.java index b9fca1e909..77cbee056c 100644 --- a/app/src/main/java/eu/faircode/email/FragmentDialogSync.java +++ b/app/src/main/java/eu/faircode/email/FragmentDialogSync.java @@ -22,6 +22,7 @@ package eu.faircode.email; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; +import android.content.SharedPreferences; import android.os.Bundle; import android.text.TextUtils; import android.view.LayoutInflater; @@ -32,11 +33,14 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; +import androidx.preference.PreferenceManager; import java.util.ArrayList; import java.util.List; public class FragmentDialogSync extends FragmentDialogBase { + private static final int DEFAULT_KEEP = 3; // months + @NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { @@ -51,15 +55,21 @@ public class FragmentDialogSync extends FragmentDialogBase { final EditText etMonths = view.findViewById(R.id.etMonths); final TextView tvRemark = view.findViewById(R.id.tvRemark); + String key; if (fid < 0) { + key = "default_keep" + (TextUtils.isEmpty(type) ? "" : "." + type); if (TextUtils.isEmpty(type)) tvFolder.setText(R.string.title_folder_unified); else tvFolder.setText(EntityFolder.localizeType(context, type)); - } else + } else { + key = "default_keep." + fid; tvFolder.setText(name); + } - etMonths.setText("3"); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + int def = prefs.getInt(key, DEFAULT_KEEP); + etMonths.setText(def < 0 ? null : Integer.toString(def)); tvRemark.setOnClickListener(new View.OnClickListener() { @Override @@ -76,11 +86,14 @@ public class FragmentDialogSync extends FragmentDialogBase { String months = etMonths.getText().toString(); Bundle args = getArguments(); - if (TextUtils.isEmpty(months)) + if (TextUtils.isEmpty(months)) { + prefs.edit().putInt(key, -1).apply(); args.putInt("months", 0); - else + } else try { - args.putInt("months", Integer.parseInt(months)); + int m = Integer.parseInt(months); + prefs.edit().putInt(key, m).apply(); + args.putInt("months", m); } catch (NumberFormatException ex) { Log.e(ex); return;