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
|
|
|
|
import androidx.fragment.app.commit
|
2021-06-11 20:15:40 +02:00
|
|
|
import com.keylesspalace.tusky.components.timeline.TimelineFragment
|
2022-01-11 19:00:29 +01:00
|
|
|
import com.keylesspalace.tusky.components.timeline.viewmodel.TimelineViewModel.Kind
|
2021-06-28 21:13:24 +02:00
|
|
|
import com.keylesspalace.tusky.databinding.ActivityStatuslistBinding
|
2019-11-19 10:15:32 +01:00
|
|
|
import dagger.android.DispatchingAndroidInjector
|
|
|
|
import dagger.android.HasAndroidInjector
|
2021-06-28 21:13:24 +02:00
|
|
|
import javax.inject.Inject
|
2019-11-19 10:15:32 +01:00
|
|
|
|
|
|
|
class StatusListActivity : BottomSheetActivity(), HasAndroidInjector {
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Any>
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
2021-03-07 19:05:51 +01:00
|
|
|
val binding = ActivityStatuslistBinding.inflate(layoutInflater)
|
|
|
|
setContentView(binding.root)
|
2019-11-19 10:15:32 +01:00
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
setSupportActionBar(binding.includedToolbar.toolbar)
|
2019-11-19 10:15:32 +01:00
|
|
|
|
2022-02-25 18:57:31 +01:00
|
|
|
val kind = Kind.valueOf(intent.getStringExtra(EXTRA_KIND)!!)
|
|
|
|
val listId = intent.getStringExtra(EXTRA_LIST_ID)
|
|
|
|
val hashtag = intent.getStringExtra(EXTRA_HASHTAG)
|
|
|
|
|
|
|
|
val title = when (kind) {
|
|
|
|
Kind.FAVOURITES -> getString(R.string.title_favourites)
|
|
|
|
Kind.BOOKMARKS -> getString(R.string.title_bookmarks)
|
|
|
|
Kind.TAG -> getString(R.string.title_tag).format(hashtag)
|
|
|
|
else -> getString(R.string.title_list_timeline)
|
2019-11-19 10:15:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
supportActionBar?.run {
|
|
|
|
setTitle(title)
|
|
|
|
setDisplayHomeAsUpEnabled(true)
|
|
|
|
setDisplayShowHomeEnabled(true)
|
|
|
|
}
|
|
|
|
|
2022-02-25 18:57:31 +01:00
|
|
|
if (supportFragmentManager.findFragmentById(R.id.fragmentContainer) == null) {
|
|
|
|
supportFragmentManager.commit {
|
|
|
|
val fragment = if (kind == Kind.TAG) {
|
|
|
|
TimelineFragment.newHashtagInstance(listOf(hashtag!!))
|
|
|
|
} else {
|
|
|
|
TimelineFragment.newInstance(kind, listId)
|
|
|
|
}
|
|
|
|
replace(R.id.fragmentContainer, fragment)
|
|
|
|
}
|
2019-11-19 10:15:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun androidInjector() = dispatchingAndroidInjector
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
private const val EXTRA_KIND = "kind"
|
2022-02-25 18:57:31 +01:00
|
|
|
private const val EXTRA_LIST_ID = "id"
|
|
|
|
private const val EXTRA_HASHTAG = "tag"
|
2019-11-19 10:15:32 +01:00
|
|
|
|
|
|
|
fun newFavouritesIntent(context: Context) =
|
2021-06-28 21:13:24 +02:00
|
|
|
Intent(context, StatusListActivity::class.java).apply {
|
|
|
|
putExtra(EXTRA_KIND, Kind.FAVOURITES.name)
|
|
|
|
}
|
2019-11-19 10:15:32 +01:00
|
|
|
|
|
|
|
fun newBookmarksIntent(context: Context) =
|
2021-06-28 21:13:24 +02:00
|
|
|
Intent(context, StatusListActivity::class.java).apply {
|
|
|
|
putExtra(EXTRA_KIND, Kind.BOOKMARKS.name)
|
|
|
|
}
|
2022-02-25 18:57:31 +01:00
|
|
|
|
|
|
|
fun newListIntent(context: Context, listId: String) =
|
|
|
|
Intent(context, StatusListActivity::class.java).apply {
|
|
|
|
putExtra(EXTRA_KIND, Kind.LIST.name)
|
|
|
|
putExtra(EXTRA_LIST_ID, listId)
|
|
|
|
}
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
fun newHashtagIntent(context: Context, hashtag: String) =
|
|
|
|
Intent(context, StatusListActivity::class.java).apply {
|
|
|
|
putExtra(EXTRA_KIND, Kind.TAG.name)
|
|
|
|
putExtra(EXTRA_HASHTAG, hashtag)
|
|
|
|
}
|
2019-11-19 10:15:32 +01:00
|
|
|
}
|
|
|
|
}
|