Issue with media

This commit is contained in:
Thomas 2022-12-28 11:44:36 +01:00
parent e265078210
commit 20c031f39e
5 changed files with 62 additions and 27 deletions

View File

@ -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,6 +244,7 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
int position = binding.mediaViewpager.getCurrentItem();
Attachment attachment = attachments.get(position);
if (Build.VERSION.SDK_INT >= 23) {
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 {
@ -253,6 +255,15 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
downloadID = -1;
}
}
} else {
Log.v(Helper.TAG, "ici");
if (attachment.type.compareTo("image") == 0) {
MediaHelper.manageMove(MediaActivity.this, attachment.url, false);
} else {
MediaHelper.manageDownloadsNoPopup(MediaActivity.this, attachment.url);
downloadID = -1;
}
}
} else {
if (attachment.type.compareToIgnoreCase("image") == 0) {
MediaHelper.manageMove(MediaActivity.this, attachment.url, false);

View File

@ -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,6 +264,7 @@ public class EditImageActivity extends BaseActivity implements OnPhotoEditorList
.setClearViewsEnabled(true)
.setTransparencyEnabled(true)
.build();
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,
@ -270,6 +272,8 @@ public class EditImageActivity extends BaseActivity implements OnPhotoEditorList
STORE_REQUEST);
return;
}
}
mPhotoEditor.saveAsFile(file.getAbsolutePath(), saveSettings, new PhotoEditor.OnSaveListener() {
@Override
public void onSuccess(@NonNull String imagePath) {

View File

@ -390,6 +390,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
* @param position - int position of the media in the message
*/
private void pickupMedia(ComposeActivity.mediaType type, int position) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions((Activity) context,
@ -397,6 +398,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
return;
}
}
Intent intent;
intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);

View File

@ -27,6 +27,7 @@ import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
@ -86,16 +87,7 @@ public class FragmentLoginMain extends Fragment {
permissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
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) {
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://")) {

View File

@ -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 -> {
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;
});
}