Use photo picker by default

pull/212/head
M66B 1 year ago
parent 00a0446600
commit 90c8ab8dec

@ -17,6 +17,7 @@ if (rootProject.file("local.properties").exists())
android { android {
compileSdkVersion 33 compileSdkVersion 33
compileSdkExtension 4 // https://developer.android.com/guide/sdk-extensions
namespace 'eu.faircode.email' namespace 'eu.faircode.email'
// https://apilevels.com/ // https://apilevels.com/

@ -364,10 +364,7 @@ public class FragmentCompose extends FragmentBase {
setTitle(R.string.page_compose); setTitle(R.string.page_compose);
setSubtitle(getResources().getQuantityString(R.plurals.page_message, 1)); setSubtitle(getResources().getQuantityString(R.plurals.page_message, 1));
int max = (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU int max = Helper.hasPhotoPicker() ? MediaStore.getPickImagesMaxLimit() : 20;
? Integer.MAX_VALUE
: MediaStore.getPickImagesMaxLimit());
pickImages = pickImages =
registerForActivityResult(new ActivityResultContracts.PickMultipleVisualMedia(max), uris -> { registerForActivityResult(new ActivityResultContracts.PickMultipleVisualMedia(max), uris -> {
if (!uris.isEmpty()) if (!uris.isEmpty())
@ -3458,24 +3455,28 @@ public class FragmentCompose extends FragmentBase {
// https://developer.android.com/training/data-storage/shared/photopicker#device-availability // https://developer.android.com/training/data-storage/shared/photopicker#device-availability
// https://developer.android.com/reference/android/provider/MediaStore#ACTION_PICK_IMAGES // https://developer.android.com/reference/android/provider/MediaStore#ACTION_PICK_IMAGES
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean photo_picker = prefs.getBoolean("photo_picker", false); boolean photo_picker = prefs.getBoolean("photo_picker", true);
if (photo_picker) { if (photo_picker)
Log.i("Using photo picker"); try {
pickImages.launch(new PickVisualMediaRequest.Builder() Log.i("Using photo picker");
.setMediaType(ActivityResultContracts.PickVisualMedia.ImageOnly.INSTANCE) pickImages.launch(new PickVisualMediaRequest.Builder()
.build()); .setMediaType(ActivityResultContracts.PickVisualMedia.ImageOnly.INSTANCE)
} else { .build());
Log.i("Using file picker"); return;
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); } catch (Throwable ex) {
intent.addCategory(Intent.CATEGORY_OPENABLE); Log.e(ex);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); }
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); Log.i("Using file picker");
if (intent.resolveActivity(pm) == null) // GET_CONTENT whitelisted Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
noStorageAccessFramework(); intent.addCategory(Intent.CATEGORY_OPENABLE);
else intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(Helper.getChooser(context, intent), REQUEST_IMAGE_FILE); intent.setType("image/*");
} intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
if (intent.resolveActivity(pm) == null) // GET_CONTENT whitelisted
noStorageAccessFramework();
else
startActivityForResult(Helper.getChooser(context, intent), REQUEST_IMAGE_FILE);
} }
} }

@ -62,7 +62,6 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
private SwitchCompat swConversationActionsReplies; private SwitchCompat swConversationActionsReplies;
private SwitchCompat swLanguageDetection; private SwitchCompat swLanguageDetection;
private EditText etDefaultSnooze; private EditText etDefaultSnooze;
private SwitchCompat swPhotoPicker;
private SwitchCompat swPull; private SwitchCompat swPull;
private SwitchCompat swAutoScroll; private SwitchCompat swAutoScroll;
private SwitchCompat swQuickFilter; private SwitchCompat swQuickFilter;
@ -94,6 +93,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
private SwitchCompat swAutoUnflag; private SwitchCompat swAutoUnflag;
private SwitchCompat swResetImportance; private SwitchCompat swResetImportance;
private SwitchCompat swThreadSentTrash; private SwitchCompat swThreadSentTrash;
private SwitchCompat swPhotoPicker;
private SwitchCompat swFlagSnoozed; private SwitchCompat swFlagSnoozed;
private SwitchCompat swAutoImportant; private SwitchCompat swAutoImportant;
private SwitchCompat swResetSnooze; private SwitchCompat swResetSnooze;
@ -142,7 +142,6 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
swConversationActionsReplies = view.findViewById(R.id.swConversationActionsReplies); swConversationActionsReplies = view.findViewById(R.id.swConversationActionsReplies);
swLanguageDetection = view.findViewById(R.id.swLanguageDetection); swLanguageDetection = view.findViewById(R.id.swLanguageDetection);
etDefaultSnooze = view.findViewById(R.id.etDefaultSnooze); etDefaultSnooze = view.findViewById(R.id.etDefaultSnooze);
swPhotoPicker = view.findViewById(R.id.swPhotoPicker);
swPull = view.findViewById(R.id.swPull); swPull = view.findViewById(R.id.swPull);
swAutoScroll = view.findViewById(R.id.swAutoScroll); swAutoScroll = view.findViewById(R.id.swAutoScroll);
swQuickFilter = view.findViewById(R.id.swQuickFilter); swQuickFilter = view.findViewById(R.id.swQuickFilter);
@ -174,6 +173,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
swAutoUnflag = view.findViewById(R.id.swAutoUnflag); swAutoUnflag = view.findViewById(R.id.swAutoUnflag);
swResetImportance = view.findViewById(R.id.swResetImportance); swResetImportance = view.findViewById(R.id.swResetImportance);
swThreadSentTrash = view.findViewById(R.id.swThreadSentTrash); swThreadSentTrash = view.findViewById(R.id.swThreadSentTrash);
swPhotoPicker = view.findViewById(R.id.swPhotoPicker);
swFlagSnoozed = view.findViewById(R.id.swFlagSnoozed); swFlagSnoozed = view.findViewById(R.id.swFlagSnoozed);
swAutoImportant = view.findViewById(R.id.swAutoImportant); swAutoImportant = view.findViewById(R.id.swAutoImportant);
swResetSnooze = view.findViewById(R.id.swResetSnooze); swResetSnooze = view.findViewById(R.id.swResetSnooze);
@ -270,14 +270,6 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
} }
}); });
swPhotoPicker.setVisibility(Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU ? View.GONE : View.VISIBLE);
swPhotoPicker.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("photo_picker", checked).apply();
}
});
swPull.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swPull.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -522,6 +514,14 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
} }
}); });
swPhotoPicker.setVisibility(Helper.hasPhotoPicker() ? View.VISIBLE : View.GONE);
swPhotoPicker.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("photo_picker", checked).apply();
}
});
swFlagSnoozed.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swFlagSnoozed.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -657,8 +657,6 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
etDefaultSnooze.setText(default_snooze == 1 ? null : Integer.toString(default_snooze)); etDefaultSnooze.setText(default_snooze == 1 ? null : Integer.toString(default_snooze));
etDefaultSnooze.setHint("1"); etDefaultSnooze.setHint("1");
swPhotoPicker.setChecked(prefs.getBoolean("photo_picker", false));
swPull.setChecked(prefs.getBoolean("pull", true)); swPull.setChecked(prefs.getBoolean("pull", true));
swAutoScroll.setChecked(prefs.getBoolean("autoscroll", false)); swAutoScroll.setChecked(prefs.getBoolean("autoscroll", false));
swQuickFilter.setChecked(prefs.getBoolean("quick_filter", false)); swQuickFilter.setChecked(prefs.getBoolean("quick_filter", false));
@ -715,6 +713,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
swResetImportance.setChecked(prefs.getBoolean("reset_importance", false)); swResetImportance.setChecked(prefs.getBoolean("reset_importance", false));
swThreadSentTrash.setChecked(prefs.getBoolean("thread_sent_trash", true)); swThreadSentTrash.setChecked(prefs.getBoolean("thread_sent_trash", true));
swPhotoPicker.setChecked(prefs.getBoolean("photo_picker", true));
swFlagSnoozed.setChecked(prefs.getBoolean("flag_snoozed", false)); swFlagSnoozed.setChecked(prefs.getBoolean("flag_snoozed", false));
swAutoImportant.setChecked(prefs.getBoolean("auto_important", false)); swAutoImportant.setChecked(prefs.getBoolean("auto_important", false));
swResetSnooze.setChecked(prefs.getBoolean("reset_snooze", true)); swResetSnooze.setChecked(prefs.getBoolean("reset_snooze", true));

@ -62,6 +62,7 @@ import android.os.Looper;
import android.os.Parcel; import android.os.Parcel;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.StatFs; import android.os.StatFs;
import android.os.ext.SdkExtensions;
import android.os.storage.StorageManager; import android.os.storage.StorageManager;
import android.provider.Browser; import android.provider.Browser;
import android.provider.DocumentsContract; import android.provider.DocumentsContract;
@ -876,6 +877,12 @@ public class Helper {
return ContextCompat.getSystemService(context.getApplicationContext(), type); return ContextCompat.getSystemService(context.getApplicationContext(), type);
} }
static boolean hasPhotoPicker() {
return (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU ||
(Build.VERSION.SDK_INT > Build.VERSION_CODES.R &&
SdkExtensions.getExtensionVersion(Build.VERSION_CODES.R) >= 2));
}
// View // View
static Integer actionBarHeight = null; static Integer actionBarHeight = null;

@ -204,18 +204,6 @@
app:layout_constraintBottom_toBottomOf="@+id/etDefaultSnooze" app:layout_constraintBottom_toBottomOf="@+id/etDefaultSnooze"
app:layout_constraintStart_toEndOf="@+id/etDefaultSnooze" app:layout_constraintStart_toEndOf="@+id/etDefaultSnooze"
app:layout_constraintTop_toTopOf="@+id/etDefaultSnooze" /> app:layout_constraintTop_toTopOf="@+id/etDefaultSnooze" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swPhotoPicker"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_advanced_photo_picker"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etDefaultSnooze"
app:switchPadding="12dp" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
@ -750,6 +738,18 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swPhotoPicker"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_advanced_photo_picker"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAdvanced"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swFlagSnoozed" android:id="@+id/swFlagSnoozed"
android:layout_width="0dp" android:layout_width="0dp"
@ -758,7 +758,7 @@
android:text="@string/title_advanced_star_snoozed" android:text="@string/title_advanced_star_snoozed"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAdvanced" app:layout_constraintTop_toBottomOf="@id/swPhotoPicker"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat

Loading…
Cancel
Save