show some suggestions at top of the contact picker screen
This commit is contained in:
parent
e792ff37ab
commit
5a462775fd
|
@ -5,16 +5,16 @@ import android.os.Bundle
|
|||
import android.view.WindowManager
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.smsmessenger.R
|
||||
import com.simplemobiletools.smsmessenger.adapters.ContactsAdapter
|
||||
import com.simplemobiletools.smsmessenger.extensions.config
|
||||
import com.simplemobiletools.smsmessenger.extensions.getAvailableContacts
|
||||
import com.simplemobiletools.smsmessenger.extensions.getThreadId
|
||||
import com.simplemobiletools.smsmessenger.extensions.*
|
||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
|
||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_TEXT
|
||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_TITLE
|
||||
import com.simplemobiletools.smsmessenger.models.Contact
|
||||
import kotlinx.android.synthetic.main.activity_new_message.*
|
||||
import kotlinx.android.synthetic.main.item_suggested_contact.view.*
|
||||
|
||||
class NewMessageActivity : SimpleActivity() {
|
||||
private var allContacts = ArrayList<Contact>()
|
||||
|
@ -46,6 +46,7 @@ class NewMessageActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
fillSuggestedContacts()
|
||||
new_message_to.onTextChangeListener {
|
||||
val searchString = it
|
||||
val filteredContacts = ArrayList<Contact>()
|
||||
|
@ -78,13 +79,35 @@ class NewMessageActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
private fun setupAdapter(contacts: ArrayList<Contact>) {
|
||||
ContactsAdapter(this, contacts, suggestions_list, null) {
|
||||
ContactsAdapter(this, contacts, contacts_list, null) {
|
||||
hideKeyboard()
|
||||
|
||||
val text = intent.getStringExtra(Intent.EXTRA_TEXT) ?: ""
|
||||
launchThreadActivity((it as Contact).phoneNumber, it.name, text)
|
||||
}.apply {
|
||||
suggestions_list.adapter = this
|
||||
contacts_list.adapter = this
|
||||
}
|
||||
}
|
||||
|
||||
private fun fillSuggestedContacts() {
|
||||
ensureBackgroundThread {
|
||||
val suggestions = getSuggestedContacts()
|
||||
runOnUiThread {
|
||||
suggestions_holder.removeAllViews()
|
||||
if (suggestions.isEmpty()) {
|
||||
suggestions_label.beGone()
|
||||
suggestions_scrollview.beGone()
|
||||
} else {
|
||||
suggestions.forEach {
|
||||
val contact = it
|
||||
layoutInflater.inflate(R.layout.item_suggested_contact, null).apply {
|
||||
suggested_contact_name.text = contact.name
|
||||
loadImage(contact.photoUri, suggested_contact_image, contact.name)
|
||||
suggestions_holder.addView(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -338,6 +338,33 @@ fun Context.getPhoneNumberFromAddressId(canonicalAddressId: Int): String {
|
|||
return ""
|
||||
}
|
||||
|
||||
fun Context.getSuggestedContacts(): ArrayList<Contact> {
|
||||
val contacts = ArrayList<Contact>()
|
||||
val uri = Sms.CONTENT_URI
|
||||
val projection = arrayOf(
|
||||
Sms.ADDRESS
|
||||
)
|
||||
|
||||
val selection = "1 == 1) GROUP BY (${Sms.ADDRESS}"
|
||||
val selectionArgs = null
|
||||
val sortOrder = "${Sms.DATE} DESC LIMIT 20"
|
||||
|
||||
queryCursor(uri, projection, selection, selectionArgs, sortOrder, showErrors = true) { cursor ->
|
||||
val senderNumber = cursor.getStringValue(Sms.ADDRESS)
|
||||
val namePhoto = getNameAndPhotoFromPhoneNumber(senderNumber)
|
||||
if (namePhoto == null || namePhoto.name == senderNumber) {
|
||||
return@queryCursor
|
||||
}
|
||||
|
||||
val senderName = namePhoto.name
|
||||
val photoUri = namePhoto.photoUri ?: ""
|
||||
val contact = Contact(0, senderName, photoUri, senderNumber)
|
||||
contacts.add(contact)
|
||||
}
|
||||
|
||||
return contacts
|
||||
}
|
||||
|
||||
fun Context.getAvailableContacts(callback: (ArrayList<Contact>) -> Unit) {
|
||||
ensureBackgroundThread {
|
||||
val names = getContactNames()
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<size
|
||||
android:width="@dimen/activity_margin"
|
||||
android:height="0dp" />
|
||||
</shape>
|
|
@ -38,11 +38,39 @@
|
|||
android:background="@color/divider_grey"
|
||||
android:importantForAccessibility="no" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/suggestions_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/message_divider_two"
|
||||
android:alpha="0.8"
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:text="@string/suggestions"
|
||||
android:textSize="@dimen/normal_text_size" />
|
||||
|
||||
<HorizontalScrollView
|
||||
android:id="@+id/suggestions_scrollview"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/suggestions_label"
|
||||
android:layout_marginBottom="@dimen/medium_margin"
|
||||
android:overScrollMode="never"
|
||||
android:scrollbars="none">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/suggestions_holder"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:divider="@drawable/linear_layout_horizontal_divider"
|
||||
android:orientation="horizontal"
|
||||
android:showDividers="middle" />
|
||||
</HorizontalScrollView>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||
android:id="@+id/suggestions_list"
|
||||
android:id="@+id/contacts_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/message_divider_two"
|
||||
android:layout_below="@+id/suggestions_scrollview"
|
||||
android:clipToPadding="false"
|
||||
android:overScrollMode="ifContentScrolls"
|
||||
android:scrollbars="none"
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/suggested_contact_holder"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/suggested_contact_image"
|
||||
android:layout_width="@dimen/bigger_avatar_size"
|
||||
android:layout_height="@dimen/bigger_avatar_size"
|
||||
android:paddingStart="@dimen/tiny_margin"
|
||||
android:paddingEnd="@dimen/tiny_margin"
|
||||
tools:src="@drawable/ic_circle_filled" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/suggested_contact_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/suggested_contact_image"
|
||||
android:layout_alignStart="@+id/suggested_contact_image"
|
||||
android:layout_alignEnd="@id/suggested_contact_image"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_horizontal"
|
||||
android:lines="1"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:paddingBottom="@dimen/medium_margin"
|
||||
android:textSize="@dimen/normal_text_size"
|
||||
tools:text="John" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -2,5 +2,6 @@
|
|||
<resources>
|
||||
<dimen name="notification_large_icon_size">72dp</dimen>
|
||||
<dimen name="avatar_size">40dp</dimen>
|
||||
<dimen name="bigger_avatar_size">64dp</dimen>
|
||||
<dimen name="play_outline_size">36dp</dimen>
|
||||
</resources>
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<!-- New message -->
|
||||
<string name="create_new_message">Create new message</string>
|
||||
<string name="add_contact_or_number">Add Contact or Number…</string>
|
||||
<string name="suggestions">Suggestions</string>
|
||||
|
||||
<!-- Notifications -->
|
||||
<string name="channel_received_sms">Received SMS</string>
|
||||
|
|
Loading…
Reference in New Issue