Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mentions V1 #33

Merged
merged 7 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions res/layout/cell_user_selection_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<org.thoughtcrime.securesms.loki.UserSelectionViewCell
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="52dp"
android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:gravity="center_vertical"
android:background="?attr/conversation_list_item_background">

<RelativeLayout
android:layout_width="36dp"
android:layout_height="38dp"
android:layout_marginTop="1dp">

<!-- The frame layout below is a workaround for an avatar image view bug -->

<FrameLayout
android:id="@+id/profilePictureImageViewContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<org.thoughtcrime.securesms.components.AvatarImageView
android:id="@+id/profilePictureImageView"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginBottom="2dp" />

</FrameLayout>

<ImageView
android:id="@+id/moderatorIconImageView"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginEnd="1.5dp"
android:src="@drawable/icon_crown"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true" />

</RelativeLayout>

<TextView
android:id="@+id/displayNameTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
style="@style/Signal.Text.Body"
android:ellipsize="end" />

</org.thoughtcrime.securesms.loki.UserSelectionViewCell>
21 changes: 15 additions & 6 deletions res/layout/conversation_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,26 @@
android:inflatedId="@+id/attachment_editor"
android:layout="@layout/conversation_activity_attachment_editor_stub" />

<FrameLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false">
android:orientation="vertical">

<include layout="@layout/view_user_selection" />

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false">

<include layout="@layout/conversation_input_panel" />

<include layout="@layout/conversation_input_panel" />
<include layout="@layout/conversation_search_nav" />

<include layout="@layout/conversation_search_nav" />
</FrameLayout>

</FrameLayout>
</LinearLayout>

<Button
android:id="@+id/register_button"
Expand Down
1 change: 1 addition & 0 deletions res/layout/conversation_input_panel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
tools:visibility="invisible"
tools:hint="Send TextSecure message" >
<requestFocus />

</org.thoughtcrime.securesms.components.ComposeText>

<FrameLayout
Expand Down
8 changes: 8 additions & 0 deletions res/layout/view_user_selection.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<org.thoughtcrime.securesms.loki.UserSelectionView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/userSelectionView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:paddingTop="6dp"
android:listSelector="@color/transparent" />
1 change: 1 addition & 0 deletions res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<resources>
<!-- Loki -->
<color name="loki_green">#78be20</color>
<color name="loki_dark_green">#419B41</color>
<color name="loki_darkest_gray">#0a0a0a</color>
<!-- Loki -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.thoughtcrime.securesms.color.MaterialColor;
import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
import org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.loki.JazzIdenticonDrawable;
import org.thoughtcrime.securesms.mms.GlideRequests;
import org.thoughtcrime.securesms.recipients.Recipient;
Expand Down Expand Up @@ -123,6 +124,10 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
setImageDrawable(image);
}

public void update(String hexEncodedPublicKey) {
this.recipient = Recipient.from(getContext(), Address.fromSerialized(hexEncodedPublicKey), false);
}

public void setAvatar(@NonNull GlideRequests requestManager, @Nullable Recipient recipient, boolean quickContactEnabled) {
this.recipient = recipient;
/*
Expand Down
114 changes: 83 additions & 31 deletions src/org/thoughtcrime/securesms/conversation/ConversationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@
import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.loki.FriendRequestViewDelegate;
import org.thoughtcrime.securesms.loki.LokiAPIUtilities;
import org.thoughtcrime.securesms.loki.LokiThreadDatabaseDelegate;
import org.thoughtcrime.securesms.loki.LokiUserDatabase;
import org.thoughtcrime.securesms.loki.UserSelectionView;
import org.thoughtcrime.securesms.mediasend.Media;
import org.thoughtcrime.securesms.mediasend.MediaSendActivity;
import org.thoughtcrime.securesms.mms.AttachmentManager;
Expand Down Expand Up @@ -224,6 +227,7 @@
import org.whispersystems.signalservice.api.SignalServiceMessageSender;
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.loki.api.LokiAPI;
import org.whispersystems.signalservice.loki.messaging.LokiMessageFriendRequestStatus;
import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus;
import org.whispersystems.signalservice.loki.utilities.Analytics;
Expand All @@ -239,7 +243,9 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

import kotlin.Unit;
import network.loki.messenger.R;
import nl.komponents.kovenant.combine.Tuple2;

import static org.thoughtcrime.securesms.TransportOption.Type;
import static org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord;
Expand Down Expand Up @@ -292,23 +298,24 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
private static final int SMS_DEFAULT = 11;
private static final int MEDIA_SENDER = 12;

private GlideRequests glideRequests;
protected ComposeText composeText;
private AnimatingToggle buttonToggle;
private SendButton sendButton;
private ImageButton attachButton;
protected ConversationTitleView titleView;
private TextView charactersLeft;
private ConversationFragment fragment;
private Button unblockButton;
private Button makeDefaultSmsButton;
private Button registerButton;
private InputAwareLayout container;
private View composePanel;
protected Stub<ReminderView> reminderView;
private Stub<UnverifiedBannerView> unverifiedBannerView;
private GlideRequests glideRequests;
protected ComposeText composeText;
private AnimatingToggle buttonToggle;
private SendButton sendButton;
private ImageButton attachButton;
protected ConversationTitleView titleView;
private TextView charactersLeft;
private ConversationFragment fragment;
private Button unblockButton;
private Button makeDefaultSmsButton;
private Button registerButton;
private InputAwareLayout container;
private View composePanel;
protected Stub<ReminderView> reminderView;
private Stub<UnverifiedBannerView> unverifiedBannerView;
private Stub<GroupShareProfileView> groupShareProfileView;
private TypingStatusTextWatcher typingTextWatcher;
private MentionTextWatcher mentionTextWatcher;
private ConversationSearchBottomBar searchNav;
private MenuItem searchViewItem;

Expand Down Expand Up @@ -338,6 +345,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
private final DynamicNoActionBarTheme dynamicTheme = new DynamicNoActionBarTheme();
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();

private UserSelectionView userSelectionView;
private int mentionStartIndex = -1;

@Override
protected void onPreCreate() {
Expand Down Expand Up @@ -389,11 +398,21 @@ public void onSuccess(Boolean loadedDraft) {
composeText.addTextChangedListener(typingTextWatcher);
}
composeText.setSelection(composeText.length(), composeText.length());
composeText.addTextChangedListener(mentionTextWatcher);
userSelectionView.setOnUserSelected(tuple -> {
String oldText = composeText.getText().toString();
String newText = oldText.substring(0, mentionStartIndex) + tuple.getFirst();
composeText.setText(newText);
composeText.setSelection(newText.length());
return Unit.INSTANCE;
});
}
});
}
});

LokiAPIUtilities.INSTANCE.populateUserIDCacheIfNeeded(threadId, this);

if (this.recipient.isGroupRecipient()) {
if (this.recipient.getName().equals("Loki Public Chat")) {
Analytics.Companion.getShared().track("Loki Public Chat Opened");
Expand Down Expand Up @@ -1552,6 +1571,7 @@ private void initializeViews() {
inlineAttachmentToggle = ViewUtil.findById(this, R.id.inline_attachment_container);
inputPanel = ViewUtil.findById(this, R.id.bottom_panel);
searchNav = ViewUtil.findById(this, R.id.conversation_search_nav);
userSelectionView = ViewUtil.findById(this, R.id.userSelectionView);

ImageButton quickCameraToggle = ViewUtil.findById(this, R.id.quick_camera_toggle);
ImageButton inlineAttachmentButton = ViewUtil.findById(this, R.id.inline_attachment_button);
Expand All @@ -1564,6 +1584,7 @@ private void initializeViews() {
attachmentManager = new AttachmentManager(this, this);
audioRecorder = new AudioRecorder(this);
typingTextWatcher = new TypingStatusTextWatcher();
mentionTextWatcher = new MentionTextWatcher();

SendButtonListener sendButtonListener = new SendButtonListener();
ComposeKeyPressedListener composeKeyPressedListener = new ComposeKeyPressedListener();
Expand Down Expand Up @@ -2591,7 +2612,9 @@ private void sendSticker(@NonNull StickerLocator stickerLocator, @NonNull Uri ur

private void silentlySetComposeText(String text) {
typingTextWatcher.setEnabled(false);
mentionTextWatcher.setEnabled(false);
composeText.setText(text);
mentionTextWatcher.setEnabled(true);
typingTextWatcher.setEnabled(true);
}

Expand Down Expand Up @@ -2706,7 +2729,6 @@ public void onFocusChange(View v, boolean hasFocus) {}
}

private class TypingStatusTextWatcher extends SimpleTextWatcher {

private boolean enabled = true;

@Override
Expand All @@ -2721,6 +2743,36 @@ public void setEnabled(boolean enabled) {
}
}

private class MentionTextWatcher extends SimpleTextWatcher {
private boolean enabled = true;

@Override
public void onTextChanged(String text) {
if (!enabled | text.length() == 0) { return; }
int currentEndIndex = text.length() - 1;
char lastCharacter = text.charAt(currentEndIndex);
LokiUserDatabase userDatabase = DatabaseFactory.getLokiUserDatabase(ConversationActivity.this);
if (lastCharacter == '@') {
List<Tuple2<String, String>> users = LokiAPI.Companion.getUsers("", threadId, userDatabase);
mentionStartIndex = currentEndIndex + 1;
userSelectionView.show(users, threadId);
} else if (Character.getType(lastCharacter) != Character.UPPERCASE_LETTER && Character.getType(lastCharacter) != Character.LOWERCASE_LETTER) {
mentionStartIndex = -1;
userSelectionView.hide();
} else {
if (mentionStartIndex != -1) {
String query = text.substring(mentionStartIndex);
List<Tuple2<String, String>> users = LokiAPI.Companion.getUsers(query, threadId, userDatabase);
userSelectionView.show(users, threadId);
}
}
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}

@Override
public void setThreadId(long threadId) {
this.threadId = threadId;
Expand All @@ -2747,11 +2799,11 @@ public void handleReplyMessage(MessageRecord messageRecord) {
}

inputPanel.setQuote(GlideApp.with(this),
messageRecord.getDateSent(),
author,
body,
slideDeck,
recipient);
messageRecord.getDateSent(),
author,
body,
slideDeck,
recipient);

} else if (messageRecord.isMms() && !((MmsMessageRecord) messageRecord).getLinkPreviews().isEmpty()) {
LinkPreview linkPreview = ((MmsMessageRecord) messageRecord).getLinkPreviews().get(0);
Expand All @@ -2762,18 +2814,18 @@ public void handleReplyMessage(MessageRecord messageRecord) {
}

inputPanel.setQuote(GlideApp.with(this),
messageRecord.getDateSent(),
author,
messageRecord.getBody(),
slideDeck,
recipient);
messageRecord.getDateSent(),
author,
messageRecord.getBody(),
slideDeck,
recipient);
} else {
inputPanel.setQuote(GlideApp.with(this),
messageRecord.getDateSent(),
author,
messageRecord.getBody(),
messageRecord.isMms() ? ((MmsMessageRecord) messageRecord).getSlideDeck() : new SlideDeck(),
recipient);
messageRecord.getDateSent(),
author,
messageRecord.getBody(),
messageRecord.isMms() ? ((MmsMessageRecord) messageRecord).getSlideDeck() : new SlideDeck(),
recipient);
}
}

Expand Down
Loading