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

Pin message video audio attachments #79

Merged
merged 5 commits into from
Mar 9, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
11 changes: 11 additions & 0 deletions res/layout/pinned_conversation_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@
android:layout_height="@dimen/media_bubble_height"
android:layout="@layout/pinned_conversation_item_sent_thumbnail" />

<ViewStub android:id="@+id/pinned_document_view_stub"
android:layout="@layout/pinned_conversation_item_sent_document"
android:layout_width="210dp"
android:layout_height="wrap_content"/>

<ViewStub
android:id="@+id/pinned_audio_view_stub"
android:layout="@layout/pinned_conversation_item_sent_audio"
android:layout_width="210dp"
android:layout_height="wrap_content"/>

<TextView
android:id="@+id/conversation_item_date"
android:layout_width="match_parent"
Expand Down
10 changes: 10 additions & 0 deletions res/layout/pinned_conversation_item_sent_audio.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<org.thoughtcrime.securesms.components.AudioView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/pinned_audio_view"
android:layout_width="210dp"
android:layout_height="wrap_content"
app:foregroundTintColor="@color/grey_500"
app:backgroundTintColor="@color/white"
android:visibility="gone"/>
12 changes: 12 additions & 0 deletions res/layout/pinned_conversation_item_sent_document.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<org.thoughtcrime.securesms.components.DocumentView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pinned_document_view"
android:layout_width="210dp"
android:layout_height="wrap_content"
app:documentForegroundTintColor="@color/grey_500"
app:documentBackgroundTintColor="@color/white"
android:visibility="gone"
tools:visibility="visible"/>
10 changes: 1 addition & 9 deletions src/org/thoughtcrime/securesms/ConversationFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public class ConversationFragment extends Fragment
private View composeDivider;
private View scrollToBottomButton;
private TextView scrollDateHeader;
private int x =1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this being used anywhere? I can't find it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has slipped


@Override
public void onCreate(Bundle icicle) {
Expand Down Expand Up @@ -334,16 +335,7 @@ public void handlePinOrUnpinMessage(final MessageRecord message, boolean pin,
databaseToQuery = pinHandler.getAppropriateDatabase(message);

if (pin) {
// Blocking Video and Audio pinning Temporarily
if(message.isMms() && ((MmsMessageRecord) message).getSlideDeck().getSlides().size() != 0) {
MediaMmsMessageRecord mediaMessage = (MediaMmsMessageRecord) message;
if (!mediaMessage.getSlideDeck().getThumbnailSlide().getContentType().contains("image")) {
showToast("You can only pin image type mms!");
return;
}
}
result = pinHandler.handlePinMessage(message, databaseToQuery);

if (result) {
outputMessage = getString(R.string.ConversationFragment_pin_new);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/org/thoughtcrime/securesms/ConversationItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ public void onModified(final Recipient modified) {
});
}

private class AttachmentDownloadClickListener implements SlideClickListener {
public class AttachmentDownloadClickListener implements SlideClickListener {
@Override
public void onClick(View v, final Slide slide) {
if (messageRecord.isMmsNotification()) {
Expand Down
58 changes: 48 additions & 10 deletions src/org/thoughtcrime/securesms/PinnedMessageAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;

import org.thoughtcrime.securesms.components.AudioView;
import org.thoughtcrime.securesms.components.DocumentView;
import org.thoughtcrime.securesms.components.ThumbnailView;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.DatabaseFactory;
Expand Down Expand Up @@ -60,14 +62,18 @@ public PinnedMessageAdapter(Activity mContext, Cursor cursor, MasterSecret maste
}

public static class ViewHolder extends RecyclerView.ViewHolder {
private Stub<AudioView> audioViewStub;
private Stub<DocumentView> documentViewStub;
private Stub<ThumbnailView> mediaThumbnailStub;
public TextView messageContent;
public TextView recipient;
public TextView time;
public View wrapper;
public TextView messageContent;
public TextView recipient;
public TextView time;
public View wrapper;

public ViewHolder(View v) {
super(v);
this.audioViewStub = new Stub<>(v.findViewById(R.id.pinned_audio_view_stub));
this.documentViewStub = new Stub<>(v.findViewById(R.id.pinned_document_view_stub));
this.mediaThumbnailStub = new Stub<>(v.findViewById(R.id.pinned_image_view_stub));
this.messageContent = v.findViewById(R.id.pinned_message_body);
this.recipient = v.findViewById(R.id.pinned_message_recipient);
Expand All @@ -84,17 +90,37 @@ public PinnedMessageAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int
return new ViewHolder(theInflatedView);
}


@Override
public void onBindViewHolder(ViewHolder holder, int position) {
dataCursor.moveToPosition(position);
MmsSmsDatabase.Reader reader = db.readerFor(dataCursor, masterSecret);
MessageRecord record = reader.getCurrent();
ConversationItem conversationItem = new ConversationItem(context);
MmsSmsDatabase.Reader reader = db.readerFor(dataCursor, masterSecret);
MessageRecord record = reader.getCurrent();

this.setMessageView(record, holder);

if (record.isMms() && ((MmsMessageRecord) record).getSlideDeck().getSlides().size() != 0) {
ConversationItem conversationItem = new ConversationItem(context);
ConversationItem.ThumbnailClickListener thumbnailClickListener = conversationItem.new ThumbnailClickListener(record);
if (isDocument(record)) {
ConversationItem.ThumbnailClickListener thumbnailClickListener
= conversationItem.new ThumbnailClickListener(record);
ConversationItem.AttachmentDownloadClickListener attachmentDownloadClickListener
= conversationItem.new AttachmentDownloadClickListener();
holder.documentViewStub.get().setDocument(((MediaMmsMessageRecord)record).getSlideDeck().getDocumentSlide(), true);
holder.documentViewStub.get().setDocumentClickListener(thumbnailClickListener);
holder.documentViewStub.get().setDownloadClickListener(attachmentDownloadClickListener);
holder.documentViewStub.get().setVisibility(view.VISIBLE);
}

if (isAudio(record)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this one also be else if?

ConversationItem.AttachmentDownloadClickListener attachmentDownloadClickListener
= conversationItem.new AttachmentDownloadClickListener();
holder.audioViewStub.get().setAudio(masterSecret, ((MediaMmsMessageRecord)record).getSlideDeck().getAudioSlide(), true);
holder.audioViewStub.get().setDownloadClickListener(attachmentDownloadClickListener);
holder.audioViewStub.get().setVisibility(view.VISIBLE);
}

else if (isVideo(record)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this should be on the same line as the closing bracket.

https://github.com/signalapp/Signal-Android/search?utf8=%E2%9C%93&q=else+if&type=Code

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting
same goes for try catch

ConversationItem.ThumbnailClickListener thumbnailClickListener
= conversationItem.new ThumbnailClickListener(record);

holder.mediaThumbnailStub.get().setImageResource(masterSecret, glideRequests,
((MmsMessageRecord) record).getSlideDeck().getThumbnailSlide(),
Expand Down Expand Up @@ -146,6 +172,18 @@ private void setMessageView(MessageRecord record, ViewHolder viewHolder) {
viewHolder.recipient.setText(messageSenderName);
}

private boolean isAudio(MessageRecord messageRecord) {
return messageRecord.isMms() && ((MmsMessageRecord)messageRecord).getSlideDeck().getAudioSlide() != null;
}

private boolean isVideo(MessageRecord messageRecord) {
return messageRecord.isMms() && ((MmsMessageRecord)messageRecord).getSlideDeck().getThumbnailSlide() != null;
}

private boolean isDocument(MessageRecord messageRecord) {
return messageRecord.isMms() && ((MmsMessageRecord)messageRecord).getSlideDeck().getDocumentSlide() != null;
}

@Override
public int getItemCount() {
return (dataCursor == null) ? 0 : dataCursor.getCount();
Expand Down