parent
ce01e6de22
commit
0b29b0330b
3 changed files with 18 additions and 10 deletions
|
@ -21,9 +21,7 @@ import com.keylesspalace.tusky.util.ViewDataUtils
|
||||||
import com.keylesspalace.tusky.viewdata.StatusViewData
|
import com.keylesspalace.tusky.viewdata.StatusViewData
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import java.util.*
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.collections.ArrayList
|
|
||||||
|
|
||||||
class SearchViewModel @Inject constructor(
|
class SearchViewModel @Inject constructor(
|
||||||
mastodonApi: MastodonApi,
|
mastodonApi: MastodonApi,
|
||||||
|
@ -78,9 +76,11 @@ 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()
|
||||||
}
|
}
|
||||||
repoResultHashTag.value = hashtagsRepository.getSearchData(SearchType.Hashtag, String.format(Locale.getDefault(),"#%s",query), disposables) {
|
val hashtagQuery = if (query != null && query.startsWith("#")) query else "#$query"
|
||||||
it?.hashtags ?: emptyList()
|
repoResultHashTag.value =
|
||||||
}
|
hashtagsRepository.getSearchData(SearchType.Hashtag, hashtagQuery, disposables) {
|
||||||
|
it?.hashtags ?: emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,17 @@ class SearchDataSource<T>(
|
||||||
}
|
}
|
||||||
.subscribe(
|
.subscribe(
|
||||||
{ data ->
|
{ data ->
|
||||||
val res = parser(data)
|
// Working around Mastodon bug where exact match is returned no matter
|
||||||
|
// which offset is requested (so if we seach for a full username, it's
|
||||||
|
// infinite)
|
||||||
|
// see https://github.com/tootsuite/mastodon/issues/11365
|
||||||
|
val res = if (data.accounts.size == 1
|
||||||
|
&& data.accounts[0].username
|
||||||
|
.equals(searchRequest, ignoreCase = true)) {
|
||||||
|
listOf()
|
||||||
|
} else {
|
||||||
|
parser(data)
|
||||||
|
}
|
||||||
callback.onResult(res)
|
callback.onResult(res)
|
||||||
networkState.postValue(NetworkState.LOADED)
|
networkState.postValue(NetworkState.LOADED)
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,7 @@ import com.keylesspalace.tusky.di.ViewModelFactory
|
||||||
import com.keylesspalace.tusky.interfaces.LinkListener
|
import com.keylesspalace.tusky.interfaces.LinkListener
|
||||||
import com.keylesspalace.tusky.util.*
|
import com.keylesspalace.tusky.util.*
|
||||||
import kotlinx.android.synthetic.main.fragment_search.*
|
import kotlinx.android.synthetic.main.fragment_search.*
|
||||||
import java.util.*
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.concurrent.schedule
|
|
||||||
|
|
||||||
abstract class SearchFragment<T> : Fragment(),
|
abstract class SearchFragment<T> : Fragment(),
|
||||||
LinkListener, Injectable, SwipeRefreshLayout.OnRefreshListener {
|
LinkListener, Injectable, SwipeRefreshLayout.OnRefreshListener {
|
||||||
|
@ -135,10 +133,10 @@ abstract class SearchFragment<T> : Fragment(),
|
||||||
override fun onRefresh() {
|
override fun onRefresh() {
|
||||||
|
|
||||||
// Dismissed here because the RecyclerView bottomProgressBar is shown as soon as the retry begins.
|
// Dismissed here because the RecyclerView bottomProgressBar is shown as soon as the retry begins.
|
||||||
Timer("DelayDismiss", false).schedule(200) {
|
swipeRefreshLayout.post {
|
||||||
|
|
||||||
swipeRefreshLayout.isRefreshing = false
|
swipeRefreshLayout.isRefreshing = false
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.retryAllSearches()
|
viewModel.retryAllSearches()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue