From 54f04fb4d752d472ac02637e37dbc25a91f8abb8 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Tue, 31 Dec 2019 13:57:24 +0100 Subject: [PATCH] address PR feedback --- .../tusky/components/compose/ComposeViewModel.kt | 13 ------------- .../scheduled/ScheduledTootActivity.kt | 2 +- .../components/scheduled/ScheduledTootAdapter.kt | 4 ++-- .../scheduled/ScheduledTootViewModel.kt | 13 ++++--------- .../keylesspalace/tusky/util/RxAwareViewModel.kt | 16 ++++++++++++++++ 5 files changed, 23 insertions(+), 25 deletions(-) create mode 100644 app/src/main/java/com/keylesspalace/tusky/util/RxAwareViewModel.kt diff --git a/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeViewModel.kt index cbcb29ce4..94613861b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeViewModel.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeViewModel.kt @@ -21,7 +21,6 @@ import androidx.core.net.toUri import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.Observer -import androidx.lifecycle.ViewModel import com.keylesspalace.tusky.adapter.ComposeAutoCompleteAdapter import com.keylesspalace.tusky.components.compose.ComposeActivity.QueuedMedia 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.TootToSend import com.keylesspalace.tusky.util.* -import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.Disposable import io.reactivex.rxkotlin.Singles import java.util.* 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 */ diff --git a/app/src/main/java/com/keylesspalace/tusky/components/scheduled/ScheduledTootActivity.kt b/app/src/main/java/com/keylesspalace/tusky/components/scheduled/ScheduledTootActivity.kt index c44a08898..17682ad3b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/scheduled/ScheduledTootActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/scheduled/ScheduledTootActivity.kt @@ -37,7 +37,7 @@ import kotlinx.android.synthetic.main.activity_scheduled_toot.* import kotlinx.android.synthetic.main.toolbar_basic.* import javax.inject.Inject -class ScheduledTootActivity : BaseActivity(), ScheduledTootAction, Injectable { +class ScheduledTootActivity : BaseActivity(), ScheduledTootActionListener, Injectable { @Inject lateinit var viewModelFactory: ViewModelFactory diff --git a/app/src/main/java/com/keylesspalace/tusky/components/scheduled/ScheduledTootAdapter.kt b/app/src/main/java/com/keylesspalace/tusky/components/scheduled/ScheduledTootAdapter.kt index 59310c407..ea12d1ffa 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/scheduled/ScheduledTootAdapter.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/scheduled/ScheduledTootAdapter.kt @@ -26,13 +26,13 @@ import androidx.recyclerview.widget.RecyclerView import com.keylesspalace.tusky.R import com.keylesspalace.tusky.entity.ScheduledStatus -interface ScheduledTootAction { +interface ScheduledTootActionListener { fun edit(item: ScheduledStatus) fun delete(item: ScheduledStatus) } class ScheduledTootAdapter( - val listener: ScheduledTootAction + val listener: ScheduledTootActionListener ) : PagedListAdapter( object: DiffUtil.ItemCallback(){ override fun areItemsTheSame(oldItem: ScheduledStatus, newItem: ScheduledStatus): Boolean { diff --git a/app/src/main/java/com/keylesspalace/tusky/components/scheduled/ScheduledTootViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/components/scheduled/ScheduledTootViewModel.kt index 3d40e0b24..4d531a455 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/scheduled/ScheduledTootViewModel.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/scheduled/ScheduledTootViewModel.kt @@ -23,6 +23,7 @@ import com.keylesspalace.tusky.appstore.EventHub import com.keylesspalace.tusky.appstore.StatusScheduledEvent import com.keylesspalace.tusky.entity.ScheduledStatus import com.keylesspalace.tusky.network.MastodonApi +import com.keylesspalace.tusky.util.RxAwareViewModel import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import io.reactivex.rxkotlin.addTo @@ -31,9 +32,7 @@ import javax.inject.Inject class ScheduledTootViewModel @Inject constructor( val mastodonApi: MastodonApi, val eventHub: EventHub -): ViewModel() { - - private val disposables = CompositeDisposable() +): RxAwareViewModel() { private val dataSourceFactory = ScheduledTootDataSourceFactory(mastodonApi, disposables) @@ -51,7 +50,7 @@ class ScheduledTootViewModel @Inject constructor( reload() } } - .addTo(disposables) + .autoDispose() } fun reload() { @@ -65,12 +64,8 @@ class ScheduledTootViewModel @Inject constructor( },{ throwable -> Log.w("ScheduledTootViewModel", "Error deleting scheduled status", throwable) }) - .addTo(disposables) + .autoDispose() } - override fun onCleared() { - disposables.clear() - } - } \ No newline at end of file diff --git a/app/src/main/java/com/keylesspalace/tusky/util/RxAwareViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/util/RxAwareViewModel.kt new file mode 100644 index 000000000..2ad4b825d --- /dev/null +++ b/app/src/main/java/com/keylesspalace/tusky/util/RxAwareViewModel.kt @@ -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() + } +} \ No newline at end of file