mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Ask contacts permission in fragment's onResume() if needed
This commit is contained in:
parent
133f533b87
commit
5d58b2a0fd
2 changed files with 40 additions and 11 deletions
|
|
@ -322,6 +322,10 @@ class MainActivity : GenericActivity() {
|
|||
return findNavController(R.id.main_nav_host_fragment)
|
||||
}
|
||||
|
||||
fun loadContacts() {
|
||||
coreContext.contactsManager.loadContacts(this)
|
||||
}
|
||||
|
||||
private fun goToLatestVisitedFragment() {
|
||||
try {
|
||||
// Prevent navigating to default fragment upon rotation (we only want to do it on first start)
|
||||
|
|
@ -647,10 +651,6 @@ class MainActivity : GenericActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun loadContacts() {
|
||||
coreContext.contactsManager.loadContacts(this)
|
||||
}
|
||||
|
||||
private fun showAuthenticationRequestedDialog(identity: String) {
|
||||
currentlyDisplayedAuthDialog?.dismiss()
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,9 @@
|
|||
*/
|
||||
package org.linphone.ui.main.contacts.fragment
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.provider.ContactsContract
|
||||
import android.view.Gravity
|
||||
|
|
@ -29,7 +31,9 @@ import android.view.ViewGroup
|
|||
import android.view.animation.Animation
|
||||
import android.view.animation.AnimationUtils
|
||||
import android.widget.PopupWindow
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
|
|
@ -42,6 +46,7 @@ import org.linphone.R
|
|||
import org.linphone.core.tools.Log
|
||||
import org.linphone.databinding.ContactsListFilterPopupMenuBinding
|
||||
import org.linphone.databinding.ContactsListFragmentBinding
|
||||
import org.linphone.ui.main.MainActivity
|
||||
import org.linphone.ui.main.contacts.adapter.ContactsListAdapter
|
||||
import org.linphone.ui.main.contacts.model.ContactAvatarModel
|
||||
import org.linphone.ui.main.contacts.viewmodel.ContactsListViewModel
|
||||
|
|
@ -65,6 +70,17 @@ class ContactsListFragment : AbstractMainFragment() {
|
|||
|
||||
private var bottomSheetDialog: BottomSheetDialogFragment? = null
|
||||
|
||||
private val requestPermissionLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.RequestPermission()
|
||||
) { isGranted ->
|
||||
if (isGranted) {
|
||||
Log.i("$TAG READ_CONTACTS permission has been granted, start contacts loader")
|
||||
(requireActivity() as MainActivity).loadContacts()
|
||||
} else {
|
||||
Log.w("$TAG READ_CONTACTS permission has been denied")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDefaultAccountChanged() {
|
||||
Log.i(
|
||||
"$TAG Default account changed, updating avatar in top bar & refreshing contacts list"
|
||||
|
|
@ -196,6 +212,26 @@ class ContactsListFragment : AbstractMainFragment() {
|
|||
)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
if (ContextCompat.checkSelfPermission(
|
||||
requireContext(),
|
||||
Manifest.permission.READ_CONTACTS
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
Log.w("$TAG READ_CONTACTS permission wasn't granted yet, asking for it now")
|
||||
requestPermissionLauncher.launch(Manifest.permission.READ_CONTACTS)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
|
||||
bottomSheetDialog?.dismiss()
|
||||
bottomSheetDialog = null
|
||||
}
|
||||
|
||||
private fun configureAdapter(adapter: ContactsListAdapter) {
|
||||
adapter.contactLongClickedEvent.observe(viewLifecycleOwner) {
|
||||
it.consume { model ->
|
||||
|
|
@ -231,13 +267,6 @@ class ContactsListFragment : AbstractMainFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
|
||||
bottomSheetDialog?.dismiss()
|
||||
bottomSheetDialog = null
|
||||
}
|
||||
|
||||
private fun shareContact(name: String, file: File) {
|
||||
val publicUri = FileProvider.getUriForFile(
|
||||
requireContext(),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue