diff --git a/app/src/main/java/org/linphone/ui/main/model/AccountModel.kt b/app/src/main/java/org/linphone/ui/main/model/AccountModel.kt index aed57118b..bcb76b138 100644 --- a/app/src/main/java/org/linphone/ui/main/model/AccountModel.kt +++ b/app/src/main/java/org/linphone/ui/main/model/AccountModel.kt @@ -49,6 +49,8 @@ class AccountModel @WorkerThread constructor( val registrationState = MutableLiveData() + val registrationStateSummary = MutableLiveData() + val isConnected = MutableLiveData() val inError = MutableLiveData() @@ -155,6 +157,23 @@ class AccountModel @WorkerThread constructor( else -> "${account.state}" } + val summary = when (account.state) { + RegistrationState.None, RegistrationState.Cleared -> AppUtils.getString( + R.string.manage_account_status_cleared_summary + ) + RegistrationState.Refreshing, RegistrationState.Progress -> AppUtils.getString( + R.string.manage_account_status_progress_summary + ) + RegistrationState.Failed -> AppUtils.getString( + R.string.manage_account_status_failed_summary + ) + RegistrationState.Ok -> AppUtils.getString( + R.string.manage_account_status_connected_summary + ) + else -> "${account.state}" + } + registrationStateSummary.postValue(summary) + isConnected.postValue(account.state == RegistrationState.Ok) inError.postValue(account.state == RegistrationState.Failed) registrationState.postValue(state) diff --git a/app/src/main/java/org/linphone/ui/main/settings/fragment/AccountProfileFragment.kt b/app/src/main/java/org/linphone/ui/main/settings/fragment/AccountProfileFragment.kt index 3a0f7adbf..2a1ac9ab4 100644 --- a/app/src/main/java/org/linphone/ui/main/settings/fragment/AccountProfileFragment.kt +++ b/app/src/main/java/org/linphone/ui/main/settings/fragment/AccountProfileFragment.kt @@ -43,7 +43,7 @@ class AccountProfileFragment : GenericFragment() { if (localFileName != null) { Log.i("$TAG Picture will be locally stored as [$localFileName]") val path = FileUtils.getProperFilePath(localFileName) - viewModel.picturePath.postValue(path) + viewModel.setNewPicturePath(path) } else { Log.e("$TAG Failed to copy [$uri] to local storage") } diff --git a/app/src/main/java/org/linphone/ui/main/settings/viewmodel/AccountProfileViewModel.kt b/app/src/main/java/org/linphone/ui/main/settings/viewmodel/AccountProfileViewModel.kt index f11f8645c..c1e85af3e 100644 --- a/app/src/main/java/org/linphone/ui/main/settings/viewmodel/AccountProfileViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/settings/viewmodel/AccountProfileViewModel.kt @@ -4,8 +4,11 @@ import androidx.annotation.UiThread import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import org.linphone.LinphoneApplication.Companion.coreContext +import org.linphone.R import org.linphone.core.Account import org.linphone.core.tools.Log +import org.linphone.ui.main.model.AccountModel +import org.linphone.utils.AppUtils import org.linphone.utils.Event class AccountProfileViewModel @UiThread constructor() : ViewModel() { @@ -13,12 +16,16 @@ class AccountProfileViewModel @UiThread constructor() : ViewModel() { private const val TAG = "[Account Profile ViewModel]" } - val picturePath = MutableLiveData() + val accountModel = MutableLiveData() val sipAddress = MutableLiveData() val displayName = MutableLiveData() + val registerEnabled = MutableLiveData() + + val currentMode = MutableLiveData() + val internationalPrefix = MutableLiveData() val accountFoundEvent = MutableLiveData>() @@ -31,6 +38,15 @@ class AccountProfileViewModel @UiThread constructor() : ViewModel() { expandDetails.value = true } + @UiThread + override fun onCleared() { + super.onCleared() + + coreContext.postOnCoreThread { core -> + accountModel.value?.destroy() + } + } + @UiThread fun findAccountMatchingIdentity(identity: String) { coreContext.postOnCoreThread { core -> @@ -40,9 +56,14 @@ class AccountProfileViewModel @UiThread constructor() : ViewModel() { if (found != null) { Log.i("$TAG Found matching account [$found]") account = found + accountModel.postValue(AccountModel(account)) + currentMode.postValue( + "Mode ${AppUtils.getString(R.string.assistant_secure_mode_default_title)}" + ) // TODO FIXME + registerEnabled.postValue(account.params.isRegisterEnabled) + sipAddress.postValue(account.params.identityAddress?.asStringUriOnly()) displayName.postValue(account.params.identityAddress?.displayName) - picturePath.postValue(account.params.pictureUri) internationalPrefix.postValue(account.params.internationalPrefix) accountFoundEvent.postValue(Event(true)) @@ -52,6 +73,25 @@ class AccountProfileViewModel @UiThread constructor() : ViewModel() { } } + @UiThread + fun setNewPicturePath(path: String) { + coreContext.postOnCoreThread { + if (::account.isInitialized) { + val params = account.params + val copy = params.clone() + + if (path.isNotEmpty() && path != params.pictureUri) { + Log.i("$TAG New account profile picture [$path]") + copy.pictureUri = path + } + + accountModel.value?.avatar?.postValue(path) + account.params = copy + account.refreshRegister() + } + } + } + @UiThread fun saveChangesWhenLeaving() { coreContext.postOnCoreThread { @@ -61,12 +101,6 @@ class AccountProfileViewModel @UiThread constructor() : ViewModel() { copy.internationalPrefix = internationalPrefix.value.orEmpty() - val newPictureUri = picturePath.value.orEmpty().trim() - if (newPictureUri.isNotEmpty() && newPictureUri != params.pictureUri) { - Log.i("$TAG New account profile picture [$newPictureUri]") - copy.pictureUri = newPictureUri - } - val address = params.identityAddress?.clone() if (address != null) { val newValue = displayName.value.orEmpty().trim() @@ -89,4 +123,15 @@ class AccountProfileViewModel @UiThread constructor() : ViewModel() { fun toggleDetailsExpand() { expandDetails.value = expandDetails.value == false } + + @UiThread + fun toggleRegister() { + coreContext.postOnCoreThread { + val params = account.params + val copy = params.clone() + copy.isRegisterEnabled = !params.isRegisterEnabled + account.params = copy + registerEnabled.postValue(account.params.isRegisterEnabled) + } + } } diff --git a/app/src/main/res/drawable/cell_background.xml b/app/src/main/res/drawable/cell_background.xml deleted file mode 100644 index fbc9e3cc0..000000000 --- a/app/src/main/res/drawable/cell_background.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable/primary_cell_background.xml b/app/src/main/res/drawable/primary_cell_background.xml new file mode 100644 index 000000000..683a126e4 --- /dev/null +++ b/app/src/main/res/drawable/primary_cell_background.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/secondary_cell_background.xml b/app/src/main/res/drawable/secondary_cell_background.xml new file mode 100644 index 000000000..b0e3d17fd --- /dev/null +++ b/app/src/main/res/drawable/secondary_cell_background.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/account_profile_fragment.xml b/app/src/main/res/layout/account_profile_fragment.xml index 7c3592e82..7e6b182c0 100644 --- a/app/src/main/res/layout/account_profile_fragment.xml +++ b/app/src/main/res/layout/account_profile_fragment.xml @@ -25,365 +25,380 @@ type="org.linphone.ui.main.settings.viewmodel.AccountProfileViewModel" /> - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/call_list_cell.xml b/app/src/main/res/layout/call_list_cell.xml index c673157fa..0f54880a9 100644 --- a/app/src/main/res/layout/call_list_cell.xml +++ b/app/src/main/res/layout/call_list_cell.xml @@ -26,7 +26,7 @@ android:onLongClickListener="@{onLongClickListener}" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="@drawable/cell_background"> + android:background="@drawable/primary_cell_background"> diff --git a/app/src/main/res/layout/contact_device_trust_list_cell.xml b/app/src/main/res/layout/contact_device_trust_list_cell.xml index 08f0da561..0f1ad5131 100644 --- a/app/src/main/res/layout/contact_device_trust_list_cell.xml +++ b/app/src/main/res/layout/contact_device_trust_list_cell.xml @@ -16,7 +16,7 @@ android:layout_height="wrap_content" android:paddingTop="8dp" android:paddingBottom="8dp" - android:background="@drawable/cell_background"> + android:background="@drawable/secondary_cell_background"> + android:background="@drawable/primary_cell_background"> + app:layout_constraintStart_toStartOf="@id/actions_background" + app:layout_constraintEnd_toEndOf="@id/actions_background"/> + app:layout_constraintStart_toStartOf="@id/actions_background" + app:layout_constraintEnd_toEndOf="@id/actions_background"/> + app:layout_constraintStart_toStartOf="@id/actions_background" + app:layout_constraintEnd_toEndOf="@id/actions_background"/> + app:layout_constraintStart_toStartOf="@id/actions_background" + app:layout_constraintEnd_toEndOf="@id/actions_background"/> + android:background="@drawable/secondary_cell_background"> + android:background="@drawable/primary_cell_background"> Details Add a picture Edit picture + This account in online, everybody can call you. + Account has been disabled, you won\'t receive any call or message. + Account is connecting to the server, please wait… + Account connection failed, check your settings. Change mode International Prefix Account settings