show the "Create new contact" button over favorites too

This commit is contained in:
tibbi
2019-12-06 22:15:15 +01:00
parent e396e4987c
commit 324d9ef399
7 changed files with 98 additions and 104 deletions

View File

@ -104,7 +104,7 @@ class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener, Refresh
val currAdapter = group_contacts_list.adapter
if (currAdapter == null) {
ContactsAdapter(this, contacts, this, LOCATION_GROUP_CONTACTS, this, group_contacts_list, group_contacts_fastscroller) {
contactClicked(it as Contact, false)
contactClicked(it as Contact)
}.apply {
group_contacts_list.adapter = this
}
@ -123,8 +123,8 @@ class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener, Refresh
refreshContacts()
}
override fun contactClicked(contact: Contact?, isCreateNewContact: Boolean) {
handleGenericContactClick(contact!!)
override fun contactClicked(contact: Contact) {
handleGenericContactClick(contact)
}
override fun removeFromGroup(contacts: ArrayList<Contact>) {

View File

@ -96,6 +96,12 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
}
insert_or_edit_tabs_holder.beVisibleIf(skippedTabs == 0)
select_contact_label?.setTextColor(getAdjustedPrimaryColor())
new_contact_tmb?.setImageDrawable(resources.getColoredDrawableWithColor(R.drawable.ic_new_contact_vector, config.textColor))
new_contact_holder?.setOnClickListener {
createNewContact()
}
}
private fun setupTabColors() {
@ -130,54 +136,52 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
}
}
override fun contactClicked(contact: Contact?, isCreateNewContact: Boolean) {
if (contact != null) {
val phoneNumber = getPhoneNumberFromIntent(intent) ?: ""
val email = getEmailFromIntent(intent) ?: ""
override fun contactClicked(contact: Contact) {
val phoneNumber = getPhoneNumberFromIntent(intent) ?: ""
val email = getEmailFromIntent(intent) ?: ""
Intent(applicationContext, EditContactActivity::class.java).apply {
data = getContactPublicUri(contact)
action = ADD_NEW_CONTACT_NUMBER
Intent(applicationContext, EditContactActivity::class.java).apply {
data = getContactPublicUri(contact)
action = ADD_NEW_CONTACT_NUMBER
if (phoneNumber.isNotEmpty()) {
putExtra(KEY_PHONE, phoneNumber)
}
if (email.isNotEmpty()) {
putExtra(KEY_EMAIL, email)
}
putExtra(IS_PRIVATE, contact.isPrivate())
startActivityForResult(this, START_EDIT_ACTIVITY)
finish()
if (phoneNumber.isNotEmpty()) {
putExtra(KEY_PHONE, phoneNumber)
}
} else if (isCreateNewContact) {
val name = intent.getStringExtra(KEY_NAME) ?: ""
val phoneNumber = getPhoneNumberFromIntent(intent) ?: ""
val email = getEmailFromIntent(intent) ?: ""
Intent().apply {
action = Intent.ACTION_INSERT
data = ContactsContract.Contacts.CONTENT_URI
if (email.isNotEmpty()) {
putExtra(KEY_EMAIL, email)
}
if (phoneNumber.isNotEmpty()) {
putExtra(KEY_PHONE, phoneNumber)
}
putExtra(IS_PRIVATE, contact.isPrivate())
startActivityForResult(this, START_EDIT_ACTIVITY)
}
}
if (name.isNotEmpty()) {
putExtra(KEY_NAME, name)
}
private fun createNewContact() {
val name = intent.getStringExtra(KEY_NAME) ?: ""
val phoneNumber = getPhoneNumberFromIntent(intent) ?: ""
val email = getEmailFromIntent(intent) ?: ""
if (email.isNotEmpty()) {
putExtra(KEY_EMAIL, email)
}
Intent().apply {
action = Intent.ACTION_INSERT
data = ContactsContract.Contacts.CONTENT_URI
if (resolveActivity(packageManager) != null) {
startActivityForResult(this, START_INSERT_ACTIVITY)
finish()
} else {
toast(R.string.no_app_found)
}
if (phoneNumber.isNotEmpty()) {
putExtra(KEY_PHONE, phoneNumber)
}
if (name.isNotEmpty()) {
putExtra(KEY_NAME, name)
}
if (email.isNotEmpty()) {
putExtra(KEY_EMAIL, email)
}
if (resolveActivity(packageManager) != null) {
startActivityForResult(this, START_INSERT_ACTIVITY)
} else {
toast(R.string.no_app_found)
}
}
}

View File

@ -560,8 +560,8 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
}
}
override fun contactClicked(contact: Contact?, isCreateNewContact: Boolean) {
handleGenericContactClick(contact!!)
override fun contactClicked(contact: Contact) {
handleGenericContactClick(contact)
}
private fun getAllFragments() = arrayListOf(contacts_fragment, favorites_fragment, groups_fragment)

View File

@ -21,11 +21,7 @@ import com.simplemobiletools.contacts.pro.helpers.*
import com.simplemobiletools.contacts.pro.interfaces.RefreshContactsListener
import com.simplemobiletools.contacts.pro.models.Contact
import com.simplemobiletools.contacts.pro.models.Group
import kotlinx.android.synthetic.main.fragment_insert_or_edit_contacts.view.*
import kotlinx.android.synthetic.main.fragment_layout.view.*
import kotlinx.android.synthetic.main.fragment_layout.view.fragment_fastscroller
import kotlinx.android.synthetic.main.fragment_layout.view.fragment_list
import kotlinx.android.synthetic.main.fragment_layout.view.fragment_wrapper
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet) {
protected var activity: SimpleActivity? = null
@ -192,7 +188,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
forceListRedraw = false
val location = if (this is FavoritesFragment) LOCATION_FAVORITES_TAB else LOCATION_CONTACTS_TAB
ContactsAdapter(activity as SimpleActivity, contacts, activity as RefreshContactsListener, location, null, fragment_list, fragment_fastscroller) {
(activity as RefreshContactsListener).contactClicked(it as Contact, false)
(activity as RefreshContactsListener).contactClicked(it as Contact)
}.apply {
fragment_list.adapter = this
}
@ -303,11 +299,6 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
fragment_fastscroller.updateBubbleColors()
fragment_fastscroller.allowBubbleDisplay = config.showInfoBubble
fragment_placeholder_2?.setTextColor(context.getAdjustedPrimaryColor())
select_contact_label?.setTextColor(context.getAdjustedPrimaryColor())
new_contact_tmb?.setImageDrawable(resources.getColoredDrawableWithColor(R.drawable.ic_new_contact_vector, context.config.textColor))
new_contact_holder?.setOnClickListener {
(activity as RefreshContactsListener).contactClicked(null, true)
}
}
private fun setupViewVisibility(hasItemsToShow: Boolean) {

View File

@ -5,5 +5,5 @@ import com.simplemobiletools.contacts.pro.models.Contact
interface RefreshContactsListener {
fun refreshContacts(refreshTabsMask: Int)
fun contactClicked(contact: Contact?, isCreateNewContact: Boolean)
fun contactClicked(contact: Contact)
}