mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-06-05 21:49:22 +02:00
Merge pull request #498 from Naveen3Singh/feature_group_details
Add ability to change group names
This commit is contained in:
@@ -141,6 +141,12 @@
|
|||||||
android:label="@string/contact_details"
|
android:label="@string/contact_details"
|
||||||
android:parentActivityName=".activities.ThreadActivity" />
|
android:parentActivityName=".activities.ThreadActivity" />
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".activities.ConversationDetailsActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:label="@string/conversation_details"
|
||||||
|
android:parentActivityName=".activities.ThreadActivity" />
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".services.HeadlessSmsSendService"
|
android:name=".services.HeadlessSmsSendService"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
|
@@ -0,0 +1,83 @@
|
|||||||
|
package com.simplemobiletools.smsmessenger.activities
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.core.content.res.ResourcesCompat
|
||||||
|
import com.simplemobiletools.commons.extensions.adjustAlpha
|
||||||
|
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||||
|
import com.simplemobiletools.commons.extensions.getProperTextColor
|
||||||
|
import com.simplemobiletools.commons.helpers.HIGHER_ALPHA
|
||||||
|
import com.simplemobiletools.commons.helpers.NavigationIcon
|
||||||
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
|
import com.simplemobiletools.commons.models.SimpleContact
|
||||||
|
import com.simplemobiletools.smsmessenger.R
|
||||||
|
import com.simplemobiletools.smsmessenger.adapters.ContactsAdapter
|
||||||
|
import com.simplemobiletools.smsmessenger.dialogs.RenameConversationDialog
|
||||||
|
import com.simplemobiletools.smsmessenger.extensions.*
|
||||||
|
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
|
||||||
|
import com.simplemobiletools.smsmessenger.models.Conversation
|
||||||
|
import kotlinx.android.synthetic.main.activity_conversation_details.*
|
||||||
|
|
||||||
|
class ConversationDetailsActivity : SimpleActivity() {
|
||||||
|
|
||||||
|
private var threadId: Long = 0L
|
||||||
|
private var conversation: Conversation? = null
|
||||||
|
private lateinit var participants: ArrayList<SimpleContact>
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setContentView(R.layout.activity_conversation_details)
|
||||||
|
|
||||||
|
threadId = intent.getLongExtra(THREAD_ID, 0L)
|
||||||
|
ensureBackgroundThread {
|
||||||
|
conversation = conversationsDB.getConversationWithThreadId(threadId)
|
||||||
|
participants = getThreadParticipants(threadId, null)
|
||||||
|
runOnUiThread {
|
||||||
|
setupTextViews()
|
||||||
|
setupParticipants()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
setupToolbar(conversation_details_toolbar, NavigationIcon.Arrow)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupTextViews() {
|
||||||
|
val textColor = getProperTextColor()
|
||||||
|
val headingColor = textColor.adjustAlpha(HIGHER_ALPHA)
|
||||||
|
|
||||||
|
members_heading.setTextColor(headingColor)
|
||||||
|
conversation_name_heading.setTextColor(headingColor)
|
||||||
|
conversation_name.apply {
|
||||||
|
setTextColor(textColor)
|
||||||
|
ResourcesCompat.getDrawable(resources, R.drawable.ic_edit_vector, theme)?.apply {
|
||||||
|
applyColorFilter(textColor)
|
||||||
|
setCompoundDrawablesWithIntrinsicBounds(null, null, this, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
text = conversation?.title
|
||||||
|
setOnClickListener {
|
||||||
|
RenameConversationDialog(this@ConversationDetailsActivity, conversation!!) { title ->
|
||||||
|
text = title
|
||||||
|
ensureBackgroundThread {
|
||||||
|
conversation = renameConversation(conversation!!, newTitle = title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupParticipants() {
|
||||||
|
val adapter = ContactsAdapter(this, participants, participants_recyclerview) {
|
||||||
|
val contact = it as SimpleContact
|
||||||
|
val address = contact.phoneNumbers.first().normalizedNumber
|
||||||
|
getContactFromAddress(address) { simpleContact ->
|
||||||
|
if (simpleContact != null) {
|
||||||
|
startContactDetailsIntent(simpleContact)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
participants_recyclerview.adapter = adapter
|
||||||
|
}
|
||||||
|
}
|
@@ -257,9 +257,14 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cachedConversations.forEach { cachedConv ->
|
cachedConversations.forEach { cachedConv ->
|
||||||
val conv = conversations.find { it.threadId == cachedConv.threadId && !Conversation.areContentsTheSame(cachedConv, it) }
|
val conv = conversations.find {
|
||||||
|
it.threadId == cachedConv.threadId && !Conversation.areContentsTheSame(cachedConv, it)
|
||||||
|
}
|
||||||
if (conv != null) {
|
if (conv != null) {
|
||||||
val conversation = conv.copy(date = maxOf(cachedConv.date, conv.date))
|
val lastModified = maxOf(cachedConv.date, conv.date)
|
||||||
|
val usesCustomTitle = cachedConv.usesCustomTitle
|
||||||
|
val title = if (usesCustomTitle) cachedConv.title else conv.title
|
||||||
|
val conversation = conv.copy(date = lastModified, title = title, usesCustomTitle = usesCustomTitle)
|
||||||
conversationsDB.insertOrUpdate(conversation)
|
conversationsDB.insertOrUpdate(conversation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -51,6 +51,7 @@ import com.simplemobiletools.smsmessenger.R
|
|||||||
import com.simplemobiletools.smsmessenger.adapters.AttachmentsAdapter
|
import com.simplemobiletools.smsmessenger.adapters.AttachmentsAdapter
|
||||||
import com.simplemobiletools.smsmessenger.adapters.AutoCompleteTextViewAdapter
|
import com.simplemobiletools.smsmessenger.adapters.AutoCompleteTextViewAdapter
|
||||||
import com.simplemobiletools.smsmessenger.adapters.ThreadAdapter
|
import com.simplemobiletools.smsmessenger.adapters.ThreadAdapter
|
||||||
|
import com.simplemobiletools.smsmessenger.dialogs.RenameConversationDialog
|
||||||
import com.simplemobiletools.smsmessenger.dialogs.ScheduleMessageDialog
|
import com.simplemobiletools.smsmessenger.dialogs.ScheduleMessageDialog
|
||||||
import com.simplemobiletools.smsmessenger.extensions.*
|
import com.simplemobiletools.smsmessenger.extensions.*
|
||||||
import com.simplemobiletools.smsmessenger.helpers.*
|
import com.simplemobiletools.smsmessenger.helpers.*
|
||||||
@@ -80,6 +81,7 @@ class ThreadActivity : SimpleActivity() {
|
|||||||
private var refreshedSinceSent = false
|
private var refreshedSinceSent = false
|
||||||
private var threadItems = ArrayList<ThreadItem>()
|
private var threadItems = ArrayList<ThreadItem>()
|
||||||
private var bus: EventBus? = null
|
private var bus: EventBus? = null
|
||||||
|
private var conversation: Conversation? = null
|
||||||
private var participants = ArrayList<SimpleContact>()
|
private var participants = ArrayList<SimpleContact>()
|
||||||
private var privateContacts = ArrayList<SimpleContact>()
|
private var privateContacts = ArrayList<SimpleContact>()
|
||||||
private var messages = ArrayList<Message>()
|
private var messages = ArrayList<Message>()
|
||||||
@@ -120,6 +122,7 @@ class ThreadActivity : SimpleActivity() {
|
|||||||
handlePermission(PERMISSION_READ_PHONE_STATE) { granted ->
|
handlePermission(PERMISSION_READ_PHONE_STATE) { granted ->
|
||||||
if (granted) {
|
if (granted) {
|
||||||
setupButtons()
|
setupButtons()
|
||||||
|
setupConversation()
|
||||||
setupCachedMessages {
|
setupCachedMessages {
|
||||||
val searchedMessageId = intent.getLongExtra(SEARCHED_MESSAGE_ID, -1L)
|
val searchedMessageId = intent.getLongExtra(SEARCHED_MESSAGE_ID, -1L)
|
||||||
intent.removeExtra(SEARCHED_MESSAGE_ID)
|
intent.removeExtra(SEARCHED_MESSAGE_ID)
|
||||||
@@ -151,6 +154,16 @@ class ThreadActivity : SimpleActivity() {
|
|||||||
thread_type_message.setText(smsDraft)
|
thread_type_message.setText(smsDraft)
|
||||||
}
|
}
|
||||||
isActivityVisible = true
|
isActivityVisible = true
|
||||||
|
|
||||||
|
ensureBackgroundThread {
|
||||||
|
val newConv = conversationsDB.getConversationWithThreadId(threadId)
|
||||||
|
if (newConv != null) {
|
||||||
|
conversation = newConv
|
||||||
|
runOnUiThread {
|
||||||
|
setupThreadTitle()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
@@ -184,6 +197,8 @@ class ThreadActivity : SimpleActivity() {
|
|||||||
val firstPhoneNumber = participants.firstOrNull()?.phoneNumbers?.firstOrNull()?.value
|
val firstPhoneNumber = participants.firstOrNull()?.phoneNumbers?.firstOrNull()?.value
|
||||||
thread_toolbar.menu.apply {
|
thread_toolbar.menu.apply {
|
||||||
findItem(R.id.delete).isVisible = threadItems.isNotEmpty()
|
findItem(R.id.delete).isVisible = threadItems.isNotEmpty()
|
||||||
|
findItem(R.id.rename_conversation).isVisible = participants.size > 1 && conversation != null
|
||||||
|
findItem(R.id.conversation_details).isVisible = participants.size > 1 && conversation != null
|
||||||
findItem(R.id.block_number).title = addLockedLabelIfNeeded(R.string.block_number)
|
findItem(R.id.block_number).title = addLockedLabelIfNeeded(R.string.block_number)
|
||||||
findItem(R.id.block_number).isVisible = isNougatPlus()
|
findItem(R.id.block_number).isVisible = isNougatPlus()
|
||||||
findItem(R.id.dial_number).isVisible = participants.size == 1
|
findItem(R.id.dial_number).isVisible = participants.size == 1
|
||||||
@@ -205,6 +220,8 @@ class ThreadActivity : SimpleActivity() {
|
|||||||
when (menuItem.itemId) {
|
when (menuItem.itemId) {
|
||||||
R.id.block_number -> tryBlocking()
|
R.id.block_number -> tryBlocking()
|
||||||
R.id.delete -> askConfirmDelete()
|
R.id.delete -> askConfirmDelete()
|
||||||
|
R.id.rename_conversation -> renameConversation()
|
||||||
|
R.id.conversation_details -> showConversationDetails()
|
||||||
R.id.add_number_to_contact -> addNumberToContact()
|
R.id.add_number_to_contact -> addNumberToContact()
|
||||||
R.id.dial_number -> dialNumber()
|
R.id.dial_number -> dialNumber()
|
||||||
R.id.manage_people -> managePeople()
|
R.id.manage_people -> managePeople()
|
||||||
@@ -485,6 +502,12 @@ class ThreadActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupConversation() {
|
||||||
|
ensureBackgroundThread {
|
||||||
|
conversation = conversationsDB.getConversationWithThreadId(threadId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun setupButtons() {
|
private fun setupButtons() {
|
||||||
updateTextColors(thread_holder)
|
updateTextColors(thread_holder)
|
||||||
val textColor = getProperTextColor()
|
val textColor = getProperTextColor()
|
||||||
@@ -638,9 +661,11 @@ class ThreadActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupThreadTitle() {
|
private fun setupThreadTitle() {
|
||||||
val threadTitle = participants.getThreadTitle()
|
val title = conversation?.title
|
||||||
if (threadTitle.isNotEmpty()) {
|
thread_toolbar.title = if (!title.isNullOrEmpty()) {
|
||||||
thread_toolbar.title = participants.getThreadTitle()
|
title
|
||||||
|
} else {
|
||||||
|
participants.getThreadTitle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -827,6 +852,24 @@ class ThreadActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun renameConversation() {
|
||||||
|
RenameConversationDialog(this, conversation!!) { title ->
|
||||||
|
ensureBackgroundThread {
|
||||||
|
conversation = renameConversation(conversation!!, newTitle = title)
|
||||||
|
runOnUiThread {
|
||||||
|
setupThreadTitle()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showConversationDetails() {
|
||||||
|
Intent(this, ConversationDetailsActivity::class.java).apply {
|
||||||
|
putExtra(THREAD_ID, threadId)
|
||||||
|
startActivity(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
private fun getThreadItems(): ArrayList<ThreadItem> {
|
private fun getThreadItems(): ArrayList<ThreadItem> {
|
||||||
val items = ArrayList<ThreadItem>()
|
val items = ArrayList<ThreadItem>()
|
||||||
@@ -1242,31 +1285,6 @@ class ThreadActivity : SimpleActivity() {
|
|||||||
return participants
|
return participants
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startContactDetailsIntent(contact: SimpleContact) {
|
|
||||||
val simpleContacts = "com.simplemobiletools.contacts.pro"
|
|
||||||
val simpleContactsDebug = "com.simplemobiletools.contacts.pro.debug"
|
|
||||||
if (contact.rawId > 1000000 && contact.contactId > 1000000 && contact.rawId == contact.contactId &&
|
|
||||||
(isPackageInstalled(simpleContacts) || isPackageInstalled(simpleContactsDebug))
|
|
||||||
) {
|
|
||||||
Intent().apply {
|
|
||||||
action = Intent.ACTION_VIEW
|
|
||||||
putExtra(CONTACT_ID, contact.rawId)
|
|
||||||
putExtra(IS_PRIVATE, true)
|
|
||||||
setPackage(if (isPackageInstalled(simpleContacts)) simpleContacts else simpleContactsDebug)
|
|
||||||
setDataAndType(ContactsContract.Contacts.CONTENT_LOOKUP_URI, "vnd.android.cursor.dir/person")
|
|
||||||
launchActivityIntent(this)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ensureBackgroundThread {
|
|
||||||
val lookupKey = SimpleContactsHelper(this).getContactLookupKey((contact).rawId.toString())
|
|
||||||
val publicUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey)
|
|
||||||
runOnUiThread {
|
|
||||||
launchViewContactIntent(publicUri)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun saveMMS(mimeType: String, path: String) {
|
fun saveMMS(mimeType: String, path: String) {
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
lastAttachmentUri = path
|
lastAttachmentUri = path
|
||||||
|
@@ -24,6 +24,7 @@ import com.simplemobiletools.commons.helpers.isNougatPlus
|
|||||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
import com.simplemobiletools.smsmessenger.R
|
import com.simplemobiletools.smsmessenger.R
|
||||||
import com.simplemobiletools.smsmessenger.activities.SimpleActivity
|
import com.simplemobiletools.smsmessenger.activities.SimpleActivity
|
||||||
|
import com.simplemobiletools.smsmessenger.dialogs.RenameConversationDialog
|
||||||
import com.simplemobiletools.smsmessenger.extensions.*
|
import com.simplemobiletools.smsmessenger.extensions.*
|
||||||
import com.simplemobiletools.smsmessenger.helpers.refreshMessages
|
import com.simplemobiletools.smsmessenger.helpers.refreshMessages
|
||||||
import com.simplemobiletools.smsmessenger.models.Conversation
|
import com.simplemobiletools.smsmessenger.models.Conversation
|
||||||
@@ -60,6 +61,7 @@ class ConversationsAdapter(
|
|||||||
findItem(R.id.cab_add_number_to_contact).isVisible = isOneItemSelected() && selectedItems.firstOrNull()?.isGroupConversation == false
|
findItem(R.id.cab_add_number_to_contact).isVisible = isOneItemSelected() && selectedItems.firstOrNull()?.isGroupConversation == false
|
||||||
findItem(R.id.cab_dial_number).isVisible = isOneItemSelected() && selectedItems.firstOrNull()?.isGroupConversation == false
|
findItem(R.id.cab_dial_number).isVisible = isOneItemSelected() && selectedItems.firstOrNull()?.isGroupConversation == false
|
||||||
findItem(R.id.cab_copy_number).isVisible = isOneItemSelected() && selectedItems.firstOrNull()?.isGroupConversation == false
|
findItem(R.id.cab_copy_number).isVisible = isOneItemSelected() && selectedItems.firstOrNull()?.isGroupConversation == false
|
||||||
|
findItem(R.id.rename_conversation).isVisible = isOneItemSelected() && selectedItems.firstOrNull()?.isGroupConversation == true
|
||||||
findItem(R.id.cab_mark_as_read).isVisible = selectedItems.any { !it.read }
|
findItem(R.id.cab_mark_as_read).isVisible = selectedItems.any { !it.read }
|
||||||
findItem(R.id.cab_mark_as_unread).isVisible = selectedItems.any { it.read }
|
findItem(R.id.cab_mark_as_unread).isVisible = selectedItems.any { it.read }
|
||||||
checkPinBtnVisibility(this)
|
checkPinBtnVisibility(this)
|
||||||
@@ -77,6 +79,7 @@ class ConversationsAdapter(
|
|||||||
R.id.cab_dial_number -> dialNumber()
|
R.id.cab_dial_number -> dialNumber()
|
||||||
R.id.cab_copy_number -> copyNumberToClipboard()
|
R.id.cab_copy_number -> copyNumberToClipboard()
|
||||||
R.id.cab_delete -> askConfirmDelete()
|
R.id.cab_delete -> askConfirmDelete()
|
||||||
|
R.id.rename_conversation -> renameConversation(getSelectedItems().first())
|
||||||
R.id.cab_mark_as_read -> markAsRead()
|
R.id.cab_mark_as_read -> markAsRead()
|
||||||
R.id.cab_mark_as_unread -> markAsUnread()
|
R.id.cab_mark_as_unread -> markAsUnread()
|
||||||
R.id.cab_pin_conversation -> pinConversation(true)
|
R.id.cab_pin_conversation -> pinConversation(true)
|
||||||
@@ -211,6 +214,21 @@ class ConversationsAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun renameConversation(conversation: Conversation) {
|
||||||
|
RenameConversationDialog(activity, conversation) {
|
||||||
|
ensureBackgroundThread {
|
||||||
|
val updatedConv = activity.renameConversation(conversation, newTitle = it)
|
||||||
|
activity.runOnUiThread {
|
||||||
|
finishActMode()
|
||||||
|
currentList.toMutableList().apply {
|
||||||
|
set(indexOf(conversation), updatedConv)
|
||||||
|
updateConversations(this as ArrayList<Conversation>)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun markAsRead() {
|
private fun markAsRead() {
|
||||||
if (selectedKeys.isEmpty()) {
|
if (selectedKeys.isEmpty()) {
|
||||||
return
|
return
|
||||||
@@ -222,10 +240,7 @@ class ConversationsAdapter(
|
|||||||
activity.markThreadMessagesRead(it.threadId)
|
activity.markThreadMessagesRead(it.threadId)
|
||||||
}
|
}
|
||||||
|
|
||||||
activity.runOnUiThread {
|
refreshConversations()
|
||||||
refreshMessages()
|
|
||||||
finishActMode()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,10 +255,7 @@ class ConversationsAdapter(
|
|||||||
activity.markThreadMessagesUnread(it.threadId)
|
activity.markThreadMessagesUnread(it.threadId)
|
||||||
}
|
}
|
||||||
|
|
||||||
activity.runOnUiThread {
|
refreshConversations()
|
||||||
refreshMessages()
|
|
||||||
finishActMode()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,10 +283,7 @@ class ConversationsAdapter(
|
|||||||
activity.config.removePinnedConversations(conversations)
|
activity.config.removePinnedConversations(conversations)
|
||||||
}
|
}
|
||||||
|
|
||||||
activity.runOnUiThread {
|
refreshConversations()
|
||||||
refreshMessages()
|
|
||||||
finishActMode()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkPinBtnVisibility(menu: Menu) {
|
private fun checkPinBtnVisibility(menu: Menu) {
|
||||||
@@ -364,6 +373,13 @@ class ConversationsAdapter(
|
|||||||
|
|
||||||
override fun onChange(position: Int) = currentList.getOrNull(position)?.title ?: ""
|
override fun onChange(position: Int) = currentList.getOrNull(position)?.title ?: ""
|
||||||
|
|
||||||
|
private fun refreshConversations() {
|
||||||
|
activity.runOnUiThread {
|
||||||
|
refreshMessages()
|
||||||
|
finishActMode()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun saveRecyclerViewState() {
|
private fun saveRecyclerViewState() {
|
||||||
recyclerViewState = recyclerView.layoutManager?.onSaveInstanceState()
|
recyclerViewState = recyclerView.layoutManager?.onSaveInstanceState()
|
||||||
}
|
}
|
||||||
|
@@ -283,7 +283,7 @@ class ThreadAdapter(
|
|||||||
val contact = message.participants.first()
|
val contact = message.participants.first()
|
||||||
context.getContactFromAddress(contact.phoneNumbers.first().normalizedNumber) {
|
context.getContactFromAddress(contact.phoneNumbers.first().normalizedNumber) {
|
||||||
if (it != null) {
|
if (it != null) {
|
||||||
(activity as ThreadActivity).startContactDetailsIntent(it)
|
activity.startContactDetailsIntent(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,7 +17,7 @@ import com.simplemobiletools.smsmessenger.models.Conversation
|
|||||||
import com.simplemobiletools.smsmessenger.models.Message
|
import com.simplemobiletools.smsmessenger.models.Message
|
||||||
import com.simplemobiletools.smsmessenger.models.MessageAttachment
|
import com.simplemobiletools.smsmessenger.models.MessageAttachment
|
||||||
|
|
||||||
@Database(entities = [Conversation::class, Attachment::class, MessageAttachment::class, Message::class], version = 5)
|
@Database(entities = [Conversation::class, Attachment::class, MessageAttachment::class, Message::class], version = 6)
|
||||||
@TypeConverters(Converters::class)
|
@TypeConverters(Converters::class)
|
||||||
abstract class MessagesDatabase : RoomDatabase() {
|
abstract class MessagesDatabase : RoomDatabase() {
|
||||||
|
|
||||||
@@ -42,6 +42,7 @@ abstract class MessagesDatabase : RoomDatabase() {
|
|||||||
.addMigrations(MIGRATION_2_3)
|
.addMigrations(MIGRATION_2_3)
|
||||||
.addMigrations(MIGRATION_3_4)
|
.addMigrations(MIGRATION_3_4)
|
||||||
.addMigrations(MIGRATION_4_5)
|
.addMigrations(MIGRATION_4_5)
|
||||||
|
.addMigrations(MIGRATION_5_6)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,5 +98,13 @@ abstract class MessagesDatabase : RoomDatabase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val MIGRATION_5_6 = object : Migration(5, 6) {
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
database.apply {
|
||||||
|
execSQL("ALTER TABLE conversations ADD COLUMN uses_custom_title INTEGER NOT NULL DEFAULT 0")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,63 @@
|
|||||||
|
package com.simplemobiletools.smsmessenger.dialogs
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.content.DialogInterface.BUTTON_POSITIVE
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import androidx.core.widget.doAfterTextChanged
|
||||||
|
import com.simplemobiletools.commons.extensions.*
|
||||||
|
import com.simplemobiletools.smsmessenger.R
|
||||||
|
import com.simplemobiletools.smsmessenger.models.Conversation
|
||||||
|
import kotlinx.android.synthetic.main.dialog_rename_conversation.view.*
|
||||||
|
|
||||||
|
class RenameConversationDialog(
|
||||||
|
private val activity: Activity,
|
||||||
|
private val conversation: Conversation,
|
||||||
|
private val callback: (name: String) -> Unit,
|
||||||
|
) {
|
||||||
|
|
||||||
|
private var dialog: AlertDialog? = null
|
||||||
|
|
||||||
|
init {
|
||||||
|
val textColor = activity.getProperTextColor()
|
||||||
|
val primaryColor = activity.getProperPrimaryColor()
|
||||||
|
val backgroundColor = activity.getProperBackgroundColor()
|
||||||
|
|
||||||
|
val view = (activity.layoutInflater.inflate(R.layout.dialog_rename_conversation, null) as ViewGroup).apply {
|
||||||
|
rename_conv_info.setTextColor(textColor)
|
||||||
|
rename_conv_input_layout.apply {
|
||||||
|
setColors(textColor, primaryColor, backgroundColor)
|
||||||
|
setBoxCornerRadiiResources(R.dimen.medium_margin, R.dimen.medium_margin, R.dimen.medium_margin, R.dimen.medium_margin)
|
||||||
|
}
|
||||||
|
rename_conv_edit_text.apply {
|
||||||
|
setTextColor(textColor)
|
||||||
|
if (conversation.usesCustomTitle) {
|
||||||
|
setText(conversation.title)
|
||||||
|
}
|
||||||
|
hint = conversation.title
|
||||||
|
|
||||||
|
doAfterTextChanged {
|
||||||
|
dialog?.getButton(BUTTON_POSITIVE)?.isEnabled = !it.isNullOrEmpty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
activity.getAlertDialogBuilder()
|
||||||
|
.setPositiveButton(R.string.ok, null)
|
||||||
|
.setNegativeButton(R.string.cancel, null)
|
||||||
|
.apply {
|
||||||
|
activity.setupDialogStuff(view, this, R.string.rename_conversation) { alertDialog ->
|
||||||
|
dialog = alertDialog
|
||||||
|
alertDialog.showKeyboard(view.rename_conv_edit_text)
|
||||||
|
alertDialog.getButton(BUTTON_POSITIVE).apply {
|
||||||
|
val newTitle = view.rename_conv_edit_text.text.toString()
|
||||||
|
isEnabled = newTitle.isNotEmpty() && (newTitle != conversation.title)
|
||||||
|
setOnClickListener {
|
||||||
|
alertDialog.dismiss()
|
||||||
|
callback(view.rename_conv_edit_text.text.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -4,10 +4,13 @@ import android.app.Activity
|
|||||||
import android.content.ActivityNotFoundException
|
import android.content.ActivityNotFoundException
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import com.simplemobiletools.commons.extensions.getMimeType
|
import android.provider.ContactsContract
|
||||||
import com.simplemobiletools.commons.extensions.hideKeyboard
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
import com.simplemobiletools.commons.helpers.CONTACT_ID
|
||||||
import com.simplemobiletools.commons.extensions.toast
|
import com.simplemobiletools.commons.helpers.IS_PRIVATE
|
||||||
|
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
|
||||||
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
|
import com.simplemobiletools.commons.models.SimpleContact
|
||||||
import com.simplemobiletools.smsmessenger.R
|
import com.simplemobiletools.smsmessenger.R
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -48,3 +51,28 @@ fun Activity.launchViewIntent(uri: Uri, mimetype: String, filename: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Activity.startContactDetailsIntent(contact: SimpleContact) {
|
||||||
|
val simpleContacts = "com.simplemobiletools.contacts.pro"
|
||||||
|
val simpleContactsDebug = "com.simplemobiletools.contacts.pro.debug"
|
||||||
|
if (contact.rawId > 1000000 && contact.contactId > 1000000 && contact.rawId == contact.contactId &&
|
||||||
|
(isPackageInstalled(simpleContacts) || isPackageInstalled(simpleContactsDebug))
|
||||||
|
) {
|
||||||
|
Intent().apply {
|
||||||
|
action = Intent.ACTION_VIEW
|
||||||
|
putExtra(CONTACT_ID, contact.rawId)
|
||||||
|
putExtra(IS_PRIVATE, true)
|
||||||
|
setPackage(if (isPackageInstalled(simpleContacts)) simpleContacts else simpleContactsDebug)
|
||||||
|
setDataAndType(ContactsContract.Contacts.CONTENT_LOOKUP_URI, "vnd.android.cursor.dir/person")
|
||||||
|
launchActivityIntent(this)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ensureBackgroundThread {
|
||||||
|
val lookupKey = SimpleContactsHelper(this).getContactLookupKey((contact).rawId.toString())
|
||||||
|
val publicUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey)
|
||||||
|
runOnUiThread {
|
||||||
|
launchViewContactIntent(publicUri)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -1014,6 +1014,16 @@ fun Context.subscriptionManagerCompat(): SubscriptionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.renameConversation(conversation: Conversation, newTitle: String): Conversation {
|
||||||
|
val updatedConv = conversation.copy(title = newTitle, usesCustomTitle = true)
|
||||||
|
try {
|
||||||
|
conversationsDB.insertOrUpdate(updatedConv)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
return updatedConv
|
||||||
|
}
|
||||||
|
|
||||||
fun Context.createTemporaryThread(message: Message, threadId: Long = generateRandomId()) {
|
fun Context.createTemporaryThread(message: Message, threadId: Long = generateRandomId()) {
|
||||||
val simpleContactHelper = SimpleContactsHelper(this)
|
val simpleContactHelper = SimpleContactsHelper(this)
|
||||||
val addresses = message.participants.getAddresses()
|
val addresses = message.participants.getAddresses()
|
||||||
|
@@ -15,7 +15,8 @@ data class Conversation(
|
|||||||
@ColumnInfo(name = "photo_uri") var photoUri: String,
|
@ColumnInfo(name = "photo_uri") var photoUri: String,
|
||||||
@ColumnInfo(name = "is_group_conversation") var isGroupConversation: Boolean,
|
@ColumnInfo(name = "is_group_conversation") var isGroupConversation: Boolean,
|
||||||
@ColumnInfo(name = "phone_number") var phoneNumber: String,
|
@ColumnInfo(name = "phone_number") var phoneNumber: String,
|
||||||
@ColumnInfo(name = "is_scheduled") var isScheduled: Boolean = false
|
@ColumnInfo(name = "is_scheduled") var isScheduled: Boolean = false,
|
||||||
|
@ColumnInfo(name = "uses_custom_title") var usesCustomTitle: Boolean = false
|
||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
84
app/src/main/res/layout/activity_conversation_details.xml
Normal file
84
app/src/main/res/layout/activity_conversation_details.xml
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
|
android:id="@+id/conversation_details_app_bar_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
|
<com.google.android.material.appbar.MaterialToolbar
|
||||||
|
android:id="@+id/conversation_details_toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
android:background="@color/color_primary"
|
||||||
|
app:title="@string/conversation_details"
|
||||||
|
app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
|
||||||
|
|
||||||
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
|
android:id="@+id/conversation_name_heading"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="@dimen/normal_margin"
|
||||||
|
android:layout_marginTop="@dimen/activity_margin"
|
||||||
|
android:text="@string/conversation_name"
|
||||||
|
android:textSize="@dimen/normal_text_size"
|
||||||
|
android:textStyle="bold"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/conversation_details_app_bar_layout" />
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
|
android:id="@+id/conversation_name"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/small_margin"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:clickable="true"
|
||||||
|
android:drawableEnd="@drawable/ic_edit_vector"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:focusable="true"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:paddingHorizontal="@dimen/normal_margin"
|
||||||
|
android:paddingVertical="@dimen/normal_margin"
|
||||||
|
android:text="@string/members"
|
||||||
|
android:textSize="@dimen/big_text_size"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/conversation_name_heading" />
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
|
android:id="@+id/members_heading"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="@dimen/normal_margin"
|
||||||
|
android:layout_marginTop="@dimen/normal_margin"
|
||||||
|
android:text="@string/members"
|
||||||
|
android:textSize="@dimen/normal_text_size"
|
||||||
|
android:textStyle="bold"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/conversation_name" />
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
|
android:id="@+id/participants_recyclerview"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/normal_margin"
|
||||||
|
android:overScrollMode="ifContentScrolls"
|
||||||
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/members_heading"
|
||||||
|
tools:itemCount="3"
|
||||||
|
tools:listitem="@layout/item_contact_with_number" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
41
app/src/main/res/layout/dialog_rename_conversation.xml
Normal file
41
app/src/main/res/layout/dialog_rename_conversation.xml
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingVertical="@dimen/big_margin">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
|
android:id="@+id/rename_conv_info"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="@dimen/big_margin"
|
||||||
|
android:paddingHorizontal="@dimen/tiny_margin"
|
||||||
|
android:text="@string/rename_conversation_warning"
|
||||||
|
app:layout_constraintBottom_toTopOf="@id/rename_conv_input_layout"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyTextInputLayout
|
||||||
|
android:id="@+id/rename_conv_input_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="@dimen/big_margin"
|
||||||
|
android:layout_marginTop="@dimen/activity_margin"
|
||||||
|
android:hint="@string/conversation_name"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/rename_conv_info">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/rename_conv_edit_text"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="text"
|
||||||
|
android:maxLength="30"
|
||||||
|
android:maxLines="1" />
|
||||||
|
|
||||||
|
</com.simplemobiletools.commons.views.MyTextInputLayout>
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@@ -28,6 +28,11 @@
|
|||||||
android:showAsAction="never"
|
android:showAsAction="never"
|
||||||
android:title="@string/copy_number_to_clipboard"
|
android:title="@string/copy_number_to_clipboard"
|
||||||
app:showAsAction="never" />
|
app:showAsAction="never" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/rename_conversation"
|
||||||
|
android:icon="@drawable/ic_edit_vector"
|
||||||
|
android:title="@string/rename_conversation"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_mark_as_read"
|
android:id="@+id/cab_mark_as_read"
|
||||||
android:showAsAction="never"
|
android:showAsAction="never"
|
||||||
|
@@ -18,6 +18,16 @@
|
|||||||
android:icon="@drawable/ic_add_person_vector"
|
android:icon="@drawable/ic_add_person_vector"
|
||||||
android:title="@string/add_person"
|
android:title="@string/add_person"
|
||||||
app:showAsAction="always" />
|
app:showAsAction="always" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/rename_conversation"
|
||||||
|
android:icon="@drawable/ic_edit_vector"
|
||||||
|
android:title="@string/rename_conversation"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/conversation_details"
|
||||||
|
android:icon="@drawable/ic_info_vector"
|
||||||
|
android:title="@string/conversation_details"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/add_number_to_contact"
|
android:id="@+id/add_number_to_contact"
|
||||||
android:title="@string/add_number_to_contact"
|
android:title="@string/add_number_to_contact"
|
||||||
|
Reference in New Issue
Block a user