Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix SearchSessionFragment : remember query text #364

Merged
merged 2 commits into from
Jan 18, 2020

Conversation

nanoyatsu
Copy link
Contributor

fix SearchSessionFragment : remember query text, when come back after query searching

Issue

Overview (Required)

  • Set(≒initialize) query text in SearchSessionsFragment::onCreateOptionsMenu.
    (SearchSessionsFragment::onCreateOptionsMenuでクエリテキストの設定をしました。)
  • Second arg of searchView.setQuery() is false. Because I think submit is unnecessary, In this case searchResult is remembered in SearchSessionsViewModel.
    (searchView.setQuery()の第2引数はfalseにしています。この時検索結果はViewModelに覚えられていて、submitが不要と考えているためです。)

Links

  • none.

Screenshot

  • none.

Please let me know if there are strange points in my code & PR.🙏🙏🙏
(変なところがあったら教えてください!🙏🙏🙏)

@@ -157,6 +157,7 @@ class SearchSessionsFragment : DaggerFragment() {
ContextCompat.getColor(requireContext(), R.color.search_close_icon)
)
searchView.isIconified = false
searchView.setQuery(searchSessionsViewModel.uiModel.value!!.searchResult.query, false)
Copy link
Member

@takahirom takahirom Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
You can use uiModel.requireValue() for it 🙏

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me think some minutes 🙇

Copy link
Member

@takahirom takahirom Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your PR. I thought a little based on your plan.
We can setQuery when not empty

data class UiModel(val searchResult: SearchResult) {
        fun isEmpty() = this == EMPTY

        companion object {
            val EMPTY = UiModel(SearchResult.EMPTY)
        }
    }
val searchResult = searchSessionsViewModel.uiModel.requireValue().searchResult
if (!searchResult.isEmpty()) {
  searchView.setQuery(searchResult.query, false)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked about LiveData.requireValue(). I should have used that.
Thank you for teaching 🙏🙏

and...
thank you code sample😭 I'll repair PR now.

@nanoyatsu
Copy link
Contributor Author

nanoyatsu commented Jan 17, 2020

sorry! I missed the sample...🙇
Which is preferred? The latter is now committed.

data class UiModel(val searchResult: SearchResult) {
        fun isEmpty() = this == EMPTY

        companion object {
            val EMPTY = UiModel(SearchResult.EMPTY)
        }
    }
val uiModel = searchSessionsViewModel.uiModel.requireValue()
if (!uiModel.isEmpty()) {
  searchView.setQuery(uiModel.searchResult.query, false)
}

or

class SearchResult(
    val sessions: List<Session>,
    val speakers: List<Speaker>,
    val query: String?
) {
    fun isEmpty() = this == EMPTY

    companion object {
        val EMPTY = SearchResult(listOf(), listOf(), null)
    }
}
val searchResult = searchSessionsViewModel.uiModel.requireValue().searchResult
if (!searchResult.isEmpty()) {
    searchView.setQuery(searchResult.query, false)
}

@takahirom
Copy link
Member

takahirom commented Jan 18, 2020

Thanks for suggestions! 🔍
Personally, there is a possibility that UiModel has something other than search results, so SearchResult.isEmpty() seems better.

@nanoyatsu
Copy link
Contributor Author

nanoyatsu commented Jan 18, 2020

thank you review.🙏
SearchResult.isEmpty() version is already committed. Because I noticed "missed the sample" after committed... 🙇
So, don't I need to commit anymore fix? (「なので、これ以降の修正は不要でしょうか?」的な意味のことを言いたいです...)

(「SearchResult.isEmpty のほうがベターだね」という読み取りをしています。そもそも間違っていたらすみません...)

@takahirom
Copy link
Member

Sorry for my bad English 🙇
You are correct!

@takahirom
Copy link
Member

LGTM! Thank you for fixing this issue!

@takahirom takahirom merged commit 72f29ee into DroidKaigi:master Jan 18, 2020
@nanoyatsu
Copy link
Contributor Author

thank you comment!
This PR was an irreplaceable experience for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When come back to search screen after query searching, editText become empty
3 participants