forked from upstream-mirrors/quik
Improve code style for Interactor
This commit is contained in:
@@ -4,7 +4,7 @@ import com.moez.QKSMS.data.repository.MessageRepository
|
|||||||
import io.reactivex.Flowable
|
import io.reactivex.Flowable
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class DeleteConversation @Inject constructor(private val messageRepo: MessageRepository): Interactor<Unit, Long>() {
|
class DeleteConversation @Inject constructor(private val messageRepo: MessageRepository): Interactor<Long, Unit>() {
|
||||||
|
|
||||||
override fun buildObservable(params: Long): Flowable<Unit> {
|
override fun buildObservable(params: Long): Flowable<Unit> {
|
||||||
return Flowable.just(Unit)
|
return Flowable.just(Unit)
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ import io.reactivex.disposables.CompositeDisposable
|
|||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
|
|
||||||
abstract class Interactor<T, in Params>: Disposable {
|
abstract class Interactor<in Params, Result>: Disposable {
|
||||||
|
|
||||||
private val disposables: CompositeDisposable = CompositeDisposable()
|
private val disposables: CompositeDisposable = CompositeDisposable()
|
||||||
|
|
||||||
abstract fun buildObservable(params: Params): Flowable<T>
|
abstract fun buildObservable(params: Params): Flowable<Result>
|
||||||
|
|
||||||
fun execute(params: Params, observer: (T) -> Unit = {}) {
|
fun execute(params: Params, observer: (Result) -> Unit = {}) {
|
||||||
disposables.add(buildObservable(params)
|
disposables.add(buildObservable(params)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import com.moez.QKSMS.data.repository.MessageRepository
|
|||||||
import io.reactivex.Flowable
|
import io.reactivex.Flowable
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class MarkAllSeen @Inject constructor(val messageRepo: MessageRepository) : Interactor<Unit, Unit>() {
|
class MarkAllSeen @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Unit, Unit>() {
|
||||||
|
|
||||||
override fun buildObservable(params: Unit): Flowable<Unit> {
|
override fun buildObservable(params: Unit): Flowable<Unit> {
|
||||||
return Flowable.just(Unit)
|
return Flowable.just(Unit)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import com.moez.QKSMS.data.repository.MessageRepository
|
|||||||
import io.reactivex.Flowable
|
import io.reactivex.Flowable
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class MarkArchived @Inject constructor(val messageRepo: MessageRepository) : Interactor<Unit, Long>() {
|
class MarkArchived @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long, Unit>() {
|
||||||
|
|
||||||
override fun buildObservable(params: Long): Flowable<Unit> {
|
override fun buildObservable(params: Long): Flowable<Unit> {
|
||||||
return Flowable.just(Unit)
|
return Flowable.just(Unit)
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import com.moez.QKSMS.data.repository.MessageRepository
|
|||||||
import io.reactivex.Flowable
|
import io.reactivex.Flowable
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class MarkFailed @Inject constructor(val messageRepo: MessageRepository) : Interactor<Unit, MarkFailed.Params>() {
|
class MarkFailed @Inject constructor(
|
||||||
|
private val messageRepo: MessageRepository)
|
||||||
|
: Interactor<MarkFailed.Params, Unit>() {
|
||||||
|
|
||||||
data class Params(val uri: Uri, val resultCode: Int)
|
data class Params(val uri: Uri, val resultCode: Int)
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import com.moez.QKSMS.data.repository.MessageRepository
|
|||||||
import io.reactivex.Flowable
|
import io.reactivex.Flowable
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class MarkRead @Inject constructor(val messageRepo: MessageRepository) : Interactor<Unit, Long>() {
|
class MarkRead @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long, Unit>() {
|
||||||
|
|
||||||
override fun buildObservable(params: Long): Flowable<Unit> {
|
override fun buildObservable(params: Long): Flowable<Unit> {
|
||||||
return Flowable.just(Unit)
|
return Flowable.just(Unit)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import com.moez.QKSMS.data.repository.MessageRepository
|
|||||||
import io.reactivex.Flowable
|
import io.reactivex.Flowable
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class MarkSeen @Inject constructor(val messageRepo: MessageRepository) : Interactor<Unit, Long>() {
|
class MarkSeen @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long, Unit>() {
|
||||||
|
|
||||||
override fun buildObservable(params: Long): Flowable<Unit> {
|
override fun buildObservable(params: Long): Flowable<Unit> {
|
||||||
return Flowable.just(Unit)
|
return Flowable.just(Unit)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import com.moez.QKSMS.data.repository.MessageRepository
|
|||||||
import io.reactivex.Flowable
|
import io.reactivex.Flowable
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class MarkSent @Inject constructor(val messageRepo: MessageRepository) : Interactor<Unit, Uri>() {
|
class MarkSent @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Uri, Unit>() {
|
||||||
|
|
||||||
override fun buildObservable(params: Uri): Flowable<Unit> {
|
override fun buildObservable(params: Uri): Flowable<Unit> {
|
||||||
return Flowable.just(Unit)
|
return Flowable.just(Unit)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import com.moez.QKSMS.data.repository.MessageRepository
|
|||||||
import io.reactivex.Flowable
|
import io.reactivex.Flowable
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class MarkUnarchived @Inject constructor(val messageRepo: MessageRepository) : Interactor<Unit, Long>() {
|
class MarkUnarchived @Inject constructor(private val messageRepo: MessageRepository) : Interactor<Long, Unit>() {
|
||||||
|
|
||||||
override fun buildObservable(params: Long): Flowable<Unit> {
|
override fun buildObservable(params: Long): Flowable<Unit> {
|
||||||
return Flowable.just(Unit)
|
return Flowable.just(Unit)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ open class PartialSync @Inject constructor(
|
|||||||
private val cursorToConversation: CursorToConversation,
|
private val cursorToConversation: CursorToConversation,
|
||||||
private val cursorToMessage: CursorToMessage,
|
private val cursorToMessage: CursorToMessage,
|
||||||
private val cursorToRecipient: CursorToRecipient)
|
private val cursorToRecipient: CursorToRecipient)
|
||||||
: Interactor<Long, Unit>() {
|
: Interactor<Unit, Long>() {
|
||||||
|
|
||||||
override fun buildObservable(params: Unit): Flowable<Long> {
|
override fun buildObservable(params: Unit): Flowable<Long> {
|
||||||
val contentResolver = context.contentResolver
|
val contentResolver = context.contentResolver
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ import io.reactivex.Flowable
|
|||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ReceiveMessage @Inject constructor(
|
class ReceiveMessage @Inject constructor(
|
||||||
val context: Context,
|
private val context: Context,
|
||||||
val messageRepo: MessageRepository,
|
private val messageRepo: MessageRepository,
|
||||||
val notificationManager: NotificationManager)
|
private val notificationManager: NotificationManager)
|
||||||
: Interactor<Unit, ReceiveMessage.Params>() {
|
: Interactor<ReceiveMessage.Params, Unit>() {
|
||||||
|
|
||||||
data class Params(val address: String, val body: String, val sentTime: Long)
|
data class Params(val address: String, val body: String, val sentTime: Long)
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,10 @@ import io.reactivex.schedulers.Schedulers
|
|||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class SendMessage @Inject constructor(
|
class SendMessage @Inject constructor(
|
||||||
val context: Context,
|
private val context: Context,
|
||||||
val prefs: Preferences,
|
private val prefs: Preferences,
|
||||||
val messageRepo: MessageRepository) : Interactor<Unit, SendMessage.Params>() {
|
private val messageRepo: MessageRepository)
|
||||||
|
: Interactor<SendMessage.Params, Unit>() {
|
||||||
|
|
||||||
data class Params(val threadId: Long, val address: String, val body: String)
|
data class Params(val threadId: Long, val address: String, val body: String)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user