mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-06-05 21:49:22 +02:00
improve the way contact selection is shown
This commit is contained in:
@@ -11,6 +11,7 @@ import android.view.WindowManager
|
|||||||
import android.view.inputmethod.EditorInfo
|
import android.view.inputmethod.EditorInfo
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.LinearLayout.LayoutParams
|
import android.widget.LinearLayout.LayoutParams
|
||||||
|
import android.widget.RelativeLayout
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
|
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
|
||||||
import com.simplemobiletools.smsmessenger.R
|
import com.simplemobiletools.smsmessenger.R
|
||||||
@@ -74,23 +75,29 @@ class NewMessageActivity : SimpleActivity() {
|
|||||||
selectedContacts.add(contact)
|
selectedContacts.add(contact)
|
||||||
selected_contacts.beVisible()
|
selected_contacts.beVisible()
|
||||||
message_divider_one.beVisible()
|
message_divider_one.beVisible()
|
||||||
|
new_message_to.setText("")
|
||||||
|
|
||||||
selected_contacts.onGlobalLayout {
|
val views = ArrayList<View>()
|
||||||
val first = layoutInflater.inflate(R.layout.item_selected_contact, null).apply {
|
selectedContacts.forEach {
|
||||||
selected_contact_name.text = contact.name
|
layoutInflater.inflate(R.layout.item_selected_contact, null).apply {
|
||||||
|
selected_contact_name.text = it.name
|
||||||
|
views.add(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
showSelectedContact(arrayListOf(first))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showSelectedContact(views)
|
||||||
}
|
}
|
||||||
|
|
||||||
// show selected contacts, properly split to new lines when appropriate
|
// show selected contacts, properly split to new lines when appropriate
|
||||||
// based on https://stackoverflow.com/a/13505029/1967672
|
// based on https://stackoverflow.com/a/13505029/1967672
|
||||||
private fun showSelectedContact(views: ArrayList<View>) {
|
private fun showSelectedContact(views: ArrayList<View>) {
|
||||||
|
selected_contacts.removeAllViews()
|
||||||
var newLinearLayout = LinearLayout(this)
|
var newLinearLayout = LinearLayout(this)
|
||||||
newLinearLayout.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
|
newLinearLayout.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
|
||||||
newLinearLayout.orientation = LinearLayout.HORIZONTAL
|
newLinearLayout.orientation = LinearLayout.HORIZONTAL
|
||||||
|
|
||||||
|
val sideMargin = (selected_contacts.layoutParams as RelativeLayout.LayoutParams).leftMargin
|
||||||
|
val parentWidth = realScreenSize.x - sideMargin
|
||||||
val mediumMargin = resources.getDimension(R.dimen.medium_margin).toInt()
|
val mediumMargin = resources.getDimension(R.dimen.medium_margin).toInt()
|
||||||
var widthSoFar = 0
|
var widthSoFar = 0
|
||||||
var isFirstRow = true
|
var isFirstRow = true
|
||||||
@@ -107,7 +114,7 @@ class NewMessageActivity : SimpleActivity() {
|
|||||||
LL.measure(0, 0)
|
LL.measure(0, 0)
|
||||||
widthSoFar += views[i].measuredWidth + mediumMargin
|
widthSoFar += views[i].measuredWidth + mediumMargin
|
||||||
|
|
||||||
if (widthSoFar >= selected_contacts.width) {
|
if (widthSoFar >= parentWidth) {
|
||||||
isFirstRow = false
|
isFirstRow = false
|
||||||
selected_contacts.addView(newLinearLayout)
|
selected_contacts.addView(newLinearLayout)
|
||||||
newLinearLayout = LinearLayout(this)
|
newLinearLayout = LinearLayout(this)
|
||||||
|
Reference in New Issue
Block a user