Skip to content

Commit a773a30

Browse files
Merge pull request #1446 from session-foundation/fix/qr-scanning-improvements
Fix/qr scanning improvements
2 parents 3d637e1 + 8b8e0c9 commit a773a30

File tree

13 files changed

+82
-27
lines changed

13 files changed

+82
-27
lines changed

app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ import kotlin.math.sqrt
231231
import kotlin.time.Duration.Companion.minutes
232232

233233
private const val TAG = "ConversationActivityV2"
234+
private const val TAG_REACTION_FRAGMENT = "ReactionsDialog"
234235

235236
// Some things that seemingly belong to the input bar (e.g. the voice message recording UI) are actually
236237
// part of the conversation activity layout. This is just because it makes the layout a lot simpler. The
@@ -540,7 +541,13 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
540541
dialogsState = dialogsState,
541542
inputBarDialogsState = inputBarDialogState,
542543
sendCommand = viewModel::onCommand,
543-
sendInputBarCommand = viewModel::onInputBarCommand
544+
sendInputBarCommand = viewModel::onInputBarCommand,
545+
onPostUserProfileModalAction = {
546+
// this function is to perform logic once an action
547+
// has been taken in the UPM, like messaging a user
548+
// in this case we want to make sure the reaction dialog is dismissed
549+
dismissReactionsDialog()
550+
}
544551
)
545552
}
546553
}
@@ -1819,6 +1826,10 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
18191826
sendEmojiRemoval(emoji, message)
18201827
}
18211828

1829+
override fun onEmojiReactionUserTapped(recipient: Recipient) {
1830+
showUserProfileModal(recipient)
1831+
}
1832+
18221833
// Called when the user is attempting to clear all instance of a specific emoji
18231834
override fun onClearAll(emoji: String, messageId: MessageId) = viewModel.onEmojiClear(emoji, messageId)
18241835

@@ -1957,10 +1968,15 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
19571968
)
19581969
} ?: false
19591970
val fragment = ReactionsDialogFragment.create(messageId, isUserModerator, emoji, viewModel.canRemoveReaction)
1960-
fragment.show(supportFragmentManager, null)
1971+
fragment.show(supportFragmentManager, TAG_REACTION_FRAGMENT)
19611972
}
19621973
}
19631974

1975+
private fun dismissReactionsDialog() {
1976+
val fragment = supportFragmentManager.findFragmentByTag(TAG_REACTION_FRAGMENT) as? ReactionsDialogFragment
1977+
fragment?.dismissAllowingStateLoss()
1978+
}
1979+
19641980
override fun playVoiceMessageAtIndexIfPossible(indexInAdapter: Int) {
19651981
if (!textSecurePreferences.autoplayAudioMessages()) return
19661982

app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationV2Dialogs.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ fun ConversationV2Dialogs(
4848
dialogsState: ConversationViewModel.DialogsState,
4949
inputBarDialogsState: InputbarViewModel.InputBarDialogsState,
5050
sendCommand: (ConversationViewModel.Commands) -> Unit,
51-
sendInputBarCommand: (InputbarViewModel.Commands) -> Unit
51+
sendInputBarCommand: (InputbarViewModel.Commands) -> Unit,
52+
onPostUserProfileModalAction: () -> Unit // a function called in the User Profile Modal once an action has been taken
5253
){
5354
SessionMaterialTheme {
5455
// inputbar dialogs
@@ -233,6 +234,7 @@ fun ConversationV2Dialogs(
233234
sendCommand = {
234235
sendCommand(ConversationViewModel.Commands.HandleUserProfileCommand(it))
235236
},
237+
onPostAction = onPostUserProfileModalAction
236238
)
237239
}
238240
}
@@ -248,7 +250,8 @@ fun PreviewURLDialog(){
248250
),
249251
inputBarDialogsState = InputbarViewModel.InputBarDialogsState(),
250252
sendCommand = {},
251-
sendInputBarCommand = {}
253+
sendInputBarCommand = {},
254+
onPostUserProfileModalAction = {}
252255
)
253256
}
254257
}

app/src/main/java/org/thoughtcrime/securesms/home/startconversation/newmessage/NewMessageViewModel.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ internal class NewMessageViewModel @Inject constructor(
3737

3838
private var loadOnsJob: Job? = null
3939

40+
private var lasQrScan: Long = 0L
41+
private val qrDebounceTime = 3000L
42+
4043
override fun onChange(value: String) {
4144
loadOnsJob?.cancel()
4245
loadOnsJob = null
@@ -68,10 +71,18 @@ internal class NewMessageViewModel @Inject constructor(
6871
}
6972

7073
override fun onScanQrCode(value: String) {
71-
if (PublicKeyValidation.isValid(value, isPrefixRequired = false) && PublicKeyValidation.hasValidPrefix(value)) {
72-
onPublicKey(value)
73-
} else {
74-
_qrErrors.tryEmit(application.getString(R.string.qrNotAccountId))
74+
val currentTime = System.currentTimeMillis()
75+
if (currentTime - lasQrScan > qrDebounceTime) {
76+
lasQrScan = currentTime
77+
if (PublicKeyValidation.isValid(
78+
value,
79+
isPrefixRequired = false
80+
) && PublicKeyValidation.hasValidPrefix(value)
81+
) {
82+
onPublicKey(value)
83+
} else {
84+
_qrErrors.tryEmit(application.getString(R.string.qrNotAccountId))
85+
}
7586
}
7687
}
7788

app/src/main/java/org/thoughtcrime/securesms/preferences/SettingsScreen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,8 @@ fun Buttons(
510510

511511
Crossfade(if (hasPaths) primaryGreen else primaryYellow, label = "path") {
512512
LargeItemButton(
513-
AnnotatedString(stringResource(R.string.onionRoutingPath)),
513+
modifier = Modifier.qaTag(R.string.qa_settings_item_path),
514+
annotatedStringText = AnnotatedString(stringResource(R.string.onionRoutingPath)),
514515
icon = {
515516
PathDot(
516517
modifier = Modifier.align(Alignment.Center),

app/src/main/java/org/thoughtcrime/securesms/reactions/ReactionRecipientsAdapter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ void bind(@NonNull ReactionDetails reaction) {
155155
callback.onRemoveReaction(reaction.getBaseEmoji(), reaction.getLocalId(), reaction.getTimestamp());
156156
});
157157

158+
itemView.setOnClickListener((v) -> {
159+
callback.onEmojiReactionUserTapped(reaction.getSender());
160+
});
161+
158162
this.avatar.update(reaction.getSender());
159163

160164
if (reaction.getSender().isLocalNumber()) {

app/src/main/java/org/thoughtcrime/securesms/reactions/ReactionViewPagerAdapter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import androidx.recyclerview.widget.ListAdapter;
1111
import androidx.recyclerview.widget.RecyclerView;
1212

13+
import org.session.libsession.utilities.recipients.Recipient;
1314
import org.thoughtcrime.securesms.database.model.MessageId;
1415
import org.thoughtcrime.securesms.util.ContextUtil;
1516
import org.thoughtcrime.securesms.util.adapter.AlwaysChangedDiffUtil;
@@ -119,6 +120,8 @@ public void setSelected(int position) {
119120
public interface Listener {
120121
void onRemoveReaction(@NonNull String emoji, @NonNull MessageId messageId, long timestamp);
121122

123+
void onEmojiReactionUserTapped(@NonNull Recipient recipient);
124+
122125
void onClearAll(@NonNull String emoji, @NonNull MessageId messageId);
123126
}
124127

app/src/main/java/org/thoughtcrime/securesms/reactions/ReactionsDialogFragment.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.android.material.tabs.TabLayout;
2121
import com.google.android.material.tabs.TabLayoutMediator;
2222

23+
import org.session.libsession.utilities.recipients.Recipient;
2324
import org.thoughtcrime.securesms.components.emoji.EmojiImageView;
2425
import org.thoughtcrime.securesms.database.model.MessageId;
2526
import org.thoughtcrime.securesms.util.LifecycleDisposable;
@@ -181,9 +182,16 @@ public void onClearAll(@NonNull String emoji, @NonNull MessageId messageId) {
181182
dismiss();
182183
}
183184

185+
@Override
186+
public void onEmojiReactionUserTapped(@NonNull Recipient recipient) {
187+
callback.onEmojiReactionUserTapped(recipient);
188+
}
189+
184190
public interface Callback {
185191
void onRemoveReaction(@NonNull String emoji, @NonNull MessageId messageId);
186192

193+
void onEmojiReactionUserTapped(@NonNull Recipient recipient);
194+
187195
void onClearAll(@NonNull String emoji, @NonNull MessageId messageId);
188196
}
189197

app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import androidx.compose.foundation.layout.height
2626
import androidx.compose.foundation.layout.heightIn
2727
import androidx.compose.foundation.layout.padding
2828
import androidx.compose.foundation.layout.size
29+
import androidx.compose.foundation.layout.widthIn
2930
import androidx.compose.foundation.layout.wrapContentHeight
3031
import androidx.compose.foundation.layout.wrapContentSize
3132
import androidx.compose.foundation.lazy.LazyColumn
@@ -766,6 +767,7 @@ fun LoadingArcOr(loading: Boolean, content: @Composable () -> Unit) {
766767
fun SpeechBubbleTooltip(
767768
text: CharSequence,
768769
modifier: Modifier = Modifier,
770+
maxWidth: Dp = LocalDimensions.current.maxTooltipWidth,
769771
tooltipState: TooltipState = rememberTooltipState(),
770772
content: @Composable () -> Unit,
771773
) {
@@ -776,23 +778,22 @@ fun SpeechBubbleTooltip(
776778
tooltip = {
777779
val bubbleColor = LocalColors.current.backgroundBubbleReceived
778780

779-
Column {
780-
Card(
781-
shape = MaterialTheme.shapes.medium,
782-
colors = CardDefaults.cardColors(containerColor = bubbleColor),
783-
elevation = CardDefaults.elevatedCardElevation(4.dp)
784-
) {
785-
Text(
786-
text = annotatedStringResource(text),
787-
modifier = Modifier.padding(
788-
horizontal = LocalDimensions.current.xsSpacing,
789-
vertical = LocalDimensions.current.xxsSpacing
790-
),
791-
style = LocalType.current.small,
792-
color = LocalColors.current.text
793-
)
794-
}
795-
781+
Card(
782+
modifier = Modifier.widthIn(max = maxWidth),
783+
shape = MaterialTheme.shapes.medium,
784+
colors = CardDefaults.cardColors(containerColor = bubbleColor),
785+
elevation = CardDefaults.elevatedCardElevation(4.dp)
786+
) {
787+
Text(
788+
text = annotatedStringResource(text),
789+
modifier = Modifier.padding(
790+
horizontal = LocalDimensions.current.xsSpacing,
791+
vertical = LocalDimensions.current.xxsSpacing
792+
),
793+
textAlign = TextAlign.Center,
794+
style = LocalType.current.small,
795+
color = LocalColors.current.text
796+
)
796797
}
797798
}
798799
) {

app/src/main/java/org/thoughtcrime/securesms/ui/ProComponents.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ fun AnimatedSessionProActivatedCTA(
515515
@Composable
516516
fun GenericProCTA(
517517
onDismissRequest: () -> Unit,
518+
onPostAction: (() -> Unit)? = null // a function for optional code once an action has been taken
518519
){
519520
val context = LocalContext.current
520521
AnimatedSessionProCTA(
@@ -532,6 +533,7 @@ fun GenericProCTA(
532533
),
533534
onUpgrade = {
534535
onDismissRequest()
536+
onPostAction?.invoke()
535537
//todo PRO go to screen once it exists
536538
},
537539
onCancel = {

app/src/main/java/org/thoughtcrime/securesms/ui/UserProfileModal.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ fun UserProfileModal(
6363
data: UserProfileModalData,
6464
sendCommand: (UserProfileModalCommands) -> Unit,
6565
onDismissRequest: () -> Unit,
66+
onPostAction: (() -> Unit)? = null // a function for optional code once an action has been taken
6667
){
6768
// the user profile modal
6869
val context = LocalContext.current
@@ -193,6 +194,9 @@ fun UserProfileModal(
193194
// close dialog
194195
onDismissRequest()
195196

197+
// optional action
198+
onPostAction?.invoke()
199+
196200
// open conversation with user
197201
context.startActivity(Intent(context, ConversationActivityV2::class.java)
198202
.putExtra(ADDRESS, Address.fromSerialized(data.rawAddress))

0 commit comments

Comments
 (0)