launch Create New intent at placeholder click

This commit is contained in:
tibbi 2020-11-04 16:41:05 +01:00
parent 567fb8212a
commit ef3b07eddd
1 changed files with 21 additions and 10 deletions

View File

@ -41,24 +41,20 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
setTextColor(context.config.primaryColor)
underlineText()
setOnClickListener {
if (context.hasPermission(PERMISSION_READ_CONTACTS)) {
launchCreateNewIntent()
} else {
requestReadContactsPermission()
}
}
}
letter_fastscroller.textColor = context.config.textColor.getColorStateList()
letter_fastscroller_thumb.setupWithFastScroller(letter_fastscroller)
letter_fastscroller_thumb.textColor = context.config.primaryColor.getContrastColor()
fragment_fab.setOnClickListener {
Intent(Intent.ACTION_INSERT).apply {
data = ContactsContract.Contacts.CONTENT_URI
if (resolveActivity(context.packageManager) != null) {
activity?.startActivity(this)
} else {
context.toast(R.string.no_app_found)
}
}
launchCreateNewIntent()
}
}
@ -172,6 +168,9 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
if (it) {
fragment_placeholder.text = context.getString(R.string.no_contacts_found)
fragment_placeholder_2.text = context.getString(R.string.create_new)
fragment_placeholder_2.setOnClickListener {
launchCreateNewIntent()
}
SimpleContactsHelper(context).getAvailableContacts(false) { contacts ->
activity?.runOnUiThread {
@ -181,4 +180,16 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
}
}
}
private fun launchCreateNewIntent() {
Intent().apply {
action = Intent.ACTION_INSERT
data = ContactsContract.Contacts.CONTENT_URI
if (resolveActivity(context.packageManager) != null) {
context.startActivity(this)
} else {
context.toast(R.string.no_app_found)
}
}
}
}