Remove search v1 (#1484)

* remove search v1, convert MastodonApi to Kotlin

* format MastodonApi nicely

* use default params in ConversationRepository

* improve code for LoginActivity
This commit is contained in:
Konrad Pozniak 2019-09-22 08:18:44 +02:00 committed by GitHub
commit 54a0d5406a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 698 additions and 660 deletions

View file

@ -36,7 +36,7 @@ class ConversationsRepository @Inject constructor(val mastodonApi: MastodonApi,
networkState.value = NetworkState.LOADING
}
mastodonApi.getConversations(null, DEFAULT_PAGE_SIZE).enqueue(
mastodonApi.getConversations(limit = DEFAULT_PAGE_SIZE).enqueue(
object : Callback<List<Conversation>> {
override fun onFailure(call: Call<List<Conversation>>, t: Throwable) {
// retrofit calls this on main thread so safe to call set value

View file

@ -113,7 +113,7 @@ class InstanceListFragment: BaseFragment(), Injectable, InstanceActionListener {
recyclerView.post { adapter.bottomLoading = true }
}
api.domainBlocks(id, bottomId, null)
api.domainBlocks(id, bottomId)
.observeOn(AndroidSchedulers.mainThread())
.autoDisposable(from(this, Lifecycle.Event.ON_DESTROY))
.subscribe({ response ->

View file

@ -61,7 +61,7 @@ class ReportViewModel @Inject constructor(
private val selectedIds = HashSet<String>()
val statusViewState = StatusViewState()
var reportNote: String? = null
var reportNote: String = ""
var isRemoteNotify = false
private var statusId: String? = null

View file

@ -72,10 +72,11 @@ class StatusesDataSource(private val accountId: String,
retryBefore = null
retryInitial = null
initialLoad.postValue(NetworkState.LOADING)
if (params.requestedInitialKey == null) {
val initialKey = params.requestedInitialKey
if (initialKey == null) {
mastodonApi.accountStatusesObservable(accountId, null, null, params.requestedLoadSize, true)
} else {
mastodonApi.statusObservable(params.requestedInitialKey).zipWith(
mastodonApi.statusObservable(initialKey).zipWith(
mastodonApi.accountStatusesObservable(accountId, params.requestedInitialKey, null, params.requestedLoadSize - 1, true),
BiFunction { status: Status, list: List<Status> ->
val ret = ArrayList<Status>()

View file

@ -61,7 +61,7 @@ class ReportNoteFragment : Fragment(), Injectable {
private fun handleChanges() {
editNote.doAfterTextChanged {
viewModel.reportNote = it?.toString()
viewModel.reportNote = it?.toString() ?: ""
}
checkIsNotifyRemote.setOnCheckedChangeListener { _, isChecked ->
viewModel.isRemoteNotify = isChecked

View file

@ -19,7 +19,7 @@ import android.annotation.SuppressLint
import androidx.lifecycle.MutableLiveData
import androidx.paging.PositionalDataSource
import com.keylesspalace.tusky.components.search.SearchType
import com.keylesspalace.tusky.entity.SearchResults2
import com.keylesspalace.tusky.entity.SearchResult
import com.keylesspalace.tusky.network.MastodonApi
import com.keylesspalace.tusky.util.NetworkState
import io.reactivex.disposables.CompositeDisposable
@ -32,7 +32,7 @@ class SearchDataSource<T>(
private val disposables: CompositeDisposable,
private val retryExecutor: Executor,
private val initialItems: List<T>? = null,
private val parser: (SearchResults2?) -> List<T>) : PositionalDataSource<T>() {
private val parser: (SearchResult?) -> List<T>) : PositionalDataSource<T>() {
val networkState = MutableLiveData<NetworkState>()
@ -56,7 +56,13 @@ class SearchDataSource<T>(
networkState.postValue(NetworkState.LOADED)
retry = null
initialLoad.postValue(NetworkState.LOADING)
mastodonApi.searchObservable(searchType.apiParameter, searchRequest, true, params.requestedLoadSize, 0, false)
mastodonApi.searchObservable(
query = searchRequest ?: "",
type = searchType.apiParameter,
resolve = true,
limit = params.requestedLoadSize,
offset = 0,
following =false)
.doOnSubscribe {
disposables.add(it)
}

View file

@ -18,7 +18,7 @@ package com.keylesspalace.tusky.components.search.adapter
import androidx.lifecycle.MutableLiveData
import androidx.paging.DataSource
import com.keylesspalace.tusky.components.search.SearchType
import com.keylesspalace.tusky.entity.SearchResults2
import com.keylesspalace.tusky.entity.SearchResult
import com.keylesspalace.tusky.network.MastodonApi
import io.reactivex.disposables.CompositeDisposable
import java.util.concurrent.Executor
@ -30,7 +30,7 @@ class SearchDataSourceFactory<T>(
private val disposables: CompositeDisposable,
private val retryExecutor: Executor,
private val cacheData: List<T>? = null,
private val parser: (SearchResults2?) -> List<T>) : DataSource.Factory<Int, T>() {
private val parser: (SearchResult?) -> List<T>) : DataSource.Factory<Int, T>() {
val sourceLiveData = MutableLiveData<SearchDataSource<T>>()
override fun create(): DataSource<Int, T> {
val source = SearchDataSource(mastodonApi, searchType, searchRequest, disposables, retryExecutor, cacheData, parser)

View file

@ -19,7 +19,7 @@ import androidx.lifecycle.Transformations
import androidx.paging.Config
import androidx.paging.toLiveData
import com.keylesspalace.tusky.components.search.SearchType
import com.keylesspalace.tusky.entity.SearchResults2
import com.keylesspalace.tusky.entity.SearchResult
import com.keylesspalace.tusky.network.MastodonApi
import com.keylesspalace.tusky.util.Listing
import io.reactivex.disposables.CompositeDisposable
@ -30,7 +30,7 @@ class SearchRepository<T>(private val mastodonApi: MastodonApi) {
private val executor = Executors.newSingleThreadExecutor()
fun getSearchData(searchType: SearchType, searchRequest: String?, disposables: CompositeDisposable, pageSize: Int = 20,
initialItems: List<T>? = null, parser: (SearchResults2?) -> List<T>): Listing<T> {
initialItems: List<T>? = null, parser: (SearchResult?) -> List<T>): Listing<T> {
val sourceFactory = SearchDataSourceFactory(mastodonApi, searchType, searchRequest, disposables, executor, initialItems, parser)
val livePagedList = sourceFactory.toLiveData(
config = Config(pageSize = pageSize, enablePlaceholders = false, initialLoadSizeHint = pageSize * 2),