mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-05-03 15:26:27 +00:00
Update devices list when removing one
This commit is contained in:
parent
92ec1940e5
commit
31d92abcdf
2 changed files with 30 additions and 13 deletions
|
|
@ -27,7 +27,7 @@ import org.linphone.utils.TimestampUtils
|
||||||
|
|
||||||
class AccountDeviceModel @WorkerThread constructor(
|
class AccountDeviceModel @WorkerThread constructor(
|
||||||
private val accountDevice: AccountDevice,
|
private val accountDevice: AccountDevice,
|
||||||
private val onRemove: (accountDevice: AccountDevice) -> (Unit)
|
private val onRemove: (model: AccountDeviceModel, accountDevice: AccountDevice) -> (Unit)
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
const val TAG = "[Account Device Model]"
|
const val TAG = "[Account Device Model]"
|
||||||
|
|
@ -63,6 +63,6 @@ class AccountDeviceModel @WorkerThread constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeDevice() {
|
fun removeDevice() {
|
||||||
onRemove(accountDevice)
|
onRemove(this, accountDevice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import org.linphone.core.AccountDevice
|
||||||
import org.linphone.core.AccountManagerServices
|
import org.linphone.core.AccountManagerServices
|
||||||
import org.linphone.core.AccountManagerServicesRequest
|
import org.linphone.core.AccountManagerServicesRequest
|
||||||
import org.linphone.core.AccountManagerServicesRequestListenerStub
|
import org.linphone.core.AccountManagerServicesRequestListenerStub
|
||||||
|
import org.linphone.core.Address
|
||||||
import org.linphone.core.DialPlan
|
import org.linphone.core.DialPlan
|
||||||
import org.linphone.core.Dictionary
|
import org.linphone.core.Dictionary
|
||||||
import org.linphone.core.Factory
|
import org.linphone.core.Factory
|
||||||
|
|
@ -98,7 +99,7 @@ class AccountProfileViewModel @UiThread constructor() : GenericViewModel() {
|
||||||
val devicesList = arrayListOf<AccountDeviceModel>()
|
val devicesList = arrayListOf<AccountDeviceModel>()
|
||||||
for (accountDevice in accountDevices) {
|
for (accountDevice in accountDevices) {
|
||||||
devicesList.add(
|
devicesList.add(
|
||||||
AccountDeviceModel(accountDevice) { device ->
|
AccountDeviceModel(accountDevice) { model, device ->
|
||||||
if (::accountManagerServices.isInitialized) {
|
if (::accountManagerServices.isInitialized) {
|
||||||
val identityAddress = account.params.identityAddress
|
val identityAddress = account.params.identityAddress
|
||||||
if (identityAddress != null) {
|
if (identityAddress != null) {
|
||||||
|
|
@ -111,6 +112,11 @@ class AccountProfileViewModel @UiThread constructor() : GenericViewModel() {
|
||||||
)
|
)
|
||||||
deleteRequest.addListener(this)
|
deleteRequest.addListener(this)
|
||||||
deleteRequest.submit()
|
deleteRequest.submit()
|
||||||
|
|
||||||
|
val newList = arrayListOf<AccountDeviceModel>()
|
||||||
|
newList.addAll(devices.value.orEmpty())
|
||||||
|
newList.remove(model)
|
||||||
|
devices.postValue(newList)
|
||||||
} else {
|
} else {
|
||||||
Log.e("$TAG Account identity address is null, can't delete device!")
|
Log.e("$TAG Account identity address is null, can't delete device!")
|
||||||
}
|
}
|
||||||
|
|
@ -122,6 +128,12 @@ class AccountProfileViewModel @UiThread constructor() : GenericViewModel() {
|
||||||
devicesFetchInProgress.postValue(false)
|
devicesFetchInProgress.postValue(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onRequestSuccessful(request: AccountManagerServicesRequest, data: String?) {
|
||||||
|
if (request.type == AccountManagerServicesRequest.Type.DeleteDevice) {
|
||||||
|
Log.i("$TAG Device successfully deleted: $data")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
override fun onRequestError(
|
override fun onRequestError(
|
||||||
request: AccountManagerServicesRequest,
|
request: AccountManagerServicesRequest,
|
||||||
|
|
@ -204,16 +216,7 @@ class AccountProfileViewModel @UiThread constructor() : GenericViewModel() {
|
||||||
val defaultDomain = corePreferences.defaultDomain
|
val defaultDomain = corePreferences.defaultDomain
|
||||||
isOnDefaultDomain.postValue(domain == defaultDomain)
|
isOnDefaultDomain.postValue(domain == defaultDomain)
|
||||||
if (domain == defaultDomain) {
|
if (domain == defaultDomain) {
|
||||||
Log.i(
|
requestDevicesList(identityAddress)
|
||||||
"$TAG Request list of known devices for account [${identityAddress.asStringUriOnly()}]"
|
|
||||||
)
|
|
||||||
accountManagerServices = core.createAccountManagerServices()
|
|
||||||
accountManagerServices.language = Locale.getDefault().language // Returns en, fr, etc...
|
|
||||||
val request = accountManagerServices.createGetDevicesListRequest(
|
|
||||||
identityAddress
|
|
||||||
)
|
|
||||||
request.addListener(accountManagerServicesListener)
|
|
||||||
request.submit()
|
|
||||||
} else {
|
} else {
|
||||||
Log.i(
|
Log.i(
|
||||||
"$TAG Account with domain [$domain] can't get devices list, only works with [$defaultDomain] domain"
|
"$TAG Account with domain [$domain] can't get devices list, only works with [$defaultDomain] domain"
|
||||||
|
|
@ -385,4 +388,18 @@ class AccountProfileViewModel @UiThread constructor() : GenericViewModel() {
|
||||||
showDeviceId.value = true
|
showDeviceId.value = true
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
|
private fun requestDevicesList(identityAddress: Address) {
|
||||||
|
Log.i(
|
||||||
|
"$TAG Request devices list for identity address [${identityAddress.asStringUriOnly()}]"
|
||||||
|
)
|
||||||
|
accountManagerServices = coreContext.core.createAccountManagerServices()
|
||||||
|
accountManagerServices.language = Locale.getDefault().language // Returns en, fr, etc...
|
||||||
|
val request = accountManagerServices.createGetDevicesListRequest(
|
||||||
|
identityAddress
|
||||||
|
)
|
||||||
|
request.addListener(accountManagerServicesListener)
|
||||||
|
request.submit()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue