mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Recreate activity when theme is changed through remote provisioning, fixed keep alive service automatically enabled after remote provisioning
This commit is contained in:
parent
935d463896
commit
75bb28cb2f
4 changed files with 38 additions and 3 deletions
|
|
@ -106,6 +106,10 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C
|
|||
MutableLiveData<Event<Pair<String, Int>>>()
|
||||
}
|
||||
|
||||
val provisioningAppliedEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
@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()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Event<Boolean>>()
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue