forked from mirrors/Fedilab
Issue with media
This commit is contained in:
parent
e265078210
commit
20c031f39e
5 changed files with 62 additions and 27 deletions
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -390,12 +390,14 @@ 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 (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) !=
|
||||
PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions((Activity) context,
|
||||
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
|
||||
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
|
||||
return;
|
||||
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,
|
||||
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
|
||||
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Intent intent;
|
||||
intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
|
|
|
@ -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) {
|
||||
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://")) {
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue