Implement View-Only mode

This commit is contained in:
Gaurav Ujjwal 2021-03-09 16:03:23 +05:30
parent 7cea09be4c
commit 79e899ecb1
4 changed files with 30 additions and 2 deletions

View file

@ -158,6 +158,7 @@ class VncViewModel(app: Application) : BaseViewModel(app), VncClient.Observer {
private fun launchConnection() {
viewModelScope.launch(Dispatchers.IO) {
client.viewOnlyMode = profile.viewOnly
try {
@ -305,7 +306,7 @@ class VncViewModel(app: Application) : BaseViewModel(app), VncClient.Observer {
val reason = client.getLastErrorStr()
if (reason.isNotBlank())
disconnectReason.postValue("( $reason )")
else if(profile.address.isBlank())
else if (profile.address.isBlank())
disconnectReason.postValue("( Invalid address )")
}
}

View file

@ -99,6 +99,10 @@ class VncClient(private val observer: Observer) {
*/
var isEncrypted = false; private set
/**
* In 'View-only' mode input to remote server is disabled
*/
var viewOnlyMode = false
/**
* Initializes VNC connection.
@ -217,7 +221,7 @@ class VncClient(private val observer: Observer) {
* events to remote server.
*/
private inline fun executeSend(block: () -> Unit) {
if (state == State.Connected)
if (state == State.Connected && !viewOnlyMode)
block()
}

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?colorOnSurface"
android:pathData="M12,4.5C7,4.5 2.73,7.61 1,12c1.73,4.39 6,7.5 11,7.5s9.27,-3.11 11,-7.5c-1.73,-4.39 -6,-7.5 -11,-7.5zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5zM12,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3z" />
</vector>

View file

@ -44,6 +44,7 @@
tools:text="192.168.1.1 | 5901" />
<ImageView
android:id="@+id/password_hint_icon"
android:layout_width="@dimen/server_card_hint_icon_size"
android:layout_height="@dimen/server_card_hint_icon_size"
android:layout_margin="@dimen/margin_normal"
@ -56,6 +57,19 @@
app:layout_constraintStart_toEndOf="@id/profile_address"
app:layout_constraintTop_toTopOf="@id/profile_address" />
<ImageView
android:layout_width="@dimen/server_card_hint_icon_size"
android:layout_height="@dimen/server_card_hint_icon_size"
android:layout_margin="@dimen/margin_normal"
android:importantForAccessibility="no"
android:src="@drawable/ic_visibility"
android:tint="?android:textColorSecondary"
android:tintMode="src_in"
app:isVisible="@{profile.viewOnly}"
app:layout_constraintBottom_toBottomOf="@id/profile_address"
app:layout_constraintStart_toEndOf="@id/password_hint_icon"
app:layout_constraintTop_toTopOf="@id/profile_address" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>