Add dialog instant checkbox visibility
This commit is contained in:
parent
53ab3ad694
commit
ab0f707501
2 changed files with 26 additions and 11 deletions
|
@ -30,6 +30,7 @@ class AddFragment : DialogFragment() {
|
||||||
private lateinit var repository: Repository
|
private lateinit var repository: Repository
|
||||||
private lateinit var subscribeListener: SubscribeListener
|
private lateinit var subscribeListener: SubscribeListener
|
||||||
private lateinit var appBaseUrl: String
|
private lateinit var appBaseUrl: String
|
||||||
|
private var defaultBaseUrl: String? = null
|
||||||
|
|
||||||
private lateinit var subscribeView: View
|
private lateinit var subscribeView: View
|
||||||
private lateinit var loginView: View
|
private lateinit var loginView: View
|
||||||
|
@ -71,8 +72,9 @@ class AddFragment : DialogFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dependencies (Fragments need a default constructor)
|
// Dependencies (Fragments need a default constructor)
|
||||||
appBaseUrl = getString(R.string.app_base_url)
|
|
||||||
repository = Repository.getInstance(requireActivity())
|
repository = Repository.getInstance(requireActivity())
|
||||||
|
appBaseUrl = getString(R.string.app_base_url)
|
||||||
|
defaultBaseUrl = repository.getDefaultBaseUrl()
|
||||||
|
|
||||||
// Build root view
|
// Build root view
|
||||||
val view = requireActivity().layoutInflater.inflate(R.layout.fragment_add_dialog, null)
|
val view = requireActivity().layoutInflater.inflate(R.layout.fragment_add_dialog, null)
|
||||||
|
@ -90,6 +92,7 @@ class AddFragment : DialogFragment() {
|
||||||
subscribeBaseUrlLayout.makeEndIconSmaller(resources) // Hack!
|
subscribeBaseUrlLayout.makeEndIconSmaller(resources) // Hack!
|
||||||
subscribeBaseUrlText = view.findViewById(R.id.add_dialog_subscribe_base_url_text)
|
subscribeBaseUrlText = view.findViewById(R.id.add_dialog_subscribe_base_url_text)
|
||||||
subscribeBaseUrlText.background = view.background
|
subscribeBaseUrlText.background = view.background
|
||||||
|
subscribeBaseUrlText.hint = defaultBaseUrl ?: appBaseUrl
|
||||||
subscribeInstantDeliveryBox = view.findViewById(R.id.add_dialog_subscribe_instant_delivery_box)
|
subscribeInstantDeliveryBox = view.findViewById(R.id.add_dialog_subscribe_instant_delivery_box)
|
||||||
subscribeInstantDeliveryCheckbox = view.findViewById(R.id.add_dialog_subscribe_instant_delivery_checkbox)
|
subscribeInstantDeliveryCheckbox = view.findViewById(R.id.add_dialog_subscribe_instant_delivery_checkbox)
|
||||||
subscribeInstantDeliveryDescription = view.findViewById(R.id.add_dialog_subscribe_instant_delivery_description)
|
subscribeInstantDeliveryDescription = view.findViewById(R.id.add_dialog_subscribe_instant_delivery_description)
|
||||||
|
@ -116,18 +119,18 @@ class AddFragment : DialogFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show/hide based on flavor
|
// Show/hide based on flavor
|
||||||
subscribeInstantDeliveryBox.visibility = if (BuildConfig.FIREBASE_AVAILABLE) View.VISIBLE else View.GONE
|
subscribeInstantDeliveryBox.visibility = instantCheckboxVisible()
|
||||||
|
|
||||||
// Add baseUrl auto-complete behavior
|
// Add baseUrl auto-complete behavior
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
val defaultBaseUrl = repository.getDefaultBaseUrl()
|
|
||||||
val baseUrlsRaw = repository.getSubscriptions()
|
val baseUrlsRaw = repository.getSubscriptions()
|
||||||
.groupBy { it.baseUrl }
|
.groupBy { it.baseUrl }
|
||||||
.map { it.key }
|
.map { it.key }
|
||||||
|
.filterNot { it == appBaseUrl }
|
||||||
val baseUrls = if (defaultBaseUrl != null) {
|
val baseUrls = if (defaultBaseUrl != null) {
|
||||||
(baseUrlsRaw.filterNot { it == defaultBaseUrl } + appBaseUrl).sorted()
|
(baseUrlsRaw.filterNot { it == defaultBaseUrl } + appBaseUrl).sorted()
|
||||||
} else {
|
} else {
|
||||||
baseUrlsRaw.filterNot { it == appBaseUrl }.sorted()
|
baseUrlsRaw.sorted()
|
||||||
}
|
}
|
||||||
val activity = activity ?: return@launch // We may have pressed "Cancel"
|
val activity = activity ?: return@launch // We may have pressed "Cancel"
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
|
@ -189,24 +192,23 @@ class AddFragment : DialogFragment() {
|
||||||
subscribeTopicText.addTextChangedListener(subscribeTextWatcher)
|
subscribeTopicText.addTextChangedListener(subscribeTextWatcher)
|
||||||
subscribeBaseUrlText.addTextChangedListener(subscribeTextWatcher)
|
subscribeBaseUrlText.addTextChangedListener(subscribeTextWatcher)
|
||||||
subscribeInstantDeliveryCheckbox.setOnCheckedChangeListener { _, isChecked ->
|
subscribeInstantDeliveryCheckbox.setOnCheckedChangeListener { _, isChecked ->
|
||||||
if (isChecked) subscribeInstantDeliveryDescription.visibility = View.VISIBLE
|
subscribeInstantDeliveryDescription.visibility = if (isChecked) View.VISIBLE else View.GONE
|
||||||
else subscribeInstantDeliveryDescription.visibility = View.GONE
|
|
||||||
}
|
}
|
||||||
subscribeUseAnotherServerCheckbox.setOnCheckedChangeListener { _, isChecked ->
|
subscribeUseAnotherServerCheckbox.setOnCheckedChangeListener { _, isChecked ->
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
subscribeUseAnotherServerDescription.visibility = View.VISIBLE
|
subscribeUseAnotherServerDescription.visibility = View.VISIBLE
|
||||||
subscribeBaseUrlLayout.visibility = View.VISIBLE
|
subscribeBaseUrlLayout.visibility = View.VISIBLE
|
||||||
subscribeInstantDeliveryBox.visibility = View.GONE
|
subscribeInstantDeliveryBox.visibility = instantCheckboxVisible()
|
||||||
subscribeInstantDeliveryDescription.visibility = View.GONE
|
subscribeInstantDeliveryDescription.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
subscribeUseAnotherServerDescription.visibility = View.GONE
|
subscribeUseAnotherServerDescription.visibility = View.GONE
|
||||||
subscribeBaseUrlLayout.visibility = View.GONE
|
subscribeBaseUrlLayout.visibility = View.GONE
|
||||||
subscribeInstantDeliveryBox.visibility = if (BuildConfig.FIREBASE_AVAILABLE) View.VISIBLE else View.GONE
|
subscribeInstantDeliveryBox.visibility = instantCheckboxVisible()
|
||||||
if (subscribeInstantDeliveryCheckbox.isChecked) subscribeInstantDeliveryDescription.visibility = View.VISIBLE
|
subscribeInstantDeliveryDescription.visibility = if (subscribeInstantDeliveryBox.visibility == View.VISIBLE && subscribeInstantDeliveryCheckbox.isChecked) View.VISIBLE else View.GONE
|
||||||
else subscribeInstantDeliveryDescription.visibility = View.GONE
|
|
||||||
}
|
}
|
||||||
validateInputSubscribeView()
|
validateInputSubscribeView()
|
||||||
}
|
}
|
||||||
|
subscribeInstantDeliveryBox.visibility = instantCheckboxVisible()
|
||||||
|
|
||||||
// Focus topic text (keyboard is shown too, see above)
|
// Focus topic text (keyboard is shown too, see above)
|
||||||
subscribeTopicText.requestFocus()
|
subscribeTopicText.requestFocus()
|
||||||
|
@ -215,6 +217,17 @@ class AddFragment : DialogFragment() {
|
||||||
return dialog
|
return dialog
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun instantCheckboxVisible(): Int {
|
||||||
|
if (!BuildConfig.FIREBASE_AVAILABLE) {
|
||||||
|
return View.GONE
|
||||||
|
} else if (subscribeUseAnotherServerCheckbox.isChecked && subscribeBaseUrlText.text.toString() == appBaseUrl) {
|
||||||
|
return View.VISIBLE
|
||||||
|
} else if (!subscribeUseAnotherServerCheckbox.isChecked && defaultBaseUrl == null) {
|
||||||
|
return View.VISIBLE
|
||||||
|
}
|
||||||
|
return View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
private fun positiveButtonClick() {
|
private fun positiveButtonClick() {
|
||||||
val topic = subscribeTopicText.text.toString()
|
val topic = subscribeTopicText.text.toString()
|
||||||
val baseUrl = getBaseUrl()
|
val baseUrl = getBaseUrl()
|
||||||
|
@ -331,6 +344,8 @@ class AddFragment : DialogFragment() {
|
||||||
} else {
|
} else {
|
||||||
positiveButton.isEnabled = validTopic(topic)
|
positiveButton.isEnabled = validTopic(topic)
|
||||||
}
|
}
|
||||||
|
subscribeInstantDeliveryBox.visibility = instantCheckboxVisible()
|
||||||
|
subscribeInstantDeliveryDescription.visibility = if (subscribeInstantDeliveryBox.visibility == View.VISIBLE && subscribeInstantDeliveryCheckbox.isChecked) View.VISIBLE else View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@
|
||||||
android:hint="@string/app_base_url"
|
android:hint="@string/app_base_url"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:layout_marginTop="0dp"
|
android:layout_marginTop="0dp"
|
||||||
android:layout_marginBottom="0dp"
|
android:layout_marginBottom="15dp"
|
||||||
android:inputType="textNoSuggestions"
|
android:inputType="textNoSuggestions"
|
||||||
android:paddingStart="0dp"
|
android:paddingStart="0dp"
|
||||||
android:paddingEnd="0dp"
|
android:paddingEnd="0dp"
|
||||||
|
|
Loading…
Reference in a new issue