2019-02-13 05:22:37 +11:00
|
|
|
/* Copyright 2019 Conny Duck
|
|
|
|
*
|
|
|
|
* 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>. */
|
|
|
|
|
|
|
|
package com.keylesspalace.tusky
|
|
|
|
|
2020-06-18 19:04:53 +10:00
|
|
|
import android.content.Context
|
2019-02-13 05:22:37 +11:00
|
|
|
import androidx.annotation.DrawableRes
|
|
|
|
import androidx.annotation.StringRes
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
import com.keylesspalace.tusky.components.conversation.ConversationsFragment
|
|
|
|
import com.keylesspalace.tusky.fragment.NotificationsFragment
|
2021-06-12 04:15:40 +10:00
|
|
|
import com.keylesspalace.tusky.components.timeline.TimelineFragment
|
|
|
|
import com.keylesspalace.tusky.components.timeline.TimelineViewModel
|
2019-02-13 05:22:37 +11:00
|
|
|
|
|
|
|
/** this would be a good case for a sealed class, but that does not work nice with Room */
|
|
|
|
|
|
|
|
const val HOME = "Home"
|
|
|
|
const val NOTIFICATIONS = "Notifications"
|
|
|
|
const val LOCAL = "Local"
|
|
|
|
const val FEDERATED = "Federated"
|
|
|
|
const val DIRECT = "Direct"
|
2019-03-24 18:59:55 +11:00
|
|
|
const val HASHTAG = "Hashtag"
|
2019-12-03 02:53:24 +11:00
|
|
|
const val LIST = "List"
|
2019-02-13 05:22:37 +11:00
|
|
|
|
|
|
|
data class TabData(val id: String,
|
|
|
|
@StringRes val text: Int,
|
|
|
|
@DrawableRes val icon: Int,
|
2019-03-24 18:59:55 +11:00
|
|
|
val fragment: (List<String>) -> Fragment,
|
2020-06-18 19:04:53 +10:00
|
|
|
val arguments: List<String> = emptyList(),
|
|
|
|
val title: (Context) -> String = { context -> context.getString(text)}
|
|
|
|
)
|
2019-02-13 05:22:37 +11:00
|
|
|
|
2019-03-24 18:59:55 +11:00
|
|
|
fun createTabDataFromId(id: String, arguments: List<String> = emptyList()): TabData {
|
2019-02-13 05:22:37 +11:00
|
|
|
return when (id) {
|
2020-06-18 19:04:53 +10:00
|
|
|
HOME -> TabData(
|
|
|
|
HOME,
|
|
|
|
R.string.title_home,
|
|
|
|
R.drawable.ic_home_24dp,
|
2021-06-12 04:15:40 +10:00
|
|
|
{ TimelineFragment.newInstance(TimelineViewModel.Kind.HOME) }
|
2020-06-18 19:04:53 +10:00
|
|
|
)
|
|
|
|
NOTIFICATIONS -> TabData(
|
|
|
|
NOTIFICATIONS,
|
|
|
|
R.string.title_notifications,
|
|
|
|
R.drawable.ic_notifications_24dp,
|
|
|
|
{ NotificationsFragment.newInstance() }
|
|
|
|
)
|
|
|
|
LOCAL -> TabData(
|
|
|
|
LOCAL,
|
|
|
|
R.string.title_public_local,
|
|
|
|
R.drawable.ic_local_24dp,
|
2021-06-12 04:15:40 +10:00
|
|
|
{ TimelineFragment.newInstance(TimelineViewModel.Kind.PUBLIC_LOCAL) }
|
2020-06-18 19:04:53 +10:00
|
|
|
)
|
|
|
|
FEDERATED -> TabData(
|
|
|
|
FEDERATED,
|
|
|
|
R.string.title_public_federated,
|
|
|
|
R.drawable.ic_public_24dp,
|
2021-06-12 04:15:40 +10:00
|
|
|
{ TimelineFragment.newInstance(TimelineViewModel.Kind.PUBLIC_FEDERATED) }
|
2020-06-18 19:04:53 +10:00
|
|
|
)
|
|
|
|
DIRECT -> TabData(
|
|
|
|
DIRECT,
|
|
|
|
R.string.title_direct_messages,
|
|
|
|
R.drawable.ic_reblog_direct_24dp,
|
|
|
|
{ ConversationsFragment.newInstance() }
|
|
|
|
)
|
|
|
|
HASHTAG -> TabData(
|
|
|
|
HASHTAG,
|
|
|
|
R.string.hashtags,
|
|
|
|
R.drawable.ic_hashtag,
|
|
|
|
{ args -> TimelineFragment.newHashtagInstance(args) },
|
|
|
|
arguments,
|
|
|
|
{ context -> arguments.joinToString(separator = " ") { context.getString(R.string.title_tag, it) }}
|
|
|
|
)
|
|
|
|
LIST -> TabData(
|
|
|
|
LIST,
|
|
|
|
R.string.list,
|
|
|
|
R.drawable.ic_list,
|
2021-06-12 04:15:40 +10:00
|
|
|
{ args -> TimelineFragment.newInstance(TimelineViewModel.Kind.LIST, args.getOrNull(0).orEmpty()) },
|
2020-06-18 19:04:53 +10:00
|
|
|
arguments,
|
|
|
|
{ arguments.getOrNull(1).orEmpty() }
|
|
|
|
)
|
2019-02-13 05:22:37 +11:00
|
|
|
else -> throw IllegalArgumentException("unknown tab type")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun defaultTabs(): List<TabData> {
|
|
|
|
return listOf(
|
|
|
|
createTabDataFromId(HOME),
|
|
|
|
createTabDataFromId(NOTIFICATIONS),
|
|
|
|
createTabDataFromId(LOCAL),
|
|
|
|
createTabDataFromId(FEDERATED)
|
|
|
|
)
|
|
|
|
}
|