mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
When upgrading from previous version, do not show AssitantLanding page after WelcomeActivity and/or PermissionsFragment
This commit is contained in:
parent
23c3a63aed
commit
fbb59cbc2a
3 changed files with 55 additions and 10 deletions
|
|
@ -40,6 +40,8 @@ import org.linphone.ui.assistant.fragment.PermissionsFragmentDirections
|
|||
class AssistantActivity : GenericActivity() {
|
||||
companion object {
|
||||
private const val TAG = "[Assistant Activity]"
|
||||
|
||||
const val SKIP_LANDING_EXTRA = "SkipLandingIfAtLeastAnAccount"
|
||||
}
|
||||
|
||||
private lateinit var binding: AssistantActivityBinding
|
||||
|
|
@ -67,6 +69,18 @@ class AssistantActivity : GenericActivity() {
|
|||
Log.w("$TAG Not all required permissions are granted, showing Permissions fragment")
|
||||
val action = PermissionsFragmentDirections.actionGlobalPermissionsFragment()
|
||||
binding.assistantNavContainer.findNavController().navigate(action)
|
||||
} else if (intent.getBooleanExtra(SKIP_LANDING_EXTRA, false)) {
|
||||
Log.w(
|
||||
"$TAG We were asked to leave assistant if at least an account is already configured"
|
||||
)
|
||||
coreContext.postOnCoreThread { core ->
|
||||
if (core.accountList.isNotEmpty()) {
|
||||
coreContext.postOnMainThread {
|
||||
Log.w("$TAG At least one account was found, leaving assistant")
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,9 +30,12 @@ import androidx.annotation.UiThread
|
|||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.R
|
||||
import org.linphone.compatibility.Compatibility
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.databinding.AssistantPermissionsFragmentBinding
|
||||
import org.linphone.ui.assistant.AssistantActivity
|
||||
|
||||
@UiThread
|
||||
class PermissionsFragment : Fragment() {
|
||||
|
|
@ -45,6 +48,7 @@ class PermissionsFragment : Fragment() {
|
|||
private val requestPermissionLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.RequestMultiplePermissions()
|
||||
) { permissions ->
|
||||
var allGranted = true
|
||||
permissions.entries.forEach {
|
||||
val permissionName = it.key
|
||||
val isGranted = it.value
|
||||
|
|
@ -52,9 +56,16 @@ class PermissionsFragment : Fragment() {
|
|||
Log.i("Permission [$permissionName] is now granted")
|
||||
} else {
|
||||
Log.i("Permission [$permissionName] has been denied")
|
||||
allGranted = false
|
||||
}
|
||||
}
|
||||
goToLoginFragment()
|
||||
|
||||
if (!allGranted) { // If all permissions were granted, the onResume() will do the navigation
|
||||
Log.w(
|
||||
"$TAG Not all permissions were granted, leaving anyway, they will be asked again later..."
|
||||
)
|
||||
goToLoginFragment()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
|
|
@ -113,8 +124,25 @@ class PermissionsFragment : Fragment() {
|
|||
}
|
||||
|
||||
private fun goToLoginFragment() {
|
||||
val action = PermissionsFragmentDirections.actionPermissionsFragmentToLandingFragment()
|
||||
findNavController().navigate(action)
|
||||
if (requireActivity().intent.getBooleanExtra(AssistantActivity.SKIP_LANDING_EXTRA, false)) {
|
||||
Log.w(
|
||||
"$TAG We were asked to leave assistant if at least an account is already configured"
|
||||
)
|
||||
coreContext.postOnCoreThread { core ->
|
||||
if (core.accountList.isNotEmpty()) {
|
||||
coreContext.postOnMainThread {
|
||||
Log.w("$TAG At least one account was found, leaving assistant")
|
||||
requireActivity().finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (findNavController().currentDestination?.id == R.id.permissionsFragment) {
|
||||
val action =
|
||||
PermissionsFragmentDirections.actionPermissionsFragmentToLandingFragment()
|
||||
findNavController().navigate(action)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun areAllPermissionsGranted(): Boolean {
|
||||
|
|
|
|||
|
|
@ -67,9 +67,7 @@ class WelcomeActivity : GenericActivity() {
|
|||
|
||||
binding.setSkipClickListener {
|
||||
Log.i("$TAG User clicked on 'skip' button, going to Assistant")
|
||||
finish()
|
||||
val intent = Intent(this, AssistantActivity::class.java)
|
||||
startActivity(intent)
|
||||
goToAssistant()
|
||||
}
|
||||
|
||||
binding.setNextClickListener {
|
||||
|
|
@ -77,11 +75,9 @@ class WelcomeActivity : GenericActivity() {
|
|||
Log.i(
|
||||
"$TAG User clicked on 'start' button, leaving activity and going into Assistant"
|
||||
)
|
||||
finish()
|
||||
val intent = Intent(this, AssistantActivity::class.java)
|
||||
startActivity(intent)
|
||||
goToAssistant()
|
||||
} else {
|
||||
viewPager.currentItem = viewPager.currentItem + 1
|
||||
viewPager.currentItem += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -96,6 +92,13 @@ class WelcomeActivity : GenericActivity() {
|
|||
super.onPause()
|
||||
}
|
||||
|
||||
private fun goToAssistant() {
|
||||
finish()
|
||||
val intent = Intent(this, AssistantActivity::class.java)
|
||||
intent.putExtra(AssistantActivity.SKIP_LANDING_EXTRA, true)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
private inner class ScreenSlidePagerAdapter(fa: FragmentActivity) : FragmentStateAdapter(fa) {
|
||||
override fun getItemCount(): Int = PAGES
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue