Restored start-up screen

This commit is contained in:
Sylvain Berfini 2024-01-30 10:21:40 +01:00
parent ddd614acd0
commit 318a487e10
6 changed files with 73 additions and 88 deletions

View file

@ -55,13 +55,6 @@ class CorePreferences @UiThread constructor(private val context: Context) {
config.setBool("app", "first_6.0_launch", value) config.setBool("app", "first_6.0_launch", value)
} }
@get:WorkerThread @set:WorkerThread
var defaultFragment: Int
get() = config.getInt("app", "default_page", -1)
set(value) {
config.setInt("app", "default_page", value)
}
@get:WorkerThread @set:WorkerThread @get:WorkerThread @set:WorkerThread
var conditionsAndPrivacyPolicyAccepted: Boolean var conditionsAndPrivacyPolicyAccepted: Boolean
get() = config.getBool("app", "read_and_agree_terms_and_privacy", false) get() = config.getBool("app", "read_and_agree_terms_and_privacy", false)

View file

@ -24,7 +24,6 @@ import android.content.res.Configuration
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat import androidx.core.view.WindowCompat
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.LinphoneApplication.Companion.corePreferences import org.linphone.LinphoneApplication.Companion.corePreferences
import org.linphone.compatibility.Compatibility import org.linphone.compatibility.Compatibility
import org.linphone.core.tools.Log import org.linphone.core.tools.Log
@ -38,10 +37,6 @@ open class GenericActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
WindowCompat.setDecorFitsSystemWindows(window, true) WindowCompat.setDecorFitsSystemWindows(window, true)
while (!coreContext.isReady()) {
Thread.sleep(20)
}
val nightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK val nightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
val darkModeEnabled = corePreferences.darkMode val darkModeEnabled = corePreferences.darkMode
Log.i( Log.i(

View file

@ -54,6 +54,10 @@ class AssistantActivity : GenericActivity() {
binding = DataBindingUtil.setContentView(this, R.layout.assistant_activity) binding = DataBindingUtil.setContentView(this, R.layout.assistant_activity)
binding.lifecycleOwner = this binding.lifecycleOwner = this
while (!coreContext.isReady()) {
Thread.sleep(20)
}
coreContext.postOnCoreThread { core -> coreContext.postOnCoreThread { core ->
if (core.accountList.isEmpty()) { if (core.accountList.isEmpty()) {
Log.i("$TAG No account configured, disabling back gesture") Log.i("$TAG No account configured, disabling back gesture")

View file

@ -21,6 +21,7 @@ package org.linphone.ui.main
import android.Manifest import android.Manifest
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.net.Uri import android.net.Uri
@ -38,6 +39,7 @@ import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavController import androidx.navigation.NavController
import androidx.navigation.NavOptions
import androidx.navigation.findNavController import androidx.navigation.findNavController
import kotlinx.coroutines.Deferred import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async import kotlinx.coroutines.async
@ -66,6 +68,7 @@ class MainActivity : GenericActivity() {
companion object { companion object {
private const val TAG = "[Main Activity]" private const val TAG = "[Main Activity]"
private const val DEFAULT_FRAGMENT_KEY = "default_fragment"
private const val CONTACTS_FRAGMENT_ID = 1 private const val CONTACTS_FRAGMENT_ID = 1
private const val HISTORY_FRAGMENT_ID = 2 private const val HISTORY_FRAGMENT_ID = 2
private const val CHAT_FRAGMENT_ID = 3 private const val CHAT_FRAGMENT_ID = 3
@ -84,13 +87,17 @@ class MainActivity : GenericActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.main_activity)
binding.lifecycleOwner = this
while (!coreContext.isReady()) {
Thread.sleep(20)
}
if (checkSelfPermission(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) { if (checkSelfPermission(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
loadContacts() loadContacts()
} }
binding = DataBindingUtil.setContentView(this, R.layout.main_activity)
binding.lifecycleOwner = this
viewModel = run { viewModel = run {
ViewModelProvider(this)[MainViewModel::class.java] ViewModelProvider(this)[MainViewModel::class.java]
} }
@ -198,41 +205,11 @@ class MainActivity : GenericActivity() {
} }
} }
coreContext.postOnCoreThread { if (intent != null) {
val startDestination = when (corePreferences.defaultFragment) { handleIntent(intent, false)
CONTACTS_FRAGMENT_ID -> { } else {
Log.i("$TAG Latest visited page is contacts, setting it as start destination") // This should never happen!
R.id.contactsListFragment Log.e("$TAG onPostCreate called without intent !")
}
HISTORY_FRAGMENT_ID -> {
Log.i(
"$TAG Latest visited page is call history, setting it as start destination"
)
R.id.historyListFragment
}
CHAT_FRAGMENT_ID -> {
Log.i(
"$TAG Latest visited page is conversations, setting it as start destination"
)
R.id.conversationsListFragment
}
MEETINGS_FRAGMENT_ID -> {
Log.i("$TAG Latest visited page is meetings, setting it as start destination")
R.id.meetingsListFragment
}
else -> { // Default
Log.i("$TAG No latest visited page stored, using default one (call history)")
R.id.historyListFragment
}
}
coreContext.postOnMainThread {
if (intent != null) {
handleIntent(intent, startDestination, false)
} else {
// This should never happen!
Log.e("$TAG onPostCreate called without intent !")
}
}
} }
} }
@ -254,11 +231,11 @@ class MainActivity : GenericActivity() {
HISTORY_FRAGMENT_ID HISTORY_FRAGMENT_ID
} }
} }
coreContext.postOnCoreThread { with(getPreferences(Context.MODE_PRIVATE).edit()) {
Log.i("$TAG Storing default page [$defaultFragmentId]") putInt(DEFAULT_FRAGMENT_KEY, defaultFragmentId)
corePreferences.defaultFragment = defaultFragmentId apply()
corePreferences.config.sync()
} }
Log.i("$TAG Stored [$defaultFragmentId] as default page")
super.onPause() super.onPause()
} }
@ -273,7 +250,7 @@ class MainActivity : GenericActivity() {
super.onNewIntent(intent) super.onNewIntent(intent)
if (intent != null) { if (intent != null) {
handleIntent(intent, -1, true) handleIntent(intent, true)
} }
} }
@ -353,7 +330,7 @@ class MainActivity : GenericActivity() {
} }
@MainThread @MainThread
private fun handleIntent(intent: Intent, defaultDestination: Int, isNewIntent: Boolean) { private fun handleIntent(intent: Intent, isNewIntent: Boolean) {
Log.i( Log.i(
"$TAG Handling intent action [${intent.action}], type [${intent.type}] and data [${intent.data}]" "$TAG Handling intent action [${intent.action}], type [${intent.type}] and data [${intent.data}]"
) )
@ -369,42 +346,58 @@ class MainActivity : GenericActivity() {
handleCallIntent(intent) handleCallIntent(intent)
} }
else -> { else -> {
handleMainIntent(intent, defaultDestination, isNewIntent) handleMainIntent(intent, isNewIntent)
} }
} }
} }
@MainThread @MainThread
private fun handleMainIntent(intent: Intent, defaultDestination: Int, isNewIntent: Boolean) { private fun handleMainIntent(intent: Intent, isNewIntent: Boolean) {
if (intent.hasExtra("Chat")) { if (intent.hasExtra("Chat")) {
Log.i("$TAG New intent with [Chat] extra") Log.i("$TAG Intent has [Chat] extra")
if (isNewIntent) { try {
try { Log.i("$TAG Trying to go to Conversations fragment")
Log.i("$TAG Trying to go to Conversations fragment") val args = intent.extras
findNavController().navigate( findNavController().navigate(R.id.conversationsListFragment, args)
R.id.action_global_conversationsListFragment, } catch (ise: IllegalStateException) {
intent.extras Log.e("$TAG Can't navigate to Conversations fragment: $ise")
)
} catch (ise: IllegalStateException) {
Log.i(
"$TAG Nav graph not set yet, loading it & set start destination to Conversations fragment instead of default"
)
findNavController().navigate(R.id.conversationsListFragment)
}
} else {
Log.i(
"$TAG Loading graph & set start destination to Conversations fragment instead of default"
)
findNavController().navigate(R.id.conversationsListFragment)
} }
} else { } else if (!isNewIntent) {
if (!isNewIntent && defaultDestination > 0) { try {
val defaultFragmentId = getPreferences(Context.MODE_PRIVATE).getInt(
DEFAULT_FRAGMENT_KEY,
CONTACTS_FRAGMENT_ID
)
Log.i("$TAG Trying to navigate to set default destination [$defaultFragmentId]")
val args = intent.extras
try { try {
Log.i("$TAG Setting nav graph with expected start destination") val navOptionsBuilder = NavOptions.Builder()
findNavController().navigate(defaultDestination) navOptionsBuilder.setPopUpTo(R.id.contactsListFragment, true)
val navOptions = navOptionsBuilder.build()
when (defaultFragmentId) {
HISTORY_FRAGMENT_ID -> {
findNavController().navigate(R.id.historyListFragment, args, navOptions)
}
CHAT_FRAGMENT_ID -> {
findNavController().navigate(
R.id.conversationsListFragment,
args,
navOptions
)
}
MEETINGS_FRAGMENT_ID -> {
findNavController().navigate(
R.id.meetingsListFragment,
args,
navOptions
)
}
}
} catch (ise: IllegalStateException) { } catch (ise: IllegalStateException) {
Log.i("$TAG Failed to handle intent: $ise") Log.e("$TAG Can't navigate to Conversations fragment: $ise")
} }
} catch (ise: IllegalStateException) {
Log.i("$TAG Failed to handle intent: $ise")
} }
} }
} }

View file

@ -168,7 +168,7 @@ class ConversationModel @WorkerThread constructor(val chatRoom: ChatRoom) {
isMuted.postValue(chatRoom.muted) isMuted.postValue(chatRoom.muted)
isEphemeral.postValue(chatRoom.isEphemeralEnabled) isEphemeral.postValue(chatRoom.isEphemeralEnabled)
Log.i( Log.d(
"$TAG Ephemeral messages are [${if (chatRoom.isEphemeralEnabled) "enabled" else "disabled"}], lifetime is [${chatRoom.ephemeralLifetime}]" "$TAG Ephemeral messages are [${if (chatRoom.isEphemeralEnabled) "enabled" else "disabled"}], lifetime is [${chatRoom.ephemeralLifetime}]"
) )
@ -305,12 +305,12 @@ class ConversationModel @WorkerThread constructor(val chatRoom: ChatRoom) {
private fun computeParticipants() { private fun computeParticipants() {
val friends = arrayListOf<Friend>() val friends = arrayListOf<Friend>()
val address = if (chatRoom.hasCapability(Capabilities.Basic.toInt())) { val address = if (chatRoom.hasCapability(Capabilities.Basic.toInt())) {
Log.i("$TAG Conversation [$id] is 'Basic'") Log.d("$TAG Conversation [$id] is 'Basic'")
chatRoom.peerAddress chatRoom.peerAddress
} else { } else {
val firstParticipant = chatRoom.participants.firstOrNull() val firstParticipant = chatRoom.participants.firstOrNull()
if (isGroup) { if (isGroup) {
Log.i( Log.d(
"$TAG Group conversation [$id] has [${chatRoom.nbParticipants}] participant(s)" "$TAG Group conversation [$id] has [${chatRoom.nbParticipants}] participant(s)"
) )
for (participant in chatRoom.participants) { for (participant in chatRoom.participants) {
@ -322,7 +322,7 @@ class ConversationModel @WorkerThread constructor(val chatRoom: ChatRoom) {
} }
} }
} else { } else {
Log.i( Log.d(
"$TAG Conversation [$id] is with participant [${firstParticipant?.address?.asStringUriOnly()}]" "$TAG Conversation [$id] is with participant [${firstParticipant?.address?.asStringUriOnly()}]"
) )
} }

View file

@ -145,7 +145,7 @@ class ConversationsListViewModel @UiThread constructor() : AbstractTopBarViewMod
// TODO: remove when SDK will do it automatically // TODO: remove when SDK will do it automatically
if (account?.isInSecureMode() == true) { if (account?.isInSecureMode() == true) {
if (!chatRoom.hasCapability(Capabilities.Encrypted.toInt()) && chatRoom.unreadMessagesCount == 0) { // TODO: remove message count check later if (!chatRoom.hasCapability(Capabilities.Encrypted.toInt()) && chatRoom.unreadMessagesCount == 0) { // TODO: remove message count check later
Log.w( Log.d(
"$TAG Skipping conversation [${LinphoneUtils.getChatRoomId(chatRoom)}] as it is not E2E encrypted and default account requires it" "$TAG Skipping conversation [${LinphoneUtils.getChatRoomId(chatRoom)}] as it is not E2E encrypted and default account requires it"
) )
continue continue
@ -181,7 +181,7 @@ class ConversationsListViewModel @UiThread constructor() : AbstractTopBarViewMod
} }
} }
if (count == 20) { if (count == 15) {
conversations.postValue(list) conversations.postValue(list)
fetchInProgress.postValue(false) fetchInProgress.postValue(false)
} }