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)
|
||||
Log.d(TAG, "Publishing to $url")
|
||||
|
||||
// XXXXXXXXXXXx
|
||||
|
||||
var builder = Request.Builder()
|
||||
.url(url)
|
||||
.put(message.toRequestBody())
|
||||
|
|
|
@ -33,6 +33,7 @@ class AddFragment : DialogFragment() {
|
|||
private lateinit var subscribeView: View
|
||||
private lateinit var loginView: View
|
||||
|
||||
// Subscribe page
|
||||
private lateinit var topicNameText: TextInputEditText
|
||||
private lateinit var baseUrlLayout: TextInputLayout
|
||||
private lateinit var baseUrlText: AutoCompleteTextView
|
||||
|
@ -43,11 +44,13 @@ class AddFragment : DialogFragment() {
|
|||
private lateinit var instantDeliveryDescription: View
|
||||
private lateinit var subscribeButton: Button
|
||||
|
||||
// Login page
|
||||
private lateinit var users: List<User>
|
||||
private lateinit var usersSpinner: Spinner
|
||||
private var userSelected: User? = null
|
||||
private lateinit var usernameText: 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
|
||||
|
||||
|
@ -90,6 +93,8 @@ class AddFragment : DialogFragment() {
|
|||
usersSpinner = view.findViewById(R.id.add_dialog_login_users_spinner)
|
||||
usernameText = view.findViewById(R.id.add_dialog_login_username)
|
||||
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
|
||||
useAnotherServerDescription.text = if (BuildConfig.FIREBASE_AVAILABLE) {
|
||||
|
@ -162,10 +167,8 @@ class AddFragment : DialogFragment() {
|
|||
if (users.isEmpty()) {
|
||||
usersSpinner.visibility = View.GONE
|
||||
} else {
|
||||
val spinnerEntries = users
|
||||
//.map { it.username }
|
||||
.toMutableList()
|
||||
spinnerEntries.add(0, User(0, "Create new", ""))
|
||||
val spinnerEntries = users.toMutableList()
|
||||
spinnerEntries.add(0, User(0, "Create new", "")) // FIXME
|
||||
usersSpinner.adapter = ArrayAdapter(requireActivity(), R.layout.fragment_add_dialog_dropdown_item, spinnerEntries)
|
||||
}
|
||||
}
|
||||
|
@ -177,11 +180,9 @@ class AddFragment : DialogFragment() {
|
|||
usersSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||
if (position == 0) {
|
||||
userSelected = null
|
||||
usernameText.visibility = View.VISIBLE
|
||||
passwordText.visibility = View.VISIBLE
|
||||
} else {
|
||||
userSelected = usersSpinner.selectedItem as User
|
||||
usernameText.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")
|
||||
requireActivity().runOnUiThread {
|
||||
subscribeView.visibility = View.GONE
|
||||
loginError.visibility = View.INVISIBLE
|
||||
loginProgress.visibility = View.INVISIBLE
|
||||
loginView.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
@ -277,6 +280,8 @@ class AddFragment : DialogFragment() {
|
|||
}
|
||||
|
||||
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 user = if (existingUser) {
|
||||
usersSpinner.selectedItem as User
|
||||
|
@ -299,7 +304,10 @@ class AddFragment : DialogFragment() {
|
|||
dismiss(authUserId = user.id)
|
||||
} else {
|
||||
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:visibility="gone"/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
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
|
||||
android:id="@+id/add_dialog_login_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="3dp"
|
||||
android:text="Login required"
|
||||
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
|
||||
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_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
|
||||
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
|
||||
android:id="@+id/add_dialog_login_username"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" android:hint="Username"
|
||||
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
|
||||
android:id="@+id/add_dialog_login_password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" android:hint="Password"
|
||||
android:importantForAutofill="no"
|
||||
android:maxLines="1" android:inputType="textPassword"/>
|
||||
</LinearLayout>
|
||||
android:maxLines="1" android:inputType="textPassword" app:layout_constraintStart_toStartOf="parent"
|
||||
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>
|
||||
|
|
Loading…
Reference in a new issue