Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ class SearchFragment : Fragment() {
it?.let { showNoInternetError(it) }
})

searchViewModel.isSearched.observe(this, Observer {
it?.let { showSearchLayout(!it) }
})

rootView.timeTextView.setOnClickListener {
val intent = Intent(activity, SearchTimeActivity::class.java)
startActivity(intent)
Expand Down Expand Up @@ -135,8 +139,6 @@ class SearchFragment : Fragment() {
override fun onQueryTextSubmit(query: String): Boolean {
// Do your search
searchViewModel.searchEvent = query
rootView.searchLinearLayout.visibility = View.GONE
rootView.fabSearch.visibility = View.GONE
if (searchViewModel.savedLocation != null && TextUtils.isEmpty(rootView.locationTextView.text.toString()) && rootView.timeTextView.text == "Anytime")
searchViewModel.loadEvents(searchViewModel.savedLocation.nullToEmpty(), searchViewModel.savedDate.nullToEmpty())
else
Expand All @@ -159,6 +161,11 @@ class SearchFragment : Fragment() {
super.onPrepareOptionsMenu(menu)
}

private fun showSearchLayout(show: Boolean) {
rootView.searchLinearLayout.visibility = if (show) View.VISIBLE else View.GONE
rootView.fabSearch.visibility = if (show) View.VISIBLE else View.GONE
}

fun handleVisibility(events: List<Event>) {
rootView.noSearchResults.visibility = if (events.isEmpty()) View.VISIBLE else View.GONE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ class SearchViewModel(private val eventService: EventService, private val prefer
val events = MutableLiveData<List<Event>>()
val error = MutableLiveData<String>()
val showNoInternetError = MutableLiveData<Boolean>()
val isSearched = MutableLiveData<Boolean>()
var searchEvent: String? = null
val savedLocation by lazy { preference.getString(tokenKey) }
val savedDate by lazy { preference.getString(tokenKeyDate) }
val savedNextDate by lazy { preference.getString(tokenKeyNextDate) }

fun loadEvents(location: String, time: String) {
isSearched.value = true
if (!isConnected()) return
preference.putString(tokenKey, location)
val query: String = if (TextUtils.isEmpty(location))
Expand Down