2019-12-30 21:09:10 +01:00
|
|
|
/* Copyright 2019 Tusky Contributors
|
|
|
|
*
|
|
|
|
* This file is a part of Tusky.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
2019-12-30 20:40:27 +01:00
|
|
|
package com.keylesspalace.tusky.components.scheduled
|
|
|
|
|
|
|
|
import android.util.Log
|
|
|
|
import androidx.paging.Config
|
|
|
|
import androidx.paging.toLiveData
|
2019-12-30 20:48:01 +01:00
|
|
|
import com.keylesspalace.tusky.appstore.EventHub
|
|
|
|
import com.keylesspalace.tusky.appstore.StatusScheduledEvent
|
2019-12-30 20:40:27 +01:00
|
|
|
import com.keylesspalace.tusky.entity.ScheduledStatus
|
|
|
|
import com.keylesspalace.tusky.network.MastodonApi
|
2019-12-31 13:57:24 +01:00
|
|
|
import com.keylesspalace.tusky.util.RxAwareViewModel
|
2021-05-16 19:53:27 +02:00
|
|
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
2019-12-30 20:40:27 +01:00
|
|
|
import javax.inject.Inject
|
|
|
|
|
|
|
|
class ScheduledTootViewModel @Inject constructor(
|
2019-12-30 20:48:01 +01:00
|
|
|
val mastodonApi: MastodonApi,
|
|
|
|
val eventHub: EventHub
|
2019-12-31 13:57:24 +01:00
|
|
|
): RxAwareViewModel() {
|
2019-12-30 20:40:27 +01:00
|
|
|
|
|
|
|
private val dataSourceFactory = ScheduledTootDataSourceFactory(mastodonApi, disposables)
|
|
|
|
|
|
|
|
val data = dataSourceFactory.toLiveData(
|
|
|
|
config = Config(pageSize = 20, initialLoadSizeHint = 20, enablePlaceholders = false)
|
|
|
|
)
|
|
|
|
|
|
|
|
val networkState = dataSourceFactory.networkState
|
|
|
|
|
2019-12-30 20:48:01 +01:00
|
|
|
init {
|
|
|
|
eventHub.events
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.subscribe { event ->
|
|
|
|
if (event is StatusScheduledEvent) {
|
|
|
|
reload()
|
|
|
|
}
|
|
|
|
}
|
2019-12-31 13:57:24 +01:00
|
|
|
.autoDispose()
|
2019-12-30 20:48:01 +01:00
|
|
|
}
|
|
|
|
|
2019-12-30 20:40:27 +01:00
|
|
|
fun reload() {
|
|
|
|
dataSourceFactory.reload()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun deleteScheduledStatus(status: ScheduledStatus) {
|
|
|
|
mastodonApi.deleteScheduledStatus(status.id)
|
|
|
|
.subscribe({
|
|
|
|
dataSourceFactory.remove(status)
|
|
|
|
},{ throwable ->
|
|
|
|
Log.w("ScheduledTootViewModel", "Error deleting scheduled status", throwable)
|
|
|
|
})
|
2019-12-31 13:57:24 +01:00
|
|
|
.autoDispose()
|
2019-12-30 20:40:27 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|