Yuito-app-android/app/src/main/java/com/keylesspalace/tusky/components/trending/viewmodel/TrendingTagsViewModel.kt

121 lines
4.7 KiB
Kotlin
Raw Normal View History

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
/* Copyright 2023 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>. */
package com.keylesspalace.tusky.components.trending.viewmodel
import android.util.Log
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
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import at.connyduck.calladapter.networkresult.fold
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
import com.keylesspalace.tusky.appstore.EventHub
import com.keylesspalace.tusky.appstore.PreferenceChangedEvent
import com.keylesspalace.tusky.entity.Filter
import com.keylesspalace.tusky.entity.end
import com.keylesspalace.tusky.entity.start
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
import com.keylesspalace.tusky.network.MastodonApi
import com.keylesspalace.tusky.util.toViewData
import com.keylesspalace.tusky.viewdata.TrendingViewData
import kotlinx.coroutines.async
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.launch
import java.io.IOException
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
import javax.inject.Inject
class TrendingTagsViewModel @Inject constructor(
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
private val mastodonApi: MastodonApi,
private val eventHub: EventHub
) : ViewModel() {
enum class LoadingState {
INITIAL, LOADING, REFRESHING, LOADED, ERROR_NETWORK, ERROR_OTHER
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
}
data class TrendingTagsUiState(
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
val trendingViewData: List<TrendingViewData>,
val loadingState: LoadingState
)
val uiState: Flow<TrendingTagsUiState> get() = _uiState
private val _uiState = MutableStateFlow(TrendingTagsUiState(listOf(), LoadingState.INITIAL))
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
init {
invalidate()
// Collect PreferenceChangedEvent, FiltersActivity creates them when a filter is created
// or deleted. Unfortunately, there's nothing in the event to determine if it's a filter
// that was modified, so refresh on every preference change.
viewModelScope.launch {
eventHub.events
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
.filterIsInstance<PreferenceChangedEvent>()
.collect {
invalidate()
}
}
}
/**
* Invalidate the current list of trending tags and fetch a new list.
*
* A tag is excluded if it is filtered by the user on their home timeline.
*/
fun invalidate(refresh: Boolean = false) = viewModelScope.launch {
if (refresh) {
_uiState.value = TrendingTagsUiState(emptyList(), LoadingState.REFRESHING)
} else {
_uiState.value = TrendingTagsUiState(emptyList(), LoadingState.LOADING)
}
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
val deferredFilters = async { mastodonApi.getFilters() }
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
mastodonApi.trendingTags().fold(
{ tagResponse ->
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
val firstTag = tagResponse.firstOrNull()
_uiState.value = if (firstTag == null) {
TrendingTagsUiState(emptyList(), LoadingState.LOADED)
} else {
val homeFilters = deferredFilters.await().getOrNull()?.filter { filter ->
filter.context.contains(Filter.Kind.HOME.kind)
}
val tags = tagResponse
.filter { tag ->
homeFilters?.none { filter ->
filter.keywords.any { keyword -> keyword.keyword.equals(tag.name, ignoreCase = true) }
} ?: false
}
.sortedByDescending { tag -> tag.history.sumOf { it.uses.toLongOrNull() ?: 0 } }
.toViewData()
val header = TrendingViewData.Header(firstTag.start(), firstTag.end())
TrendingTagsUiState(listOf(header) + tags, LoadingState.LOADED)
}
},
{ error ->
Log.w(TAG, "failed loading trending tags", error)
if (error is IOException) {
_uiState.value = TrendingTagsUiState(emptyList(), LoadingState.ERROR_NETWORK)
} else {
_uiState.value = TrendingTagsUiState(emptyList(), LoadingState.ERROR_OTHER)
}
}
)
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
}
companion object {
private const val TAG = "TrendingViewModel"
}
}