diff --git a/app/src/main/java/com/gaurav/avnc/Architecture.kt b/app/src/main/java/com/gaurav/avnc/Architecture.kt index 61983f0..f94ec9b 100644 --- a/app/src/main/java/com/gaurav/avnc/Architecture.kt +++ b/app/src/main/java/com/gaurav/avnc/Architecture.kt @@ -95,7 +95,7 @@ import com.gaurav.avnc.vnc.VncClient * - Connection to VNC server is managed by [VncViewModel], using [VncClient]. * - [VncClient] is a wrapper around native `rfbClient` from LibVNCClient. * - * - [CredentialFragment] is used to ask username & password from user. + * - [LoginFragment] is used to ask username & password from user. * - [SshTunnel] is used to create a SSH tunnel, which can be used for connection. * - [HostKeyFragment] is used to verify unknown SSH hosts. * - diff --git a/app/src/main/java/com/gaurav/avnc/model/db/ServerProfileDao.kt b/app/src/main/java/com/gaurav/avnc/model/db/ServerProfileDao.kt index 3196f7d..3255eb9 100644 --- a/app/src/main/java/com/gaurav/avnc/model/db/ServerProfileDao.kt +++ b/app/src/main/java/com/gaurav/avnc/model/db/ServerProfileDao.kt @@ -10,7 +10,6 @@ package com.gaurav.avnc.model.db import androidx.lifecycle.LiveData import androidx.room.* -import com.gaurav.avnc.model.LoginInfo import com.gaurav.avnc.model.ServerProfile @Dao @@ -32,9 +31,6 @@ interface ServerProfileDao { @Query("SELECT * FROM profiles WHERE name = :name") suspend fun getByName(name: String): List - @Query("SELECT name, host, username, password FROM profiles") - fun getCredentials(): LiveData> - @Insert suspend fun insert(profile: ServerProfile): Long diff --git a/app/src/main/java/com/gaurav/avnc/ui/vnc/CredentialFragment.kt b/app/src/main/java/com/gaurav/avnc/ui/vnc/LoginFragment.kt similarity index 93% rename from app/src/main/java/com/gaurav/avnc/ui/vnc/CredentialFragment.kt rename to app/src/main/java/com/gaurav/avnc/ui/vnc/LoginFragment.kt index 3b61c60..d282906 100644 --- a/app/src/main/java/com/gaurav/avnc/ui/vnc/CredentialFragment.kt +++ b/app/src/main/java/com/gaurav/avnc/ui/vnc/LoginFragment.kt @@ -25,7 +25,7 @@ import com.google.android.material.textfield.TextInputLayout /** * Allows user to enter credentials for remote server. */ -class CredentialFragment : DialogFragment() { +class LoginFragment : DialogFragment() { val viewModel by activityViewModels() lateinit var binding: FragmentCredentialBinding @@ -100,9 +100,10 @@ class CredentialFragment : DialogFragment() { if (viewModel.pref.server.lockSavedServer) return - viewModel.knownCredentials.observe(this) { list -> - val usernames = list.map { it.username }.filter { it.isNotEmpty() }.distinct() - val passwords = preparePasswordSuggestions(list) + viewModel.savedProfiles.observe(this) { profiles -> + val logins = profiles.map { LoginInfo(it.name, it.host, it.username, it.password) } + val usernames = logins.map { it.username }.filter { it.isNotEmpty() }.distinct() + val passwords = preparePasswordSuggestions(logins) if (usernames.isNotEmpty()) { val usernameAdapter = ArrayAdapter(requireContext(), android.R.layout.simple_list_item_1, usernames) diff --git a/app/src/main/java/com/gaurav/avnc/ui/vnc/VncActivity.kt b/app/src/main/java/com/gaurav/avnc/ui/vnc/VncActivity.kt index d3a26bd..da6ac72 100644 --- a/app/src/main/java/com/gaurav/avnc/ui/vnc/VncActivity.kt +++ b/app/src/main/java/com/gaurav/avnc/ui/vnc/VncActivity.kt @@ -113,7 +113,7 @@ class VncActivity : AppCompatActivity() { binding.reconnectBtn.setOnClickListener { retryConnection() } //Observers - viewModel.credentialRequest.observe(this) { showCredentialDialog() } + viewModel.credentialRequest.observe(this) { showLoginDialog() } viewModel.sshHostKeyVerifyRequest.observe(this) { showHostKeyDialog() } viewModel.state.observe(this) { onClientStateChanged(it) } } @@ -191,8 +191,8 @@ class VncActivity : AppCompatActivity() { } } - private fun showCredentialDialog() { - CredentialFragment().show(supportFragmentManager, "CredentialDialog") + private fun showLoginDialog() { + LoginFragment().show(supportFragmentManager, "LoginDialog") } private fun showHostKeyDialog() { diff --git a/app/src/main/java/com/gaurav/avnc/viewmodel/VncViewModel.kt b/app/src/main/java/com/gaurav/avnc/viewmodel/VncViewModel.kt index 18599ce..08c6192 100644 --- a/app/src/main/java/com/gaurav/avnc/viewmodel/VncViewModel.kt +++ b/app/src/main/java/com/gaurav/avnc/viewmodel/VncViewModel.kt @@ -116,10 +116,10 @@ class VncViewModel(val profile: ServerProfile, app: Application) : BaseViewModel val serverUnlockRequest = LiveRequest(false, viewModelScope) /** - * List of known credentials. Used for providing suggestion when - * new credentials are required. + * List of saved profiles. + * Used by login-autocompletion. */ - val knownCredentials by lazy { serverProfileDao.getCredentials() } + val savedProfiles by lazy { serverProfileDao.getLiveList() } /** * Holds a weak reference to [FrameView] instance.