mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Improved account mode fragment
This commit is contained in:
parent
8858deb42f
commit
ae1e2599a8
7 changed files with 86 additions and 39 deletions
|
|
@ -145,7 +145,7 @@ class AccountProfileFragment : GenericFragment() {
|
|||
viewModel.accountRemovedEvent.observe(viewLifecycleOwner) {
|
||||
it.consume {
|
||||
Log.i("$TAG Account has been removed, leaving profile")
|
||||
findNavController().popBackStack()
|
||||
goBack()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,19 +24,26 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.navGraphViewModels
|
||||
import org.linphone.R
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.databinding.AccountProfileSecureModeFragmentBinding
|
||||
import org.linphone.ui.main.fragment.GenericFragment
|
||||
import org.linphone.ui.main.settings.viewmodel.AccountProfileViewModel
|
||||
import org.linphone.utils.DialogUtils
|
||||
|
||||
@UiThread
|
||||
class AccountProfileModeFragment : Fragment() {
|
||||
class AccountProfileModeFragment : GenericFragment() {
|
||||
companion object {
|
||||
private const val TAG = "[Account Profile Mode Fragment]"
|
||||
}
|
||||
|
||||
private lateinit var binding: AccountProfileSecureModeFragmentBinding
|
||||
|
||||
private val viewModel: AccountProfileViewModel by navGraphViewModels(
|
||||
R.id.main_nav_graph
|
||||
)
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
|
|
@ -50,13 +57,17 @@ class AccountProfileModeFragment : Fragment() {
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding.lifecycleOwner = viewLifecycleOwner
|
||||
binding.viewModel = viewModel
|
||||
|
||||
binding.setBackClickListener {
|
||||
findNavController().popBackStack()
|
||||
Log.i("$TAG Leaving without saving changes...")
|
||||
goBack()
|
||||
}
|
||||
|
||||
binding.setContinueClickListener {
|
||||
findNavController().popBackStack()
|
||||
Log.i("$TAG Applying changes and leaving...")
|
||||
viewModel.applySelectedMode()
|
||||
goBack()
|
||||
}
|
||||
|
||||
binding.setDefaultModeTooltipClickListener {
|
||||
|
|
|
|||
|
|
@ -4,14 +4,13 @@ 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.DialPlan
|
||||
import org.linphone.core.Factory
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.ui.main.model.AccountModel
|
||||
import org.linphone.ui.main.model.isInSecureMode
|
||||
import org.linphone.ui.main.settings.model.AccountDeviceModel
|
||||
import org.linphone.utils.AppUtils
|
||||
import org.linphone.utils.Event
|
||||
|
||||
class AccountProfileViewModel @UiThread constructor() : ViewModel() {
|
||||
|
|
@ -33,7 +32,7 @@ class AccountProfileViewModel @UiThread constructor() : ViewModel() {
|
|||
|
||||
val registerEnabled = MutableLiveData<Boolean>()
|
||||
|
||||
val currentMode = MutableLiveData<String>()
|
||||
val isCurrentlySelectedModeSecure = MutableLiveData<Boolean>()
|
||||
|
||||
val devices = MutableLiveData<ArrayList<AccountDeviceModel>>()
|
||||
|
||||
|
|
@ -83,9 +82,7 @@ class AccountProfileViewModel @UiThread constructor() : ViewModel() {
|
|||
Log.i("$TAG Found matching account [$found]")
|
||||
account = found
|
||||
accountModel.postValue(AccountModel(account))
|
||||
currentMode.postValue(
|
||||
AppUtils.getString(R.string.manage_account_secure_mode_default_title)
|
||||
) // TODO: use real API when available
|
||||
isCurrentlySelectedModeSecure.postValue(account.isInSecureMode())
|
||||
registerEnabled.postValue(account.params.isRegisterEnabled)
|
||||
|
||||
sipAddress.postValue(account.params.identityAddress?.asStringUriOnly())
|
||||
|
|
@ -241,4 +238,19 @@ class AccountProfileViewModel @UiThread constructor() : ViewModel() {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun switchToSecureMode() {
|
||||
isCurrentlySelectedModeSecure.value = true
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun switchToInteropMode() {
|
||||
isCurrentlySelectedModeSecure.value = false
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun applySelectedMode() {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -227,6 +227,15 @@ fun ShapeableImageView.loadAvatarWithCoil(model: AbstractAvatarModel?) {
|
|||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
@BindingAdapter("coilAvatarNoTrust")
|
||||
fun ShapeableImageView.loadAvatarWithCoilWithoutTrust(model: AbstractAvatarModel?) {
|
||||
val imageView = this
|
||||
(context as AppCompatActivity).lifecycleScope.launch {
|
||||
loadContactPictureWithCoil(imageView, model, skipTrust = true)
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
@BindingAdapter("coilBubbleAvatar")
|
||||
fun ShapeableImageView.loadBubbleAvatarWithCoil(model: AbstractAvatarModel?) {
|
||||
|
|
@ -279,31 +288,36 @@ private suspend fun loadContactPictureWithCoil(
|
|||
imageView: ShapeableImageView,
|
||||
model: AbstractAvatarModel?,
|
||||
@DimenRes size: Int = 0,
|
||||
@DimenRes textSize: Int = 0
|
||||
@DimenRes textSize: Int = 0,
|
||||
skipTrust: Boolean = false
|
||||
) {
|
||||
withContext(Dispatchers.IO) {
|
||||
imageView.dispose()
|
||||
|
||||
val context = imageView.context
|
||||
if (model != null) {
|
||||
if (model.showTrust.value == true) {
|
||||
when (model.trust.value) {
|
||||
ChatRoom.SecurityLevel.Safe -> {
|
||||
imageView.setStrokeColorResource(R.color.blue_info_500)
|
||||
imageView.setStrokeWidthResource(R.dimen.avatar_trust_border_width)
|
||||
}
|
||||
ChatRoom.SecurityLevel.Unsafe -> {
|
||||
imageView.setStrokeColorResource(R.color.red_danger_500)
|
||||
imageView.setStrokeWidthResource(R.dimen.avatar_trust_border_width)
|
||||
}
|
||||
else -> {
|
||||
imageView.setStrokeColorResource(R.color.transparent_color)
|
||||
imageView.setStrokeWidthResource(R.dimen.zero)
|
||||
if (!skipTrust) {
|
||||
if (model.showTrust.value == true) {
|
||||
when (model.trust.value) {
|
||||
ChatRoom.SecurityLevel.Safe -> {
|
||||
imageView.setStrokeColorResource(R.color.blue_info_500)
|
||||
imageView.setStrokeWidthResource(R.dimen.avatar_trust_border_width)
|
||||
}
|
||||
|
||||
ChatRoom.SecurityLevel.Unsafe -> {
|
||||
imageView.setStrokeColorResource(R.color.red_danger_500)
|
||||
imageView.setStrokeWidthResource(R.dimen.avatar_trust_border_width)
|
||||
}
|
||||
|
||||
else -> {
|
||||
imageView.setStrokeColorResource(R.color.transparent_color)
|
||||
imageView.setStrokeWidthResource(R.dimen.zero)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
imageView.setStrokeColorResource(R.color.transparent_color)
|
||||
imageView.setStrokeWidthResource(R.dimen.zero)
|
||||
}
|
||||
} else {
|
||||
imageView.setStrokeColorResource(R.color.transparent_color)
|
||||
imageView.setStrokeWidthResource(R.dimen.zero)
|
||||
}
|
||||
|
||||
val images = model.images.value.orEmpty()
|
||||
|
|
|
|||
|
|
@ -397,7 +397,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:text="@{viewModel.currentMode, default=@string/manage_account_secure_mode_default_title}"
|
||||
android:text="@{viewModel.isCurrentlySelectedModeSecure ? @string/manage_account_secure_mode_default_title : @string/manage_account_secure_mode_interoperable_title, default=@string/manage_account_secure_mode_default_title}"
|
||||
app:layout_constraintTop_toTopOf="@id/mode_background"
|
||||
app:layout_constraintStart_toStartOf="@id/mode_background"
|
||||
app:layout_constraintBottom_toBottomOf="@id/mode_background"/>
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@
|
|||
<variable
|
||||
name="continueClickListener"
|
||||
type="View.OnClickListener" />
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="org.linphone.ui.main.settings.viewmodel.AccountProfileViewModel" />
|
||||
</data>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
|
@ -65,15 +68,17 @@
|
|||
android:layout_marginTop="16dp">
|
||||
|
||||
<com.google.android.material.radiobutton.MaterialRadioButton
|
||||
android:id="@+id/default_mode"
|
||||
style="@style/default_text_style_800"
|
||||
android:id="@+id/default_mode"
|
||||
android:onClick="@{() -> viewModel.switchToSecureMode()}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:text="@string/assistant_secure_mode_default_title"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/black"
|
||||
android:checked="true"
|
||||
android:checked="@{viewModel.isCurrentlySelectedModeSecure}"
|
||||
android:enabled="@{!viewModel.isCurrentlySelectedModeSecure}"
|
||||
app:useMaterialThemeColors="false"
|
||||
app:buttonTint="@color/orange_main_500"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
|
|
@ -118,7 +123,9 @@
|
|||
android:layout_height="@dimen/avatar_list_cell_size"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginTop="20dp"
|
||||
coilInitials="@{`JD`}"
|
||||
coilAvatarNoTrust="@{viewModel.accountModel}"
|
||||
app:strokeWidth="0dp"
|
||||
app:strokeColor="@color/transparent_color"
|
||||
app:layout_constraintHorizontal_chainStyle="packed"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/arrow"
|
||||
|
|
@ -152,7 +159,7 @@
|
|||
android:id="@+id/image2"
|
||||
android:layout_width="@dimen/avatar_list_cell_size"
|
||||
android:layout_height="@dimen/avatar_list_cell_size"
|
||||
coilInitials="@{`JD`}"
|
||||
coilAvatarNoTrust="@{viewModel.accountModel}"
|
||||
app:strokeWidth="@dimen/avatar_trust_border_width"
|
||||
app:strokeColor="@color/blue_info_500"
|
||||
app:layout_constraintStart_toEndOf="@id/arrow"
|
||||
|
|
@ -180,8 +187,9 @@
|
|||
app:layout_constraintBottom_toBottomOf="@id/image2"/>
|
||||
|
||||
<com.google.android.material.radiobutton.MaterialRadioButton
|
||||
android:id="@+id/interop_mode"
|
||||
style="@style/default_text_style_800"
|
||||
android:id="@+id/interop_mode"
|
||||
android:onClick="@{() -> viewModel.switchToInteropMode()}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="32dp"
|
||||
|
|
@ -189,6 +197,8 @@
|
|||
android:text="@string/assistant_secure_mode_interoperable_title"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/black"
|
||||
android:checked="@{!viewModel.isCurrentlySelectedModeSecure}"
|
||||
android:enabled="@{viewModel.isCurrentlySelectedModeSecure}"
|
||||
app:useMaterialThemeColors="false"
|
||||
app:buttonTint="@color/orange_main_500"
|
||||
app:layout_constraintTop_toBottomOf="@id/image1"
|
||||
|
|
@ -238,7 +248,7 @@
|
|||
android:layout_marginEnd="16dp"
|
||||
android:paddingStart="20dp"
|
||||
android:paddingEnd="20dp"
|
||||
android:text="@string/manage_account_choose_mode_save_changes"
|
||||
android:text="@string/manage_account_choose_mode_apply_label"
|
||||
app:layout_constraintWidth_max="@dimen/button_max_width"
|
||||
app:layout_constraintVertical_bias="1"
|
||||
app:layout_constraintTop_toBottomOf="@id/interop_mode_summary"
|
||||
|
|
|
|||
|
|
@ -242,11 +242,11 @@
|
|||
<string name="manage_account_settings">Account settings</string>
|
||||
<string name="manage_account_delete">Delete account</string>
|
||||
<string name="manage_account_choose_mode_title">Choose account mode</string>
|
||||
<string name="manage_account_choose_mode_save_changes">Apply</string>
|
||||
<string name="manage_account_choose_mode_apply_label">Apply</string>
|
||||
<string name="manage_account_secure_mode_default_title">Default mode</string>
|
||||
<string name="manage_account_secure_mode_interoperable_title">Interoperable mode</string>
|
||||
<string name="manage_account_secure_mode_default_summary">Blah</string> <!-- TODO -->
|
||||
<string name="manage_account_secure_mode_interoperable_summary">Blah</string> <!-- TODO -->
|
||||
<string name="manage_account_secure_mode_default_summary">End-to-end encryption of your communications</string>
|
||||
<string name="manage_account_secure_mode_interoperable_summary">Allows to communicate with other SIP services, point to point encryption</string>
|
||||
<string name="manage_account_device_remove">Remove</string>
|
||||
<string name="manage_account_device_last_connection">Last connection:</string>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue