mirror of
				https://github.com/SimpleMobileTools/Simple-Contacts.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	require Contacts permission at third party intents
This commit is contained in:
		@@ -16,6 +16,8 @@ import android.widget.ImageView
 | 
			
		||||
import android.widget.TextView
 | 
			
		||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
 | 
			
		||||
import com.simplemobiletools.commons.extensions.*
 | 
			
		||||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
 | 
			
		||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS
 | 
			
		||||
import com.simplemobiletools.commons.models.RadioItem
 | 
			
		||||
import com.simplemobiletools.contacts.R
 | 
			
		||||
import com.simplemobiletools.contacts.dialogs.SelectGroupsDialog
 | 
			
		||||
@@ -51,12 +53,34 @@ class EditContactActivity : ContactActivity() {
 | 
			
		||||
    private var wasActivityInitialized = false
 | 
			
		||||
    private var lastPhotoIntentUri: Uri? = null
 | 
			
		||||
    private var isSaving = false
 | 
			
		||||
    private var isThirdPartyIntent = false
 | 
			
		||||
 | 
			
		||||
    override fun onCreate(savedInstanceState: Bundle?) {
 | 
			
		||||
        super.onCreate(savedInstanceState)
 | 
			
		||||
        setContentView(R.layout.activity_edit_contact)
 | 
			
		||||
        supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_cross)
 | 
			
		||||
        initContact()
 | 
			
		||||
 | 
			
		||||
        val action = intent.action
 | 
			
		||||
        isThirdPartyIntent = action == Intent.ACTION_EDIT || action == Intent.ACTION_INSERT_OR_EDIT || action == Intent.ACTION_INSERT
 | 
			
		||||
        if (isThirdPartyIntent) {
 | 
			
		||||
            handlePermission(PERMISSION_READ_CONTACTS) {
 | 
			
		||||
                if (it) {
 | 
			
		||||
                    handlePermission(PERMISSION_WRITE_CONTACTS) {
 | 
			
		||||
                        if (it) {
 | 
			
		||||
                            initContact()
 | 
			
		||||
                        } else {
 | 
			
		||||
                            toast(R.string.no_contacts_permission)
 | 
			
		||||
                            finish()
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                } else {
 | 
			
		||||
                    toast(R.string.no_contacts_permission)
 | 
			
		||||
                    finish()
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            initContact()
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun onCreateOptionsMenu(menu: Menu): Boolean {
 | 
			
		||||
@@ -121,7 +145,7 @@ class EditContactActivity : ContactActivity() {
 | 
			
		||||
            setupEditContact()
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (contact!!.id == 0 && intent.extras?.containsKey(KEY_PHONE) == true && (intent.action == Intent.ACTION_INSERT_OR_EDIT || intent.action == Intent.ACTION_INSERT)) {
 | 
			
		||||
        if (contact!!.id == 0 && intent.extras?.containsKey(KEY_PHONE) == true && (action == Intent.ACTION_INSERT_OR_EDIT || action == Intent.ACTION_INSERT)) {
 | 
			
		||||
            val phoneNumber = intent.extras.get(KEY_PHONE).toString()
 | 
			
		||||
            contact!!.phoneNumbers.add(PhoneNumber(phoneNumber, DEFAULT_PHONE_NUMBER_TYPE))
 | 
			
		||||
            setupPhoneNumbers()
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@ import android.view.MenuItem
 | 
			
		||||
import android.view.WindowManager
 | 
			
		||||
import android.widget.RelativeLayout
 | 
			
		||||
import com.simplemobiletools.commons.extensions.*
 | 
			
		||||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
 | 
			
		||||
import com.simplemobiletools.contacts.R
 | 
			
		||||
import com.simplemobiletools.contacts.extensions.*
 | 
			
		||||
import com.simplemobiletools.contacts.helpers.CONTACT_ID
 | 
			
		||||
@@ -22,6 +23,7 @@ import kotlinx.android.synthetic.main.item_view_group.view.*
 | 
			
		||||
import kotlinx.android.synthetic.main.item_view_phone_number.view.*
 | 
			
		||||
 | 
			
		||||
class ViewContactActivity : ContactActivity() {
 | 
			
		||||
    private var isViewIntent = false
 | 
			
		||||
    override fun onCreate(savedInstanceState: Bundle?) {
 | 
			
		||||
        super.onCreate(savedInstanceState)
 | 
			
		||||
        setContentView(R.layout.activity_view_contact)
 | 
			
		||||
@@ -29,7 +31,19 @@ class ViewContactActivity : ContactActivity() {
 | 
			
		||||
 | 
			
		||||
    override fun onResume() {
 | 
			
		||||
        super.onResume()
 | 
			
		||||
        initContact()
 | 
			
		||||
        isViewIntent = intent.action == ContactsContract.QuickContact.ACTION_QUICK_CONTACT || intent.action == Intent.ACTION_VIEW
 | 
			
		||||
        if (isViewIntent) {
 | 
			
		||||
            handlePermission(PERMISSION_READ_CONTACTS) {
 | 
			
		||||
                if (it) {
 | 
			
		||||
                    initContact()
 | 
			
		||||
                } else {
 | 
			
		||||
                    toast(R.string.no_contacts_permission)
 | 
			
		||||
                    finish()
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            initContact()
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun onCreateOptionsMenu(menu: Menu): Boolean {
 | 
			
		||||
@@ -50,8 +64,7 @@ class ViewContactActivity : ContactActivity() {
 | 
			
		||||
    private fun initContact() {
 | 
			
		||||
        var wasLookupKeyUsed = false
 | 
			
		||||
        var contactId = intent.getIntExtra(CONTACT_ID, 0)
 | 
			
		||||
        val action = intent.action
 | 
			
		||||
        if (contactId == 0 && (action == ContactsContract.QuickContact.ACTION_QUICK_CONTACT || action == Intent.ACTION_VIEW)) {
 | 
			
		||||
        if (contactId == 0 && isViewIntent) {
 | 
			
		||||
            val data = intent.data
 | 
			
		||||
            if (data != null) {
 | 
			
		||||
                val rawId = if (data.path.contains("lookup")) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user