fix null search when refreshing hashtags (#1562)

This commit is contained in:
Konrad Pozniak 2019-11-17 20:58:54 +01:00 committed by GitHub
parent ad810b8be1
commit 7bccf23f69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 12 deletions

View file

@ -79,9 +79,7 @@ class SearchActivity : BottomSheetActivity(), SearchView.OnQueryTextListener, Ha
.actionView as SearchView .actionView as SearchView
setupSearchView(searchView) setupSearchView(searchView)
if (viewModel.currentQuery != null) { searchView.setQuery(viewModel.currentQuery, false)
searchView.setQuery(viewModel.currentQuery, false)
}
return true return true
} }
@ -115,7 +113,7 @@ class SearchActivity : BottomSheetActivity(), SearchView.OnQueryTextListener, Ha
private fun handleIntent(intent: Intent) { private fun handleIntent(intent: Intent) {
if (Intent.ACTION_SEARCH == intent.action) { if (Intent.ACTION_SEARCH == intent.action) {
viewModel.currentQuery = intent.getStringExtra(SearchManager.QUERY) viewModel.currentQuery = intent.getStringExtra(SearchManager.QUERY) ?: ""
viewModel.search(viewModel.currentQuery) viewModel.search(viewModel.currentQuery)
} }
} }

View file

@ -26,7 +26,7 @@ class SearchViewModel @Inject constructor(
private val timelineCases: TimelineCases, private val timelineCases: TimelineCases,
private val accountManager: AccountManager) : ViewModel() { private val accountManager: AccountManager) : ViewModel() {
var currentQuery: String? = null var currentQuery: String = ""
var activeAccount: AccountEntity? var activeAccount: AccountEntity?
get() = accountManager.activeAccount get() = accountManager.activeAccount
@ -62,7 +62,7 @@ class SearchViewModel @Inject constructor(
val networkStateHashTagRefresh: LiveData<NetworkState> = Transformations.switchMap(repoResultHashTag) { it.refreshState } val networkStateHashTagRefresh: LiveData<NetworkState> = Transformations.switchMap(repoResultHashTag) { it.refreshState }
private val loadedStatuses = ArrayList<Pair<Status, StatusViewData.Concrete>>() private val loadedStatuses = ArrayList<Pair<Status, StatusViewData.Concrete>>()
fun search(query: String?) { fun search(query: String) {
loadedStatuses.clear() loadedStatuses.clear()
repoResultStatus.value = statusesRepository.getSearchData(SearchType.Status, query, disposables, initialItems = loadedStatuses) { repoResultStatus.value = statusesRepository.getSearchData(SearchType.Status, query, disposables, initialItems = loadedStatuses) {
(it?.statuses?.map { status -> Pair(status, ViewDataUtils.statusToViewData(status, alwaysShowSensitiveMedia, alwaysOpenSpoiler)!!) } (it?.statuses?.map { status -> Pair(status, ViewDataUtils.statusToViewData(status, alwaysShowSensitiveMedia, alwaysOpenSpoiler)!!) }
@ -74,7 +74,7 @@ class SearchViewModel @Inject constructor(
repoResultAccount.value = accountsRepository.getSearchData(SearchType.Account, query, disposables) { repoResultAccount.value = accountsRepository.getSearchData(SearchType.Account, query, disposables) {
it?.accounts ?: emptyList() it?.accounts ?: emptyList()
} }
val hashtagQuery = if (query != null && query.startsWith("#")) query else "#$query" val hashtagQuery = if (query.startsWith("#")) query else "#$query"
repoResultHashTag.value = repoResultHashTag.value =
hashtagsRepository.getSearchData(SearchType.Hashtag, hashtagQuery, disposables) { hashtagsRepository.getSearchData(SearchType.Hashtag, hashtagQuery, disposables) {
it?.hashtags ?: emptyList() it?.hashtags ?: emptyList()

View file

@ -22,12 +22,8 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.keylesspalace.tusky.R import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.adapter.AccountViewHolder import com.keylesspalace.tusky.adapter.AccountViewHolder
import com.keylesspalace.tusky.adapter.StatusViewHolder
import com.keylesspalace.tusky.entity.Account import com.keylesspalace.tusky.entity.Account
import com.keylesspalace.tusky.entity.Status
import com.keylesspalace.tusky.interfaces.LinkListener import com.keylesspalace.tusky.interfaces.LinkListener
import com.keylesspalace.tusky.interfaces.StatusActionListener
import com.keylesspalace.tusky.viewdata.StatusViewData
class SearchAccountsAdapter(private val linkListener: LinkListener) class SearchAccountsAdapter(private val linkListener: LinkListener)
: PagedListAdapter<Account, RecyclerView.ViewHolder>(STATUS_COMPARATOR) { : PagedListAdapter<Account, RecyclerView.ViewHolder>(STATUS_COMPARATOR) {

View file

@ -28,7 +28,7 @@ import javax.inject.Inject
abstract class SearchFragment<T> : Fragment(), abstract class SearchFragment<T> : Fragment(),
LinkListener, Injectable, SwipeRefreshLayout.OnRefreshListener { LinkListener, Injectable, SwipeRefreshLayout.OnRefreshListener {
private var isSwipeToRefreshEnabled: Boolean = true
private var snackbarErrorRetry: Snackbar? = null private var snackbarErrorRetry: Snackbar? = null
@Inject @Inject
lateinit var viewModelFactory: ViewModelFactory lateinit var viewModelFactory: ViewModelFactory