From 125a010f038b10331a720b47a800f4284f487d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Borcz?= Date: Thu, 24 Oct 2019 22:56:49 +0200 Subject: [PATCH] Fix restoring state in exposed dropdown menu (#569) --- .../modules/login/form/LoginFormFragment.kt | 9 ++----- .../modules/login/form/LoginSymbolAdapter.kt | 16 ++++++++++++ .../message/preview/MessagePreviewFragment.kt | 2 +- .../main/res/layout/fragment_login_form.xml | 26 ++++++++++--------- 4 files changed, 33 insertions(+), 20 deletions(-) create mode 100644 app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginSymbolAdapter.kt diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormFragment.kt index 8ea4222c..6dd1a586 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormFragment.kt @@ -9,7 +9,6 @@ import android.view.View.VISIBLE import android.view.ViewGroup import android.view.inputmethod.EditorInfo.IME_ACTION_DONE import android.view.inputmethod.EditorInfo.IME_NULL -import android.widget.ArrayAdapter import androidx.core.widget.doOnTextChanged import io.github.wulkanowy.R import io.github.wulkanowy.data.db.entities.Student @@ -17,11 +16,11 @@ import io.github.wulkanowy.ui.base.BaseFragment import io.github.wulkanowy.ui.modules.login.LoginActivity import io.github.wulkanowy.utils.AppInfo import io.github.wulkanowy.utils.hideSoftInput +import io.github.wulkanowy.utils.openEmail import io.github.wulkanowy.utils.openInternetBrowser import io.github.wulkanowy.utils.showSoftInput import kotlinx.android.synthetic.main.fragment_login_form.* import javax.inject.Inject -import io.github.wulkanowy.utils.openEmail class LoginFormFragment : BaseFragment(), LoginFormView { @@ -71,12 +70,8 @@ class LoginFormFragment : BaseFragment(), LoginFormView { } with(loginFormHost) { - //Bug with filter in ExposedDropdownMenu on restoring state - isSaveEnabled = false - setText(hostKeys.getOrElse(0) { "" }) - setAdapter(ArrayAdapter(context, R.layout.support_simple_spinner_dropdown_item, hostKeys)) - keyListener = null + setAdapter(LoginSymbolAdapter(context, R.layout.support_simple_spinner_dropdown_item, hostKeys)) } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginSymbolAdapter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginSymbolAdapter.kt new file mode 100644 index 00000000..87fa038e --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginSymbolAdapter.kt @@ -0,0 +1,16 @@ +package io.github.wulkanowy.ui.modules.login.form + +import android.content.Context +import android.widget.ArrayAdapter +import android.widget.Filter + +class LoginSymbolAdapter(context: Context, resource: Int, objects: Array) : + ArrayAdapter(context, resource, objects) { + + override fun getFilter() = object : Filter() { + + override fun performFiltering(constraint: CharSequence?) = null + + override fun publishResults(constraint: CharSequence?, results: FilterResults?) {} + } +} diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewFragment.kt index 93ef502f..4f881e8f 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewFragment.kt @@ -143,7 +143,7 @@ class MessagePreviewFragment : BaseFragment(), MessagePreviewView, MainView.Titl } override fun notifyParentMessageDeleted(message: Message) { - fragmentManager?.fragments?.forEach { if (it is MessageFragment) it.onDeleteMessage(message) } + parentFragmentManager.fragments.forEach { if (it is MessageFragment) it.onDeleteMessage(message) } } override fun onSaveInstanceState(outState: Bundle) { diff --git a/app/src/main/res/layout/fragment_login_form.xml b/app/src/main/res/layout/fragment_login_form.xml index 545b7726..29943515 100644 --- a/app/src/main/res/layout/fragment_login_form.xml +++ b/app/src/main/res/layout/fragment_login_form.xml @@ -30,10 +30,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" + android:visibility="gone" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - android:visibility="gone" tools:visibility="visible"> + android:layout_marginRight="16dp" + android:orientation="horizontal"> + @@ -95,9 +96,9 @@ android:layout_height="wrap_content" android:layout_marginStart="32dp" android:layout_marginLeft="32dp" + android:layout_marginTop="48dp" android:layout_marginEnd="32dp" android:layout_marginRight="32dp" - android:layout_marginTop="48dp" android:gravity="center_horizontal" android:text="@string/login_header_default" android:textSize="16sp" @@ -191,7 +192,8 @@ android:id="@+id/loginFormHost" android:layout_width="match_parent" android:layout_height="wrap_content" - tools:ignore="LabelFor" /> + android:editable="false" + tools:ignore="Deprecated,LabelFor" />