diff --git a/app/src/main/java/app/fedilab/android/activities/MediaActivity.java b/app/src/main/java/app/fedilab/android/activities/MediaActivity.java index a93697f6..729d5c9d 100644 --- a/app/src/main/java/app/fedilab/android/activities/MediaActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/MediaActivity.java @@ -27,6 +27,7 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Handler; +import android.util.Log; import android.view.Display; import android.view.Menu; import android.view.MenuItem; @@ -243,9 +244,19 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload int position = binding.mediaViewpager.getCurrentItem(); Attachment attachment = attachments.get(position); if (Build.VERSION.SDK_INT >= 23) { - if (ContextCompat.checkSelfPermission(MediaActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(MediaActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { - ActivityCompat.requestPermissions(MediaActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE_MEDIA_SAVE); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { + if (ContextCompat.checkSelfPermission(MediaActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(MediaActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(MediaActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE_MEDIA_SAVE); + } else { + if (attachment.type.compareTo("image") == 0) { + MediaHelper.manageMove(MediaActivity.this, attachment.url, false); + } else { + MediaHelper.manageDownloadsNoPopup(MediaActivity.this, attachment.url); + downloadID = -1; + } + } } else { + Log.v(Helper.TAG, "ici"); if (attachment.type.compareTo("image") == 0) { MediaHelper.manageMove(MediaActivity.this, attachment.url, false); } else { diff --git a/app/src/main/java/app/fedilab/android/imageeditor/EditImageActivity.java b/app/src/main/java/app/fedilab/android/imageeditor/EditImageActivity.java index 65c5545e..f0d5ea6b 100644 --- a/app/src/main/java/app/fedilab/android/imageeditor/EditImageActivity.java +++ b/app/src/main/java/app/fedilab/android/imageeditor/EditImageActivity.java @@ -8,6 +8,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Typeface; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.provider.MediaStore; import android.view.MotionEvent; @@ -252,7 +253,7 @@ public class EditImageActivity extends BaseActivity implements OnPhotoEditorList } private void saveImage() { - if (requestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + if (requestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) || Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { showLoading(getString(R.string.saving)); File file = new File(path); try { @@ -263,13 +264,16 @@ public class EditImageActivity extends BaseActivity implements OnPhotoEditorList .setClearViewsEnabled(true) .setTransparencyEnabled(true) .build(); - if (ContextCompat.checkSelfPermission(EditImageActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != - PackageManager.PERMISSION_GRANTED) { - ActivityCompat.requestPermissions(EditImageActivity.this, - new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, - STORE_REQUEST); - return; + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { + if (ContextCompat.checkSelfPermission(EditImageActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != + PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(EditImageActivity.this, + new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, + STORE_REQUEST); + return; + } } + mPhotoEditor.saveAsFile(file.getAbsolutePath(), saveSettings, new PhotoEditor.OnSaveListener() { @Override public void onSuccess(@NonNull String imagePath) { diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java index 75f794be..332bb58e 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java @@ -390,12 +390,14 @@ public class ComposeAdapter extends RecyclerView.Adapter { if (isGranted) { - Intent openFileIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT); - openFileIntent.addCategory(Intent.CATEGORY_OPENABLE); - openFileIntent.setType("application/zip"); - String[] mimeTypes = new String[]{"application/zip"}; - openFileIntent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes); - //noinspection deprecation - startActivityForResult( - Intent.createChooser( - openFileIntent, - getString(R.string.load_settings)), PICK_IMPORT); + proceed(); } else { ActivityCompat.requestPermissions(requireActivity(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE); } @@ -233,13 +225,30 @@ public class FragmentLoginMain extends Fragment { } }); } else if (itemId == R.id.action_import_data) { - permissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { + permissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE); + } else { + proceed(); + } } return false; }); popupMenu.show(); } + private void proceed() { + Intent openFileIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT); + openFileIntent.addCategory(Intent.CATEGORY_OPENABLE); + openFileIntent.setType("application/zip"); + String[] mimeTypes = new String[]{"application/zip"}; + openFileIntent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes); + //noinspection deprecation + startActivityForResult( + Intent.createChooser( + openFileIntent, + getString(R.string.load_settings)), PICK_IMPORT); + } + private void retrievesClientId(String instance) { String oldInstance = instance; if (!instance.startsWith("http://") && !instance.startsWith("https://")) { diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentSettingsCategories.java b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentSettingsCategories.java index 36d5b60e..eb11a00b 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentSettingsCategories.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentSettingsCategories.java @@ -18,6 +18,7 @@ import android.Manifest; import android.app.Activity; import android.content.Intent; import android.content.pm.PackageManager; +import android.os.Build; import android.os.Bundle; import android.webkit.URLUtil; import android.widget.Toast; @@ -135,7 +136,15 @@ public class FragmentSettingsCategories extends PreferenceFragmentCompat { Preference pref_export_settings = findPreference(getString(R.string.pref_export_settings)); if (pref_export_settings != null) { pref_export_settings.setOnPreferenceClickListener(preference -> { - permissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { + permissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE); + } else { + try { + ZipHelper.exportData(requireActivity()); + } catch (IOException e) { + e.printStackTrace(); + } + } return false; }); }