From 45b41219e1451d1bb21693fbcb1b3fe6000dd73c Mon Sep 17 00:00:00 2001 From: Anton Chekulaev Date: Wed, 9 Sep 2020 17:12:06 +1000 Subject: [PATCH] Media repository no longer uses deprecated API. --- res/drawable-hdpi/ic_folder_white_48dp.png | Bin 245 -> 0 bytes res/drawable-mdpi/ic_folder_white_48dp.png | Bin 181 -> 0 bytes res/drawable-xhdpi/ic_folder_white_48dp.png | Bin 325 -> 0 bytes res/drawable-xxhdpi/ic_folder_white_48dp.png | Bin 499 -> 0 bytes res/drawable-xxxhdpi/ic_folder_white_48dp.png | Bin 681 -> 0 bytes res/drawable/ic_baseline_folder_24.xml | 10 +++++ res/layout/mediapicker_folder_item.xml | 3 +- .../securesms/mediasend/MediaFolder.java | 8 +--- .../mediasend/MediaPickerFolderAdapter.java | 1 - .../securesms/mediasend/MediaRepository.java | 42 +++--------------- .../mediasend/MediaSendActivity.java | 4 +- .../securesms/mms/AttachmentManager.java | 39 +++++++++------- 12 files changed, 44 insertions(+), 63 deletions(-) delete mode 100644 res/drawable-hdpi/ic_folder_white_48dp.png delete mode 100644 res/drawable-mdpi/ic_folder_white_48dp.png delete mode 100644 res/drawable-xhdpi/ic_folder_white_48dp.png delete mode 100644 res/drawable-xxhdpi/ic_folder_white_48dp.png delete mode 100644 res/drawable-xxxhdpi/ic_folder_white_48dp.png create mode 100644 res/drawable/ic_baseline_folder_24.xml diff --git a/res/drawable-hdpi/ic_folder_white_48dp.png b/res/drawable-hdpi/ic_folder_white_48dp.png deleted file mode 100644 index b93d5a1e4a48fb9cddfa530aacfc84e5ea4ad9c9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 245 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY0wn)GsXhaw_ISEDhGg7(d&7~dDL|z4q4_1- z7ebF0dKZ*BYIUwt;W*;>)jV%O+J|}OmjAiz^vX--1bb;NmdKI;Vst0GcUV@&Et; diff --git a/res/drawable-mdpi/ic_folder_white_48dp.png b/res/drawable-mdpi/ic_folder_white_48dp.png deleted file mode 100644 index 71a5a137c463dfd97dfad592c86b7eac773664c5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 181 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA0wn)(8}b0D8c!F;kch)?uX*!1I0(1~u3k7j z(@|)CtD?lCSzab=p|%h2vhJCDWr_9aDM8CMGG^>pz2)3<9-DOK6&2^5E;t7@iOv_Z za^ku1A-hLl9mAHDjh3bd#2aH97>pYj7@1i1Fnhmp-(Sr7N?SnU?z8GoH}30QFuL9E fEIT*+)p6OLF7v?Cmm9c&?qKkA^>bP0l+XkK)+RzI diff --git a/res/drawable-xhdpi/ic_folder_white_48dp.png b/res/drawable-xhdpi/ic_folder_white_48dp.png deleted file mode 100644 index a1afbe9daf5a5e3945f33915f8817be26b539148..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 325 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD0wg^q?%&M7z{un2;uunK>+P+xzK0zI93I~B z(C26sy3FL&q}$ba<$&VE(+|=Gi?KQ4VXb{{b%I@HcvNQkRwH8&_$~OogvaO4 zw%oRd*KGoKY|H)oF+L(JmZ@K7yH~M)rTJtXSd}W-{epFln3^$y#Qw2YO4`4lFD^P$~Ceo|M5hK8FSd#^MHkMkW@H6#Nv%Xop z`uOoFkL`HenK;g;u9pWO^ufBT^1bLU+-`^-9uCPcnl{j2kn()Z}QE;mo-HoefB z*Zy-}Zisf^y_D#y9#hyORXX0WRn2=FCLL&}+VQJlp9+WovC=X(&#pQ9T;}=5T@Ln_ z%3|%(!~^O#+c0lg!?_^UmUYV;M``9)?_)VHd~Imh)$}_jz~Q9ef`8{2zM8XMxzBWA zQW*O$P7VPDhX#gF?l0V62IDHR7v>-lMy3$m3oh<%mmE)$H! z3ef=JHkk37tjQO7zM9#Woi)Uuzt~P=K~v+>>CH@0wZ4Xr8TVd)ajK2!K0n)wB{^B2 z0ylRb_+K`4?xmfVnjIP5uHVdAbHnER!(F>C`4?UNaCobI)c!Y5a+}SgrcZvf`T2hK wZz{`oW;_VLU%AZk^pY1z(_z6pN$M>>-_mtyZ3drtfRV}I>FVdQ&MBb@0M_rzSO5S3 diff --git a/res/drawable-xxxhdpi/ic_folder_white_48dp.png b/res/drawable-xxxhdpi/ic_folder_white_48dp.png deleted file mode 100644 index 862a359c659632d51853ffdd9fed00ea359e0d26..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 681 zcmeAS@N?(olHy`uVBq!ia0vp^2SAvE1xWt5x}=AJfvLdL#WAGf*4w+WUZRCE$3E`V zQjT>Lxbac%MCul%qh`W!o?LgekJoN#VZJvdc57o#^S5{2w@zP<6-aqC^WuD?`R9e^ zy`TBezF|1DYTUllOX!bez1HgR53{E~nDR6I zvsS3eiNkM}1nn1oQg?4zRK4(%ux&-MUrZh6J=^snx#`a7Kqbf6hUYuuru{Daf8SeW z1@{Mw>w)z`Pa>5ZQyauPS*9}HQxOVbyWy#_f@g#Hzvn8uZ=N#np1E@l!~5JCKlYnv z<}h5nemH6w%ZjaY8yU79oB3Yv0DHCHlmrEbue}*w4N=hA3smF8LF;*ngxP73*WwP-|dd;wV_mTw}I~fk~l(;R?%-Bo{^&hlYD> zKe9j!2F4Yf8}ebSf&@4#1I|hTu|OKq;6gcY7T7e9As_B`FmV8F3lM(LF32jtz*r^y zU^$q+8c{b(VF1}lnHv9C%m20d7=N5j7eEH?x z|MRaCUffPvZc~<9Que_{`A~`2=6Qj~;+{`=++%#IO3bSA6)P-J0O`C1_v5v{7>Z3f Q;tUe?boFyt=akR{005H`djJ3c diff --git a/res/drawable/ic_baseline_folder_24.xml b/res/drawable/ic_baseline_folder_24.xml new file mode 100644 index 0000000000..dc6b080235 --- /dev/null +++ b/res/drawable/ic_baseline_folder_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/res/layout/mediapicker_folder_item.xml b/res/layout/mediapicker_folder_item.xml index 9d1d729ebe..b52ace6f4a 100644 --- a/res/layout/mediapicker_folder_item.xml +++ b/res/layout/mediapicker_folder_item.xml @@ -33,7 +33,8 @@ android:layout_width="20dp" android:layout_height="20dp" android:layout_marginEnd="6dp" - android:src="@drawable/ic_folder_white_48dp"/> + android:tint="@android:color/white" + android:src="@drawable/ic_baseline_folder_24"/> - * The functionality of this class should be refactored to use - * MediaStore. */ class MediaRepository { @@ -82,30 +76,17 @@ class MediaRepository { } } - String cameraBucketId = imageFolders.getCameraBucketId() != null ? imageFolders.getCameraBucketId() : videoFolders.getCameraBucketId(); - FolderData cameraFolder = cameraBucketId != null ? folders.remove(cameraBucketId) : null; - List mediaFolders = Stream.of(folders.values()).map(folder -> new MediaFolder(folder.getThumbnail(), + List mediaFolders = Stream.of(folders.values()).map(folder -> new MediaFolder(folder.getThumbnail(), folder.getTitle(), folder.getCount(), - folder.getBucketId(), - MediaFolder.FolderType.NORMAL)) + folder.getBucketId())) .sorted((o1, o2) -> o1.getTitle().toLowerCase().compareTo(o2.getTitle().toLowerCase())) .toList(); Uri allMediaThumbnail = imageFolders.getThumbnailTimestamp() > videoFolders.getThumbnailTimestamp() ? imageFolders.getThumbnail() : videoFolders.getThumbnail(); - if (allMediaThumbnail != null) { int allMediaCount = Stream.of(mediaFolders).reduce(0, (count, folder) -> count + folder.getItemCount()); - - if (cameraFolder != null) { - allMediaCount += cameraFolder.getCount(); - } - - mediaFolders.add(0, new MediaFolder(allMediaThumbnail, context.getString(R.string.MediaRepository_all_media), allMediaCount, Media.ALL_MEDIA_BUCKET_ID, MediaFolder.FolderType.NORMAL)); - } - - if (cameraFolder != null) { - mediaFolders.add(0, new MediaFolder(cameraFolder.getThumbnail(), cameraFolder.getTitle(), cameraFolder.getCount(), cameraFolder.getBucketId(), MediaFolder.FolderType.CAMERA)); + mediaFolders.add(0, new MediaFolder(allMediaThumbnail, context.getString(R.string.MediaRepository_all_media), allMediaCount, Media.ALL_MEDIA_BUCKET_ID)); } return mediaFolders; @@ -113,8 +94,6 @@ class MediaRepository { @WorkerThread private @NonNull FolderResult getFolders(@NonNull Context context, @NonNull Uri contentUri) { - String cameraPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath() + File.separator + "Camera"; - String cameraBucketId = null; Uri globalThumbnail = null; long thumbnailTimestamp = 0; Map folders = new HashMap<>(); @@ -135,10 +114,6 @@ class MediaRepository { folder.incrementCount(); folders.put(bucketId, folder); - if (cameraBucketId == null && path.startsWith(cameraPath)) { - cameraBucketId = bucketId; - } - if (timestamp > thumbnailTimestamp) { globalThumbnail = thumbnail; thumbnailTimestamp = timestamp; @@ -146,7 +121,7 @@ class MediaRepository { } } - return new FolderResult(cameraBucketId, globalThumbnail, thumbnailTimestamp, folders); + return new FolderResult(globalThumbnail, thumbnailTimestamp, folders); } @WorkerThread @@ -284,26 +259,19 @@ class MediaRepository { } private static class FolderResult { - private final String cameraBucketId; private final Uri thumbnail; private final long thumbnailTimestamp; private final Map folderData; - private FolderResult(@Nullable String cameraBucketId, - @Nullable Uri thumbnail, + private FolderResult(@Nullable Uri thumbnail, long thumbnailTimestamp, @NonNull Map folderData) { - this.cameraBucketId = cameraBucketId; this.thumbnail = thumbnail; this.thumbnailTimestamp = thumbnailTimestamp; this.folderData = folderData; } - @Nullable String getCameraBucketId() { - return cameraBucketId; - } - @Nullable Uri getThumbnail() { return thumbnail; } diff --git a/src/org/thoughtcrime/securesms/mediasend/MediaSendActivity.java b/src/org/thoughtcrime/securesms/mediasend/MediaSendActivity.java index adfc09a060..ff1792ec1a 100644 --- a/src/org/thoughtcrime/securesms/mediasend/MediaSendActivity.java +++ b/src/org/thoughtcrime/securesms/mediasend/MediaSendActivity.java @@ -1,6 +1,8 @@ package org.thoughtcrime.securesms.mediasend; import android.Manifest; + +import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProviders; import android.content.Context; import android.content.Intent; @@ -133,7 +135,7 @@ public class MediaSendActivity extends PassphraseRequiredActionBarActivity imple countButtonText = findViewById(R.id.mediasend_count_button_text); cameraButton = findViewById(R.id.mediasend_camera_button); - viewModel = ViewModelProviders.of(this, new MediaSendViewModel.Factory(getApplication(), new MediaRepository())).get(MediaSendViewModel.class); + viewModel = new ViewModelProvider(this, new MediaSendViewModel.Factory(getApplication(), new MediaRepository())).get(MediaSendViewModel.class); recipient = Recipient.from(this, Address.fromSerialized(getIntent().getStringExtra(KEY_ADDRESS)), true); transport = getIntent().getParcelableExtra(KEY_TRANSPORT); diff --git a/src/org/thoughtcrime/securesms/mms/AttachmentManager.java b/src/org/thoughtcrime/securesms/mms/AttachmentManager.java index 3ae608ee8c..f6f0cbbc23 100644 --- a/src/org/thoughtcrime/securesms/mms/AttachmentManager.java +++ b/src/org/thoughtcrime/securesms/mms/AttachmentManager.java @@ -371,28 +371,34 @@ public class AttachmentManager { } public static void selectDocument(Activity activity, int requestCode) { - Permissions.with(activity) - .request(Manifest.permission.WRITE_EXTERNAL_STORAGE) - .withPermanentDenialDialog(activity.getString(R.string.AttachmentManager_signal_requires_the_external_storage_permission_in_order_to_attach_photos_videos_or_audio)) - .onAllGranted(() -> selectMediaType(activity, "*/*", null, requestCode)) - .execute(); +// Permissions.with(activity) +// .request(Manifest.permission.WRITE_EXTERNAL_STORAGE) +// .withPermanentDenialDialog(activity.getString(R.string.AttachmentManager_signal_requires_the_external_storage_permission_in_order_to_attach_photos_videos_or_audio)) +// .onAllGranted(() -> selectMediaType(activity, "*/*", null, requestCode)) +// .execute(); + + selectMediaType(activity, "*/*", null, requestCode); } public static void selectGallery(Activity activity, int requestCode, @NonNull Recipient recipient, @NonNull String body, @NonNull TransportOption transport) { - Permissions.with(activity) - .request(Manifest.permission.WRITE_EXTERNAL_STORAGE) - .withPermanentDenialDialog(activity.getString(R.string.AttachmentManager_signal_requires_the_external_storage_permission_in_order_to_attach_photos_videos_or_audio)) - .onAllGranted(() -> selectMediaType(activity, "image/*", new String[] {"image/*", "video/*"}, requestCode)) - .onAllGranted(() -> activity.startActivityForResult(MediaSendActivity.buildGalleryIntent(activity, recipient, body, transport), requestCode)) - .execute(); +// Permissions.with(activity) +// .request(Manifest.permission.WRITE_EXTERNAL_STORAGE) +// .withPermanentDenialDialog(activity.getString(R.string.AttachmentManager_signal_requires_the_external_storage_permission_in_order_to_attach_photos_videos_or_audio)) +//// .onAllGranted(() -> selectMediaType(activity, "image/*", new String[] {"image/*", "video/*"}, requestCode)) +// .onAllGranted(() -> activity.startActivityForResult(MediaSendActivity.buildGalleryIntent(activity, recipient, body, transport), requestCode)) +// .execute(); + + activity.startActivityForResult(MediaSendActivity.buildGalleryIntent(activity, recipient, body, transport), requestCode); } public static void selectAudio(Activity activity, int requestCode) { - Permissions.with(activity) - .request(Manifest.permission.WRITE_EXTERNAL_STORAGE) - .withPermanentDenialDialog(activity.getString(R.string.AttachmentManager_signal_requires_the_external_storage_permission_in_order_to_attach_photos_videos_or_audio)) - .onAllGranted(() -> selectMediaType(activity, "audio/*", null, requestCode)) - .execute(); +// Permissions.with(activity) +//// .request(Manifest.permission.WRITE_EXTERNAL_STORAGE) +//// .withPermanentDenialDialog(activity.getString(R.string.AttachmentManager_signal_requires_the_external_storage_permission_in_order_to_attach_photos_videos_or_audio)) +//// .onAllGranted(() -> selectMediaType(activity, "audio/*", null, requestCode)) +//// .execute(); + + selectMediaType(activity, "audio/*", null, requestCode); } public static void selectContactInfo(Activity activity, int requestCode) { @@ -463,6 +469,7 @@ public class AttachmentManager { } private static void selectMediaType(Activity activity, @NonNull String type, @Nullable String[] extraMimeType, int requestCode) { + //TODO Constrain media file size to match the Loki protocol limit. final Intent intent = new Intent(); intent.setType(type);