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) {
|
||||
var currConvertedName = ""
|
||||
convertedName.toLowerCase().forEach { char ->
|
||||
convertedName.lowercase(Locale.getDefault()).forEach { char ->
|
||||
val convertedChar = russianCharsMap.getOrElse(char) { char }
|
||||
currConvertedName += convertedChar
|
||||
}
|
||||
@@ -279,13 +279,18 @@ class DialpadActivity : SimpleActivity() {
|
||||
try {
|
||||
val name = filtered[position].getNameToDisplay()
|
||||
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) {
|
||||
FastScrollItemIndicator.Text("")
|
||||
}
|
||||
})
|
||||
|
||||
ContactsAdapter(this, filtered, dialpad_list, null, text) {
|
||||
ContactsAdapter(
|
||||
activity = this,
|
||||
contacts = filtered,
|
||||
recyclerView = dialpad_list,
|
||||
highlightText = text
|
||||
) {
|
||||
val contact = it as Contact
|
||||
if (config.showCallConfirmation) {
|
||||
CallConfirmationDialog(this@DialpadActivity, contact.getNameToDisplay()) {
|
||||
@@ -406,12 +411,14 @@ class DialpadActivity : SimpleActivity() {
|
||||
}, longPressTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
||||
stopDialpadTone(char)
|
||||
if (longClickable) {
|
||||
longPressHandler.removeCallbacksAndMessages(null)
|
||||
}
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
val viewContainsTouchEvent = if (event.rawX.isNaN() || event.rawY.isNaN()) {
|
||||
false
|
||||
|
@@ -21,10 +21,7 @@ import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.dialogs.FeatureLockedDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.PERMISSION_CALL_PHONE
|
||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS
|
||||
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
|
||||
import com.simplemobiletools.commons.helpers.isOreoPlus
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.commons.interfaces.ItemMoveCallback
|
||||
import com.simplemobiletools.commons.interfaces.ItemTouchHelperContract
|
||||
import com.simplemobiletools.commons.interfaces.StartReorderDragListener
|
||||
@@ -43,9 +40,10 @@ class ContactsAdapter(
|
||||
activity: SimpleActivity,
|
||||
var contacts: MutableList<Contact>,
|
||||
recyclerView: MyRecyclerView,
|
||||
val refreshItemsListener: RefreshItemsListener? = null,
|
||||
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,
|
||||
itemClick: (Any) -> Unit
|
||||
) : MyRecyclerViewAdapter(activity, recyclerView, itemClick), ItemTouchHelperContract {
|
||||
@@ -123,7 +121,17 @@ class ContactsAdapter(
|
||||
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) {
|
||||
val contact = contacts[position]
|
||||
|
@@ -15,7 +15,7 @@ import com.simplemobiletools.dialer.extensions.launchCreateNewContactIntent
|
||||
import com.simplemobiletools.dialer.extensions.startContactDetailsIntent
|
||||
import com.simplemobiletools.dialer.interfaces.RefreshItemsListener
|
||||
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 {
|
||||
private var allContacts = ArrayList<Contact>()
|
||||
@@ -82,7 +82,7 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
|
||||
}
|
||||
|
||||
private fun gotContacts(contacts: ArrayList<Contact>) {
|
||||
setupLetterFastscroller(contacts)
|
||||
setupLetterFastScroller(contacts)
|
||||
if (contacts.isEmpty()) {
|
||||
fragment_placeholder.beVisible()
|
||||
fragment_placeholder_2.beVisible()
|
||||
@@ -94,7 +94,12 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
|
||||
|
||||
val currAdapter = fragment_list.adapter
|
||||
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
|
||||
activity?.startContactDetailsIntent(contact)
|
||||
}.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 ->
|
||||
try {
|
||||
val name = contacts[position].getNameToDisplay()
|
||||
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) {
|
||||
FastScrollItemIndicator.Text("")
|
||||
}
|
||||
@@ -125,7 +130,7 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
|
||||
override fun onSearchClosed() {
|
||||
fragment_placeholder.beVisibleIf(allContacts.isEmpty())
|
||||
(fragment_list.adapter as? ContactsAdapter)?.updateItems(allContacts)
|
||||
setupLetterFastscroller(allContacts)
|
||||
setupLetterFastScroller(allContacts)
|
||||
}
|
||||
|
||||
override fun onSearchQueryChanged(text: String) {
|
||||
@@ -152,8 +157,9 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
|
||||
|
||||
fragment_placeholder.beVisibleIf(filtered.isEmpty())
|
||||
(fragment_list.adapter as? ContactsAdapter)?.updateItems(filtered, text)
|
||||
setupLetterFastscroller(filtered)
|
||||
setupLetterFastScroller(filtered)
|
||||
}
|
||||
|
||||
private fun requestReadContactsPermission() {
|
||||
activity?.handlePermission(PERMISSION_READ_CONTACTS) {
|
||||
if (it) {
|
||||
|
Reference in New Issue
Block a user