mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
Adapter improving for grid view and refactoring
This commit is contained in:
@@ -263,7 +263,7 @@ class DialpadActivity : SimpleActivity() {
|
|||||||
|
|
||||||
if (hasRussianLocale) {
|
if (hasRussianLocale) {
|
||||||
var currConvertedName = ""
|
var currConvertedName = ""
|
||||||
convertedName.toLowerCase().forEach { char ->
|
convertedName.lowercase(Locale.getDefault()).forEach { char ->
|
||||||
val convertedChar = russianCharsMap.getOrElse(char) { char }
|
val convertedChar = russianCharsMap.getOrElse(char) { char }
|
||||||
currConvertedName += convertedChar
|
currConvertedName += convertedChar
|
||||||
}
|
}
|
||||||
@@ -279,13 +279,18 @@ class DialpadActivity : SimpleActivity() {
|
|||||||
try {
|
try {
|
||||||
val name = filtered[position].getNameToDisplay()
|
val name = filtered[position].getNameToDisplay()
|
||||||
val character = if (name.isNotEmpty()) name.substring(0, 1) else ""
|
val character = if (name.isNotEmpty()) name.substring(0, 1) else ""
|
||||||
FastScrollItemIndicator.Text(character.toUpperCase(Locale.getDefault()))
|
FastScrollItemIndicator.Text(character.uppercase(Locale.getDefault()))
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
FastScrollItemIndicator.Text("")
|
FastScrollItemIndicator.Text("")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ContactsAdapter(this, filtered, dialpad_list, null, text) {
|
ContactsAdapter(
|
||||||
|
activity = this,
|
||||||
|
contacts = filtered,
|
||||||
|
recyclerView = dialpad_list,
|
||||||
|
highlightText = text
|
||||||
|
) {
|
||||||
val contact = it as Contact
|
val contact = it as Contact
|
||||||
if (config.showCallConfirmation) {
|
if (config.showCallConfirmation) {
|
||||||
CallConfirmationDialog(this@DialpadActivity, contact.getNameToDisplay()) {
|
CallConfirmationDialog(this@DialpadActivity, contact.getNameToDisplay()) {
|
||||||
@@ -316,7 +321,7 @@ class DialpadActivity : SimpleActivity() {
|
|||||||
CallConfirmationDialog(this, number) {
|
CallConfirmationDialog(this, number) {
|
||||||
callContactWithSim(number, handleIndex == 0)
|
callContactWithSim(number, handleIndex == 0)
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
callContactWithSim(number, handleIndex == 0)
|
callContactWithSim(number, handleIndex == 0)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -324,7 +329,7 @@ class DialpadActivity : SimpleActivity() {
|
|||||||
CallConfirmationDialog(this, number) {
|
CallConfirmationDialog(this, number) {
|
||||||
startCallIntent(number)
|
startCallIntent(number)
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
startCallIntent(number)
|
startCallIntent(number)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -406,12 +411,14 @@ class DialpadActivity : SimpleActivity() {
|
|||||||
}, longPressTimeout)
|
}, longPressTimeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
||||||
stopDialpadTone(char)
|
stopDialpadTone(char)
|
||||||
if (longClickable) {
|
if (longClickable) {
|
||||||
longPressHandler.removeCallbacksAndMessages(null)
|
longPressHandler.removeCallbacksAndMessages(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MotionEvent.ACTION_MOVE -> {
|
MotionEvent.ACTION_MOVE -> {
|
||||||
val viewContainsTouchEvent = if (event.rawX.isNaN() || event.rawY.isNaN()) {
|
val viewContainsTouchEvent = if (event.rawX.isNaN() || event.rawY.isNaN()) {
|
||||||
false
|
false
|
||||||
|
@@ -21,10 +21,7 @@ import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
|||||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||||
import com.simplemobiletools.commons.dialogs.FeatureLockedDialog
|
import com.simplemobiletools.commons.dialogs.FeatureLockedDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_CALL_PHONE
|
import com.simplemobiletools.commons.helpers.*
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS
|
|
||||||
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
|
|
||||||
import com.simplemobiletools.commons.helpers.isOreoPlus
|
|
||||||
import com.simplemobiletools.commons.interfaces.ItemMoveCallback
|
import com.simplemobiletools.commons.interfaces.ItemMoveCallback
|
||||||
import com.simplemobiletools.commons.interfaces.ItemTouchHelperContract
|
import com.simplemobiletools.commons.interfaces.ItemTouchHelperContract
|
||||||
import com.simplemobiletools.commons.interfaces.StartReorderDragListener
|
import com.simplemobiletools.commons.interfaces.StartReorderDragListener
|
||||||
@@ -43,9 +40,10 @@ class ContactsAdapter(
|
|||||||
activity: SimpleActivity,
|
activity: SimpleActivity,
|
||||||
var contacts: MutableList<Contact>,
|
var contacts: MutableList<Contact>,
|
||||||
recyclerView: MyRecyclerView,
|
recyclerView: MyRecyclerView,
|
||||||
val refreshItemsListener: RefreshItemsListener? = null,
|
|
||||||
highlightText: String = "",
|
highlightText: String = "",
|
||||||
val showDeleteButton: Boolean = true,
|
private val refreshItemsListener: RefreshItemsListener? = null,
|
||||||
|
private val viewType: Int = VIEW_TYPE_LIST,
|
||||||
|
private val showDeleteButton: Boolean = true,
|
||||||
private val enableDrag: Boolean = false,
|
private val enableDrag: Boolean = false,
|
||||||
itemClick: (Any) -> Unit
|
itemClick: (Any) -> Unit
|
||||||
) : MyRecyclerViewAdapter(activity, recyclerView, itemClick), ItemTouchHelperContract {
|
) : MyRecyclerViewAdapter(activity, recyclerView, itemClick), ItemTouchHelperContract {
|
||||||
@@ -123,7 +121,17 @@ class ContactsAdapter(
|
|||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_contact_without_number, parent)
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
|
val layout = when (viewType) {
|
||||||
|
VIEW_TYPE_GRID -> R.layout.item_contact_grid
|
||||||
|
else -> R.layout.item_contact_without_number
|
||||||
|
}
|
||||||
|
return createViewHolder(layout, parent)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemViewType(position: Int): Int {
|
||||||
|
return viewType
|
||||||
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
val contact = contacts[position]
|
val contact = contacts[position]
|
||||||
|
@@ -15,7 +15,7 @@ import com.simplemobiletools.dialer.extensions.launchCreateNewContactIntent
|
|||||||
import com.simplemobiletools.dialer.extensions.startContactDetailsIntent
|
import com.simplemobiletools.dialer.extensions.startContactDetailsIntent
|
||||||
import com.simplemobiletools.dialer.interfaces.RefreshItemsListener
|
import com.simplemobiletools.dialer.interfaces.RefreshItemsListener
|
||||||
import kotlinx.android.synthetic.main.fragment_letters_layout.view.*
|
import kotlinx.android.synthetic.main.fragment_letters_layout.view.*
|
||||||
import java.util.*
|
import java.util.Locale
|
||||||
|
|
||||||
class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), RefreshItemsListener {
|
class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), RefreshItemsListener {
|
||||||
private var allContacts = ArrayList<Contact>()
|
private var allContacts = ArrayList<Contact>()
|
||||||
@@ -82,7 +82,7 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun gotContacts(contacts: ArrayList<Contact>) {
|
private fun gotContacts(contacts: ArrayList<Contact>) {
|
||||||
setupLetterFastscroller(contacts)
|
setupLetterFastScroller(contacts)
|
||||||
if (contacts.isEmpty()) {
|
if (contacts.isEmpty()) {
|
||||||
fragment_placeholder.beVisible()
|
fragment_placeholder.beVisible()
|
||||||
fragment_placeholder_2.beVisible()
|
fragment_placeholder_2.beVisible()
|
||||||
@@ -94,7 +94,12 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
|
|||||||
|
|
||||||
val currAdapter = fragment_list.adapter
|
val currAdapter = fragment_list.adapter
|
||||||
if (currAdapter == null) {
|
if (currAdapter == null) {
|
||||||
ContactsAdapter(activity as SimpleActivity, contacts, fragment_list, this) {
|
ContactsAdapter(
|
||||||
|
activity = activity as SimpleActivity,
|
||||||
|
contacts = contacts,
|
||||||
|
recyclerView = fragment_list,
|
||||||
|
refreshItemsListener = this
|
||||||
|
) {
|
||||||
val contact = it as Contact
|
val contact = it as Contact
|
||||||
activity?.startContactDetailsIntent(contact)
|
activity?.startContactDetailsIntent(contact)
|
||||||
}.apply {
|
}.apply {
|
||||||
@@ -110,12 +115,12 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupLetterFastscroller(contacts: ArrayList<Contact>) {
|
private fun setupLetterFastScroller(contacts: ArrayList<Contact>) {
|
||||||
letter_fastscroller.setupWithRecyclerView(fragment_list, { position ->
|
letter_fastscroller.setupWithRecyclerView(fragment_list, { position ->
|
||||||
try {
|
try {
|
||||||
val name = contacts[position].getNameToDisplay()
|
val name = contacts[position].getNameToDisplay()
|
||||||
val character = if (name.isNotEmpty()) name.substring(0, 1) else ""
|
val character = if (name.isNotEmpty()) name.substring(0, 1) else ""
|
||||||
FastScrollItemIndicator.Text(character.toUpperCase(Locale.getDefault()).normalizeString())
|
FastScrollItemIndicator.Text(character.uppercase(Locale.getDefault()).normalizeString())
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
FastScrollItemIndicator.Text("")
|
FastScrollItemIndicator.Text("")
|
||||||
}
|
}
|
||||||
@@ -125,35 +130,36 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
|
|||||||
override fun onSearchClosed() {
|
override fun onSearchClosed() {
|
||||||
fragment_placeholder.beVisibleIf(allContacts.isEmpty())
|
fragment_placeholder.beVisibleIf(allContacts.isEmpty())
|
||||||
(fragment_list.adapter as? ContactsAdapter)?.updateItems(allContacts)
|
(fragment_list.adapter as? ContactsAdapter)?.updateItems(allContacts)
|
||||||
setupLetterFastscroller(allContacts)
|
setupLetterFastScroller(allContacts)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSearchQueryChanged(text: String) {
|
override fun onSearchQueryChanged(text: String) {
|
||||||
val shouldNormalize = text.normalizeString() == text
|
val shouldNormalize = text.normalizeString() == text
|
||||||
val filtered = allContacts.filter {
|
val filtered = allContacts.filter {
|
||||||
getProperText(it.getNameToDisplay(), shouldNormalize).contains(text, true) ||
|
getProperText(it.getNameToDisplay(), shouldNormalize).contains(text, true) ||
|
||||||
getProperText(it.nickname, shouldNormalize).contains(text, true) ||
|
getProperText(it.nickname, shouldNormalize).contains(text, true) ||
|
||||||
it.phoneNumbers.any {
|
it.phoneNumbers.any {
|
||||||
text.normalizePhoneNumber().isNotEmpty() && it.normalizedNumber.contains(text.normalizePhoneNumber(), true)
|
text.normalizePhoneNumber().isNotEmpty() && it.normalizedNumber.contains(text.normalizePhoneNumber(), true)
|
||||||
} ||
|
} ||
|
||||||
it.emails.any { it.value.contains(text, true) } ||
|
it.emails.any { it.value.contains(text, true) } ||
|
||||||
it.addresses.any { getProperText(it.value, shouldNormalize).contains(text, true) } ||
|
it.addresses.any { getProperText(it.value, shouldNormalize).contains(text, true) } ||
|
||||||
it.IMs.any { it.value.contains(text, true) } ||
|
it.IMs.any { it.value.contains(text, true) } ||
|
||||||
getProperText(it.notes, shouldNormalize).contains(text, true) ||
|
getProperText(it.notes, shouldNormalize).contains(text, true) ||
|
||||||
getProperText(it.organization.company, shouldNormalize).contains(text, true) ||
|
getProperText(it.organization.company, shouldNormalize).contains(text, true) ||
|
||||||
getProperText(it.organization.jobPosition, shouldNormalize).contains(text, true) ||
|
getProperText(it.organization.jobPosition, shouldNormalize).contains(text, true) ||
|
||||||
it.websites.any { it.contains(text, true) }
|
it.websites.any { it.contains(text, true) }
|
||||||
} as ArrayList
|
} as ArrayList
|
||||||
|
|
||||||
filtered.sortBy {
|
filtered.sortBy {
|
||||||
val nameToDisplay = it.getNameToDisplay()
|
val nameToDisplay = it.getNameToDisplay()
|
||||||
!getProperText(nameToDisplay, shouldNormalize).startsWith(text, true) && !nameToDisplay.contains(text, true)
|
!getProperText(nameToDisplay, shouldNormalize).startsWith(text, true) && !nameToDisplay.contains(text, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fragment_placeholder.beVisibleIf(filtered.isEmpty())
|
fragment_placeholder.beVisibleIf(filtered.isEmpty())
|
||||||
(fragment_list.adapter as? ContactsAdapter)?.updateItems(filtered, text)
|
(fragment_list.adapter as? ContactsAdapter)?.updateItems(filtered, text)
|
||||||
setupLetterFastscroller(filtered)
|
setupLetterFastScroller(filtered)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun requestReadContactsPermission() {
|
private fun requestReadContactsPermission() {
|
||||||
activity?.handlePermission(PERMISSION_READ_CONTACTS) {
|
activity?.handlePermission(PERMISSION_READ_CONTACTS) {
|
||||||
if (it) {
|
if (it) {
|
||||||
|
Reference in New Issue
Block a user