Yuito-app-android/app/src/main/java/com/keylesspalace/tusky/components/preference/PreferencesFragment.kt

406 lines
17 KiB
Kotlin
Raw Normal View History

/* Copyright 2018 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.components.preference
import android.os.Bundle
2018-12-18 22:05:33 +01:00
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.components.compose.ComposeActivity
import com.keylesspalace.tusky.components.compose.ComposeActivity.ComposeOptions
2021-01-03 06:42:50 +01:00
import com.keylesspalace.tusky.db.AccountManager
import com.keylesspalace.tusky.di.Injectable
import com.keylesspalace.tusky.entity.Notification
import com.keylesspalace.tusky.settings.AppTheme
import com.keylesspalace.tusky.settings.PrefKeys
import com.keylesspalace.tusky.settings.emojiPreference
import com.keylesspalace.tusky.settings.listPreference
import com.keylesspalace.tusky.settings.makePreferenceScreen
import com.keylesspalace.tusky.settings.preference
import com.keylesspalace.tusky.settings.preferenceCategory
import com.keylesspalace.tusky.settings.sliderPreference
import com.keylesspalace.tusky.settings.switchPreference
import com.keylesspalace.tusky.util.LocaleManager
import com.keylesspalace.tusky.util.deserialize
import com.keylesspalace.tusky.util.makeIcon
import com.keylesspalace.tusky.util.serialize
import com.keylesspalace.tusky.util.unsafeLazy
import com.mikepenz.iconics.IconicsDrawable
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
import de.c1710.filemojicompat_ui.views.picker.preference.EmojiPickerPreference
import javax.inject.Inject
class PreferencesFragment : PreferenceFragmentCompat(), Injectable {
@Inject
lateinit var accountManager: AccountManager
@Inject
lateinit var localeManager: LocaleManager
private val iconSize by unsafeLazy { resources.getDimensionPixelSize(R.dimen.preference_icon_size) }
Keep scroll position when loading missing statuses (#3000) * Change "Load more" to load oldest statuses first in home timeline Previous behaviour loaded missing statuses by using "since_id" and "max_id". This loads the most recent N statuses, looking backwards from "max_id". Change to load the oldest statuses first, assuming the user is scrolling up through the timeline and will want to load statuses in reverse chronological order. * Scroll to the bottom of new entries added by "Load more" - Remember the position of the "Load more" placeholder - Check the position of inserted entries - If they match, scroll to the bottom * Change "Load more" to load oldest statuses first in home timeline Previous behaviour loaded missing statuses by using "since_id" and "max_id". This loads the most recent N statuses, looking backwards from "max_id". Change to load the oldest statuses first, assuming the user is scrolling up through the timeline and will want to load statuses in reverse chronological order. * Scroll to the bottom of new entries added by "Load more" - Remember the position of the "Load more" placeholder - Check the position of inserted entries - If they match, scroll to the bottom * Ensure the user can't have two simultaneous "Load more" coroutines Having two simultanous coroutines would break the calculation used to figure out which item in the list to scroll to after a "Load more" in the timeline. Do this by: - Creating a TimelineUiState and associated flow that tracks the "Load more" state - Updating this in the (Cached|Network)TimelineViewModel - Listening for changes to it in TimelineFragment, and notifying the adapter - The adapter will disable any placeholder views while "Load more" is active * Revert changes that loaded the oldest statuses instead of the newest * Be more robust about locating the status to scroll to Weirdness with the PagingData library meant that positionStart could still be wrong after "Load more" was clicked. Instead, remember the position of the "Load more" item and the ID of the status immediately after it. When new items are added, search for the remembered status at the position of the "Load more" item. This is quick, testing at most LOAD_AT_ONCE items in the adapter. If the remembered status is not visible on screen then scroll to it. * Lint * Add a preference to specify the reading order Default behaviour (oldest first) is for "load more" to load statuses and stay at the oldest of the new statuses. Alternative behaviour (if the user is reading from top to bottom) is to stay at the newest of the new statuses. * Move ReadingOrder enum construction logic in to the enum * Jump to top if swipe/refresh while preferring newest-first order * Show a circular progress spinner during "Load more" operations Remove a dedicated view, and use an icon on the button instead. Adjust the placeholder attributes and styles accordingly. * Remove the "loadMoreActive" property Complicates the code and doesn't really achieve the desired effect. If the user wants to tap multiple "Load more" buttons they can. * Update comments in TimelineFragment * Respect the user's reading order preference if it changes * Add developer tools This is for functionality that makes it easier for developers to interact with the app, or get it in to a known-state. These features are for use by users, so are only visible in debug builds. * Adjust how content is loaded based on preferred reading order - Add the readingOrder to TimelineViewModel so derived classes can use it. - Update the homeTimeline API to support the `minId` parameter and update calls in NetworkTimelineViewModel In CachedTimelineViewModel: - Set the bounds of the load to be the status IDs on either side of the placeholder ID (update TimelineDao with a new query for this) - Load statuses using either minId or sinceId depending on the reading order - Is there was no overlap then insert the new placeholder at the start/end of the list depending on reading order * Lint * Rename unused dialog parameter to _ * Update API arguments in tests * Simplify ReadingOrder preference handling * Fix bug with Placeholder and the "expanded" property If a status is a Placeholder the "expanded" propery is used to indicate whether or not it is loading. replaceStatusRange() set this property based on the old value, and the user's alwaysOpenSpoiler preference setting. This shouldn't have been used if the status is a Placeholder, as it can lead to incorrect loading states. Fix this. While I'm here, introduce an explicit computed property for whether a TimelineStatusEntity is a placeholder, and use that for code clarity. * Set the "Load more" button background to transparent * Fix typo. * Inline spec, update comment * Revert 1480c6aa3ac5c0c2d362fb271f47ea2259ab14e2 Turns out the behaviour is not desired. * Remove unnecessary Log call * Extract function * Change default to newest first
2023-01-13 19:26:24 +01:00
enum class ReadingOrder {
/** User scrolls up, reading statuses oldest to newest */
OLDEST_FIRST,
/** User scrolls down, reading statuses newest to oldest. Default behaviour. */
NEWEST_FIRST;
companion object {
fun from(s: String?): ReadingOrder {
s ?: return NEWEST_FIRST
return try {
valueOf(s.uppercase())
} catch (_: Throwable) {
NEWEST_FIRST
}
}
}
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
makePreferenceScreen {
lateinit var limitedBandwidthMobilePref: SwitchPreference
lateinit var limitedBandwidthTimelinePref: SwitchPreference
preferenceCategory(R.string.pref_title_appearance_settings) {
listPreference {
setDefaultValue(AppTheme.DEFAULT.value)
setEntries(R.array.app_theme_names)
entryValues = AppTheme.stringValues()
key = PrefKeys.APP_THEME
setSummaryProvider { entry }
setTitle(R.string.pref_title_app_theme)
icon = makeIcon(GoogleMaterial.Icon.gmd_palette)
}
emojiPreference(requireActivity()) {
setTitle(R.string.emoji_style)
icon = makeIcon(GoogleMaterial.Icon.gmd_sentiment_satisfied)
}
listPreference {
setDefaultValue("default")
setEntries(R.array.language_entries)
setEntryValues(R.array.language_values)
key = PrefKeys.LANGUAGE + "_" // deliberately not the actual key, the real handling happens in LocaleManager
setSummaryProvider { entry }
setTitle(R.string.pref_title_language)
icon = makeIcon(GoogleMaterial.Icon.gmd_translate)
preferenceDataStore = localeManager
}
sliderPreference {
key = PrefKeys.UI_TEXT_SCALE_RATIO
setDefaultValue(100F)
valueTo = 150F
valueFrom = 50F
stepSize = 5F
setTitle(R.string.pref_ui_text_size)
format = "%.0f%%"
decrementIcon = makeIcon(GoogleMaterial.Icon.gmd_zoom_out)
incrementIcon = makeIcon(GoogleMaterial.Icon.gmd_zoom_in)
icon = makeIcon(GoogleMaterial.Icon.gmd_format_size)
}
listPreference {
setDefaultValue("medium")
setEntries(R.array.post_text_size_names)
setEntryValues(R.array.post_text_size_values)
key = PrefKeys.STATUS_TEXT_SIZE
setSummaryProvider { entry }
setTitle(R.string.pref_post_text_size)
icon = makeIcon(GoogleMaterial.Icon.gmd_format_size)
}
Keep scroll position when loading missing statuses (#3000) * Change "Load more" to load oldest statuses first in home timeline Previous behaviour loaded missing statuses by using "since_id" and "max_id". This loads the most recent N statuses, looking backwards from "max_id". Change to load the oldest statuses first, assuming the user is scrolling up through the timeline and will want to load statuses in reverse chronological order. * Scroll to the bottom of new entries added by "Load more" - Remember the position of the "Load more" placeholder - Check the position of inserted entries - If they match, scroll to the bottom * Change "Load more" to load oldest statuses first in home timeline Previous behaviour loaded missing statuses by using "since_id" and "max_id". This loads the most recent N statuses, looking backwards from "max_id". Change to load the oldest statuses first, assuming the user is scrolling up through the timeline and will want to load statuses in reverse chronological order. * Scroll to the bottom of new entries added by "Load more" - Remember the position of the "Load more" placeholder - Check the position of inserted entries - If they match, scroll to the bottom * Ensure the user can't have two simultaneous "Load more" coroutines Having two simultanous coroutines would break the calculation used to figure out which item in the list to scroll to after a "Load more" in the timeline. Do this by: - Creating a TimelineUiState and associated flow that tracks the "Load more" state - Updating this in the (Cached|Network)TimelineViewModel - Listening for changes to it in TimelineFragment, and notifying the adapter - The adapter will disable any placeholder views while "Load more" is active * Revert changes that loaded the oldest statuses instead of the newest * Be more robust about locating the status to scroll to Weirdness with the PagingData library meant that positionStart could still be wrong after "Load more" was clicked. Instead, remember the position of the "Load more" item and the ID of the status immediately after it. When new items are added, search for the remembered status at the position of the "Load more" item. This is quick, testing at most LOAD_AT_ONCE items in the adapter. If the remembered status is not visible on screen then scroll to it. * Lint * Add a preference to specify the reading order Default behaviour (oldest first) is for "load more" to load statuses and stay at the oldest of the new statuses. Alternative behaviour (if the user is reading from top to bottom) is to stay at the newest of the new statuses. * Move ReadingOrder enum construction logic in to the enum * Jump to top if swipe/refresh while preferring newest-first order * Show a circular progress spinner during "Load more" operations Remove a dedicated view, and use an icon on the button instead. Adjust the placeholder attributes and styles accordingly. * Remove the "loadMoreActive" property Complicates the code and doesn't really achieve the desired effect. If the user wants to tap multiple "Load more" buttons they can. * Update comments in TimelineFragment * Respect the user's reading order preference if it changes * Add developer tools This is for functionality that makes it easier for developers to interact with the app, or get it in to a known-state. These features are for use by users, so are only visible in debug builds. * Adjust how content is loaded based on preferred reading order - Add the readingOrder to TimelineViewModel so derived classes can use it. - Update the homeTimeline API to support the `minId` parameter and update calls in NetworkTimelineViewModel In CachedTimelineViewModel: - Set the bounds of the load to be the status IDs on either side of the placeholder ID (update TimelineDao with a new query for this) - Load statuses using either minId or sinceId depending on the reading order - Is there was no overlap then insert the new placeholder at the start/end of the list depending on reading order * Lint * Rename unused dialog parameter to _ * Update API arguments in tests * Simplify ReadingOrder preference handling * Fix bug with Placeholder and the "expanded" property If a status is a Placeholder the "expanded" propery is used to indicate whether or not it is loading. replaceStatusRange() set this property based on the old value, and the user's alwaysOpenSpoiler preference setting. This shouldn't have been used if the status is a Placeholder, as it can lead to incorrect loading states. Fix this. While I'm here, introduce an explicit computed property for whether a TimelineStatusEntity is a placeholder, and use that for code clarity. * Set the "Load more" button background to transparent * Fix typo. * Inline spec, update comment * Revert 1480c6aa3ac5c0c2d362fb271f47ea2259ab14e2 Turns out the behaviour is not desired. * Remove unnecessary Log call * Extract function * Change default to newest first
2023-01-13 19:26:24 +01:00
listPreference {
setDefaultValue(ReadingOrder.NEWEST_FIRST.name)
setEntries(R.array.reading_order_names)
setEntryValues(R.array.reading_order_values)
key = PrefKeys.READING_ORDER
setSummaryProvider { entry }
setTitle(R.string.pref_title_reading_order)
icon = makeIcon(GoogleMaterial.Icon.gmd_sort)
}
listPreference {
setDefaultValue("top")
setEntries(R.array.pref_main_nav_position_options)
setEntryValues(R.array.pref_main_nav_position_values)
key = PrefKeys.MAIN_NAV_POSITION
setSummaryProvider { entry }
setTitle(R.string.pref_main_nav_position)
}
listPreference {
setDefaultValue("disambiguate")
setEntries(R.array.pref_show_self_username_names)
setEntryValues(R.array.pref_show_self_username_values)
key = PrefKeys.SHOW_SELF_USERNAME
setSummaryProvider { entry }
setTitle(R.string.pref_title_show_self_username)
isSingleLineTitle = false
}
2020-08-16 10:01:51 +02:00
switchPreference {
setDefaultValue(false)
key = PrefKeys.HIDE_TOP_TOOLBAR
setTitle(R.string.pref_title_hide_top_toolbar)
}
switchPreference {
setDefaultValue(false)
key = PrefKeys.FAB_HIDE
setTitle(R.string.pref_title_hide_follow_button)
isSingleLineTitle = false
}
switchPreference {
setDefaultValue(false)
key = PrefKeys.ABSOLUTE_TIME_VIEW
setTitle(R.string.pref_title_absolute_time)
isSingleLineTitle = false
}
switchPreference {
setDefaultValue(true)
key = PrefKeys.SHOW_BOT_OVERLAY
setTitle(R.string.pref_title_bot_overlay)
isSingleLineTitle = false
setIcon(R.drawable.ic_bot_24dp)
}
switchPreference {
setDefaultValue(false)
key = PrefKeys.ANIMATE_GIF_AVATARS
setTitle(R.string.pref_title_animate_gif_avatars)
isSingleLineTitle = false
}
switchPreference {
setDefaultValue(false)
key = PrefKeys.ANIMATE_CUSTOM_EMOJIS
setTitle(R.string.pref_title_animate_custom_emojis)
isSingleLineTitle = false
}
switchPreference {
setDefaultValue(true)
key = PrefKeys.USE_BLURHASH
setTitle(R.string.pref_title_gradient_for_media)
isSingleLineTitle = false
}
switchPreference {
setDefaultValue(false)
key = PrefKeys.SHOW_CARDS_IN_TIMELINES
setTitle(R.string.pref_title_show_cards_in_timelines)
isSingleLineTitle = false
}
switchPreference {
setDefaultValue(true)
key = PrefKeys.CONFIRM_REBLOGS
setTitle(R.string.pref_title_confirm_reblogs)
isSingleLineTitle = false
}
switchPreference {
setDefaultValue(false)
key = PrefKeys.CONFIRM_FAVOURITES
setTitle(R.string.pref_title_confirm_favourites)
isSingleLineTitle = false
}
switchPreference {
setDefaultValue(true)
key = PrefKeys.ENABLE_SWIPE_FOR_TABS
setTitle(R.string.pref_title_enable_swipe_for_tabs)
isSingleLineTitle = false
}
switchPreference {
setDefaultValue(false)
key = PrefKeys.SHOW_STATS_INLINE
setTitle(R.string.pref_title_show_stat_inline)
isSingleLineTitle = false
}
Merge remote-tracking branch 'tuskyapp/develop' # Conflicts: # .gitignore # README.md # app/build.gradle # app/src/green/res/mipmap-hdpi/ic_launcher.png # app/src/green/res/mipmap-mdpi/ic_launcher.png # app/src/green/res/mipmap-xhdpi/ic_launcher.png # app/src/green/res/mipmap-xxhdpi/ic_launcher.png # app/src/green/res/mipmap-xxxhdpi/ic_launcher.png # app/src/main/java/com/keylesspalace/tusky/EditProfileActivity.kt # app/src/main/java/com/keylesspalace/tusky/MainActivity.kt # app/src/main/java/com/keylesspalace/tusky/StatusListActivity.kt # app/src/main/java/com/keylesspalace/tusky/TabData.kt # app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java # app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java # app/src/main/java/com/keylesspalace/tusky/appstore/Events.kt # app/src/main/java/com/keylesspalace/tusky/components/account/AccountActivity.kt # app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt # app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeViewModel.kt # app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationEntity.kt # app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationsFragment.kt # app/src/main/java/com/keylesspalace/tusky/components/preference/PreferencesActivity.kt # app/src/main/java/com/keylesspalace/tusky/components/preference/PreferencesFragment.kt # app/src/main/java/com/keylesspalace/tusky/components/report/fragments/ReportStatusesFragment.kt # app/src/main/java/com/keylesspalace/tusky/components/search/SearchViewModel.kt # app/src/main/java/com/keylesspalace/tusky/components/search/fragments/SearchStatusesFragment.kt # app/src/main/java/com/keylesspalace/tusky/components/timeline/TimelineFragment.kt # app/src/main/java/com/keylesspalace/tusky/components/timeline/TimelineTypeMappers.kt # app/src/main/java/com/keylesspalace/tusky/components/timeline/viewmodel/TimelineViewModel.kt # app/src/main/java/com/keylesspalace/tusky/components/viewthread/ViewThreadFragment.kt # app/src/main/java/com/keylesspalace/tusky/db/TimelineDao.kt # app/src/main/java/com/keylesspalace/tusky/db/TimelineStatusEntity.kt # app/src/main/java/com/keylesspalace/tusky/di/ActivitiesModule.kt # app/src/main/java/com/keylesspalace/tusky/di/FragmentBuildersModule.kt # app/src/main/java/com/keylesspalace/tusky/di/ViewModelFactory.kt # app/src/main/java/com/keylesspalace/tusky/entity/NewStatus.kt # app/src/main/java/com/keylesspalace/tusky/entity/Status.kt # app/src/main/java/com/keylesspalace/tusky/entity/TimelineAccount.kt # app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java # app/src/main/java/com/keylesspalace/tusky/service/SendStatusService.kt # app/src/main/java/com/keylesspalace/tusky/settings/SettingsConstants.kt # app/src/main/java/com/keylesspalace/tusky/util/StatusDisplayOptions.kt # app/src/main/java/com/keylesspalace/tusky/util/StatusParsingHelper.kt # app/src/main/res/layout/activity_about.xml # app/src/main/res/layout/activity_main.xml # app/src/main/res/layout/item_status.xml # app/src/main/res/layout/item_status_notification.xml # app/src/main/res/values-ar/strings.xml # app/src/main/res/values-be/strings.xml # app/src/main/res/values-bn-rBD/strings.xml # app/src/main/res/values-ca/strings.xml # app/src/main/res/values-cy/strings.xml # app/src/main/res/values-de/strings.xml # app/src/main/res/values-es/strings.xml # app/src/main/res/values-eu/strings.xml # app/src/main/res/values-fa/strings.xml # app/src/main/res/values-fr/strings.xml # app/src/main/res/values-gd/strings.xml # app/src/main/res/values-gl/strings.xml # app/src/main/res/values-hu/strings.xml # app/src/main/res/values-in/strings.xml # app/src/main/res/values-is/strings.xml # app/src/main/res/values-it/strings.xml # app/src/main/res/values-ja/strings.xml # app/src/main/res/values-lv/strings.xml # app/src/main/res/values-nb-rNO/strings.xml # app/src/main/res/values-night/theme_colors.xml # app/src/main/res/values-oc/strings.xml # app/src/main/res/values-pl/strings.xml # app/src/main/res/values-pt-rBR/strings.xml # app/src/main/res/values-ru/strings.xml # app/src/main/res/values-sa/strings.xml # app/src/main/res/values-sv/strings.xml # app/src/main/res/values-tr/strings.xml # app/src/main/res/values-uk/strings.xml # app/src/main/res/values-vi/strings.xml # app/src/main/res/values-zh-rCN/strings.xml # app/src/main/res/values/attrs.xml # app/src/main/res/values/styles.xml # app/src/main/res/values/theme_colors.xml # app/src/test/java/com/keylesspalace/tusky/BottomSheetActivityTest.kt # app/src/test/java/com/keylesspalace/tusky/FilterV1Test.kt # app/src/test/java/com/keylesspalace/tusky/components/timeline/StatusMocker.kt # app/src/test/java/com/keylesspalace/tusky/db/TimelineDaoTest.kt # app/src/test/java/com/keylesspalace/tusky/usecase/TimelineCasesTest.kt # app/src/test/java/com/keylesspalace/tusky/util/RickRollTest.kt # assets/tusky_banner.xcf # fastlane/metadata/android/ca/changelogs/58.txt # fastlane/metadata/android/ca/full_description.txt # fastlane/metadata/android/de/changelogs/58.txt # fastlane/metadata/android/de/changelogs/61.txt # fastlane/metadata/android/de/changelogs/67.txt # fastlane/metadata/android/de/changelogs/68.txt # fastlane/metadata/android/de/changelogs/70.txt # fastlane/metadata/android/de/changelogs/72.txt # fastlane/metadata/android/de/changelogs/74.txt # fastlane/metadata/android/de/changelogs/77.txt # fastlane/metadata/android/de/changelogs/80.txt # fastlane/metadata/android/de/changelogs/82.txt # fastlane/metadata/android/de/changelogs/83.txt # fastlane/metadata/android/de/changelogs/87.txt # fastlane/metadata/android/de/changelogs/89.txt # fastlane/metadata/android/de/changelogs/94.txt # fastlane/metadata/android/de/full_description.txt # fastlane/metadata/android/de/short_description.txt # fastlane/metadata/android/fa/changelogs/58.txt # fastlane/metadata/android/it/changelogs/58.txt # gradle.properties # gradle/libs.versions.toml # instance-build.gradle
2023-05-26 17:42:56 +02:00
2021-08-03 17:16:40 +02:00
switchPreference {
setDefaultValue(true)
key = PrefKeys.USE_QUICK_TOOT
setTitle(R.string.pref_title_use_quick_toot)
isSingleLineTitle = false
}
}
preferenceCategory(R.string.pref_title_limited_bandwidth_settings) {
switchPreference {
setDefaultValue(false)
key = PrefKeys.LIMITED_BANDWIDTH_ACTIVE
setTitle(R.string.pref_title_limited_bandwidth_active)
disableDependentsState = false
isSingleLineTitle = false
}
limitedBandwidthMobilePref = switchPreference {
setDefaultValue(true)
key = PrefKeys.LIMITED_BANDWIDTH_ONLY_MOBILE_NETWORK
setTitle(R.string.pref_title_limited_bandwidth_mobile)
isSingleLineTitle = false
}
limitedBandwidthTimelinePref = switchPreference {
setDefaultValue(true)
key = PrefKeys.LIMITED_BANDWIDTH_TIMELINE_LOADING
setTitle(R.string.pref_title_limited_bandwidth_timeline)
isSingleLineTitle = false
}
}
arrayOf(limitedBandwidthMobilePref, limitedBandwidthTimelinePref).forEach {
it.dependency = PrefKeys.LIMITED_BANDWIDTH_ACTIVE
}
preferenceCategory(R.string.pref_title_browser_settings) {
switchPreference {
setDefaultValue(false)
key = PrefKeys.CUSTOM_TABS
setTitle(R.string.pref_title_custom_tabs)
isSingleLineTitle = false
}
}
preferenceCategory(R.string.pref_title_timeline_filters) {
preference {
setTitle(R.string.pref_title_post_tabs)
fragment = TabFilterPreferencesFragment::class.qualifiedName
}
}
preferenceCategory(R.string.pref_title_wellbeing_mode) {
switchPreference {
title = getString(R.string.limit_notifications)
setDefaultValue(false)
key = PrefKeys.WELLBEING_LIMITED_NOTIFICATIONS
setOnPreferenceChangeListener { _, value ->
for (account in accountManager.accounts) {
val notificationFilter = deserialize(account.notificationsFilter).toMutableSet()
if (value == true) {
notificationFilter.add(Notification.Type.FAVOURITE)
notificationFilter.add(Notification.Type.FOLLOW)
notificationFilter.add(Notification.Type.REBLOG)
} else {
notificationFilter.remove(Notification.Type.FAVOURITE)
notificationFilter.remove(Notification.Type.FOLLOW)
notificationFilter.remove(Notification.Type.REBLOG)
}
account.notificationsFilter = serialize(notificationFilter)
accountManager.saveAccount(account)
}
true
}
}
switchPreference {
title = getString(R.string.wellbeing_hide_stats_posts)
setDefaultValue(false)
key = PrefKeys.WELLBEING_HIDE_STATS_POSTS
}
switchPreference {
title = getString(R.string.wellbeing_hide_stats_profile)
setDefaultValue(false)
key = PrefKeys.WELLBEING_HIDE_STATS_PROFILE
}
}
preferenceCategory(R.string.pref_title_proxy_settings) {
preference {
setTitle(R.string.pref_title_http_proxy_settings)
fragment = ProxyPreferencesFragment::class.qualifiedName
summaryProvider = ProxyPreferencesFragment.SummaryProvider
}
}
2021-01-03 06:42:50 +01:00
preferenceCategory(R.string.pref_title_experimental) {
switchPreference {
title = getString(R.string.pref_title_experimental_viewpager_offscreen)
setDefaultValue(false)
key = PrefKeys.VIEW_PAGER_OFF_SCREEN_LIMIT
}
}
preferenceManager.sharedPreferences?.let { prefs ->
2021-01-03 06:42:50 +01:00
prefs.getString(PrefKeys.STACK_TRACE, null)?.let { stackTrace ->
preferenceCategory(R.string.pref_title_stacktrace) {
preference {
setTitle(R.string.pref_title_stacktrace_send)
setOnPreferenceClickListener {
activity?.let { activity ->
2022-11-10 15:16:52 +01:00
val intent = ComposeActivity.startIntent(
activity,
ComposeOptions(
content = "@ars42525@odakyu.app $stackTrace".substring(0, 400),
contentWarning = "Yuito StackTrace"
2022-11-10 15:16:52 +01:00
)
)
activity.startActivity(intent)
prefs.edit()
2022-11-10 15:16:52 +01:00
.remove(PrefKeys.STACK_TRACE)
.apply()
}
true
}
2021-01-03 06:42:50 +01:00
key = PrefKeys.SEND_CRASH_REPORT
}
preference {
summary = stackTrace
isSelectable = false
}
}
}
}
}
}
private fun makeIcon(icon: GoogleMaterial.Icon): IconicsDrawable {
return makeIcon(requireContext(), icon, iconSize)
}
override fun onResume() {
super.onResume()
requireActivity().setTitle(R.string.action_view_preferences)
}
override fun onDisplayPreferenceDialog(preference: Preference) {
if (!EmojiPickerPreference.onDisplayPreferenceDialog(this, preference)) {
super.onDisplayPreferenceDialog(preference)
}
}
companion object {
fun newInstance(): PreferencesFragment {
return PreferencesFragment()
}
}
}