From dbec5ad53cdeb07ae71759b85ca64a8a9c1b2e11 Mon Sep 17 00:00:00 2001 From: Harris Date: Mon, 16 Aug 2021 14:05:49 +1000 Subject: [PATCH] fix: fixing the message dismissal of notifications for threads upon activity resume. using media send activity's camera intent for consistency --- .../conversation/v2/ConversationActivityV2.kt | 14 +++----- .../v2/utilities/AttachmentManager.java | 36 +++++-------------- .../mediasend/MediaSendActivity.java | 13 ++++--- .../notifications/DefaultMessageNotifier.java | 3 +- .../utilities/TextSecurePreferences.kt | 2 +- 5 files changed, 23 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt index 4a86d5edc5..58e9697414 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -241,7 +241,6 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe searchBottomBar.setEventListener(this) setUpSearchResultObserver() scrollToFirstUnreadMessageIfNeeded() - markAllAsRead() showOrHideInputIfNeeded() if (this.thread.isOpenGroupRecipient) { val openGroup = DatabaseFactory.getLokiThreadDatabase(this).getOpenGroupChat(threadID) @@ -255,6 +254,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe override fun onResume() { super.onResume() ApplicationContext.getInstance(this).messageNotifier.setVisibleThread(threadID) + markAllAsRead() } override fun onPause() { @@ -498,7 +498,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe } else { MarkReadReceiver.process(this, messages) } - ApplicationContext.getInstance(this).messageNotifier.updateNotification(this, threadID) + ApplicationContext.getInstance(this).messageNotifier.updateNotification(this, false, 0) } override fun inputBarHeightChanged(newValue: Int) { @@ -977,7 +977,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe } private fun showCamera() { - attachmentManager.capturePhoto(this, ConversationActivityV2.TAKE_PHOTO) + attachmentManager.capturePhoto(this, ConversationActivityV2.TAKE_PHOTO, thread); } override fun onAttachmentChanged() { @@ -1006,11 +1006,6 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe val uri = intent?.data ?: return prepMediaForSending(uri, AttachmentManager.MediaType.DOCUMENT).addListener(mediaPreppedListener) } - TAKE_PHOTO -> { - if (resultCode != RESULT_OK) { return } - val uri = attachmentManager.captureUri ?: return - prepMediaForSending(uri, AttachmentManager.MediaType.IMAGE).addListener(mediaPreppedListener) - } PICK_GIF -> { intent ?: return val uri = intent.data ?: return @@ -1019,7 +1014,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe val height = intent.getIntExtra(GiphyActivity.EXTRA_HEIGHT, 0) prepMediaForSending(uri, type, width, height).addListener(mediaPreppedListener) } - PICK_FROM_LIBRARY -> { + PICK_FROM_LIBRARY, + TAKE_PHOTO -> { intent ?: return val body = intent.getStringExtra(MediaSendActivity.EXTRA_MESSAGE) val media = intent.getParcelableArrayListExtra(MediaSendActivity.EXTRA_MEDIA) ?: return diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/AttachmentManager.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/AttachmentManager.java index d1d7e0b81c..dd90b699e3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/AttachmentManager.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/AttachmentManager.java @@ -25,7 +25,6 @@ import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.AsyncTask; -import android.provider.MediaStore; import android.provider.OpenableColumns; import android.text.TextUtils; import android.util.Pair; @@ -34,9 +33,12 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import org.session.libsignal.utilities.NoExternalStorageException; -import org.thoughtcrime.securesms.giph.ui.GiphyActivity; +import org.session.libsession.utilities.recipients.Recipient; +import org.session.libsignal.utilities.ListenableFuture; import org.session.libsignal.utilities.Log; +import org.session.libsignal.utilities.SettableFuture; +import org.session.libsignal.utilities.guava.Optional; +import org.thoughtcrime.securesms.giph.ui.GiphyActivity; import org.thoughtcrime.securesms.mediasend.MediaSendActivity; import org.thoughtcrime.securesms.mms.AudioSlide; import org.thoughtcrime.securesms.mms.DocumentSlide; @@ -50,16 +52,8 @@ import org.thoughtcrime.securesms.mms.SlideDeck; import org.thoughtcrime.securesms.mms.VideoSlide; import org.thoughtcrime.securesms.permissions.Permissions; import org.thoughtcrime.securesms.providers.BlobProvider; -import org.session.libsignal.utilities.ExternalStorageUtil; -import org.thoughtcrime.securesms.util.FileProviderUtil; import org.thoughtcrime.securesms.util.MediaUtil; -import org.session.libsignal.utilities.guava.Optional; -import org.session.libsession.utilities.recipients.Recipient; -import org.session.libsignal.utilities.ListenableFuture; -import org.session.libsignal.utilities.SettableFuture; - -import java.io.File; import java.io.IOException; import java.util.Iterator; import java.util.LinkedList; @@ -67,8 +61,6 @@ import java.util.List; import network.loki.messenger.R; -import static android.provider.MediaStore.EXTRA_OUTPUT; - public class AttachmentManager { private final static String TAG = AttachmentManager.class.getSimpleName(); @@ -278,25 +270,15 @@ public class AttachmentManager { return captureUri; } - public void capturePhoto(Activity activity, int requestCode) { + public void capturePhoto(Activity activity, int requestCode, Recipient recipient) { Permissions.with(activity) .request(Manifest.permission.CAMERA) .withPermanentDenialDialog(activity.getString(R.string.AttachmentManager_signal_requires_the_camera_permission_in_order_to_take_photos_but_it_has_been_permanently_denied)) .withRationaleDialog(activity.getString(R.string.ConversationActivity_to_capture_photos_and_video_allow_signal_access_to_the_camera),R.drawable.ic_baseline_photo_camera_24) .onAllGranted(() -> { - try { - File captureFile = File.createTempFile("conversation-capture", ".jpg", ExternalStorageUtil.getImageDir(activity)); - Uri captureUri = FileProviderUtil.getUriFor(context, captureFile); - Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - captureIntent.putExtra(EXTRA_OUTPUT, captureUri); - captureIntent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); - if (captureIntent.resolveActivity(activity.getPackageManager()) != null) { - Log.d(TAG, "captureUri path is " + captureUri.getPath()); - this.captureUri = captureUri; - activity.startActivityForResult(captureIntent, requestCode); - } - } catch (IOException | NoExternalStorageException e) { - throw new RuntimeException("Error creating image capture intent.", e); + Intent captureIntent = MediaSendActivity.buildCameraIntent(activity, recipient); + if (captureIntent.resolveActivity(activity.getPackageManager()) != null) { + activity.startActivityForResult(captureIntent, requestCode); } }) .execute(); diff --git a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendActivity.java b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendActivity.java index d2b36a6892..3e9fd7905e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendActivity.java @@ -20,19 +20,18 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.lifecycle.ViewModelProvider; +import org.session.libsession.utilities.Address; import org.session.libsession.utilities.MediaTypes; +import org.session.libsession.utilities.Util; +import org.session.libsession.utilities.concurrent.SimpleTask; +import org.session.libsession.utilities.recipients.Recipient; +import org.session.libsignal.utilities.Log; import org.session.libsignal.utilities.guava.Optional; import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity; -import org.session.libsignal.utilities.Log; import org.thoughtcrime.securesms.permissions.Permissions; import org.thoughtcrime.securesms.providers.BlobProvider; import org.thoughtcrime.securesms.scribbles.ImageEditorFragment; -import org.session.libsession.utilities.Address; -import org.session.libsession.utilities.recipients.Recipient; -import org.session.libsession.utilities.concurrent.SimpleTask; -import org.session.libsession.utilities.Util; - import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -87,7 +86,7 @@ public class MediaSendActivity extends PassphraseRequiredActionBarActivity imple } /** - * Get an intent to launch the media send flow starting with the picker. + * Get an intent to launch the media send flow starting with the camera. */ public static Intent buildCameraIntent(@NonNull Context context, @NonNull Recipient recipient) { Intent intent = buildGalleryIntent(context, recipient, ""); diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java index e7f8e8e5c8..616b17799d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java @@ -90,8 +90,9 @@ public class DefaultMessageNotifier implements MessageNotifier { private static final String TAG = DefaultMessageNotifier.class.getSimpleName(); - public static final String EXTRA_REMOTE_REPLY = "extra_remote_reply"; + public static final String EXTRA_REMOTE_REPLY = "extra_remote_reply"; public static final String LATEST_MESSAGE_ID_TAG = "extra_latest_message_id"; + public static final String EXTRA_THREAD_ID = "extra_thread_id"; private static final int FOREGROUND_ID = 313399; private static final int SUMMARY_NOTIFICATION_ID = 1338; diff --git a/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt b/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt index 7ac0feae6d..cef0b9315f 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt @@ -380,7 +380,7 @@ object TextSecurePreferences { @JvmStatic fun isInThreadNotifications(context: Context): Boolean { - return getBooleanPreference(context, IN_THREAD_NOTIFICATION_PREF, true) + return getBooleanPreference(context, IN_THREAD_NOTIFICATION_PREF, false) } @JvmStatic