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-22 11:47:34 +01:00
|
|
|
package com.keylesspalace.tusky.components.scheduled
|
2019-10-02 21:28:12 +02:00
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.content.Intent
|
|
|
|
import android.os.Bundle
|
2019-12-20 19:14:22 +01:00
|
|
|
import android.view.MenuItem
|
2019-12-30 20:40:27 +01:00
|
|
|
import androidx.lifecycle.Observer
|
|
|
|
import androidx.lifecycle.ViewModelProvider
|
2019-10-02 21:28:12 +02:00
|
|
|
import androidx.recyclerview.widget.DividerItemDecoration
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
2019-12-22 11:47:34 +01:00
|
|
|
import com.keylesspalace.tusky.BaseActivity
|
|
|
|
import com.keylesspalace.tusky.R
|
2019-12-19 19:09:40 +01:00
|
|
|
import com.keylesspalace.tusky.components.compose.ComposeActivity
|
2019-10-02 21:28:12 +02:00
|
|
|
import com.keylesspalace.tusky.di.Injectable
|
2019-12-30 20:40:27 +01:00
|
|
|
import com.keylesspalace.tusky.di.ViewModelFactory
|
2019-10-02 21:28:12 +02:00
|
|
|
import com.keylesspalace.tusky.entity.ScheduledStatus
|
2019-12-30 20:40:27 +01:00
|
|
|
import com.keylesspalace.tusky.util.Status
|
2019-12-30 20:54:00 +01:00
|
|
|
import com.keylesspalace.tusky.util.ThemeUtils
|
2019-10-02 21:28:12 +02:00
|
|
|
import com.keylesspalace.tusky.util.hide
|
|
|
|
import com.keylesspalace.tusky.util.show
|
|
|
|
import kotlinx.android.synthetic.main.activity_scheduled_toot.*
|
2019-12-22 11:55:26 +01:00
|
|
|
import kotlinx.android.synthetic.main.toolbar_basic.*
|
2019-10-02 21:28:12 +02:00
|
|
|
import javax.inject.Inject
|
|
|
|
|
2019-12-31 13:57:24 +01:00
|
|
|
class ScheduledTootActivity : BaseActivity(), ScheduledTootActionListener, Injectable {
|
2019-10-02 21:28:12 +02:00
|
|
|
|
2019-12-30 20:40:27 +01:00
|
|
|
@Inject
|
|
|
|
lateinit var viewModelFactory: ViewModelFactory
|
|
|
|
|
|
|
|
lateinit var viewModel: ScheduledTootViewModel
|
2019-10-02 21:28:12 +02:00
|
|
|
|
2019-12-30 20:48:01 +01:00
|
|
|
private val adapter = ScheduledTootAdapter(this)
|
|
|
|
|
2019-10-02 21:28:12 +02:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setContentView(R.layout.activity_scheduled_toot)
|
|
|
|
|
|
|
|
setSupportActionBar(toolbar)
|
2019-12-22 11:55:26 +01:00
|
|
|
supportActionBar?.run {
|
|
|
|
title = getString(R.string.title_scheduled_toot)
|
|
|
|
setDisplayHomeAsUpEnabled(true)
|
|
|
|
setDisplayShowHomeEnabled(true)
|
2019-10-02 21:28:12 +02:00
|
|
|
}
|
|
|
|
|
2019-12-22 11:55:26 +01:00
|
|
|
swipeRefreshLayout.setOnRefreshListener(this::refreshStatuses)
|
2019-12-30 20:54:00 +01:00
|
|
|
swipeRefreshLayout.setColorSchemeResources(R.color.tusky_blue)
|
2019-10-02 21:28:12 +02:00
|
|
|
|
2019-12-22 11:55:26 +01:00
|
|
|
scheduledTootList.setHasFixedSize(true)
|
2019-12-30 20:48:01 +01:00
|
|
|
scheduledTootList.layoutManager = LinearLayoutManager(this)
|
|
|
|
val divider = DividerItemDecoration(this, DividerItemDecoration.VERTICAL)
|
2019-12-22 11:55:26 +01:00
|
|
|
scheduledTootList.addItemDecoration(divider)
|
|
|
|
scheduledTootList.adapter = adapter
|
2019-10-02 21:28:12 +02:00
|
|
|
|
2019-12-30 20:40:27 +01:00
|
|
|
viewModel = ViewModelProvider(this, viewModelFactory)[ScheduledTootViewModel::class.java]
|
|
|
|
|
|
|
|
viewModel.data.observe(this, Observer {
|
|
|
|
adapter.submitList(it)
|
|
|
|
})
|
|
|
|
|
|
|
|
viewModel.networkState.observe(this, Observer { (status) ->
|
|
|
|
when(status) {
|
|
|
|
Status.SUCCESS -> {
|
|
|
|
progressBar.hide()
|
|
|
|
swipeRefreshLayout.isRefreshing = false
|
2019-12-30 21:01:38 +01:00
|
|
|
if(viewModel.data.value?.loadedCount == 0) {
|
|
|
|
errorMessageView.setup(R.drawable.elephant_friend_empty, R.string.no_scheduled_status)
|
|
|
|
errorMessageView.show()
|
|
|
|
} else {
|
|
|
|
errorMessageView.hide()
|
|
|
|
}
|
2019-12-30 20:40:27 +01:00
|
|
|
}
|
|
|
|
Status.RUNNING -> {
|
|
|
|
errorMessageView.hide()
|
|
|
|
if(viewModel.data.value?.loadedCount ?: 0 > 0) {
|
|
|
|
swipeRefreshLayout.isRefreshing = true
|
|
|
|
} else {
|
|
|
|
progressBar.show()
|
2019-10-02 21:28:12 +02:00
|
|
|
}
|
2019-12-30 20:40:27 +01:00
|
|
|
}
|
|
|
|
Status.FAILED -> {
|
|
|
|
if(viewModel.data.value?.loadedCount ?: 0 >= 0) {
|
|
|
|
progressBar.hide()
|
2019-12-22 11:55:26 +01:00
|
|
|
swipeRefreshLayout.isRefreshing = false
|
2019-12-30 20:40:27 +01:00
|
|
|
errorMessageView.setup(R.drawable.elephant_error, R.string.error_generic) {
|
|
|
|
refreshStatuses()
|
2019-10-02 21:28:12 +02:00
|
|
|
}
|
2019-12-30 20:40:27 +01:00
|
|
|
errorMessageView.show()
|
2019-10-02 21:28:12 +02:00
|
|
|
}
|
2019-12-30 20:40:27 +01:00
|
|
|
}
|
|
|
|
}
|
2019-10-02 21:28:12 +02:00
|
|
|
|
2019-12-30 20:40:27 +01:00
|
|
|
})
|
2019-12-30 20:48:01 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
|
|
when (item.itemId) {
|
|
|
|
android.R.id.home -> {
|
|
|
|
onBackPressed()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item)
|
2019-10-02 21:28:12 +02:00
|
|
|
}
|
|
|
|
|
2019-12-30 20:40:27 +01:00
|
|
|
private fun refreshStatuses() {
|
|
|
|
viewModel.reload()
|
2019-10-02 21:28:12 +02:00
|
|
|
}
|
|
|
|
|
2019-12-30 20:48:01 +01:00
|
|
|
override fun edit(item: ScheduledStatus) {
|
2019-12-19 19:09:40 +01:00
|
|
|
val intent = ComposeActivity.startIntent(this, ComposeActivity.ComposeOptions(
|
|
|
|
tootText = item.params.text,
|
|
|
|
contentWarning = item.params.spoilerText,
|
|
|
|
mediaAttachments = item.mediaAttachments,
|
|
|
|
inReplyToId = item.params.inReplyToId,
|
|
|
|
visibility = item.params.visibility,
|
|
|
|
scheduledAt = item.scheduledAt,
|
|
|
|
sensitive = item.params.sensitive
|
|
|
|
))
|
2019-10-02 21:28:12 +02:00
|
|
|
startActivity(intent)
|
|
|
|
}
|
|
|
|
|
2019-12-30 20:48:01 +01:00
|
|
|
override fun delete(item: ScheduledStatus) {
|
2019-12-30 20:40:27 +01:00
|
|
|
viewModel.deleteScheduledStatus(item)
|
2019-10-02 21:28:12 +02:00
|
|
|
}
|
2019-12-30 20:48:01 +01:00
|
|
|
|
|
|
|
companion object {
|
|
|
|
@JvmStatic
|
|
|
|
fun newIntent(context: Context): Intent {
|
|
|
|
return Intent(context, ScheduledTootActivity::class.java)
|
|
|
|
}
|
|
|
|
}
|
2019-10-02 21:28:12 +02:00
|
|
|
}
|