forked from traccar/traccar-sms-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a "Properties" menu button in conversation, when one message is selected, which displays details about the message: - Type (SMS or MMS) - Sender phone number (or receiver if it is a sent message) - Used SIM - Date sent at - Date received at (if it is an incoming message) This closes traccar#19
- Loading branch information
Showing
56 changed files
with
530 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
app/src/main/kotlin/com/simplemobiletools/smsmessenger/dialogs/MessageDetailsDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.simplemobiletools.smsmessenger.dialogs | ||
|
||
import android.annotation.SuppressLint | ||
import android.telephony.SubscriptionInfo | ||
import com.simplemobiletools.commons.activities.BaseSimpleActivity | ||
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder | ||
import com.simplemobiletools.commons.extensions.getTimeFormat | ||
import com.simplemobiletools.commons.extensions.setupDialogStuff | ||
import com.simplemobiletools.smsmessenger.R | ||
import com.simplemobiletools.smsmessenger.extensions.config | ||
import com.simplemobiletools.smsmessenger.extensions.subscriptionManagerCompat | ||
import com.simplemobiletools.smsmessenger.models.Message | ||
import kotlinx.android.synthetic.main.dialog_message_details.view.dialog_message_details_text_value | ||
import org.joda.time.DateTime | ||
|
||
class MessageDetailsDialog(val activity: BaseSimpleActivity, val message: Message) { | ||
init { | ||
@SuppressLint("MissingPermission") | ||
val availableSIMs = activity.subscriptionManagerCompat().activeSubscriptionInfoList | ||
|
||
@SuppressLint("SetTextI18n") | ||
val view = activity.layoutInflater.inflate(R.layout.dialog_message_details, null).apply { | ||
dialog_message_details_text_value.text = """ | ||
${activity.getString(R.string.message_details_type)}: ${message.getMessageType()} | ||
${message.getReceiverOrSenderLabel()}: ${message.getReceiverOrSenderPhoneNumbers()} | ||
SIM: ${message.getSIM(availableSIMs)} | ||
${activity.getString(R.string.message_details_sent_at)}: ${message.getSentAt()} | ||
${message.getReceivedAtLine()} | ||
""".trimIndent().trimEnd() | ||
} | ||
|
||
activity.getAlertDialogBuilder() | ||
.setPositiveButton(R.string.ok) { _, _ -> } | ||
.apply { | ||
activity.setupDialogStuff(view, this, R.string.message_details) | ||
} | ||
} | ||
|
||
private fun Message.getMessageType(): String = if (isMMS) "MMS" else "SMS" | ||
|
||
private fun Message.getReceiverOrSenderLabel(): String { | ||
return if (isReceivedMessage()) { | ||
activity.getString(R.string.message_details_sender) | ||
} else { | ||
activity.getString(R.string.message_details_receiver) | ||
} | ||
} | ||
|
||
private fun Message.getReceiverOrSenderPhoneNumbers(): String { | ||
return participants.joinToString(", ") { it.phoneNumbers.first().value } | ||
} | ||
|
||
private fun Message.getSIM(availableSIMs: List<SubscriptionInfo>): String { | ||
return availableSIMs.firstOrNull { it.subscriptionId == subscriptionId }?.displayName?.toString() ?: activity.getString(R.string.unknown) | ||
} | ||
|
||
private fun Message.getSentAt(): String { | ||
return DateTime(dateSent * 1000L).toString(activity.config.dateFormat + " " + activity.getTimeFormat()) | ||
} | ||
|
||
private fun Message.getReceivedAtLine(): String { | ||
return if (isReceivedMessage()) { | ||
"${activity.getString(R.string.message_details_received_at)}: ${getReceivedAt()}" | ||
} else { | ||
"" | ||
} | ||
} | ||
|
||
private fun Message.getReceivedAt(): String { | ||
return DateTime(date * 1000L).toString(activity.config.dateFormat + " " + activity.getTimeFormat()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<com.simplemobiletools.commons.views.MyTextView xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/dialog_message_details_text_value" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:paddingStart="@dimen/big_margin" | ||
android:paddingTop="@dimen/big_margin" | ||
android:paddingEnd="@dimen/big_margin" | ||
android:textIsSelectable="true" | ||
android:textSize="@dimen/big_text_size" | ||
tools:text="My sample text" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.