2019-02-12 19:22:37 +01: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-10-19 14:57:55 +02:00
|
|
|
import android.graphics.Color
|
2019-02-12 19:22:37 +01:00
|
|
|
import android.os.Bundle
|
2020-10-19 14:57:55 +02:00
|
|
|
import android.view.View
|
2020-05-15 22:10:29 +02:00
|
|
|
import android.widget.FrameLayout
|
2022-11-04 19:22:38 +01:00
|
|
|
import androidx.activity.OnBackPressedCallback
|
2019-03-24 08:59:55 +01:00
|
|
|
import androidx.appcompat.app.AlertDialog
|
|
|
|
import androidx.appcompat.widget.AppCompatEditText
|
2020-05-15 22:10:29 +02:00
|
|
|
import androidx.core.view.updatePadding
|
2023-03-10 20:27:24 +01:00
|
|
|
import androidx.core.widget.doOnTextChanged
|
2022-05-18 18:45:35 +02:00
|
|
|
import androidx.lifecycle.lifecycleScope
|
2019-02-12 19:22:37 +01:00
|
|
|
import androidx.recyclerview.widget.DividerItemDecoration
|
|
|
|
import androidx.recyclerview.widget.ItemTouchHelper
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
2020-10-19 14:57:55 +02:00
|
|
|
import androidx.transition.TransitionManager
|
2020-05-15 22:10:29 +02:00
|
|
|
import at.connyduck.sparkbutton.helpers.Utils
|
2020-10-19 14:57:55 +02:00
|
|
|
import com.google.android.material.transition.MaterialArcMotion
|
|
|
|
import com.google.android.material.transition.MaterialContainerTransform
|
2019-02-12 19:22:37 +01:00
|
|
|
import com.keylesspalace.tusky.adapter.ItemInteractionListener
|
|
|
|
import com.keylesspalace.tusky.adapter.TabAdapter
|
|
|
|
import com.keylesspalace.tusky.appstore.EventHub
|
|
|
|
import com.keylesspalace.tusky.appstore.MainTabsChangedEvent
|
2024-01-03 21:17:03 +01:00
|
|
|
import com.keylesspalace.tusky.components.account.list.ListSelectionFragment
|
2021-03-07 19:05:51 +01:00
|
|
|
import com.keylesspalace.tusky.databinding.ActivityTabPreferenceBinding
|
2019-02-12 19:22:37 +01:00
|
|
|
import com.keylesspalace.tusky.di.Injectable
|
Adjust list UX for platform consistency (#3142)
Most lists in the app use (explicitly or implicitly) platform metrics for dimensions, text size, colour, and so on, possibly via styles.
A few don't, inadvertently using the user's setting for status text size
Fix these, and simplify code where possible.
- Use android attributes for padding and height, for consistent UX.
- Remove explicit usage of app:tabTextAppearance, rely on the style.
- Remove ListSelectionAdapter and item_picker_list.xml, and adjust TabPreferenceActivity to use an ArrayAdapter with simple_list_item_1.xml
- Simplify item_followed_hashtag.xml, consistent with item_list.xml.
Fixes https://github.com/tuskyapp/Tusky/issues/3131
2023-06-29 18:36:19 +02:00
|
|
|
import com.keylesspalace.tusky.entity.MastoList
|
2019-12-02 16:53:24 +01:00
|
|
|
import com.keylesspalace.tusky.network.MastodonApi
|
2023-02-20 20:14:54 +01:00
|
|
|
import com.keylesspalace.tusky.util.unsafeLazy
|
2021-03-07 19:05:51 +01:00
|
|
|
import com.keylesspalace.tusky.util.viewBinding
|
2019-02-12 19:22:37 +01:00
|
|
|
import com.keylesspalace.tusky.util.visible
|
2024-01-03 21:17:03 +01:00
|
|
|
import dagger.android.DispatchingAndroidInjector
|
|
|
|
import dagger.android.HasAndroidInjector
|
2023-03-13 13:16:58 +01:00
|
|
|
import kotlinx.coroutines.Dispatchers
|
2022-05-18 18:45:35 +02:00
|
|
|
import kotlinx.coroutines.launch
|
2019-03-24 08:59:55 +01:00
|
|
|
import java.util.regex.Pattern
|
2019-02-12 19:22:37 +01:00
|
|
|
import javax.inject.Inject
|
|
|
|
|
2024-01-03 21:17:03 +01:00
|
|
|
class TabPreferenceActivity : BaseActivity(), Injectable, HasAndroidInjector, ItemInteractionListener, ListSelectionFragment.ListSelectionListener {
|
2019-02-12 19:22:37 +01:00
|
|
|
|
2019-12-02 16:53:24 +01:00
|
|
|
@Inject
|
|
|
|
lateinit var mastodonApi: MastodonApi
|
2023-03-13 13:16:39 +01:00
|
|
|
|
2019-02-12 19:22:37 +01:00
|
|
|
@Inject
|
|
|
|
lateinit var eventHub: EventHub
|
|
|
|
|
2024-01-03 21:17:03 +01:00
|
|
|
@Inject
|
|
|
|
lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Any>
|
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
private val binding by viewBinding(ActivityTabPreferenceBinding::inflate)
|
|
|
|
|
2019-02-12 19:22:37 +01:00
|
|
|
private lateinit var currentTabs: MutableList<TabData>
|
|
|
|
private lateinit var currentTabsAdapter: TabAdapter
|
|
|
|
private lateinit var touchHelper: ItemTouchHelper
|
|
|
|
private lateinit var addTabAdapter: TabAdapter
|
|
|
|
|
2019-03-13 09:32:59 +01:00
|
|
|
private var tabsChanged = false
|
|
|
|
|
2023-02-20 20:14:54 +01:00
|
|
|
private val selectedItemElevation by unsafeLazy { resources.getDimension(R.dimen.selected_drag_item_elevation) }
|
2019-02-12 19:22:37 +01:00
|
|
|
|
2023-02-20 20:14:54 +01:00
|
|
|
private val hashtagRegex by unsafeLazy { Pattern.compile("([\\w_]*[\\p{Alpha}_][\\w_]*)", Pattern.CASE_INSENSITIVE) }
|
2019-03-24 08:59:55 +01:00
|
|
|
|
2022-11-04 19:22:38 +01:00
|
|
|
private val onFabDismissedCallback = object : OnBackPressedCallback(false) {
|
|
|
|
override fun handleOnBackPressed() {
|
|
|
|
toggleFab(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-12 19:22:37 +01:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
setContentView(binding.root)
|
2019-02-12 19:22:37 +01:00
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
setSupportActionBar(binding.includedToolbar.toolbar)
|
2019-02-12 19:22:37 +01:00
|
|
|
|
|
|
|
supportActionBar?.apply {
|
|
|
|
setTitle(R.string.title_tab_preferences)
|
|
|
|
setDisplayHomeAsUpEnabled(true)
|
|
|
|
setDisplayShowHomeEnabled(true)
|
|
|
|
}
|
|
|
|
|
2020-09-02 12:28:13 +02:00
|
|
|
currentTabs = accountManager.activeAccount?.tabPreferences.orEmpty().toMutableList()
|
2019-12-19 18:35:55 +01:00
|
|
|
currentTabsAdapter = TabAdapter(currentTabs, false, this, currentTabs.size <= MIN_TAB_COUNT)
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.currentTabsRecyclerView.adapter = currentTabsAdapter
|
|
|
|
binding.currentTabsRecyclerView.layoutManager = LinearLayoutManager(this)
|
|
|
|
binding.currentTabsRecyclerView.addItemDecoration(DividerItemDecoration(this, LinearLayoutManager.VERTICAL))
|
2019-02-12 19:22:37 +01:00
|
|
|
|
|
|
|
addTabAdapter = TabAdapter(listOf(createTabDataFromId(DIRECT)), true, this)
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.addTabRecyclerView.adapter = addTabAdapter
|
|
|
|
binding.addTabRecyclerView.layoutManager = LinearLayoutManager(this)
|
2019-02-12 19:22:37 +01:00
|
|
|
|
2019-03-24 08:59:55 +01:00
|
|
|
touchHelper = ItemTouchHelper(object : ItemTouchHelper.Callback() {
|
2019-02-12 19:22:37 +01:00
|
|
|
override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int {
|
|
|
|
return makeMovementFlags(ItemTouchHelper.UP or ItemTouchHelper.DOWN, ItemTouchHelper.END)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun isLongPressDragEnabled(): Boolean {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun isItemViewSwipeEnabled(): Boolean {
|
|
|
|
return MIN_TAB_COUNT < currentTabs.size
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean {
|
2021-04-10 20:30:44 +02:00
|
|
|
val temp = currentTabs[viewHolder.bindingAdapterPosition]
|
|
|
|
currentTabs[viewHolder.bindingAdapterPosition] = currentTabs[target.bindingAdapterPosition]
|
|
|
|
currentTabs[target.bindingAdapterPosition] = temp
|
2019-02-12 19:22:37 +01:00
|
|
|
|
2021-04-10 20:30:44 +02:00
|
|
|
currentTabsAdapter.notifyItemMoved(viewHolder.bindingAdapterPosition, target.bindingAdapterPosition)
|
2019-02-12 19:22:37 +01:00
|
|
|
saveTabs()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
|
2021-04-10 20:30:44 +02:00
|
|
|
onTabRemoved(viewHolder.bindingAdapterPosition)
|
2019-02-12 19:22:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
|
2019-03-24 08:59:55 +01:00
|
|
|
if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
|
2019-02-12 19:22:37 +01:00
|
|
|
viewHolder?.itemView?.elevation = selectedItemElevation
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) {
|
|
|
|
super.clearView(recyclerView, viewHolder)
|
|
|
|
viewHolder.itemView.elevation = 0f
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
touchHelper.attachToRecyclerView(binding.currentTabsRecyclerView)
|
2019-02-12 19:22:37 +01:00
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.actionButton.setOnClickListener {
|
2020-10-19 14:57:55 +02:00
|
|
|
toggleFab(true)
|
2019-02-12 19:22:37 +01:00
|
|
|
}
|
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.scrim.setOnClickListener {
|
2020-10-19 14:57:55 +02:00
|
|
|
toggleFab(false)
|
2019-02-12 19:22:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
updateAvailableTabs()
|
2022-11-04 19:22:38 +01:00
|
|
|
|
|
|
|
onBackPressedDispatcher.addCallback(onFabDismissedCallback)
|
2019-02-12 19:22:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onTabAdded(tab: TabData) {
|
2020-10-19 14:57:55 +02:00
|
|
|
toggleFab(false)
|
2019-03-24 08:59:55 +01:00
|
|
|
|
|
|
|
if (tab.id == HASHTAG) {
|
2020-05-15 22:10:29 +02:00
|
|
|
showAddHashtagDialog()
|
2019-03-24 08:59:55 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-12-02 16:53:24 +01:00
|
|
|
if (tab.id == LIST) {
|
|
|
|
showSelectListDialog()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-02-12 19:22:37 +01:00
|
|
|
currentTabs.add(tab)
|
|
|
|
currentTabsAdapter.notifyItemInserted(currentTabs.size - 1)
|
|
|
|
updateAvailableTabs()
|
|
|
|
saveTabs()
|
|
|
|
}
|
|
|
|
|
2019-12-19 18:35:55 +01:00
|
|
|
override fun onTabRemoved(position: Int) {
|
|
|
|
currentTabs.removeAt(position)
|
|
|
|
currentTabsAdapter.notifyItemRemoved(position)
|
|
|
|
updateAvailableTabs()
|
|
|
|
saveTabs()
|
|
|
|
}
|
|
|
|
|
2020-09-02 12:28:13 +02:00
|
|
|
override fun onActionChipClicked(tab: TabData, tabPosition: Int) {
|
|
|
|
showAddHashtagDialog(tab, tabPosition)
|
2019-03-24 08:59:55 +01:00
|
|
|
}
|
|
|
|
|
2020-09-02 12:28:13 +02:00
|
|
|
override fun onChipClicked(tab: TabData, tabPosition: Int, chipPosition: Int) {
|
2020-05-15 22:10:29 +02:00
|
|
|
val newArguments = tab.arguments.filterIndexed { i, _ -> i != chipPosition }
|
|
|
|
val newTab = tab.copy(arguments = newArguments)
|
2020-09-02 12:28:13 +02:00
|
|
|
currentTabs[tabPosition] = newTab
|
|
|
|
saveTabs()
|
2020-05-15 22:10:29 +02:00
|
|
|
|
2020-09-02 12:28:13 +02:00
|
|
|
currentTabsAdapter.notifyItemChanged(tabPosition)
|
2020-05-15 22:10:29 +02:00
|
|
|
}
|
|
|
|
|
2020-10-19 14:57:55 +02:00
|
|
|
private fun toggleFab(expand: Boolean) {
|
|
|
|
val transition = MaterialContainerTransform().apply {
|
2021-03-07 19:05:51 +01:00
|
|
|
startView = if (expand) binding.actionButton else binding.sheet
|
|
|
|
val endView: View = if (expand) binding.sheet else binding.actionButton
|
2020-10-19 14:57:55 +02:00
|
|
|
this.endView = endView
|
|
|
|
addTarget(endView)
|
|
|
|
scrimColor = Color.TRANSPARENT
|
|
|
|
setPathMotion(MaterialArcMotion())
|
|
|
|
}
|
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
TransitionManager.beginDelayedTransition(binding.root, transition)
|
|
|
|
binding.actionButton.visible(!expand)
|
|
|
|
binding.sheet.visible(expand)
|
|
|
|
binding.scrim.visible(expand)
|
2022-11-04 19:22:38 +01:00
|
|
|
|
|
|
|
onFabDismissedCallback.isEnabled = expand
|
2020-10-19 14:57:55 +02:00
|
|
|
}
|
|
|
|
|
2020-09-02 12:28:13 +02:00
|
|
|
private fun showAddHashtagDialog(tab: TabData? = null, tabPosition: Int = 0) {
|
2020-05-15 22:10:29 +02:00
|
|
|
val frameLayout = FrameLayout(this)
|
|
|
|
val padding = Utils.dpToPx(this, 8)
|
|
|
|
frameLayout.updatePadding(left = padding, right = padding)
|
2019-03-24 08:59:55 +01:00
|
|
|
|
|
|
|
val editText = AppCompatEditText(this)
|
|
|
|
editText.setHint(R.string.edit_hashtag_hint)
|
|
|
|
editText.setText("")
|
2020-05-15 22:10:29 +02:00
|
|
|
frameLayout.addView(editText)
|
2019-03-24 08:59:55 +01:00
|
|
|
|
|
|
|
val dialog = AlertDialog.Builder(this)
|
2021-06-28 21:13:24 +02:00
|
|
|
.setTitle(R.string.add_hashtag_title)
|
|
|
|
.setView(frameLayout)
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.setPositiveButton(R.string.action_save) { _, _ ->
|
|
|
|
val input = editText.text.toString().trim()
|
|
|
|
if (tab == null) {
|
|
|
|
val newTab = createTabDataFromId(HASHTAG, listOf(input))
|
|
|
|
currentTabs.add(newTab)
|
|
|
|
currentTabsAdapter.notifyItemInserted(currentTabs.size - 1)
|
|
|
|
} else {
|
|
|
|
val newTab = tab.copy(arguments = tab.arguments + input)
|
|
|
|
currentTabs[tabPosition] = newTab
|
|
|
|
|
|
|
|
currentTabsAdapter.notifyItemChanged(tabPosition)
|
2019-03-24 08:59:55 +01:00
|
|
|
}
|
2021-06-28 21:13:24 +02:00
|
|
|
|
|
|
|
updateAvailableTabs()
|
|
|
|
saveTabs()
|
|
|
|
}
|
|
|
|
.create()
|
2019-03-24 08:59:55 +01:00
|
|
|
|
2023-03-10 20:27:24 +01:00
|
|
|
editText.doOnTextChanged { s, _, _, _ ->
|
2019-03-28 21:10:53 +01:00
|
|
|
dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = validateHashtag(s)
|
2019-03-24 08:59:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
dialog.show()
|
2019-03-28 21:10:53 +01:00
|
|
|
dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = validateHashtag(editText.text)
|
2019-03-24 08:59:55 +01:00
|
|
|
editText.requestFocus()
|
|
|
|
}
|
|
|
|
|
2024-01-03 21:17:03 +01:00
|
|
|
private var listSelectDialog: ListSelectionFragment? = null
|
2023-03-30 21:23:08 +02:00
|
|
|
|
2024-01-03 21:17:03 +01:00
|
|
|
private fun showSelectListDialog() {
|
|
|
|
listSelectDialog = ListSelectionFragment.newInstance(null)
|
|
|
|
listSelectDialog?.show(supportFragmentManager, null)
|
2023-03-30 21:23:08 +02:00
|
|
|
|
2024-01-03 21:17:03 +01:00
|
|
|
return
|
2023-03-30 21:23:08 +02:00
|
|
|
}
|
2019-12-02 16:53:24 +01:00
|
|
|
|
2024-01-03 21:17:03 +01:00
|
|
|
override fun onListSelected(list: MastoList) {
|
|
|
|
listSelectDialog?.dismiss()
|
|
|
|
listSelectDialog = null
|
|
|
|
|
|
|
|
val newTab = createTabDataFromId(LIST, listOf(list.id, list.title))
|
|
|
|
currentTabs.add(newTab)
|
|
|
|
currentTabsAdapter.notifyItemInserted(currentTabs.size - 1)
|
|
|
|
updateAvailableTabs()
|
|
|
|
saveTabs()
|
2019-12-02 16:53:24 +01:00
|
|
|
}
|
|
|
|
|
2019-03-28 21:10:53 +01:00
|
|
|
private fun validateHashtag(input: CharSequence?): Boolean {
|
|
|
|
val trimmedInput = input?.trim() ?: ""
|
|
|
|
return trimmedInput.isNotEmpty() && hashtagRegex.matcher(trimmedInput).matches()
|
|
|
|
}
|
|
|
|
|
2019-02-12 19:22:37 +01:00
|
|
|
private fun updateAvailableTabs() {
|
|
|
|
val addableTabs: MutableList<TabData> = mutableListOf()
|
|
|
|
|
|
|
|
val homeTab = createTabDataFromId(HOME)
|
2019-03-24 08:59:55 +01:00
|
|
|
if (!currentTabs.contains(homeTab)) {
|
2019-02-12 19:22:37 +01:00
|
|
|
addableTabs.add(homeTab)
|
|
|
|
}
|
|
|
|
val notificationTab = createTabDataFromId(NOTIFICATIONS)
|
2019-03-24 08:59:55 +01:00
|
|
|
if (!currentTabs.contains(notificationTab)) {
|
2019-02-12 19:22:37 +01:00
|
|
|
addableTabs.add(notificationTab)
|
|
|
|
}
|
|
|
|
val localTab = createTabDataFromId(LOCAL)
|
2019-03-24 08:59:55 +01:00
|
|
|
if (!currentTabs.contains(localTab)) {
|
2019-02-12 19:22:37 +01:00
|
|
|
addableTabs.add(localTab)
|
|
|
|
}
|
|
|
|
val federatedTab = createTabDataFromId(FEDERATED)
|
2019-03-24 08:59:55 +01:00
|
|
|
if (!currentTabs.contains(federatedTab)) {
|
2019-02-12 19:22:37 +01:00
|
|
|
addableTabs.add(federatedTab)
|
|
|
|
}
|
|
|
|
val directMessagesTab = createTabDataFromId(DIRECT)
|
2019-03-24 08:59:55 +01:00
|
|
|
if (!currentTabs.contains(directMessagesTab)) {
|
2019-02-12 19:22:37 +01:00
|
|
|
addableTabs.add(directMessagesTab)
|
|
|
|
}
|
2023-08-19 12:54:35 +02:00
|
|
|
val trendingTagsTab = createTabDataFromId(TRENDING_TAGS)
|
|
|
|
if (!currentTabs.contains(trendingTagsTab)) {
|
|
|
|
addableTabs.add(trendingTagsTab)
|
Add trending tags (#3149)
* Add initial feature for viewing trending graphs. Currently only views hash tag trends.
Contains API additions, tab additions and a set of trending components.
* Add clickable system through a LinkListener. Duplicates a little code from SFragment.
* Add accessibility description.
* The background for the graph should match the background for black theme too.
* Add error handling through a state flow system using existing code as an example.
* Graphing: Use a primary and a secondary line. Remove under line fill. Apply line thickness. Dotted end of line.
* Trending changes: New layout for trending: Cell. Use ViewBinding. Add padding to RecyclerView to stop the FAB from hiding content. Multiple bugs in GraphView resolved. Wide (landscape, for example) will show 4 columns, portrait will show 2. Remove unused base holder class. ViewModel invalidate scoping changed. Some renaming to variables made. For uses and accounts, use longs. These could be big numbers eventually. TagViewHolder renamed to TrendingTagViewHolder.
* Trending changes: Remove old layout. Update cell textsizes and use proper string. Remove bad comment.
* Trending changes: Refresh the main drawer when the tabs are edited. This will allow the trending item to toggle.
* Trending changes: Add a trending activity to be able to view the trending data from the main drawer.
* Trending changes: The title text should be changed to Trending Hashtags.
* Trending changes: Add meta color to draw axis etc. Draw the date boundaries on the graph. Remove dates from each cell and place them in the list as a header. Graphs should be proportional to the highest historical value. Add a new interface to control whether the FAB should be visible (important when switching tabs, the state is lost). Add header to the adapter and viewdata structures. Add QOL extensions for getting the dates from history.
* Trending changes: Refresh FAB through the main activity and FabFragment interface. Trending has no FAB.
* Trending changes: Make graph proportional to the highest usage value. Fixes to the graph ratio calculations.
* Trending changes: KtLintFix
* Trending changes: Remove accidental build gradle change. Remove trending cases. Remove unused progress. Set drawer button addition explicitly to false, leaving the code there for future issue #3010. Remove unnecessary arguments for intent. Remove media preview preferences, there is nothing to preview. No padding between hashtag symbol and text. Do not ellipsize hashtags.
* Trending changes: Use bottomsheet slide in animation helper for opening the hashtag intent. Remove explicit layout height from the XML and apply it to the view holder itself. The height was not being respected in XML.
* Use some platform standards for styling
- Align on an 8dp grid
- Use android:attr for paddingStart and paddingEnd
- Use textAppearanceListItem variants
- Adjust constraints to handle different size containers
* Correct lineWidth calculations
Previous code didn't convert the value to pixels, so it was always displaying
as a hairline stroke, irrespective of the value in the layout file.
While I'm here, rename from lineThickness to lineWidth, to be consistent
with parameters like strokeWidth.
* Does not need to inherit from FabFragment
* Rename to TrendingAdapter
"Paging" in the adapter name is a misnomer here
* Clean up comments, use full class name as tag
* Simplify TrendingViewModel
- Remove unncessary properties
- Fetch tags and map in invalidate()
- emptyList() instead of listOf() for clarity
* Remove line dividers, use X-axis to separate content
Experiment with UI -- instead of dividers between each item, draw an explicit
x-axis for each chart, and add a little more vertical padding, to see if that
provides a cleaner separation between the content
* Adjust date format
- Show day and year
- Use platform attributes for size
* Locale-aware format of numbers
Format numbers < 100,000 by inserting locale-aware separators. Numbers larger
are scaled and have K, M, G, ... etc suffix appended.
* Prevent a crash if viewData is empty
Don't access viewData without first checking if it's empty. This can be the
case if the server returned an empty list for some reason, or the data has
been filtered.
* Filter out tags the user has filtered from their home timeline
Invalidate the list if the user's preferences change, as that may indicate
they've changed their filters.
* Experiment with alternative layout
* Set chart height to 160dp to align to an 8dp grid
* Draw ticks that are 5% the height of the x-axis
* Legend adjustments
- Use tuskyblue for the ticks
- Wrap legend components in a layout so they can have a dedicated background
- Use a 60% transparent background for the legend to retain legibility
if lines go under it
* Bezier curves, shorter cell height
* More tweaks
- List tags in order of popularity, most popular first
- Make it clear that uses/accounts in the legend are totals, not current
- Show current values at end of the chart
* Hide FAB
* Fix crash, it's not always hosted in an ActionButtonActivity
* Arrange totals vertically in landscape layout
* Always add the Trending drawer menu if it's not a tab
* Revert unrelated whitespace changes
* One more whitespace revert
---------
Co-authored-by: Nik Clayton <nik@ngo.org.uk>
2023-02-14 19:52:11 +01:00
|
|
|
}
|
2023-08-24 16:21:43 +02:00
|
|
|
val bookmarksTab = createTabDataFromId(BOOKMARKS)
|
|
|
|
if (!currentTabs.contains(trendingTagsTab)) {
|
|
|
|
addableTabs.add(bookmarksTab)
|
|
|
|
}
|
2023-09-14 22:37:41 +02:00
|
|
|
val trendingStatusesTab = createTabDataFromId(TRENDING_STATUSES)
|
|
|
|
if (!currentTabs.contains(trendingStatusesTab)) {
|
|
|
|
addableTabs.add(trendingStatusesTab)
|
|
|
|
}
|
2019-02-12 19:22:37 +01:00
|
|
|
|
2019-03-24 08:59:55 +01:00
|
|
|
addableTabs.add(createTabDataFromId(HASHTAG))
|
2019-12-02 16:53:24 +01:00
|
|
|
addableTabs.add(createTabDataFromId(LIST))
|
2019-03-24 08:59:55 +01:00
|
|
|
|
2019-02-12 19:22:37 +01:00
|
|
|
addTabAdapter.updateData(addableTabs)
|
2020-04-06 11:46:38 +02:00
|
|
|
currentTabsAdapter.setRemoveButtonVisible(currentTabs.size > MIN_TAB_COUNT)
|
2019-02-12 19:22:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onStartDelete(viewHolder: RecyclerView.ViewHolder) {
|
|
|
|
touchHelper.startSwipe(viewHolder)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onStartDrag(viewHolder: RecyclerView.ViewHolder) {
|
|
|
|
touchHelper.startDrag(viewHolder)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun saveTabs() {
|
|
|
|
accountManager.activeAccount?.let {
|
2023-03-13 13:16:58 +01:00
|
|
|
lifecycleScope.launch(Dispatchers.IO) {
|
2019-02-13 19:20:43 +01:00
|
|
|
it.tabPreferences = currentTabs
|
|
|
|
accountManager.saveAccount(it)
|
|
|
|
}
|
2019-02-12 19:22:37 +01:00
|
|
|
}
|
2019-03-13 09:32:59 +01:00
|
|
|
tabsChanged = true
|
2019-02-12 19:22:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onPause() {
|
|
|
|
super.onPause()
|
2019-03-24 08:59:55 +01:00
|
|
|
if (tabsChanged) {
|
2023-03-18 10:11:47 +01:00
|
|
|
lifecycleScope.launch {
|
|
|
|
eventHub.dispatch(MainTabsChangedEvent(currentTabs))
|
|
|
|
}
|
2019-03-13 09:32:59 +01:00
|
|
|
}
|
2019-02-12 19:22:37 +01:00
|
|
|
}
|
|
|
|
|
2024-01-03 21:17:03 +01:00
|
|
|
override fun androidInjector() = dispatchingAndroidInjector
|
|
|
|
|
2019-02-12 19:22:37 +01:00
|
|
|
companion object {
|
|
|
|
private const val MIN_TAB_COUNT = 2
|
|
|
|
}
|
|
|
|
}
|