mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-17 13:28:26 +00:00
re-introduce the message detail screen
This commit is contained in:
parent
496d9683e3
commit
dc33e28826
@ -221,6 +221,11 @@
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="org.thoughtcrime.securesms.home.HomeActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name="org.thoughtcrime.securesms.conversation.v2.MessageDetailActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/Theme.TextSecure.DayNight">
|
||||
</activity>
|
||||
<activity
|
||||
android:name="org.thoughtcrime.securesms.groups.OpenGroupGuidelinesActivity"
|
||||
android:screenOrientation="portrait"
|
||||
|
@ -1251,7 +1251,11 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
}
|
||||
|
||||
override fun showMessageDetail(messages: Set<MessageRecord>) {
|
||||
TODO("Not yet implemented")
|
||||
val message = messages.first()
|
||||
val intent = Intent(this, MessageDetailActivity::class.java)
|
||||
intent.putExtra(MessageDetailActivity.MESSAGE_TIMESTAMP, message.timestamp)
|
||||
push(intent)
|
||||
endActionMode()
|
||||
}
|
||||
|
||||
override fun saveAttachment(messages: Set<MessageRecord>) {
|
||||
|
@ -0,0 +1,118 @@
|
||||
package org.thoughtcrime.securesms.conversation.v2
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.LinearLayout
|
||||
import androidx.annotation.DimenRes
|
||||
import kotlinx.android.synthetic.main.activity_conversation_v2_action_bar.*
|
||||
import kotlinx.android.synthetic.main.activity_message_detail.*
|
||||
import network.loki.messenger.R
|
||||
import org.session.libsession.messaging.MessagingModuleConfiguration
|
||||
import org.session.libsession.messaging.messages.visible.LinkPreview
|
||||
import org.session.libsession.messaging.messages.visible.OpenGroupInvitation
|
||||
import org.session.libsession.messaging.messages.visible.Quote
|
||||
import org.session.libsession.messaging.messages.visible.VisibleMessage
|
||||
import org.session.libsession.messaging.sending_receiving.MessageSender
|
||||
import org.session.libsession.messaging.utilities.UpdateMessageData
|
||||
import org.session.libsession.utilities.Address
|
||||
import org.session.libsession.utilities.ExpirationUtil
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
import org.session.libsession.utilities.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
|
||||
import org.thoughtcrime.securesms.util.DateUtils
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
||||
class MessageDetailActivity: PassphraseRequiredActionBarActivity() {
|
||||
|
||||
var messageRecord: MessageRecord? = null
|
||||
|
||||
// region Settings
|
||||
companion object {
|
||||
// Extras
|
||||
const val MESSAGE_TIMESTAMP = "message_timestamp"
|
||||
}
|
||||
// endregion
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?, ready: Boolean) {
|
||||
super.onCreate(savedInstanceState, ready)
|
||||
setContentView(R.layout.activity_message_detail)
|
||||
title = resources.getString(R.string.conversation_context__menu_message_details)
|
||||
val timestamp = intent.getLongExtra(MESSAGE_TIMESTAMP, -1L)
|
||||
val author = Address.fromSerialized(TextSecurePreferences.getLocalNumber(this)!!)
|
||||
messageRecord = DatabaseFactory.getMmsSmsDatabase (this).getMessageFor(timestamp, author)
|
||||
updateContent()
|
||||
resend_button.setOnClickListener {
|
||||
resend()
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
fun updateContent() {
|
||||
val dateLocale = Locale.getDefault()
|
||||
val dateFormatter: SimpleDateFormat = DateUtils.getDetailedDateFormatter(this, dateLocale)
|
||||
sent_time.text = dateFormatter.format(Date(messageRecord!!.dateSent))
|
||||
|
||||
val errorMessage = DatabaseFactory.getLokiMessageDatabase(this).getErrorMessage(messageRecord!!.getId()) ?: "Message failed to send."
|
||||
error_message.text = errorMessage
|
||||
|
||||
if (messageRecord!!.getExpiresIn() <= 0 || messageRecord!!.getExpireStarted() <= 0) {
|
||||
expires_container.visibility = View.GONE
|
||||
} else {
|
||||
expires_container.visibility = View.VISIBLE
|
||||
val elapsed = System.currentTimeMillis() - messageRecord!!.expireStarted
|
||||
val remaining = messageRecord!!.expiresIn - elapsed
|
||||
|
||||
val duration = ExpirationUtil.getExpirationDisplayValue(this, Math.max((remaining / 1000).toInt(), 1))
|
||||
expires_in.text = duration
|
||||
}
|
||||
}
|
||||
|
||||
fun resend() {
|
||||
val messageRecord = messageRecord!!
|
||||
val recipient: Recipient = messageRecord.recipient
|
||||
val message = VisibleMessage()
|
||||
message.id = messageRecord.getId()
|
||||
if (messageRecord.isOpenGroupInvitation) {
|
||||
val openGroupInvitation = OpenGroupInvitation()
|
||||
UpdateMessageData.fromJSON(messageRecord.body)?.let { updateMessageData ->
|
||||
val kind = updateMessageData.kind
|
||||
if (kind is UpdateMessageData.Kind.OpenGroupInvitation) {
|
||||
openGroupInvitation.name = kind.groupName
|
||||
openGroupInvitation.url = kind.groupUrl
|
||||
}
|
||||
}
|
||||
message.openGroupInvitation = openGroupInvitation
|
||||
} else {
|
||||
message.text = messageRecord.body
|
||||
}
|
||||
message.sentTimestamp = messageRecord.timestamp
|
||||
if (recipient.isGroupRecipient) {
|
||||
message.groupPublicKey = recipient.address.toGroupString()
|
||||
} else {
|
||||
message.recipient = messageRecord.recipient.address.serialize()
|
||||
}
|
||||
message.threadID = messageRecord.threadId
|
||||
if (messageRecord.isMms) {
|
||||
val mmsMessageRecord = messageRecord as MmsMessageRecord
|
||||
if (mmsMessageRecord.linkPreviews.isNotEmpty()) {
|
||||
message.linkPreview = LinkPreview.from(mmsMessageRecord.linkPreviews[0])
|
||||
}
|
||||
if (mmsMessageRecord.quote != null) {
|
||||
message.quote = Quote.from(mmsMessageRecord.quote!!.quoteModel)
|
||||
}
|
||||
message.addSignalAttachments(mmsMessageRecord.slideDeck.asAttachments())
|
||||
}
|
||||
val sentTimestamp = message.sentTimestamp
|
||||
val sender = MessagingModuleConfiguration.shared.storage.getUserPublicKey()
|
||||
if (sentTimestamp != null && sender != null) {
|
||||
MessagingModuleConfiguration.shared.storage.markAsSending(sentTimestamp, sender)
|
||||
}
|
||||
MessageSender.send(message, recipient.address)
|
||||
}
|
||||
}
|
108
app/src/main/res/layout/activity_message_detail.xml
Normal file
108
app/src/main/res/layout/activity_message_detail.xml
Normal file
@ -0,0 +1,108 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:background="@color/transparent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<FrameLayout android:id="@+id/item_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/medium_spacing"
|
||||
android:paddingBottom="@dimen/medium_spacing"
|
||||
android:elevation="10dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="@dimen/medium_spacing"
|
||||
android:paddingEnd="@dimen/medium_spacing">
|
||||
|
||||
<TableLayout android:id="@+id/metadata_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:shrinkColumns="1">
|
||||
|
||||
<TableRow android:id="@+id/sent_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dp">
|
||||
|
||||
<TextView android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/message_details_header__sent"
|
||||
android:gravity="end"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView android:id="@+id/sent_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
tools:text="Jan 18, 2015, 12:29:37 AM GMT-08:00" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow android:id="@+id/expires_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dp"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<TextView android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/message_details_header__disappears"
|
||||
android:gravity="end"
|
||||
android:textStyle="bold"/>
|
||||
|
||||
<TextView android:id="@+id/expires_in"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
tools:text="1 week"/>
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dp">
|
||||
|
||||
<TextView android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/message_details_header__error"
|
||||
android:gravity="end"
|
||||
android:textStyle="bold"/>
|
||||
|
||||
<TextView android:id="@+id/error_message"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
tools:text="Send Failed"/>
|
||||
|
||||
</TableRow>
|
||||
|
||||
</TableLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="40dp"
|
||||
android:gravity="end">
|
||||
|
||||
|
||||
<Button
|
||||
android:id="@+id/resend_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/medium_button_height"
|
||||
android:paddingStart="30dp"
|
||||
android:paddingEnd="30dp"
|
||||
style="@style/Widget.Session.Button.Common.ProminentOutline"
|
||||
android:text="@string/message_recipients_list_item__resend" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -22,7 +22,7 @@
|
||||
app:showAsAction="always" />
|
||||
|
||||
<item
|
||||
android:title="@string/details"
|
||||
android:title="@string/conversation_context__menu_message_details"
|
||||
android:id="@+id/menu_message_details"
|
||||
android:icon="?menu_info_icon"
|
||||
app:showAsAction="always" />
|
||||
|
@ -881,4 +881,5 @@
|
||||
<string name="activity_conversation_attachment_prep_failed">Failed to prepare attachment for sending.</string>
|
||||
<string name="media">Media</string>
|
||||
<string name="UntrustedAttachmentView_download_attachment">Tap to download %s</string>
|
||||
<string name="message_details_header__error">Error</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user