From 81e1f2d60b87f1dca2f7c81e7cfcd051165e0e07 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 11 Sep 2020 13:51:14 +1000 Subject: [PATCH 1/4] Minor refactoring --- .../securesms/mediasend/MediaRepository.java | 7 ++++--- .../securesms/mms/AttachmentManager.java | 7 +++---- .../securesms/permissions/Permissions.java | 18 ++++++++++-------- .../securesms/util/SaveAttachmentTask.kt | 2 +- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/org/thoughtcrime/securesms/mediasend/MediaRepository.java b/src/org/thoughtcrime/securesms/mediasend/MediaRepository.java index ffdfecbac5..401ecabeab 100644 --- a/src/org/thoughtcrime/securesms/mediasend/MediaRepository.java +++ b/src/org/thoughtcrime/securesms/mediasend/MediaRepository.java @@ -8,14 +8,14 @@ import android.os.AsyncTask; import android.provider.MediaStore.Images; import android.provider.MediaStore.Video; import android.provider.OpenableColumns; +import android.util.Pair; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.WorkerThread; -import android.util.Pair; import com.annimon.stream.Stream; -import network.loki.messenger.R; import org.thoughtcrime.securesms.mms.PartAuthority; import org.thoughtcrime.securesms.util.MediaUtil; import org.thoughtcrime.securesms.util.Util; @@ -30,6 +30,8 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import network.loki.messenger.R; + /** * Handles the retrieval of media present on the user's device. */ @@ -139,7 +141,6 @@ class MediaRepository { @WorkerThread private @NonNull List getMediaInBucket(@NonNull Context context, @NonNull String bucketId, @NonNull Uri contentUri, boolean hasOrientation) { - //TODO Constrain media file size to match the Loki protocol limit. List media = new LinkedList<>(); String selection = Images.Media.BUCKET_ID + " = ? AND " + Images.Media.DATA + " NOT NULL"; String[] selectionArgs = new String[] { bucketId }; diff --git a/src/org/thoughtcrime/securesms/mms/AttachmentManager.java b/src/org/thoughtcrime/securesms/mms/AttachmentManager.java index 16c0d44ed0..80af560c00 100644 --- a/src/org/thoughtcrime/securesms/mms/AttachmentManager.java +++ b/src/org/thoughtcrime/securesms/mms/AttachmentManager.java @@ -30,13 +30,14 @@ import android.os.AsyncTask; import android.provider.ContactsContract; import android.provider.MediaStore; import android.provider.OpenableColumns; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import android.text.TextUtils; import android.util.Pair; import android.view.View; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import org.thoughtcrime.securesms.MediaPreviewActivity; import org.thoughtcrime.securesms.TransportOption; import org.thoughtcrime.securesms.attachments.Attachment; @@ -378,7 +379,6 @@ public class AttachmentManager { Permissions.with(activity) .request(Manifest.permission.READ_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(); } @@ -455,7 +455,6 @@ 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); diff --git a/src/org/thoughtcrime/securesms/permissions/Permissions.java b/src/org/thoughtcrime/securesms/permissions/Permissions.java index 41cce6f8ef..638c9512e8 100644 --- a/src/org/thoughtcrime/securesms/permissions/Permissions.java +++ b/src/org/thoughtcrime/securesms/permissions/Permissions.java @@ -8,20 +8,20 @@ import android.content.pm.PackageManager; import android.net.Uri; import android.os.Build; import android.provider.Settings; -import androidx.annotation.DrawableRes; -import androidx.annotation.NonNull; -import androidx.core.app.ActivityCompat; -import androidx.fragment.app.Fragment; -import androidx.core.content.ContextCompat; import android.util.DisplayMetrics; import android.view.Display; import android.view.ViewGroup; import android.view.WindowManager; +import androidx.annotation.DrawableRes; +import androidx.annotation.NonNull; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; +import androidx.fragment.app.Fragment; + import com.annimon.stream.Stream; import com.annimon.stream.function.Consumer; -import network.loki.messenger.R; import org.thoughtcrime.securesms.util.LRUCache; import org.thoughtcrime.securesms.util.ServiceUtil; @@ -31,6 +31,8 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import network.loki.messenger.R; + public class Permissions { private static final Map OUTSTANDING = new LRUCache<>(2); @@ -140,9 +142,9 @@ public class Permissions { PermissionsRequest request = new PermissionsRequest(allGrantedListener, anyDeniedListener, anyPermanentlyDeniedListener, anyResultListener, someGrantedListener, someDeniedListener, somePermanentlyDeniedListener); - boolean targetSdk = Build.VERSION.SDK_INT >= minSdkVersion && Build.VERSION.SDK_INT <= maxSdkVersion; + boolean isInTargetSDKRange = (Build.VERSION.SDK_INT >= minSdkVersion && Build.VERSION.SDK_INT <= maxSdkVersion); - if (!targetSdk || permissionObject.hasAll(requestedPermissions)) { + if (!isInTargetSDKRange || permissionObject.hasAll(requestedPermissions)) { executePreGrantedPermissionsRequest(request); } else if (rationaleDialogMessage != null && rationalDialogHeader != null) { executePermissionsRequestWithRationale(request); diff --git a/src/org/thoughtcrime/securesms/util/SaveAttachmentTask.kt b/src/org/thoughtcrime/securesms/util/SaveAttachmentTask.kt index 6e4938dd8c..d4dc58eb7b 100644 --- a/src/org/thoughtcrime/securesms/util/SaveAttachmentTask.kt +++ b/src/org/thoughtcrime/securesms/util/SaveAttachmentTask.kt @@ -157,7 +157,7 @@ class SaveAttachmentTask : ProgressDialogAsyncTask Date: Fri, 11 Sep 2020 13:52:03 +1000 Subject: [PATCH 2/4] Update version number --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 8d5a6f88ab..1b72fc29a1 100644 --- a/build.gradle +++ b/build.gradle @@ -181,8 +181,8 @@ dependencies { testImplementation 'org.robolectric:shadows-multidex:4.2' } -def canonicalVersionCode = 93 -def canonicalVersionName = "1.5.2" +def canonicalVersionCode = 94 +def canonicalVersionName = "1.5.3" def postFixSize = 10 def abiPostFix = ['armeabi-v7a' : 1, From 4f3526d20d4b2b61452bd7eb958b41091ac9827a Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Sat, 12 Sep 2020 08:52:44 +1000 Subject: [PATCH 3/4] Fix open group profile picture bug --- .../securesms/conversation/ConversationItem.java | 13 ++++++++++--- .../securesms/loki/views/ProfilePictureView.kt | 7 ++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationItem.java b/src/org/thoughtcrime/securesms/conversation/ConversationItem.java index ed4f24d110..a86f02e073 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationItem.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationItem.java @@ -797,14 +797,21 @@ public class ConversationItem extends LinearLayout LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)bodyBubble.getLayoutParams(); int groupThreadMargin = (int)((12 * getResources().getDisplayMetrics().density) + getResources().getDimension(R.dimen.small_profile_picture_size)); int defaultMargin = 0; - Recipient r = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(messageRecord.getThreadId()); + long threadID = messageRecord.getThreadId(); + Recipient r = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadID); String threadName = r != null ? r.getName() : ""; boolean isRSSFeed = threadName != null && (threadName.equals("Loki News") || threadName.equals("Session Updates")); layoutParams.setMarginStart((groupThread && !isRSSFeed) ? groupThreadMargin : defaultMargin); bodyBubble.setLayoutParams(layoutParams); if (profilePictureView == null) return; - profilePictureView.setPublicKey(recipient.getAddress().toString()); - profilePictureView.setDisplayName(recipient.getName()); + String publicKey = recipient.getAddress().toString(); + profilePictureView.setPublicKey(publicKey); + String displayName = recipient.getName(); + PublicChat publicChat = DatabaseFactory.getLokiThreadDatabase(context).getPublicChat(threadID); + if (displayName == null && publicChat != null) { + displayName = DatabaseFactory.getLokiUserDatabase(context).getServerDisplayName(publicChat.getId(), publicKey); + } + profilePictureView.setDisplayName(displayName); profilePictureView.setAdditionalPublicKey(null); profilePictureView.setRSSFeed(false); profilePictureView.setGlide(glideRequests); diff --git a/src/org/thoughtcrime/securesms/loki/views/ProfilePictureView.kt b/src/org/thoughtcrime/securesms/loki/views/ProfilePictureView.kt index 3ca3317f4f..9a7b9f0c11 100644 --- a/src/org/thoughtcrime/securesms/loki/views/ProfilePictureView.kt +++ b/src/org/thoughtcrime/securesms/loki/views/ProfilePictureView.kt @@ -60,7 +60,12 @@ class ProfilePictureView : RelativeLayout { if (publicKey == null || publicKey.isBlank()) { return null } else { - return DatabaseFactory.getLokiUserDatabase(context).getDisplayName(publicKey!!) + var result = DatabaseFactory.getLokiUserDatabase(context).getDisplayName(publicKey) + val publicChat = DatabaseFactory.getLokiThreadDatabase(context).getPublicChat(threadID) + if (result == null && publicChat != null) { + result = DatabaseFactory.getLokiUserDatabase(context).getServerDisplayName(publicChat.id, publicKey) + } + return result } } if (recipient.isGroupRecipient) { From cb91e6f0f635e50ef7218a8bfc43a0e31dc73a1b Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Sat, 12 Sep 2020 08:55:03 +1000 Subject: [PATCH 4/4] Update build number --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 1b72fc29a1..c7dbb48acd 100644 --- a/build.gradle +++ b/build.gradle @@ -181,7 +181,7 @@ dependencies { testImplementation 'org.robolectric:shadows-multidex:4.2' } -def canonicalVersionCode = 94 +def canonicalVersionCode = 95 def canonicalVersionName = "1.5.3" def postFixSize = 10