diff --git a/app/src/main/java/org/linphone/core/CoreContext.kt b/app/src/main/java/org/linphone/core/CoreContext.kt index 2fe1fd3ec..e752d2b90 100644 --- a/app/src/main/java/org/linphone/core/CoreContext.kt +++ b/app/src/main/java/org/linphone/core/CoreContext.kt @@ -106,6 +106,10 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C MutableLiveData>>() } + val provisioningAppliedEvent: MutableLiveData> by lazy { + MutableLiveData>() + } + @SuppressLint("HandlerLeak") private lateinit var coreThread: Handler @@ -166,6 +170,7 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C ) { Log.i("$TAG Configuring state changed [$status], message is [$message]") if (status == ConfiguringState.Successful) { + provisioningAppliedEvent.postValue(Event(true)) corePreferences.firstLaunch = false showGreenToastEvent.postValue( Event( @@ -339,6 +344,9 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C } override fun onAccountAdded(core: Core, account: Account) { + // Prevent this trigger when core is stopped/start in remote prov + if (core.globalState == GlobalState.Off) return + Log.i( "$TAG New account configured: [${account.params.identityAddress?.asStringUriOnly()}]" ) @@ -507,6 +515,7 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C } if (corePreferences.keepServiceAlive) { + Log.i("$TAG Starting keep alive service") startKeepAliveService() } diff --git a/app/src/main/java/org/linphone/ui/GenericActivity.kt b/app/src/main/java/org/linphone/ui/GenericActivity.kt index e48ca87be..5ab9172a9 100644 --- a/app/src/main/java/org/linphone/ui/GenericActivity.kt +++ b/app/src/main/java/org/linphone/ui/GenericActivity.kt @@ -49,9 +49,11 @@ open class GenericActivity : AppCompatActivity() { private lateinit var toastsArea: ViewGroup + private var mainColor: String = "orange" + override fun getTheme(): Resources.Theme { - val mainColor = corePreferences.themeMainColor - val theme = super.getTheme() + mainColor = corePreferences.themeMainColor + val theme = super.theme when (mainColor) { "yellow" -> theme.applyStyle(R.style.Theme_LinphoneYellow, true) "green" -> theme.applyStyle(R.style.Theme_LinphoneGreen, true) @@ -89,6 +91,13 @@ open class GenericActivity : AppCompatActivity() { super.onCreate(savedInstanceState) } + protected fun checkMainColorTheme() { + if (mainColor != corePreferences.themeMainColor) { + Log.i("$TAG Main color setting has changed, re-creating activity") + recreate() + } + } + fun setUpToastsArea(viewGroup: ViewGroup) { toastsArea = viewGroup } diff --git a/app/src/main/java/org/linphone/ui/assistant/viewmodel/QrCodeViewModel.kt b/app/src/main/java/org/linphone/ui/assistant/viewmodel/QrCodeViewModel.kt index e8787c1c3..57073ff98 100644 --- a/app/src/main/java/org/linphone/ui/assistant/viewmodel/QrCodeViewModel.kt +++ b/app/src/main/java/org/linphone/ui/assistant/viewmodel/QrCodeViewModel.kt @@ -24,6 +24,7 @@ import androidx.annotation.UiThread import androidx.annotation.WorkerThread import androidx.lifecycle.MutableLiveData import org.linphone.LinphoneApplication.Companion.coreContext +import org.linphone.core.ConfiguringState import org.linphone.core.Core import org.linphone.core.CoreListenerStub import org.linphone.core.tools.Log @@ -38,6 +39,14 @@ class QrCodeViewModel @UiThread constructor() : GenericViewModel() { val qrCodeFoundEvent = MutableLiveData>() private val coreListener = object : CoreListenerStub() { + @WorkerThread + override fun onConfiguringStatus(core: Core, status: ConfiguringState, message: String?) { + Log.i("$TAG Configuring state is [$status]") + if (status == ConfiguringState.Successful) { + qrCodeFoundEvent.postValue(Event(true)) + } + } + @WorkerThread override fun onQrcodeFound(core: Core, result: String?) { Log.i("$TAG QR Code found: [$result]") @@ -47,6 +56,7 @@ class QrCodeViewModel @UiThread constructor() : GenericViewModel() { val isValidUrl = Patterns.WEB_URL.matcher(result).matches() if (!isValidUrl) { Log.e("$TAG The content of the QR Code doesn't seem to be a valid web URL") + qrCodeFoundEvent.postValue(Event(false)) } else { Log.i( "$TAG QR code URL set, restarting the Core to apply configuration changes" @@ -57,7 +67,6 @@ class QrCodeViewModel @UiThread constructor() : GenericViewModel() { coreContext.core.start() Log.i("$TAG Core has been restarted") } - qrCodeFoundEvent.postValue(Event(isValidUrl)) } } } diff --git a/app/src/main/java/org/linphone/ui/main/MainActivity.kt b/app/src/main/java/org/linphone/ui/main/MainActivity.kt index ae643b0d1..8f4917372 100644 --- a/app/src/main/java/org/linphone/ui/main/MainActivity.kt +++ b/app/src/main/java/org/linphone/ui/main/MainActivity.kt @@ -45,6 +45,7 @@ import androidx.core.view.updatePadding import androidx.databinding.DataBindingUtil import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.lifecycleScope +import androidx.lifecycle.observe import androidx.navigation.NavController import androidx.navigation.NavDestination import androidx.navigation.NavOptions @@ -295,6 +296,13 @@ class MainActivity : GenericActivity() { } } + coreContext.provisioningAppliedEvent.observe(this) { + it.consume { + Log.i("$TAG Remote provisioning was applied, checking if theme has changed") + checkMainColorTheme() + } + } + CarConnection(this).type.observe(this) { val asString = when (it) { CarConnection.CONNECTION_TYPE_NOT_CONNECTED -> "NOT CONNECTED"