mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-17 19:58:57 +03:00
Render current session.
This commit is contained in:
parent
d336d1921b
commit
042f24c749
5 changed files with 100 additions and 17 deletions
|
@ -24,7 +24,11 @@ import android.view.ViewGroup
|
|||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.isVisible
|
||||
import com.airbnb.mvrx.Async
|
||||
import com.airbnb.mvrx.Loading
|
||||
import com.airbnb.mvrx.Success
|
||||
import com.airbnb.mvrx.fragmentViewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.dialogs.ManuallyVerifyDialog
|
||||
|
@ -35,6 +39,7 @@ import im.vector.app.features.crypto.verification.VerificationBottomSheet
|
|||
import im.vector.app.features.settings.devices.DevicesAction
|
||||
import im.vector.app.features.settings.devices.DevicesViewEvents
|
||||
import im.vector.app.features.settings.devices.DevicesViewModel
|
||||
import im.vector.app.features.settings.devices.DevicesViewState
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
|
@ -117,4 +122,40 @@ class VectorSettingsDevicesFragment @Inject constructor() : VectorBaseFragment<F
|
|||
private fun cleanUpLearnMoreButtonsListeners() {
|
||||
views.deviceListHeaderSectionOther.onLearnMoreClickListener = null
|
||||
}
|
||||
|
||||
override fun invalidate() = withState(viewModel) { state ->
|
||||
val currentDeviceInfo = state.devices()
|
||||
?.firstOrNull {
|
||||
it.deviceInfo.deviceId == state.myDeviceId
|
||||
}
|
||||
|
||||
if (state.devices is Success && currentDeviceInfo != null) {
|
||||
renderCurrentDevice(state)
|
||||
} else {
|
||||
hideCurrentSessionView()
|
||||
}
|
||||
|
||||
handleRequestStatus(state.request)
|
||||
}
|
||||
|
||||
private fun hideCurrentSessionView() {
|
||||
views.deviceListHeaderSectionCurrent.isVisible = false
|
||||
views.deviceListCurrentSession.isVisible = false
|
||||
}
|
||||
|
||||
private fun renderCurrentDevice(state: DevicesViewState) {
|
||||
views.deviceListHeaderSectionCurrent.isVisible = true
|
||||
views.deviceListCurrentSession.isVisible = true
|
||||
views.deviceListCurrentSession.update(
|
||||
accountCrossSigningIsTrusted = state.accountCrossSigningIsTrusted,
|
||||
legacyMode = !state.hasAccountCrossSigning
|
||||
)
|
||||
}
|
||||
|
||||
private fun handleRequestStatus(unIgnoreRequest: Async<Unit>) {
|
||||
views.waitingView.root.isVisible = when (unIgnoreRequest) {
|
||||
is Loading -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,12 @@ package im.vector.app.features.settings.devices.v2.list
|
|||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.view.isVisible
|
||||
import im.vector.app.R
|
||||
import im.vector.app.databinding.ViewCurrentSessionBinding
|
||||
import im.vector.app.features.settings.devices.TrustUtils
|
||||
import org.matrix.android.sdk.api.session.crypto.crosssigning.DeviceTrustLevel
|
||||
|
||||
class CurrentSessionView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
@ -28,8 +31,41 @@ class CurrentSessionView @JvmOverloads constructor(
|
|||
defStyleAttr: Int = 0
|
||||
) : ConstraintLayout(context, attrs, defStyleAttr) {
|
||||
|
||||
private val binding = ViewCurrentSessionBinding.inflate(
|
||||
LayoutInflater.from(context),
|
||||
this
|
||||
)
|
||||
private val views: ViewCurrentSessionBinding
|
||||
|
||||
init {
|
||||
inflate(context, R.layout.view_current_session, this)
|
||||
views = ViewCurrentSessionBinding.bind(this)
|
||||
}
|
||||
|
||||
fun update(accountCrossSigningIsTrusted: Boolean, legacyMode: Boolean) {
|
||||
renderDeviceType()
|
||||
renderVerificationStatus(accountCrossSigningIsTrusted, legacyMode)
|
||||
}
|
||||
|
||||
private fun renderVerificationStatus(accountCrossSigningIsTrusted: Boolean, legacyMode: Boolean) {
|
||||
val deviceTrustLevel = DeviceTrustLevel(crossSigningVerified = accountCrossSigningIsTrusted, locallyVerified = true)
|
||||
val shield = TrustUtils.shieldForTrust(
|
||||
currentDevice = true,
|
||||
trustMSK = accountCrossSigningIsTrusted,
|
||||
legacyMode = legacyMode,
|
||||
deviceTrustLevel = deviceTrustLevel
|
||||
)
|
||||
views.currentSessionVerificationStatusImageView.render(shield)
|
||||
if (deviceTrustLevel.crossSigningVerified) {
|
||||
views.currentSessionVerificationStatusTextView.text = context.getString(R.string.device_manager_verification_status_verified)
|
||||
views.currentSessionVerificationStatusDetailTextView.text = context.getString(R.string.device_manager_verification_status_detail_verified)
|
||||
views.currentSessionVerifySessionButton.isVisible = false
|
||||
} else {
|
||||
views.currentSessionVerificationStatusTextView.text = context.getString(R.string.device_manager_verification_status_unverified)
|
||||
views.currentSessionVerificationStatusDetailTextView.text = context.getString(R.string.device_manager_verification_status_detail_unverified)
|
||||
views.currentSessionVerifySessionButton.isVisible = true
|
||||
}
|
||||
}
|
||||
|
||||
// TODO. We don't have this info yet. Update later accordingly.
|
||||
private fun renderDeviceType() {
|
||||
views.currentSessionDeviceTypeImageView.setImageResource(R.drawable.ic_device_type_mobile)
|
||||
views.currentSessionDeviceTypeTextView.text = context.getString(R.string.device_manager_device_type_android)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.util.AttributeSet
|
|||
import android.view.LayoutInflater
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.content.res.use
|
||||
import androidx.core.view.isVisible
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.extensions.setTextWithColoredPart
|
||||
import im.vector.app.databinding.ViewDevicesListHeaderBinding
|
||||
|
@ -58,12 +59,18 @@ class DevicesListHeaderView @JvmOverloads constructor(
|
|||
|
||||
private fun setDescription(typedArray: TypedArray) {
|
||||
val description = typedArray.getString(R.styleable.DevicesListHeaderView_devicesListHeaderDescription)
|
||||
if (description.isNullOrEmpty()) {
|
||||
binding.devicesListHeaderDescription.isVisible = false
|
||||
return
|
||||
}
|
||||
|
||||
val learnMore = context.getString(R.string.action_learn_more)
|
||||
val stringBuilder = StringBuilder()
|
||||
stringBuilder.append(description)
|
||||
stringBuilder.append(" ")
|
||||
stringBuilder.append(learnMore)
|
||||
|
||||
binding.devicesListHeaderDescription.isVisible = true
|
||||
binding.devicesListHeaderDescription.setTextWithColoredPart(
|
||||
fullText = stringBuilder.toString(),
|
||||
coloredPart = learnMore,
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
android:id="@+id/deviceListCurrentSession"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginVertical="24dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:layout_marginVertical="24dp"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/deviceListHeaderSectionCurrent" />
|
||||
|
||||
<im.vector.app.features.settings.devices.v2.list.DevicesListHeaderView
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_current_session"
|
||||
android:paddingBottom="24dp"
|
||||
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
|
||||
android:paddingBottom="16dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/currentSessionDeviceTypeImageView"
|
||||
|
@ -43,7 +42,7 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/currentSessionDeviceTypeTextView">
|
||||
|
||||
<ImageView
|
||||
<im.vector.app.core.ui.views.ShieldImageView
|
||||
android:id="@+id/currentSessionVerificationStatusImageView"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
|
@ -79,10 +78,10 @@
|
|||
android:layout_height="52dp"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/device_manager_verify_session"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/currentSessionVerificationStatusDetailTextView"
|
||||
tools:text="@string/device_manager_verify_session" />
|
||||
app:layout_constraintTop_toBottomOf="@id/currentSessionVerificationStatusDetailTextView" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/currentSessionViewDetailsButton"
|
||||
|
@ -90,10 +89,10 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="@string/device_manager_view_details"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/currentSessionVerifySessionButton"
|
||||
tools:text="@string/device_manager_view_details" />
|
||||
app:layout_constraintTop_toBottomOf="@id/currentSessionVerifySessionButton" />
|
||||
|
||||
</merge>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
Loading…
Add table
Reference in a new issue