address PR feedback
This commit is contained in:
parent
76026f5afa
commit
54f04fb4d7
|
@ -21,7 +21,6 @@ import androidx.core.net.toUri
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.lifecycle.ViewModel
|
|
||||||
import com.keylesspalace.tusky.adapter.ComposeAutoCompleteAdapter
|
import com.keylesspalace.tusky.adapter.ComposeAutoCompleteAdapter
|
||||||
import com.keylesspalace.tusky.components.compose.ComposeActivity.QueuedMedia
|
import com.keylesspalace.tusky.components.compose.ComposeActivity.QueuedMedia
|
||||||
import com.keylesspalace.tusky.components.search.SearchType
|
import com.keylesspalace.tusky.components.search.SearchType
|
||||||
|
@ -34,23 +33,11 @@ import com.keylesspalace.tusky.network.MastodonApi
|
||||||
import com.keylesspalace.tusky.service.ServiceClient
|
import com.keylesspalace.tusky.service.ServiceClient
|
||||||
import com.keylesspalace.tusky.service.TootToSend
|
import com.keylesspalace.tusky.service.TootToSend
|
||||||
import com.keylesspalace.tusky.util.*
|
import com.keylesspalace.tusky.util.*
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
import io.reactivex.rxkotlin.Singles
|
import io.reactivex.rxkotlin.Singles
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
open class RxAwareViewModel : ViewModel() {
|
|
||||||
private val disposables = CompositeDisposable()
|
|
||||||
|
|
||||||
fun Disposable.autoDispose() = disposables.add(this)
|
|
||||||
|
|
||||||
override fun onCleared() {
|
|
||||||
super.onCleared()
|
|
||||||
disposables.clear()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throw when trying to add an image when video is already present or the other way around
|
* Throw when trying to add an image when video is already present or the other way around
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -37,7 +37,7 @@ import kotlinx.android.synthetic.main.activity_scheduled_toot.*
|
||||||
import kotlinx.android.synthetic.main.toolbar_basic.*
|
import kotlinx.android.synthetic.main.toolbar_basic.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ScheduledTootActivity : BaseActivity(), ScheduledTootAction, Injectable {
|
class ScheduledTootActivity : BaseActivity(), ScheduledTootActionListener, Injectable {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var viewModelFactory: ViewModelFactory
|
lateinit var viewModelFactory: ViewModelFactory
|
||||||
|
|
|
@ -26,13 +26,13 @@ import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.keylesspalace.tusky.R
|
import com.keylesspalace.tusky.R
|
||||||
import com.keylesspalace.tusky.entity.ScheduledStatus
|
import com.keylesspalace.tusky.entity.ScheduledStatus
|
||||||
|
|
||||||
interface ScheduledTootAction {
|
interface ScheduledTootActionListener {
|
||||||
fun edit(item: ScheduledStatus)
|
fun edit(item: ScheduledStatus)
|
||||||
fun delete(item: ScheduledStatus)
|
fun delete(item: ScheduledStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
class ScheduledTootAdapter(
|
class ScheduledTootAdapter(
|
||||||
val listener: ScheduledTootAction
|
val listener: ScheduledTootActionListener
|
||||||
) : PagedListAdapter<ScheduledStatus, ScheduledTootAdapter.TootViewHolder>(
|
) : PagedListAdapter<ScheduledStatus, ScheduledTootAdapter.TootViewHolder>(
|
||||||
object: DiffUtil.ItemCallback<ScheduledStatus>(){
|
object: DiffUtil.ItemCallback<ScheduledStatus>(){
|
||||||
override fun areItemsTheSame(oldItem: ScheduledStatus, newItem: ScheduledStatus): Boolean {
|
override fun areItemsTheSame(oldItem: ScheduledStatus, newItem: ScheduledStatus): Boolean {
|
||||||
|
|
|
@ -23,6 +23,7 @@ import com.keylesspalace.tusky.appstore.EventHub
|
||||||
import com.keylesspalace.tusky.appstore.StatusScheduledEvent
|
import com.keylesspalace.tusky.appstore.StatusScheduledEvent
|
||||||
import com.keylesspalace.tusky.entity.ScheduledStatus
|
import com.keylesspalace.tusky.entity.ScheduledStatus
|
||||||
import com.keylesspalace.tusky.network.MastodonApi
|
import com.keylesspalace.tusky.network.MastodonApi
|
||||||
|
import com.keylesspalace.tusky.util.RxAwareViewModel
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import io.reactivex.rxkotlin.addTo
|
import io.reactivex.rxkotlin.addTo
|
||||||
|
@ -31,9 +32,7 @@ import javax.inject.Inject
|
||||||
class ScheduledTootViewModel @Inject constructor(
|
class ScheduledTootViewModel @Inject constructor(
|
||||||
val mastodonApi: MastodonApi,
|
val mastodonApi: MastodonApi,
|
||||||
val eventHub: EventHub
|
val eventHub: EventHub
|
||||||
): ViewModel() {
|
): RxAwareViewModel() {
|
||||||
|
|
||||||
private val disposables = CompositeDisposable()
|
|
||||||
|
|
||||||
private val dataSourceFactory = ScheduledTootDataSourceFactory(mastodonApi, disposables)
|
private val dataSourceFactory = ScheduledTootDataSourceFactory(mastodonApi, disposables)
|
||||||
|
|
||||||
|
@ -51,7 +50,7 @@ class ScheduledTootViewModel @Inject constructor(
|
||||||
reload()
|
reload()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.addTo(disposables)
|
.autoDispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reload() {
|
fun reload() {
|
||||||
|
@ -65,12 +64,8 @@ class ScheduledTootViewModel @Inject constructor(
|
||||||
},{ throwable ->
|
},{ throwable ->
|
||||||
Log.w("ScheduledTootViewModel", "Error deleting scheduled status", throwable)
|
Log.w("ScheduledTootViewModel", "Error deleting scheduled status", throwable)
|
||||||
})
|
})
|
||||||
.addTo(disposables)
|
.autoDispose()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCleared() {
|
|
||||||
disposables.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.keylesspalace.tusky.util
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
|
import io.reactivex.disposables.Disposable
|
||||||
|
|
||||||
|
open class RxAwareViewModel : ViewModel() {
|
||||||
|
val disposables = CompositeDisposable()
|
||||||
|
|
||||||
|
fun Disposable.autoDispose() = disposables.add(this)
|
||||||
|
|
||||||
|
override fun onCleared() {
|
||||||
|
super.onCleared()
|
||||||
|
disposables.clear()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue