Add keyboard actions for pi-hole auth screen and progress bars
This commit is contained in:
parent
738d2cc81d
commit
a5fd369f9a
6 changed files with 133 additions and 98 deletions
|
@ -95,7 +95,7 @@ class AddPiHelperViewModel(
|
|||
} catch (ignored: SocketTimeoutException) {
|
||||
null
|
||||
} catch (e: Exception) {
|
||||
Log.e("Pi-Helper", "Failed to load Pi-Hole version at $ipAddress", e)
|
||||
Log.e("Pi-helper", "Failed to load Pi-Hole version at $ipAddress", e)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ class AddPiHelperViewModel(
|
|||
this.apiKey = apiKey
|
||||
authenticated.postValue(true)
|
||||
} catch (e: Exception) {
|
||||
Log.e("Pi-Helper", "Unable to authenticate with API key", e)
|
||||
Log.e("Pi-helper", "Unable to authenticate with API key", e)
|
||||
authenticated.postValue(false)
|
||||
throw e
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ class MainFragment : Fragment(), CoroutineScope {
|
|||
try {
|
||||
viewModel.enablePiHole()
|
||||
} catch (ignored: Exception) {
|
||||
Log.e("Pi-Helper", "Failed to enable Pi-Hole", ignored)
|
||||
Log.e("Pi-helper", "Failed to enable Pi-Hole", ignored)
|
||||
}
|
||||
}
|
||||
disable10SecondsButton?.setSuspendingOnClickListener(this) {
|
||||
|
@ -102,7 +102,7 @@ class MainFragment : Fragment(), CoroutineScope {
|
|||
try {
|
||||
viewModel.disablePiHole(10)
|
||||
} catch (ignored: Exception) {
|
||||
Log.e("Pi-Helper", "Failed to disable Pi-Hole", ignored)
|
||||
Log.e("Pi-helper", "Failed to disable Pi-Hole", ignored)
|
||||
}
|
||||
}
|
||||
disable30SecondsButton?.setSuspendingOnClickListener(this) {
|
||||
|
@ -110,7 +110,7 @@ class MainFragment : Fragment(), CoroutineScope {
|
|||
try {
|
||||
viewModel.disablePiHole(30)
|
||||
} catch (ignored: Exception) {
|
||||
Log.e("Pi-Helper", "Failed to disable Pi-Hole", ignored)
|
||||
Log.e("Pi-helper", "Failed to disable Pi-Hole", ignored)
|
||||
}
|
||||
}
|
||||
disable5MinutesButton?.setSuspendingOnClickListener(this) {
|
||||
|
@ -118,7 +118,7 @@ class MainFragment : Fragment(), CoroutineScope {
|
|||
try {
|
||||
viewModel.disablePiHole(300)
|
||||
} catch (ignored: Exception) {
|
||||
Log.e("Pi-Helper", "Failed to disable Pi-Hole", ignored)
|
||||
Log.e("Pi-helper", "Failed to disable Pi-Hole", ignored)
|
||||
}
|
||||
}
|
||||
disableCustomTimeButton?.setOnClickListener {
|
||||
|
@ -159,7 +159,7 @@ class MainFragment : Fragment(), CoroutineScope {
|
|||
try {
|
||||
viewModel.disablePiHole()
|
||||
} catch (ignored: Exception) {
|
||||
Log.e("Pi-Helper", "Failed to disable Pi-Hole", ignored)
|
||||
Log.e("Pi-helper", "Failed to disable Pi-Hole", ignored)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,6 @@ import androidx.transition.TransitionInflater
|
|||
import kotlinx.android.synthetic.main.fragment_retrieve_api_key.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koin.android.ext.android.inject
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
|
@ -38,32 +36,42 @@ class RetrieveApiKeyFragment : Fragment(), CoroutineScope {
|
|||
): View? = inflater.inflate(R.layout.fragment_retrieve_api_key, container, false)
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
connectWithPasswordButton.setOnClickListener {
|
||||
launch {
|
||||
try {
|
||||
viewModel.authenticateWithPassword(password.text.toString())
|
||||
} catch (ignored: Exception) {
|
||||
Log.e("Pi-Helper", "Failed to authenticate with password", ignored)
|
||||
password.error = "Failed to authenticate with given password. Please verify " +
|
||||
"you've entered it correctly and try again."
|
||||
}
|
||||
password.setOnEditorActionListener { _, _, _ ->
|
||||
connectWithPasswordButton.performClick()
|
||||
}
|
||||
connectWithPasswordButton.setSuspendingOnClickListener(this) {
|
||||
showProgress(true)
|
||||
try {
|
||||
viewModel.authenticateWithPassword(password.text.toString())
|
||||
} catch (ignored: Exception) {
|
||||
Log.e("Pi-helper", "Failed to authenticate with password", ignored)
|
||||
password.error = "Failed to authenticate with given password. Please verify " +
|
||||
"you've entered it correctly and try again."
|
||||
showProgress(false)
|
||||
}
|
||||
}
|
||||
apiKey.setOnEditorActionListener { _, _, _ ->
|
||||
connectWithApiKeyButton.performClick()
|
||||
}
|
||||
connectWithApiKeyButton.setSuspendingOnClickListener(this) {
|
||||
showProgress(true)
|
||||
try {
|
||||
viewModel.authenticateWithApiKey(apiKey.text.toString())
|
||||
} catch (ignored: Exception) {
|
||||
apiKey.error = "Failed to authenticate with given API key. Please verify " +
|
||||
"you've entered it correctly and try again."
|
||||
showProgress(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
connectWithApiKeyButton.setOnClickListener {
|
||||
launch {
|
||||
try {
|
||||
viewModel.authenticateWithApiKey(apiKey.text.toString())
|
||||
} catch (ignored: Exception) {
|
||||
apiKey.error = "Failed to authenticate with given API key. Please verify " +
|
||||
"you've entered it correctly and try again."
|
||||
}
|
||||
}
|
||||
}
|
||||
private fun showProgress(show: Boolean) {
|
||||
progressBar.visibility = if (show) View.VISIBLE else View.GONE
|
||||
authenticationForm.visibility = if (show) View.GONE else View.VISIBLE
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
coroutineContext[Job]?.cancel()
|
||||
cancel()
|
||||
super.onDestroyView()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,10 @@ import androidx.navigation.fragment.findNavController
|
|||
import androidx.transition.Transition
|
||||
import androidx.transition.TransitionInflater
|
||||
import kotlinx.android.synthetic.main.fragment_scan_network.*
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koin.android.ext.android.inject
|
||||
import java.net.Inet4Address
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
@ -109,7 +112,7 @@ class ScanNetworkFragment : Fragment(), CoroutineScope {
|
|||
?.filter { !it.address.isLoopbackAddress && it.address is Inet4Address }
|
||||
?.forEach { address ->
|
||||
Log.d(
|
||||
"Pi-Helper",
|
||||
"Pi-helper",
|
||||
"Found link address: ${address.address.hostName}"
|
||||
)
|
||||
viewModel.beginScanning(address.address.hostAddress)
|
||||
|
|
|
@ -1,82 +1,106 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView 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="match_parent"
|
||||
android:animateLayoutChanges="true"
|
||||
android:fillViewport="true"
|
||||
tools:background="@color/colorSurface"
|
||||
tools:context=".RetrieveApiKeyFragment">
|
||||
|
||||
<LinearLayout
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
android:layout_gravity="center">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/piHelperLogo"
|
||||
<LinearLayout
|
||||
android:id="@+id/authenticationForm"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/piHelperLogo"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:contentDescription="@string/accessibility_description_pi_helper_logo"
|
||||
android:src="@drawable/ic_app_logo"
|
||||
android:tint="@color/colorOnSurface"
|
||||
android:transitionName="piHelperLogo" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/info_connection_success"
|
||||
android:textAlignment="center" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="32dp"
|
||||
android:text="@string/info_authentication_required"
|
||||
android:textAlignment="center" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/prompt_password">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:imeOptions="actionGo"
|
||||
android:inputType="textPassword" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/connectWithPasswordButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/action_authenticate_password" />
|
||||
|
||||
<include layout="@layout/or_divider" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/prompt_api_key">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/apiKey"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:imeOptions="actionGo"
|
||||
android:inputType="textPassword" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/connectWithApiKeyButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/action_authenticate_api_key" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:contentDescription="@string/accessibility_description_pi_helper_logo"
|
||||
android:src="@drawable/ic_app_logo"
|
||||
android:tint="@color/colorOnSurface"
|
||||
android:transitionName="piHelperLogo" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/info_connection_success"
|
||||
android:textAlignment="center" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="32dp"
|
||||
android:text="@string/info_authentication_required"
|
||||
android:textAlignment="center" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/prompt_password">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/connectWithPasswordButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/action_authenticate_password" />
|
||||
|
||||
<include layout="@layout/or_divider" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/prompt_api_key">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/apiKey"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/connectWithApiKeyButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/action_authenticate_api_key" />
|
||||
|
||||
</LinearLayout>
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</ScrollView>
|
|
@ -1,2 +1,2 @@
|
|||
include ':app', ':piholeclient'
|
||||
rootProject.name='Pi-Helper'
|
||||
rootProject.name='Pi-helper'
|
||||
|
|
Loading…
Reference in a new issue