diff --git a/CHANGELOG.md b/CHANGELOG.md index 5aea950..2431fc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### v3.2.2 - Fixed crash when using raw color value for `icdIconColor` and `icdSelectedIconColor`. +- Fixed search EditText state sometimes lost when dialog is recreated. ### v3.2.1 - Updated Kotlin version to 1.3.72. diff --git a/lib/src/main/kotlin/com/maltaisn/icondialog/IconDialog.kt b/lib/src/main/kotlin/com/maltaisn/icondialog/IconDialog.kt index fe2e22e..d4b0d9e 100644 --- a/lib/src/main/kotlin/com/maltaisn/icondialog/IconDialog.kt +++ b/lib/src/main/kotlin/com/maltaisn/icondialog/IconDialog.kt @@ -211,6 +211,11 @@ class IconDialog : DialogFragment(), IconDialogContract.View { // Restore layout manager state, which isn't saved by recycler view. listLayout.onRestoreInstanceState(state.getParcelable("listLayoutState")) + + // Restore search EditText state, which *should* be restored, but apparently isn't. + // The state of the view is actually saved in onSaveInstanceState, and it is still + // present here in the "state" bundle, but it doesn't get restored for some reason! + searchEdt.onRestoreInstanceState(state.getParcelable("searchEdtState")) } return dialog @@ -234,11 +239,15 @@ class IconDialog : DialogFragment(), IconDialogContract.View { state.putParcelable("settings", settings) state.putParcelable("listLayoutState", listLayout.onSaveInstanceState()) + + state.putParcelable("searchEdtState", searchEdt.onSaveInstanceState()) + presenter?.saveState(state) } - override fun onDestroy() { - super.onDestroy() + override fun onDismiss(dialog: DialogInterface) { + super.onDismiss(dialog) + searchHandler.removeCallbacks(searchCallback) // Detach the presenter