2019-11-19 10:15:32 +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 <https://www.gnu.org/licenses>. */
|
|
|
|
|
|
|
|
package com.keylesspalace.tusky
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.content.Intent
|
|
|
|
import android.os.Bundle
|
2020-09-07 15:57:59 +02:00
|
|
|
import androidx.activity.viewModels
|
2019-11-19 10:15:32 +01:00
|
|
|
import androidx.fragment.app.commit
|
2019-11-19 15:42:22 +01:00
|
|
|
import androidx.lifecycle.Lifecycle
|
|
|
|
import com.keylesspalace.tusky.appstore.EventHub
|
2020-09-07 15:57:59 +02:00
|
|
|
import com.keylesspalace.tusky.di.ViewModelFactory
|
2019-11-19 10:15:32 +01:00
|
|
|
import com.keylesspalace.tusky.fragment.TimelineFragment
|
|
|
|
import com.keylesspalace.tusky.fragment.TimelineFragment.Kind
|
2019-11-19 15:42:22 +01:00
|
|
|
import com.uber.autodispose.AutoDispose
|
|
|
|
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider
|
2019-11-19 10:15:32 +01:00
|
|
|
import dagger.android.DispatchingAndroidInjector
|
|
|
|
import dagger.android.HasAndroidInjector
|
2019-11-19 15:42:22 +01:00
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
2019-11-19 10:15:32 +01:00
|
|
|
import kotlinx.android.extensions.CacheImplementation
|
|
|
|
import kotlinx.android.extensions.ContainerOptions
|
2020-09-07 15:57:59 +02:00
|
|
|
import kotlinx.android.synthetic.main.activity_statuslist.*
|
2019-11-19 10:15:32 +01:00
|
|
|
import kotlinx.android.synthetic.main.toolbar_basic.*
|
2020-09-07 15:57:59 +02:00
|
|
|
import net.accelf.yuito.QuickTootViewModel
|
2020-01-27 17:11:10 +01:00
|
|
|
import javax.inject.Inject
|
2019-11-19 10:15:32 +01:00
|
|
|
|
|
|
|
class StatusListActivity : BottomSheetActivity(), HasAndroidInjector {
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Any>
|
2019-11-19 15:42:22 +01:00
|
|
|
@Inject
|
|
|
|
lateinit var eventHub: EventHub
|
2020-09-07 15:57:59 +02:00
|
|
|
@Inject
|
|
|
|
lateinit var viewModelFactory: ViewModelFactory
|
|
|
|
|
|
|
|
private val quickTootViewModel: QuickTootViewModel by viewModels{ viewModelFactory }
|
2019-11-19 10:15:32 +01:00
|
|
|
|
|
|
|
private val kind: Kind
|
|
|
|
get() = Kind.valueOf(intent.getStringExtra(EXTRA_KIND)!!)
|
|
|
|
|
|
|
|
@ContainerOptions(cache = CacheImplementation.NO_CACHE)
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setContentView(R.layout.activity_statuslist)
|
|
|
|
|
|
|
|
setSupportActionBar(toolbar)
|
|
|
|
|
|
|
|
val title = if(kind == Kind.FAVOURITES) {
|
|
|
|
R.string.title_favourites
|
|
|
|
} else {
|
|
|
|
R.string.title_bookmarks
|
|
|
|
}
|
|
|
|
|
|
|
|
supportActionBar?.run {
|
|
|
|
setTitle(title)
|
|
|
|
setDisplayHomeAsUpEnabled(true)
|
|
|
|
setDisplayShowHomeEnabled(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
supportFragmentManager.commit {
|
|
|
|
val fragment = TimelineFragment.newInstance(kind)
|
|
|
|
replace(R.id.fragment_container, fragment)
|
|
|
|
}
|
|
|
|
|
2020-09-07 15:57:59 +02:00
|
|
|
viewQuickToot.attachViewModel(quickTootViewModel, this)
|
2019-11-19 15:42:22 +01:00
|
|
|
|
|
|
|
eventHub.events
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.`as`(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(this, Lifecycle.Event.ON_DESTROY)))
|
2020-09-07 15:57:59 +02:00
|
|
|
.subscribe(viewQuickToot::handleEvent)
|
|
|
|
floating_btn.setOnClickListener(viewQuickToot::onFABClicked)
|
2019-11-19 10:15:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun androidInjector() = dispatchingAndroidInjector
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
private const val EXTRA_KIND = "kind"
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
fun newFavouritesIntent(context: Context) =
|
|
|
|
Intent(context, StatusListActivity::class.java).apply {
|
|
|
|
putExtra(EXTRA_KIND, Kind.FAVOURITES.name)
|
|
|
|
}
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
fun newBookmarksIntent(context: Context) =
|
|
|
|
Intent(context, StatusListActivity::class.java).apply {
|
|
|
|
putExtra(EXTRA_KIND, Kind.BOOKMARKS.name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|