Skip to content

Commit

Permalink
Restore Repeater support
Browse files Browse the repository at this point in the history
  • Loading branch information
gujjwal00 committed Feb 18, 2024
1 parent 7e840ff commit 9417ccf
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
10 changes: 9 additions & 1 deletion app/src/main/java/com/gaurav/avnc/model/ServerProfile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,16 @@ data class ServerProfile(
*/
var useCount: Int = 0,

// These fields are not used, as repeater support has been removed
/**
* Whether UltraVNC Repeater is used for connections.
* When repeater is used, [host] & [port] identifies the repeater.
*/
var useRepeater: Boolean = false,

/**
* When using a repeater, this value identifies the VNC server.
* Valid IDs: [0, 999999999].
*/
var idOnRepeater: Int = 0,

/**
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/gaurav/avnc/ui/home/ProfileEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ class AdvancedProfileEditor : Fragment() {
private fun validate(): Boolean {
var result = validateNotEmpty(binding.host) and validateNotEmpty(binding.port)

if (binding.useRepeater.isChecked)
result = result and validateNotEmpty(binding.idOnRepeater)

if (binding.useSshTunnel.isChecked) {
result = result and
validateNotEmpty(binding.sshHost) and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class EditorViewModel(app: Application, state: SavedStateHandle, initialProfile:
* more complex handling, and live feedback in UI.
* For these, we have to use dedicated LiveData fields.
*/
val useRepeater = state.getLiveData("useRepeater", profile.useRepeater)
val idOnRepeater = state.getLiveData("idOnRepeater", if (profile.useRepeater) profile.idOnRepeater.toString() else "")
val useRawEncoding = state.getLiveData("useRawEncoding", profile.useRawEncoding)
val useSshTunnel = state.getLiveData("useSshTunnel", profile.channelType == ServerProfile.CHANNEL_SSH_TUNNEL)
val sshUsePassword = state.getLiveData("sshUsePassword", profile.sshAuthType == ServerProfile.SSH_AUTH_PASSWORD)
Expand All @@ -39,6 +41,8 @@ class EditorViewModel(app: Application, state: SavedStateHandle, initialProfile:


fun prepareProfileForSave(): ServerProfile {
profile.useRepeater = useRepeater.value ?: false
profile.idOnRepeater = idOnRepeater.value?.toIntOrNull() ?: 0
profile.useRawEncoding = useRawEncoding.value ?: false
profile.channelType = if (useSshTunnel.value == true) ServerProfile.CHANNEL_SSH_TUNNEL else ServerProfile.CHANNEL_TCP
profile.sshAuthType = if (sshUsePassword.value == true) ServerProfile.SSH_AUTH_PASSWORD else ServerProfile.SSH_AUTH_KEY
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/gaurav/avnc/viewmodel/VncViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ class VncViewModel(val profile: ServerProfile, app: Application) : BaseViewModel

client.configure(profile.viewOnly, profile.securityType, true /* Hardcoded to true */,
profile.imageQuality, profile.useRawEncoding)

if (profile.useRepeater)
client.setupRepeater(profile.idOnRepeater)
}

private fun connect() {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/fragment_profile_editor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
android:id="@+id/host"
style="@style/FormField.EditText"
android:layout_weight=".8"
android:drawableStart="@drawable/ic_computer"
android:hint="@string/hint_host"
android:drawableStart="@{profile.useRepeater ? @drawable/ic_swap : @drawable/ic_computer}"
android:hint="@{profile.useRepeater ? @string/hint_repeater_host : @string/hint_host}"
android:importantForAutofill="no"
android:inputType="textUri"
android:text="@={profile.host}" />
Expand Down
29 changes: 26 additions & 3 deletions app/src/main/res/layout/fragment_profile_editor_advanced.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
<EditText
android:id="@+id/host"
style="@style/FormField.EditText"
android:drawableStart="@drawable/ic_computer"
android:hint="@string/hint_host"
android:drawableStart="@{viewModel.useRepeater ? @drawable/ic_swap : @drawable/ic_computer}"
android:hint="@{viewModel.useRepeater ? @string/hint_repeater_host : @string/hint_host}"
android:importantForAutofill="no"
android:inputType="textUri"
android:text="@={viewModel.profile.host}"
Expand All @@ -109,6 +109,29 @@
app:layout_constraintTop_toTopOf="@id/host"
app:layout_constraintWidth_percent=".2" />

<!--Repeater-->
<CheckBox
android:id="@+id/use_repeater"
style="@style/FormField.CheckBox"
android:checked="@={viewModel.useRepeater}"
android:text="@string/title_use_repeater"
app:layout_constraintEnd_toStartOf="@id/id_on_repeater"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/host" />

<EditText
android:id="@+id/id_on_repeater"
style="@style/FormField.EditText"
android:hint="@string/hint_server_id"
android:importantForAutofill="no"
android:inputType="number"
android:minWidth="100dp"
android:text="@={viewModel.idOnRepeater}"
app:isVisible="@{viewModel.useRepeater}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/use_repeater"
app:layout_constraintTop_toBottomOf="@id/host" />


<!--View-only mode-->
<CheckBox
Expand All @@ -118,7 +141,7 @@
android:text="@string/title_view_only_mode"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/host" />
app:layout_constraintTop_toBottomOf="@id/use_repeater" />

<!--Key Compatibility mode-->
<CheckBox
Expand Down

0 comments on commit 9417ccf

Please sign in to comment.