Loading spinner
This commit is contained in:
parent
cdd345face
commit
a263246060
3 changed files with 60 additions and 18 deletions
|
@ -34,6 +34,8 @@ class ApiService {
|
||||||
val url = topicUrl(baseUrl, topic)
|
val url = topicUrl(baseUrl, topic)
|
||||||
Log.d(TAG, "Publishing to $url")
|
Log.d(TAG, "Publishing to $url")
|
||||||
|
|
||||||
|
// XXXXXXXXXXXx
|
||||||
|
|
||||||
var builder = Request.Builder()
|
var builder = Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.put(message.toRequestBody())
|
.put(message.toRequestBody())
|
||||||
|
|
|
@ -33,6 +33,7 @@ class AddFragment : DialogFragment() {
|
||||||
private lateinit var subscribeView: View
|
private lateinit var subscribeView: View
|
||||||
private lateinit var loginView: View
|
private lateinit var loginView: View
|
||||||
|
|
||||||
|
// Subscribe page
|
||||||
private lateinit var topicNameText: TextInputEditText
|
private lateinit var topicNameText: TextInputEditText
|
||||||
private lateinit var baseUrlLayout: TextInputLayout
|
private lateinit var baseUrlLayout: TextInputLayout
|
||||||
private lateinit var baseUrlText: AutoCompleteTextView
|
private lateinit var baseUrlText: AutoCompleteTextView
|
||||||
|
@ -43,11 +44,13 @@ class AddFragment : DialogFragment() {
|
||||||
private lateinit var instantDeliveryDescription: View
|
private lateinit var instantDeliveryDescription: View
|
||||||
private lateinit var subscribeButton: Button
|
private lateinit var subscribeButton: Button
|
||||||
|
|
||||||
|
// Login page
|
||||||
private lateinit var users: List<User>
|
private lateinit var users: List<User>
|
||||||
private lateinit var usersSpinner: Spinner
|
private lateinit var usersSpinner: Spinner
|
||||||
private var userSelected: User? = null
|
|
||||||
private lateinit var usernameText: TextInputEditText
|
private lateinit var usernameText: TextInputEditText
|
||||||
private lateinit var passwordText: TextInputEditText
|
private lateinit var passwordText: TextInputEditText
|
||||||
|
private lateinit var loginProgress: ProgressBar
|
||||||
|
private lateinit var loginError: TextView
|
||||||
|
|
||||||
private lateinit var baseUrls: List<String> // List of base URLs already used, excluding app_base_url
|
private lateinit var baseUrls: List<String> // List of base URLs already used, excluding app_base_url
|
||||||
|
|
||||||
|
@ -90,6 +93,8 @@ class AddFragment : DialogFragment() {
|
||||||
usersSpinner = view.findViewById(R.id.add_dialog_login_users_spinner)
|
usersSpinner = view.findViewById(R.id.add_dialog_login_users_spinner)
|
||||||
usernameText = view.findViewById(R.id.add_dialog_login_username)
|
usernameText = view.findViewById(R.id.add_dialog_login_username)
|
||||||
passwordText = view.findViewById(R.id.add_dialog_login_password)
|
passwordText = view.findViewById(R.id.add_dialog_login_password)
|
||||||
|
loginProgress = view.findViewById(R.id.add_dialog_login_progress)
|
||||||
|
loginError = view.findViewById(R.id.add_dialog_login_error)
|
||||||
|
|
||||||
// Set "Use another server" description based on flavor
|
// Set "Use another server" description based on flavor
|
||||||
useAnotherServerDescription.text = if (BuildConfig.FIREBASE_AVAILABLE) {
|
useAnotherServerDescription.text = if (BuildConfig.FIREBASE_AVAILABLE) {
|
||||||
|
@ -162,10 +167,8 @@ class AddFragment : DialogFragment() {
|
||||||
if (users.isEmpty()) {
|
if (users.isEmpty()) {
|
||||||
usersSpinner.visibility = View.GONE
|
usersSpinner.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
val spinnerEntries = users
|
val spinnerEntries = users.toMutableList()
|
||||||
//.map { it.username }
|
spinnerEntries.add(0, User(0, "Create new", "")) // FIXME
|
||||||
.toMutableList()
|
|
||||||
spinnerEntries.add(0, User(0, "Create new", ""))
|
|
||||||
usersSpinner.adapter = ArrayAdapter(requireActivity(), R.layout.fragment_add_dialog_dropdown_item, spinnerEntries)
|
usersSpinner.adapter = ArrayAdapter(requireActivity(), R.layout.fragment_add_dialog_dropdown_item, spinnerEntries)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,11 +180,9 @@ class AddFragment : DialogFragment() {
|
||||||
usersSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
usersSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||||
if (position == 0) {
|
if (position == 0) {
|
||||||
userSelected = null
|
|
||||||
usernameText.visibility = View.VISIBLE
|
usernameText.visibility = View.VISIBLE
|
||||||
passwordText.visibility = View.VISIBLE
|
passwordText.visibility = View.VISIBLE
|
||||||
} else {
|
} else {
|
||||||
userSelected = usersSpinner.selectedItem as User
|
|
||||||
usernameText.visibility = View.GONE
|
usernameText.visibility = View.GONE
|
||||||
passwordText.visibility = View.GONE
|
passwordText.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
@ -270,6 +271,8 @@ class AddFragment : DialogFragment() {
|
||||||
Log.w(TAG, "Anonymous access not allowed to topic ${topicUrl(baseUrl, topic)}, showing login dialog")
|
Log.w(TAG, "Anonymous access not allowed to topic ${topicUrl(baseUrl, topic)}, showing login dialog")
|
||||||
requireActivity().runOnUiThread {
|
requireActivity().runOnUiThread {
|
||||||
subscribeView.visibility = View.GONE
|
subscribeView.visibility = View.GONE
|
||||||
|
loginError.visibility = View.INVISIBLE
|
||||||
|
loginProgress.visibility = View.INVISIBLE
|
||||||
loginView.visibility = View.VISIBLE
|
loginView.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -277,6 +280,8 @@ class AddFragment : DialogFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkAuthAndMaybeDismiss(baseUrl: String, topic: String) {
|
private fun checkAuthAndMaybeDismiss(baseUrl: String, topic: String) {
|
||||||
|
loginProgress.visibility = View.VISIBLE
|
||||||
|
loginError.visibility = View.INVISIBLE
|
||||||
val existingUser = usersSpinner.selectedItem != null && usersSpinner.selectedItem is User && usersSpinner.selectedItemPosition > 0
|
val existingUser = usersSpinner.selectedItem != null && usersSpinner.selectedItem is User && usersSpinner.selectedItemPosition > 0
|
||||||
val user = if (existingUser) {
|
val user = if (existingUser) {
|
||||||
usersSpinner.selectedItem as User
|
usersSpinner.selectedItem as User
|
||||||
|
@ -299,7 +304,10 @@ class AddFragment : DialogFragment() {
|
||||||
dismiss(authUserId = user.id)
|
dismiss(authUserId = user.id)
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "Access not allowed for user ${user.username} to topic ${topicUrl(baseUrl, topic)}")
|
Log.w(TAG, "Access not allowed for user ${user.username} to topic ${topicUrl(baseUrl, topic)}")
|
||||||
// Show some error message
|
requireActivity().runOnUiThread {
|
||||||
|
loginProgress.visibility = View.GONE
|
||||||
|
loginError.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,38 +98,70 @@
|
||||||
android:paddingStart="4dp" android:paddingTop="0dp" android:layout_marginTop="-5dp"
|
android:paddingStart="4dp" android:paddingTop="0dp" android:layout_marginTop="-5dp"
|
||||||
android:visibility="gone"/>
|
android:visibility="gone"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
<LinearLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" android:id="@+id/add_dialog_login_view" tools:visibility="visible">
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:id="@+id/add_dialog_login_view"
|
||||||
|
>
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/add_dialog_login_title"
|
android:id="@+id/add_dialog_login_title"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingTop="16dp"
|
android:paddingTop="16dp"
|
||||||
android:paddingBottom="3dp"
|
android:paddingBottom="3dp"
|
||||||
android:text="Login required"
|
android:text="Login required"
|
||||||
android:textAlignment="viewStart"
|
android:textAlignment="viewStart"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Large" android:paddingStart="4dp"/>
|
android:textAppearance="@style/TextAppearance.AppCompat.Large" android:paddingStart="4dp"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintEnd_toStartOf="@id/add_dialog_login_progress"/>
|
||||||
<TextView
|
<TextView
|
||||||
android:text="This topic requires you to login. Please pick an existing user or type in a username and password."
|
android:text="This topic requires you to login. Please pick an existing user or type in a username and password."
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" android:id="@+id/add_dialog_login_description"
|
android:layout_height="wrap_content" android:id="@+id/add_dialog_login_description"
|
||||||
android:paddingStart="4dp" android:paddingTop="3dp"/>
|
android:paddingStart="4dp" android:paddingTop="3dp" app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/add_dialog_login_title"/>
|
||||||
<Spinner
|
<Spinner
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" android:id="@+id/add_dialog_login_users_spinner"/>
|
android:layout_height="wrap_content" android:id="@+id/add_dialog_login_users_spinner"
|
||||||
|
app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/add_dialog_login_description"/>
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
android:id="@+id/add_dialog_login_username"
|
android:id="@+id/add_dialog_login_username"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" android:hint="Username"
|
android:layout_height="wrap_content" android:hint="Username"
|
||||||
android:importantForAutofill="no"
|
android:importantForAutofill="no"
|
||||||
android:maxLines="1" android:inputType="text" android:maxLength="64"/>
|
android:maxLines="1" android:inputType="text" android:maxLength="64"
|
||||||
|
app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/add_dialog_login_users_spinner"/>
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
android:id="@+id/add_dialog_login_password"
|
android:id="@+id/add_dialog_login_password"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" android:hint="Password"
|
android:layout_height="wrap_content" android:hint="Password"
|
||||||
android:importantForAutofill="no"
|
android:importantForAutofill="no"
|
||||||
android:maxLines="1" android:inputType="textPassword"/>
|
android:maxLines="1" android:inputType="textPassword" app:layout_constraintStart_toStartOf="parent"
|
||||||
</LinearLayout>
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/add_dialog_login_username"/>
|
||||||
|
<TextView
|
||||||
|
android:text="Login failed"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content" android:id="@+id/add_dialog_login_error"
|
||||||
|
android:paddingStart="4dp" android:paddingTop="3dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/add_dialog_login_password"
|
||||||
|
app:layout_constraintStart_toStartOf="parent" android:visibility="invisible"/>
|
||||||
|
<ProgressBar
|
||||||
|
style="?android:attr/progressBarStyle"
|
||||||
|
android:layout_width="25dp"
|
||||||
|
android:layout_height="25dp"
|
||||||
|
android:id="@+id/add_dialog_login_progress"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/add_dialog_login_title"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/add_dialog_login_description" android:layout_marginTop="5dp"
|
||||||
|
android:indeterminate="true"/>
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
Loading…
Reference in a new issue