Fixed incoming files display + store them in a Linphone directory instead of /

This commit is contained in:
Sylvain Berfini 2018-09-06 12:16:22 +02:00
parent 3d94dc0629
commit 417ed4e121
4 changed files with 12 additions and 8 deletions

View file

@ -757,5 +757,9 @@ public final class LinphoneUtils {
}
return null;
}
public static String getStorageDirectory(Context mContext) {
return Environment.getExternalStorageDirectory() + "/" + mContext.getString(mContext.getResources().getIdentifier("app_name", "string", mContext.getPackageName()));
}
}

View file

@ -325,10 +325,10 @@ public class ChatEventsAdapter extends SelectableAdapter<ChatBubbleViewHolder> {
if (mContext.getPackageManager().checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, mContext.getPackageName()) == PackageManager.PERMISSION_GRANTED) {
v.setEnabled(false);
String filename = message.getFileTransferInformation().getName();
File file = new File(Environment.getExternalStorageDirectory(), filename);
File file = new File(LinphoneUtils.getStorageDirectory(mContext), filename);
int prefix = 1;
while (file.exists()) {
file = new File(Environment.getExternalStorageDirectory(), prefix + "_" + filename);
file = new File(LinphoneUtils.getStorageDirectory(mContext), prefix + "_" + filename);
Log.w("File with that name already exists, renamed to " + prefix + "_" + filename);
prefix += 1;
}
@ -468,8 +468,8 @@ public class ChatEventsAdapter extends SelectableAdapter<ChatBubbleViewHolder> {
private void openFile(String path) {
Intent intent = new Intent(Intent.ACTION_VIEW);
File file = null;
Uri contentUri = null;
File file;
Uri contentUri;
if (path.startsWith("file://")) {
path = path.substring("file://".length());
file = new File(path);

View file

@ -589,7 +589,7 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
private void pickFile() {
List<Intent> cameraIntents = new ArrayList<>();
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.temp_photo_name_with_date).replace("%s", String.valueOf(System.currentTimeMillis()) + ".jpeg"));
File file = new File(LinphoneUtils.getStorageDirectory(mContext), getString(R.string.temp_photo_name_with_date).replace("%s", String.valueOf(System.currentTimeMillis()) + ".jpeg"));
mImageToUploadUri = Uri.fromFile(file);
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageToUploadUri);
cameraIntents.add(captureIntent);

View file

@ -339,9 +339,9 @@ public class ContactEditorFragment extends Fragment {
private void pickImage() {
pickedPhotoForContactUri = null;
final List<Intent> cameraIntents = new ArrayList<Intent>();
final List<Intent> cameraIntents = new ArrayList<>();
final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.temp_photo_name));
File file = new File(LinphoneUtils.getStorageDirectory(LinphoneActivity.instance()), getString(R.string.temp_photo_name));
pickedPhotoForContactUri = Uri.fromFile(file);
captureIntent.putExtra("outputX", PHOTO_SIZE);
captureIntent.putExtra("outputY", PHOTO_SIZE);
@ -381,7 +381,7 @@ public class ContactEditorFragment extends Fragment {
String filePath = pickedPhotoForContactUri.getPath();
editContactPicture(filePath, null);
} else {
File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.temp_photo_name));
File file = new File(LinphoneUtils.getStorageDirectory(LinphoneActivity.instance()), getString(R.string.temp_photo_name));
if (file.exists()) {
pickedPhotoForContactUri = Uri.fromFile(file);
String filePath = pickedPhotoForContactUri.getPath();