forked from upstream-mirrors/quik
#975 - Show message details
This commit is contained in:
@@ -41,6 +41,10 @@ class DateFormatter @Inject constructor(val context: Context) {
|
||||
else SimpleDateFormat(pattern, Locale.getDefault())
|
||||
}
|
||||
|
||||
fun getDetailedTimestamp(date: Long): String {
|
||||
return getFormatter("M/d/y, h:mm:ss a").format(date)
|
||||
}
|
||||
|
||||
fun getTimestamp(date: Long): String {
|
||||
return getFormatter("h:mm a").format(date)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package common.util
|
||||
|
||||
import android.content.Context
|
||||
import com.google.android.mms.pdu_alt.EncodedStringValue
|
||||
import com.google.android.mms.pdu_alt.MultimediaMessagePdu
|
||||
import com.google.android.mms.pdu_alt.PduPersister
|
||||
import com.moez.QKSMS.R
|
||||
import model.Message
|
||||
import util.tryOrNull
|
||||
import javax.inject.Inject
|
||||
|
||||
class MessageDetailsFormatter @Inject constructor(
|
||||
private val context: Context,
|
||||
private val dateFormatter: DateFormatter
|
||||
) {
|
||||
|
||||
fun format(message: Message): String {
|
||||
val builder = StringBuilder()
|
||||
|
||||
message.type
|
||||
.takeIf { it.isNotBlank() }
|
||||
?.toUpperCase()
|
||||
?.let { context.getString(R.string.compose_details_type, it) }
|
||||
?.let(builder::appendln)
|
||||
|
||||
if (message.isSms()) {
|
||||
message.address
|
||||
.takeIf { it.isNotBlank() && !message.isMe() }
|
||||
?.let { context.getString(R.string.compose_details_from, it) }
|
||||
?.let(builder::appendln)
|
||||
|
||||
message.address
|
||||
.takeIf { it.isNotBlank() && message.isMe() }
|
||||
?.let { context.getString(R.string.compose_details_to, it) }
|
||||
?.let(builder::appendln)
|
||||
} else {
|
||||
val pdu = tryOrNull {
|
||||
PduPersister.getPduPersister(context)
|
||||
.load(message.getUri())
|
||||
as MultimediaMessagePdu
|
||||
}
|
||||
|
||||
pdu?.from?.string
|
||||
?.takeIf { it.isNotBlank() }
|
||||
?.let { context.getString(R.string.compose_details_from, it) }
|
||||
?.let(builder::appendln)
|
||||
|
||||
pdu?.to
|
||||
?.let(EncodedStringValue::concat)
|
||||
?.takeIf { it.isNotBlank() }
|
||||
?.let { context.getString(R.string.compose_details_to, it) }
|
||||
?.let(builder::appendln)
|
||||
}
|
||||
|
||||
message.date
|
||||
.takeIf { it > 0 && message.isMe() }
|
||||
?.let(dateFormatter::getDetailedTimestamp)
|
||||
?.let { context.getString(R.string.compose_details_sent, it) }
|
||||
?.let(builder::appendln)
|
||||
|
||||
message.dateSent
|
||||
.takeIf { it > 0 && !message.isMe() }
|
||||
?.let(dateFormatter::getDetailedTimestamp)
|
||||
?.let { context.getString(R.string.compose_details_sent, it) }
|
||||
?.let(builder::appendln)
|
||||
|
||||
message.date
|
||||
.takeIf { it > 0 && !message.isMe() }
|
||||
?.let(dateFormatter::getDetailedTimestamp)
|
||||
?.let { context.getString(R.string.compose_details_received, it) }
|
||||
?.let(builder::appendln)
|
||||
|
||||
message.dateSent
|
||||
.takeIf { it > 0 && message.isMe() }
|
||||
?.let(dateFormatter::getDetailedTimestamp)
|
||||
?.let { context.getString(R.string.compose_details_delivered, it) }
|
||||
?.let(builder::appendln)
|
||||
|
||||
message.errorCode
|
||||
.takeIf { it != 0 && message.isSms() }
|
||||
?.let { context.getString(R.string.compose_details_error_code, it) }
|
||||
?.let(builder::appendln)
|
||||
|
||||
return builder.toString().trim()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.MediaStore
|
||||
import android.support.v4.app.ActivityCompat
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
@@ -182,6 +183,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
toolbar.menu.findItem(R.id.call)?.isVisible = !state.editingMode && state.selectedMessages == 0 && state.query.isEmpty()
|
||||
toolbar.menu.findItem(R.id.info)?.isVisible = !state.editingMode && state.selectedMessages == 0 && state.query.isEmpty()
|
||||
toolbar.menu.findItem(R.id.copy)?.isVisible = !state.editingMode && state.selectedMessages == 1
|
||||
toolbar.menu.findItem(R.id.details)?.isVisible = !state.editingMode && state.selectedMessages == 1
|
||||
toolbar.menu.findItem(R.id.delete)?.isVisible = !state.editingMode && state.selectedMessages > 0
|
||||
toolbar.menu.findItem(R.id.forward)?.isVisible = !state.editingMode && state.selectedMessages == 1
|
||||
toolbar.menu.findItem(R.id.previous)?.isVisible = state.selectedMessages == 0 && state.query.isNotEmpty()
|
||||
@@ -225,6 +227,14 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
messageAdapter.clearSelection()
|
||||
}
|
||||
|
||||
override fun showDetails(details: String) {
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.compose_details_title)
|
||||
.setMessage(details)
|
||||
.setCancelable(true)
|
||||
.show()
|
||||
}
|
||||
|
||||
override fun requestStoragePermission() {
|
||||
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 0)
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ interface ComposeView : QkView<ComposeState> {
|
||||
val sendIntent: Observable<Unit>
|
||||
|
||||
fun clearSelection()
|
||||
fun showDetails(details: String)
|
||||
fun requestStoragePermission()
|
||||
fun requestCamera()
|
||||
fun requestGallery()
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.Navigator
|
||||
import common.base.QkViewModel
|
||||
import common.util.ClipboardUtils
|
||||
import common.util.MessageDetailsFormatter
|
||||
import common.util.extensions.makeToast
|
||||
import compat.SubscriptionManagerCompat
|
||||
import compat.TelephonyCompat
|
||||
@@ -82,6 +83,7 @@ class ComposeViewModel @Inject constructor(
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val deleteMessages: DeleteMessages,
|
||||
private val markRead: MarkRead,
|
||||
private val messageDetailsFormatter: MessageDetailsFormatter,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val navigator: Navigator,
|
||||
private val permissionManager: PermissionManager,
|
||||
@@ -315,6 +317,16 @@ class ComposeViewModel @Inject constructor(
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.clearSelection() }
|
||||
|
||||
// Show the message details
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.details }
|
||||
.withLatestFrom(view.messagesSelectedIntent) { _, messages -> messages }
|
||||
.mapNotNull { messages -> messages.firstOrNull().also { view.clearSelection() } }
|
||||
.mapNotNull(messageRepo::getMessage)
|
||||
.map(messageDetailsFormatter::format)
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.showDetails(it) }
|
||||
|
||||
// Delete the messages
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.delete }
|
||||
|
||||
+1
-1
@@ -5,5 +5,5 @@
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M11,17h2v-6h-2v6zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM11,9h2L13,7h-2v2z"/>
|
||||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-6h2v6zM13,9h-2L11,7h2v2z"/>
|
||||
</vector>
|
||||
@@ -200,7 +200,7 @@
|
||||
android:id="@+id/about"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:icon="@drawable/ic_info_outline_black_24dp"
|
||||
app:icon="@drawable/ic_info_black_24dp"
|
||||
app:title="@string/settings_about_title"
|
||||
tools:summary="Version 3.0.7" />
|
||||
|
||||
|
||||
@@ -40,6 +40,13 @@
|
||||
android:visible="false"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/details"
|
||||
android:icon="@drawable/ic_info_black_24dp"
|
||||
android:title="@string/compose_menu_copy"
|
||||
android:visible="false"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/delete"
|
||||
android:icon="@drawable/ic_delete_black_24dp"
|
||||
|
||||
@@ -96,6 +96,17 @@
|
||||
<string name="compose_menu_previous">Previous</string>
|
||||
<string name="compose_menu_next">Next</string>
|
||||
<string name="compose_menu_clear">Clear</string>
|
||||
<string name="compose_details_title">Message details</string>
|
||||
<string name="compose_details_type">Type: %s</string>
|
||||
<string name="compose_details_from">From: %s</string>
|
||||
<string name="compose_details_to">To: %s</string>
|
||||
<string name="compose_details_subject">Subject: %s</string>
|
||||
<string name="compose_details_priority">Priority: %s</string>
|
||||
<string name="compose_details_size">Size: %s</string>
|
||||
<string name="compose_details_sent">Sent: %s</string>
|
||||
<string name="compose_details_received">Received: %s</string>
|
||||
<string name="compose_details_delivered">Delivered: %s</string>
|
||||
<string name="compose_details_error_code">Error code: %d</string>
|
||||
<string name="compose_attach_cd">Add an attachment</string>
|
||||
<string name="compose_gallery_cd">Attach a photo</string>
|
||||
<string name="compose_camera_cd">Take a photo</string>
|
||||
|
||||
Reference in New Issue
Block a user