2018-06-18 13:26:18 +02:00
|
|
|
/* 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>. */
|
|
|
|
|
2022-01-11 19:55:17 +01:00
|
|
|
package com.keylesspalace.tusky.components.account
|
2018-06-18 13:26:18 +02:00
|
|
|
|
|
|
|
import android.animation.ArgbEvaluator
|
2023-01-09 21:08:46 +01:00
|
|
|
import android.content.ClipData
|
|
|
|
import android.content.ClipboardManager
|
2018-06-18 13:26:18 +02:00
|
|
|
import android.content.Context
|
|
|
|
import android.content.Intent
|
2019-10-12 20:00:29 +02:00
|
|
|
import android.content.res.ColorStateList
|
2020-01-30 21:37:28 +01:00
|
|
|
import android.graphics.Color
|
2023-02-23 19:30:27 +01:00
|
|
|
import android.graphics.drawable.LayerDrawable
|
2018-06-18 13:26:18 +02:00
|
|
|
import android.os.Bundle
|
2023-03-10 20:27:24 +01:00
|
|
|
import android.text.TextWatcher
|
2019-01-21 08:37:25 +01:00
|
|
|
import android.view.Menu
|
Add "Refresh" accessibility menu (#3121)
* Add "Refresh" accessibility menu to TimelineFragment
Per https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout
the layout does not provide accessibility events, and a menu item should be
provided as an alternative method for refreshing the content.
In `TimelineFragment`:
- Implement the `MenuProvider` interface so it can populate the action bar
menu in activities that host the fragment
- Create a "Refresh" menu item, and refresh the state when it is selected
`MainActivity` has to change how the menu is created, so that fragments
can add items to it.
In `MainActivity`:
- Call `setSupportActionBar` so `mainToolbar` participates in menus
- Implement the `MenuProvider` interface, and move menu creation there
- Set the title via supportActionBar
* Never show the refresh item as a menubar action
Per guidelines in https://developer.android.com/develop/ui/views/touch-and-input/swipe/add-swipe-interface#AddRefreshAction
* Add "Refresh" menu item for AccountMediaFragment
Also, fix the colour of the refresh progress indicator
* Implement "Refresh" for AnnouncementsActivity
* Add "Refresh" menu for ConversationsFragment
* Keep the tabs adapter over the life of the viewpager
Make `tabs` `var` instead of `val` in `MainPagerAdapter` so it can be updated
when tabs change.
Then detach the `tabLayoutMediator`, update the tabs, and call
`notifyItemRangeChanged` in `setupTabs()`.
This fixes a bug (not sure if it's this code, or in ViewPager2) where
assigning a new adapter to the view pager seemed to result in a leak of one
or more fragments. This wasn't user-visible, but it's a leak, and it becomes
user-visible when fragments want to display menus.
This also fixes two other bugs:
1. Be on the left-most tab. Scroll down a bit. Then modify the tabs at
"Account preferences > tabs", but keep the left-most tab as-is.
Then go back to MainActivity. Your reading position in the left-most
tab has been jumped to the top.
2. Be on any non-left-most tab. Then modify the tab list by reordering tabs
(adding/removing tabs is also OK).
Then go back to MainActivity. Your tab selection has been overridden,
and the left-most tab has been selected.
Because the fragments are not destroyed unnecessarily your reading position
is retained. And it remembers the tab you had selected, and as long as that
tab is still present you will be returned to it, even if it's changed
position in the list.
Fixes https://github.com/tuskyapp/Tusky/issues/3251
* Add "Refresh" menu for ScheduledStatusActivity
* Lint
* Add "Refresh" menu for SearchFragment / SearchActivity
* Explicitly set the searchview width
Using "collapseActionView" requires the user to press "Back" twice to exit
the activity, which is not acceptable.
* Move toolbar handling in to ViewThreadActivity
Previous code had the toolbar in the fragment's layout. Refactor to make
consistent with other activities, and move the toolbar in to the activity
layout.
Implement MenuProvider in ViewThreadFragment to adjust the menu in the
activity.
* Add "Refresh" menu to ViewThreadFragment
* Implement "Refresh" for ViewEditsFragment
* Lint
* Add "Refresh" menu to ReportStatusesFragment
* Add "Refresh" menu to NotificationsFragment
* Rename menu resource files
Be consistent with the layout resource files, which have an activity/fragment
prefix, then the lower_snake_case name of the activity or fragment it's for.
* Only enable refresh menu if swiptorefresh is enabled
Some timelines don't have swipetorefresh enabled (e.g., those shown on
AccountActivity). In those cases don't add the refresh menu, rely on the
hosting activity to provide it.
Update AccountActivity to provide the refresh menu item.
2023-03-01 19:58:18 +01:00
|
|
|
import android.view.MenuInflater
|
2019-01-21 08:37:25 +01:00
|
|
|
import android.view.MenuItem
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2020-02-25 19:49:41 +01:00
|
|
|
import androidx.activity.viewModels
|
2018-12-17 15:25:35 +01:00
|
|
|
import androidx.annotation.ColorInt
|
|
|
|
import androidx.annotation.Px
|
2019-01-21 08:37:25 +01:00
|
|
|
import androidx.appcompat.app.AlertDialog
|
2023-02-23 19:30:27 +01:00
|
|
|
import androidx.appcompat.content.res.AppCompatResources
|
2018-12-17 15:25:35 +01:00
|
|
|
import androidx.core.app.ActivityOptionsCompat
|
Add "Refresh" accessibility menu (#3121)
* Add "Refresh" accessibility menu to TimelineFragment
Per https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout
the layout does not provide accessibility events, and a menu item should be
provided as an alternative method for refreshing the content.
In `TimelineFragment`:
- Implement the `MenuProvider` interface so it can populate the action bar
menu in activities that host the fragment
- Create a "Refresh" menu item, and refresh the state when it is selected
`MainActivity` has to change how the menu is created, so that fragments
can add items to it.
In `MainActivity`:
- Call `setSupportActionBar` so `mainToolbar` participates in menus
- Implement the `MenuProvider` interface, and move menu creation there
- Set the title via supportActionBar
* Never show the refresh item as a menubar action
Per guidelines in https://developer.android.com/develop/ui/views/touch-and-input/swipe/add-swipe-interface#AddRefreshAction
* Add "Refresh" menu item for AccountMediaFragment
Also, fix the colour of the refresh progress indicator
* Implement "Refresh" for AnnouncementsActivity
* Add "Refresh" menu for ConversationsFragment
* Keep the tabs adapter over the life of the viewpager
Make `tabs` `var` instead of `val` in `MainPagerAdapter` so it can be updated
when tabs change.
Then detach the `tabLayoutMediator`, update the tabs, and call
`notifyItemRangeChanged` in `setupTabs()`.
This fixes a bug (not sure if it's this code, or in ViewPager2) where
assigning a new adapter to the view pager seemed to result in a leak of one
or more fragments. This wasn't user-visible, but it's a leak, and it becomes
user-visible when fragments want to display menus.
This also fixes two other bugs:
1. Be on the left-most tab. Scroll down a bit. Then modify the tabs at
"Account preferences > tabs", but keep the left-most tab as-is.
Then go back to MainActivity. Your reading position in the left-most
tab has been jumped to the top.
2. Be on any non-left-most tab. Then modify the tab list by reordering tabs
(adding/removing tabs is also OK).
Then go back to MainActivity. Your tab selection has been overridden,
and the left-most tab has been selected.
Because the fragments are not destroyed unnecessarily your reading position
is retained. And it remembers the tab you had selected, and as long as that
tab is still present you will be returned to it, even if it's changed
position in the list.
Fixes https://github.com/tuskyapp/Tusky/issues/3251
* Add "Refresh" menu for ScheduledStatusActivity
* Lint
* Add "Refresh" menu for SearchFragment / SearchActivity
* Explicitly set the searchview width
Using "collapseActionView" requires the user to press "Back" twice to exit
the activity, which is not acceptable.
* Move toolbar handling in to ViewThreadActivity
Previous code had the toolbar in the fragment's layout. Refactor to make
consistent with other activities, and move the toolbar in to the activity
layout.
Implement MenuProvider in ViewThreadFragment to adjust the menu in the
activity.
* Add "Refresh" menu to ViewThreadFragment
* Implement "Refresh" for ViewEditsFragment
* Lint
* Add "Refresh" menu to ReportStatusesFragment
* Add "Refresh" menu to NotificationsFragment
* Rename menu resource files
Be consistent with the layout resource files, which have an activity/fragment
prefix, then the lower_snake_case name of the activity or fragment it's for.
* Only enable refresh menu if swiptorefresh is enabled
Some timelines don't have swipetorefresh enabled (e.g., those shown on
AccountActivity). In those cases don't add the refresh menu, rely on the
hosting activity to provide it.
Update AccountActivity to provide the refresh menu item.
2023-03-01 19:58:18 +01:00
|
|
|
import androidx.core.view.MenuProvider
|
2021-06-01 19:46:07 +02:00
|
|
|
import androidx.core.view.ViewCompat
|
|
|
|
import androidx.core.view.WindowCompat
|
|
|
|
import androidx.core.view.WindowInsetsCompat
|
|
|
|
import androidx.core.view.WindowInsetsCompat.Type.systemBars
|
2021-11-16 21:38:59 +01:00
|
|
|
import androidx.core.view.updatePadding
|
2023-03-10 20:27:24 +01:00
|
|
|
import androidx.core.widget.doAfterTextChanged
|
2019-10-22 21:18:20 +02:00
|
|
|
import androidx.preference.PreferenceManager
|
2018-12-17 15:25:35 +01:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
2019-11-06 20:17:53 +01:00
|
|
|
import androidx.viewpager2.widget.MarginPageTransformer
|
2019-04-16 21:39:12 +02:00
|
|
|
import com.bumptech.glide.Glide
|
2018-12-17 15:25:35 +01:00
|
|
|
import com.google.android.material.appbar.AppBarLayout
|
2022-12-31 13:01:35 +01:00
|
|
|
import com.google.android.material.color.MaterialColors
|
2018-12-17 15:25:35 +01:00
|
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
2019-10-12 20:00:29 +02:00
|
|
|
import com.google.android.material.shape.MaterialShapeDrawable
|
|
|
|
import com.google.android.material.shape.ShapeAppearanceModel
|
2018-12-17 15:25:35 +01:00
|
|
|
import com.google.android.material.snackbar.Snackbar
|
2019-04-08 15:40:16 +02:00
|
|
|
import com.google.android.material.tabs.TabLayout
|
2019-11-06 20:17:53 +01:00
|
|
|
import com.google.android.material.tabs.TabLayoutMediator
|
2022-01-11 19:55:17 +01:00
|
|
|
import com.keylesspalace.tusky.BottomSheetActivity
|
|
|
|
import com.keylesspalace.tusky.EditProfileActivity
|
|
|
|
import com.keylesspalace.tusky.R
|
2022-02-25 18:57:31 +01:00
|
|
|
import com.keylesspalace.tusky.StatusListActivity
|
2022-01-11 19:55:17 +01:00
|
|
|
import com.keylesspalace.tusky.ViewMediaActivity
|
2022-11-12 22:05:55 +01:00
|
|
|
import com.keylesspalace.tusky.components.account.list.ListsForAccountFragment
|
2023-02-04 20:29:13 +01:00
|
|
|
import com.keylesspalace.tusky.components.accountlist.AccountListActivity
|
2019-12-19 19:09:40 +01:00
|
|
|
import com.keylesspalace.tusky.components.compose.ComposeActivity
|
2019-08-17 09:08:58 +02:00
|
|
|
import com.keylesspalace.tusky.components.report.ReportActivity
|
2021-03-07 19:05:51 +01:00
|
|
|
import com.keylesspalace.tusky.databinding.ActivityAccountBinding
|
2022-02-25 18:55:58 +01:00
|
|
|
import com.keylesspalace.tusky.db.AccountEntity
|
2023-01-27 20:50:45 +01:00
|
|
|
import com.keylesspalace.tusky.db.DraftsAlert
|
2018-06-18 13:26:18 +02:00
|
|
|
import com.keylesspalace.tusky.di.ViewModelFactory
|
|
|
|
import com.keylesspalace.tusky.entity.Account
|
|
|
|
import com.keylesspalace.tusky.entity.Relationship
|
2022-02-25 18:55:58 +01:00
|
|
|
import com.keylesspalace.tusky.interfaces.AccountSelectionListener
|
2018-06-18 13:26:18 +02:00
|
|
|
import com.keylesspalace.tusky.interfaces.ActionButtonActivity
|
|
|
|
import com.keylesspalace.tusky.interfaces.LinkListener
|
2019-04-08 15:40:16 +02:00
|
|
|
import com.keylesspalace.tusky.interfaces.ReselectableFragment
|
2020-12-23 19:13:37 +01:00
|
|
|
import com.keylesspalace.tusky.settings.PrefKeys
|
2022-01-20 21:10:32 +01:00
|
|
|
import com.keylesspalace.tusky.util.Error
|
|
|
|
import com.keylesspalace.tusky.util.Loading
|
2021-06-28 21:13:24 +02:00
|
|
|
import com.keylesspalace.tusky.util.Success
|
|
|
|
import com.keylesspalace.tusky.util.emojify
|
2022-02-25 18:56:21 +01:00
|
|
|
import com.keylesspalace.tusky.util.getDomain
|
2021-06-28 21:13:24 +02:00
|
|
|
import com.keylesspalace.tusky.util.hide
|
|
|
|
import com.keylesspalace.tusky.util.loadAvatar
|
2022-04-15 13:20:27 +02:00
|
|
|
import com.keylesspalace.tusky.util.parseAsMastodonHtml
|
2023-01-13 19:51:09 +01:00
|
|
|
import com.keylesspalace.tusky.util.reduceSwipeSensitivity
|
2022-02-25 18:56:21 +01:00
|
|
|
import com.keylesspalace.tusky.util.setClickableText
|
2021-06-28 21:13:24 +02:00
|
|
|
import com.keylesspalace.tusky.util.show
|
2023-02-20 20:14:54 +01:00
|
|
|
import com.keylesspalace.tusky.util.unsafeLazy
|
2021-06-28 21:13:24 +02:00
|
|
|
import com.keylesspalace.tusky.util.viewBinding
|
|
|
|
import com.keylesspalace.tusky.util.visible
|
2020-07-27 10:28:59 +02:00
|
|
|
import com.keylesspalace.tusky.view.showMuteAccountDialog
|
Add "Refresh" accessibility menu (#3121)
* Add "Refresh" accessibility menu to TimelineFragment
Per https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout
the layout does not provide accessibility events, and a menu item should be
provided as an alternative method for refreshing the content.
In `TimelineFragment`:
- Implement the `MenuProvider` interface so it can populate the action bar
menu in activities that host the fragment
- Create a "Refresh" menu item, and refresh the state when it is selected
`MainActivity` has to change how the menu is created, so that fragments
can add items to it.
In `MainActivity`:
- Call `setSupportActionBar` so `mainToolbar` participates in menus
- Implement the `MenuProvider` interface, and move menu creation there
- Set the title via supportActionBar
* Never show the refresh item as a menubar action
Per guidelines in https://developer.android.com/develop/ui/views/touch-and-input/swipe/add-swipe-interface#AddRefreshAction
* Add "Refresh" menu item for AccountMediaFragment
Also, fix the colour of the refresh progress indicator
* Implement "Refresh" for AnnouncementsActivity
* Add "Refresh" menu for ConversationsFragment
* Keep the tabs adapter over the life of the viewpager
Make `tabs` `var` instead of `val` in `MainPagerAdapter` so it can be updated
when tabs change.
Then detach the `tabLayoutMediator`, update the tabs, and call
`notifyItemRangeChanged` in `setupTabs()`.
This fixes a bug (not sure if it's this code, or in ViewPager2) where
assigning a new adapter to the view pager seemed to result in a leak of one
or more fragments. This wasn't user-visible, but it's a leak, and it becomes
user-visible when fragments want to display menus.
This also fixes two other bugs:
1. Be on the left-most tab. Scroll down a bit. Then modify the tabs at
"Account preferences > tabs", but keep the left-most tab as-is.
Then go back to MainActivity. Your reading position in the left-most
tab has been jumped to the top.
2. Be on any non-left-most tab. Then modify the tab list by reordering tabs
(adding/removing tabs is also OK).
Then go back to MainActivity. Your tab selection has been overridden,
and the left-most tab has been selected.
Because the fragments are not destroyed unnecessarily your reading position
is retained. And it remembers the tab you had selected, and as long as that
tab is still present you will be returned to it, even if it's changed
position in the list.
Fixes https://github.com/tuskyapp/Tusky/issues/3251
* Add "Refresh" menu for ScheduledStatusActivity
* Lint
* Add "Refresh" menu for SearchFragment / SearchActivity
* Explicitly set the searchview width
Using "collapseActionView" requires the user to press "Back" twice to exit
the activity, which is not acceptable.
* Move toolbar handling in to ViewThreadActivity
Previous code had the toolbar in the fragment's layout. Refactor to make
consistent with other activities, and move the toolbar in to the activity
layout.
Implement MenuProvider in ViewThreadFragment to adjust the menu in the
activity.
* Add "Refresh" menu to ViewThreadFragment
* Implement "Refresh" for ViewEditsFragment
* Lint
* Add "Refresh" menu to ReportStatusesFragment
* Add "Refresh" menu to NotificationsFragment
* Rename menu resource files
Be consistent with the layout resource files, which have an activity/fragment
prefix, then the lower_snake_case name of the activity or fragment it's for.
* Only enable refresh menu if swiptorefresh is enabled
Some timelines don't have swipetorefresh enabled (e.g., those shown on
AccountActivity). In those cases don't add the refresh menu, rely on the
hosting activity to provide it.
Update AccountActivity to provide the refresh menu item.
2023-03-01 19:58:18 +01:00
|
|
|
import com.mikepenz.iconics.IconicsDrawable
|
|
|
|
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
|
|
|
|
import com.mikepenz.iconics.utils.colorInt
|
|
|
|
import com.mikepenz.iconics.utils.sizeDp
|
2018-06-18 13:26:18 +02:00
|
|
|
import dagger.android.DispatchingAndroidInjector
|
2019-06-09 19:48:04 +02:00
|
|
|
import dagger.android.HasAndroidInjector
|
2018-06-18 13:26:18 +02:00
|
|
|
import java.text.NumberFormat
|
2022-05-17 19:49:42 +02:00
|
|
|
import java.text.ParseException
|
|
|
|
import java.text.SimpleDateFormat
|
|
|
|
import java.util.Locale
|
2018-06-18 13:26:18 +02:00
|
|
|
import javax.inject.Inject
|
2019-07-16 19:26:55 +02:00
|
|
|
import kotlin.math.abs
|
2018-06-18 13:26:18 +02:00
|
|
|
|
Add "Refresh" accessibility menu (#3121)
* Add "Refresh" accessibility menu to TimelineFragment
Per https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout
the layout does not provide accessibility events, and a menu item should be
provided as an alternative method for refreshing the content.
In `TimelineFragment`:
- Implement the `MenuProvider` interface so it can populate the action bar
menu in activities that host the fragment
- Create a "Refresh" menu item, and refresh the state when it is selected
`MainActivity` has to change how the menu is created, so that fragments
can add items to it.
In `MainActivity`:
- Call `setSupportActionBar` so `mainToolbar` participates in menus
- Implement the `MenuProvider` interface, and move menu creation there
- Set the title via supportActionBar
* Never show the refresh item as a menubar action
Per guidelines in https://developer.android.com/develop/ui/views/touch-and-input/swipe/add-swipe-interface#AddRefreshAction
* Add "Refresh" menu item for AccountMediaFragment
Also, fix the colour of the refresh progress indicator
* Implement "Refresh" for AnnouncementsActivity
* Add "Refresh" menu for ConversationsFragment
* Keep the tabs adapter over the life of the viewpager
Make `tabs` `var` instead of `val` in `MainPagerAdapter` so it can be updated
when tabs change.
Then detach the `tabLayoutMediator`, update the tabs, and call
`notifyItemRangeChanged` in `setupTabs()`.
This fixes a bug (not sure if it's this code, or in ViewPager2) where
assigning a new adapter to the view pager seemed to result in a leak of one
or more fragments. This wasn't user-visible, but it's a leak, and it becomes
user-visible when fragments want to display menus.
This also fixes two other bugs:
1. Be on the left-most tab. Scroll down a bit. Then modify the tabs at
"Account preferences > tabs", but keep the left-most tab as-is.
Then go back to MainActivity. Your reading position in the left-most
tab has been jumped to the top.
2. Be on any non-left-most tab. Then modify the tab list by reordering tabs
(adding/removing tabs is also OK).
Then go back to MainActivity. Your tab selection has been overridden,
and the left-most tab has been selected.
Because the fragments are not destroyed unnecessarily your reading position
is retained. And it remembers the tab you had selected, and as long as that
tab is still present you will be returned to it, even if it's changed
position in the list.
Fixes https://github.com/tuskyapp/Tusky/issues/3251
* Add "Refresh" menu for ScheduledStatusActivity
* Lint
* Add "Refresh" menu for SearchFragment / SearchActivity
* Explicitly set the searchview width
Using "collapseActionView" requires the user to press "Back" twice to exit
the activity, which is not acceptable.
* Move toolbar handling in to ViewThreadActivity
Previous code had the toolbar in the fragment's layout. Refactor to make
consistent with other activities, and move the toolbar in to the activity
layout.
Implement MenuProvider in ViewThreadFragment to adjust the menu in the
activity.
* Add "Refresh" menu to ViewThreadFragment
* Implement "Refresh" for ViewEditsFragment
* Lint
* Add "Refresh" menu to ReportStatusesFragment
* Add "Refresh" menu to NotificationsFragment
* Rename menu resource files
Be consistent with the layout resource files, which have an activity/fragment
prefix, then the lower_snake_case name of the activity or fragment it's for.
* Only enable refresh menu if swiptorefresh is enabled
Some timelines don't have swipetorefresh enabled (e.g., those shown on
AccountActivity). In those cases don't add the refresh menu, rely on the
hosting activity to provide it.
Update AccountActivity to provide the refresh menu item.
2023-03-01 19:58:18 +01:00
|
|
|
class AccountActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider, HasAndroidInjector, LinkListener {
|
2018-06-18 13:26:18 +02:00
|
|
|
|
|
|
|
@Inject
|
2019-06-09 19:48:04 +02:00
|
|
|
lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Any>
|
2023-03-13 13:16:39 +01:00
|
|
|
|
2018-06-18 13:26:18 +02:00
|
|
|
@Inject
|
|
|
|
lateinit var viewModelFactory: ViewModelFactory
|
2023-03-13 13:16:39 +01:00
|
|
|
|
2023-01-27 20:50:45 +01:00
|
|
|
@Inject
|
|
|
|
lateinit var draftsAlert: DraftsAlert
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2020-02-25 19:49:41 +01:00
|
|
|
private val viewModel: AccountViewModel by viewModels { viewModelFactory }
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
private val binding: ActivityAccountBinding by viewBinding(ActivityAccountBinding::inflate)
|
|
|
|
|
2021-06-28 21:13:24 +02:00
|
|
|
private lateinit var accountFieldAdapter: AccountFieldAdapter
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2023-02-20 20:14:54 +01:00
|
|
|
private val preferences by unsafeLazy { PreferenceManager.getDefaultSharedPreferences(this) }
|
2022-12-01 19:51:13 +01:00
|
|
|
|
2018-07-05 21:14:32 +02:00
|
|
|
private var followState: FollowState = FollowState.NOT_FOLLOWING
|
2018-06-18 13:26:18 +02:00
|
|
|
private var blocking: Boolean = false
|
|
|
|
private var muting: Boolean = false
|
2020-06-23 19:59:49 +02:00
|
|
|
private var blockingDomain: Boolean = false
|
2018-06-18 13:26:18 +02:00
|
|
|
private var showingReblogs: Boolean = false
|
2020-12-23 12:52:39 +01:00
|
|
|
private var subscribing: Boolean = false
|
2018-06-18 13:26:18 +02:00
|
|
|
private var loadedAccount: Account? = null
|
|
|
|
|
2019-05-26 08:46:08 +02:00
|
|
|
private var animateAvatar: Boolean = false
|
2021-02-06 08:14:51 +01:00
|
|
|
private var animateEmojis: Boolean = false
|
2019-05-26 08:46:08 +02:00
|
|
|
|
2018-06-18 13:26:18 +02:00
|
|
|
// fields for scroll animation
|
|
|
|
private var hideFab: Boolean = false
|
|
|
|
private var oldOffset: Int = 0
|
2023-03-13 13:16:39 +01:00
|
|
|
|
2018-06-18 13:26:18 +02:00
|
|
|
@ColorInt
|
|
|
|
private var toolbarColor: Int = 0
|
2023-03-13 13:16:39 +01:00
|
|
|
|
2018-06-18 13:26:18 +02:00
|
|
|
@ColorInt
|
|
|
|
private var statusBarColorTransparent: Int = 0
|
2023-03-13 13:16:39 +01:00
|
|
|
|
2018-06-18 13:26:18 +02:00
|
|
|
@ColorInt
|
|
|
|
private var statusBarColorOpaque: Int = 0
|
2019-05-15 12:43:16 +02:00
|
|
|
|
2018-06-18 13:26:18 +02:00
|
|
|
private var avatarSize: Float = 0f
|
2023-03-13 13:16:39 +01:00
|
|
|
|
2018-06-18 13:26:18 +02:00
|
|
|
@Px
|
|
|
|
private var titleVisibleHeight: Int = 0
|
2019-06-11 15:56:27 +02:00
|
|
|
private lateinit var domain: String
|
2018-06-18 13:26:18 +02:00
|
|
|
|
|
|
|
private enum class FollowState {
|
|
|
|
NOT_FOLLOWING,
|
|
|
|
FOLLOWING,
|
|
|
|
REQUESTED
|
|
|
|
}
|
|
|
|
|
2019-05-15 12:43:16 +02:00
|
|
|
private lateinit var adapter: AccountPagerAdapter
|
2019-04-08 15:40:16 +02:00
|
|
|
|
2023-03-10 20:27:24 +01:00
|
|
|
private var noteWatcher: TextWatcher? = null
|
|
|
|
|
2018-06-18 13:26:18 +02:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
2019-10-12 20:00:29 +02:00
|
|
|
loadResources()
|
2019-05-15 12:43:16 +02:00
|
|
|
makeNotificationBarTransparent()
|
2021-03-07 19:05:51 +01:00
|
|
|
setContentView(binding.root)
|
Add "Refresh" accessibility menu (#3121)
* Add "Refresh" accessibility menu to TimelineFragment
Per https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout
the layout does not provide accessibility events, and a menu item should be
provided as an alternative method for refreshing the content.
In `TimelineFragment`:
- Implement the `MenuProvider` interface so it can populate the action bar
menu in activities that host the fragment
- Create a "Refresh" menu item, and refresh the state when it is selected
`MainActivity` has to change how the menu is created, so that fragments
can add items to it.
In `MainActivity`:
- Call `setSupportActionBar` so `mainToolbar` participates in menus
- Implement the `MenuProvider` interface, and move menu creation there
- Set the title via supportActionBar
* Never show the refresh item as a menubar action
Per guidelines in https://developer.android.com/develop/ui/views/touch-and-input/swipe/add-swipe-interface#AddRefreshAction
* Add "Refresh" menu item for AccountMediaFragment
Also, fix the colour of the refresh progress indicator
* Implement "Refresh" for AnnouncementsActivity
* Add "Refresh" menu for ConversationsFragment
* Keep the tabs adapter over the life of the viewpager
Make `tabs` `var` instead of `val` in `MainPagerAdapter` so it can be updated
when tabs change.
Then detach the `tabLayoutMediator`, update the tabs, and call
`notifyItemRangeChanged` in `setupTabs()`.
This fixes a bug (not sure if it's this code, or in ViewPager2) where
assigning a new adapter to the view pager seemed to result in a leak of one
or more fragments. This wasn't user-visible, but it's a leak, and it becomes
user-visible when fragments want to display menus.
This also fixes two other bugs:
1. Be on the left-most tab. Scroll down a bit. Then modify the tabs at
"Account preferences > tabs", but keep the left-most tab as-is.
Then go back to MainActivity. Your reading position in the left-most
tab has been jumped to the top.
2. Be on any non-left-most tab. Then modify the tab list by reordering tabs
(adding/removing tabs is also OK).
Then go back to MainActivity. Your tab selection has been overridden,
and the left-most tab has been selected.
Because the fragments are not destroyed unnecessarily your reading position
is retained. And it remembers the tab you had selected, and as long as that
tab is still present you will be returned to it, even if it's changed
position in the list.
Fixes https://github.com/tuskyapp/Tusky/issues/3251
* Add "Refresh" menu for ScheduledStatusActivity
* Lint
* Add "Refresh" menu for SearchFragment / SearchActivity
* Explicitly set the searchview width
Using "collapseActionView" requires the user to press "Back" twice to exit
the activity, which is not acceptable.
* Move toolbar handling in to ViewThreadActivity
Previous code had the toolbar in the fragment's layout. Refactor to make
consistent with other activities, and move the toolbar in to the activity
layout.
Implement MenuProvider in ViewThreadFragment to adjust the menu in the
activity.
* Add "Refresh" menu to ViewThreadFragment
* Implement "Refresh" for ViewEditsFragment
* Lint
* Add "Refresh" menu to ReportStatusesFragment
* Add "Refresh" menu to NotificationsFragment
* Rename menu resource files
Be consistent with the layout resource files, which have an activity/fragment
prefix, then the lower_snake_case name of the activity or fragment it's for.
* Only enable refresh menu if swiptorefresh is enabled
Some timelines don't have swipetorefresh enabled (e.g., those shown on
AccountActivity). In those cases don't add the refresh menu, rely on the
hosting activity to provide it.
Update AccountActivity to provide the refresh menu item.
2023-03-01 19:58:18 +01:00
|
|
|
addMenuProvider(this)
|
2020-12-23 12:52:39 +01:00
|
|
|
|
2019-05-15 12:43:16 +02:00
|
|
|
// Obtain information to fill out the profile.
|
2019-12-21 18:56:16 +01:00
|
|
|
viewModel.setAccountInfo(intent.getStringExtra(KEY_ACCOUNT_ID)!!)
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2019-05-26 08:46:08 +02:00
|
|
|
val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this)
|
|
|
|
animateAvatar = sharedPrefs.getBoolean("animateGifAvatars", false)
|
2021-02-06 08:14:51 +01:00
|
|
|
animateEmojis = sharedPrefs.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false)
|
2019-05-26 08:46:08 +02:00
|
|
|
hideFab = sharedPrefs.getBoolean("fabHide", false)
|
2019-05-15 12:43:16 +02:00
|
|
|
|
2021-11-16 21:38:59 +01:00
|
|
|
handleWindowInsets()
|
2019-05-15 12:43:16 +02:00
|
|
|
setupToolbar()
|
|
|
|
setupTabs()
|
|
|
|
setupAccountViews()
|
|
|
|
setupRefreshLayout()
|
|
|
|
subscribeObservables()
|
2019-09-07 16:34:17 +02:00
|
|
|
|
|
|
|
if (viewModel.isSelf) {
|
|
|
|
updateButtons()
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.saveNoteInfo.hide()
|
2020-11-17 20:10:54 +01:00
|
|
|
} else {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.saveNoteInfo.visibility = View.INVISIBLE
|
2019-09-07 16:34:17 +02:00
|
|
|
}
|
2019-05-15 12:43:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load colors and dimensions from resources
|
|
|
|
*/
|
|
|
|
private fun loadResources() {
|
2023-02-04 19:58:53 +01:00
|
|
|
toolbarColor = MaterialColors.getColor(this, com.google.android.material.R.attr.colorSurface, Color.BLACK)
|
2022-08-04 16:48:26 +02:00
|
|
|
statusBarColorTransparent = getColor(R.color.transparent_statusbar_background)
|
2023-02-04 19:58:53 +01:00
|
|
|
statusBarColorOpaque = MaterialColors.getColor(this, androidx.appcompat.R.attr.colorPrimaryDark, Color.BLACK)
|
2019-05-15 12:43:16 +02:00
|
|
|
avatarSize = resources.getDimension(R.dimen.account_activity_avatar_size)
|
|
|
|
titleVisibleHeight = resources.getDimensionPixelSize(R.dimen.account_activity_scroll_title_visible_height)
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup account widgets visibility and actions
|
|
|
|
*/
|
|
|
|
private fun setupAccountViews() {
|
|
|
|
// Initialise the default UI states.
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFloatingActionButton.hide()
|
|
|
|
binding.accountFollowButton.hide()
|
|
|
|
binding.accountMuteButton.hide()
|
|
|
|
binding.accountFollowsYouTextView.hide()
|
2019-05-15 12:43:16 +02:00
|
|
|
|
|
|
|
// setup the RecyclerView for the account fields
|
2021-02-06 08:14:51 +01:00
|
|
|
accountFieldAdapter = AccountFieldAdapter(this, animateEmojis)
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFieldList.isNestedScrollingEnabled = false
|
|
|
|
binding.accountFieldList.layoutManager = LinearLayoutManager(this)
|
|
|
|
binding.accountFieldList.adapter = accountFieldAdapter
|
2019-05-15 12:43:16 +02:00
|
|
|
|
|
|
|
val accountListClickListener = { v: View ->
|
|
|
|
val type = when (v.id) {
|
|
|
|
R.id.accountFollowers -> AccountListActivity.Type.FOLLOWERS
|
|
|
|
R.id.accountFollowing -> AccountListActivity.Type.FOLLOWS
|
|
|
|
else -> throw AssertionError()
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
2019-05-15 12:43:16 +02:00
|
|
|
val accountListIntent = AccountListActivity.newIntent(this, type, viewModel.accountId)
|
|
|
|
startActivityWithSlideInAnimation(accountListIntent)
|
|
|
|
}
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFollowers.setOnClickListener(accountListClickListener)
|
|
|
|
binding.accountFollowing.setOnClickListener(accountListClickListener)
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountStatuses.setOnClickListener {
|
2019-05-15 12:43:16 +02:00
|
|
|
// Make nice ripple effect on tab
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountTabLayout.getTabAt(0)!!.select()
|
|
|
|
val poorTabView = (binding.accountTabLayout.getChildAt(0) as ViewGroup).getChildAt(0)
|
2019-05-15 12:43:16 +02:00
|
|
|
poorTabView.isPressed = true
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountTabLayout.postDelayed({ poorTabView.isPressed = false }, 300)
|
2019-05-15 12:43:16 +02:00
|
|
|
}
|
2020-12-23 19:13:37 +01:00
|
|
|
|
|
|
|
// If wellbeing mode is enabled, follow stats and posts count should be hidden
|
|
|
|
val preferences = PreferenceManager.getDefaultSharedPreferences(this)
|
|
|
|
val wellbeingEnabled = preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_PROFILE, false)
|
|
|
|
|
|
|
|
if (wellbeingEnabled) {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountStatuses.hide()
|
|
|
|
binding.accountFollowers.hide()
|
|
|
|
binding.accountFollowing.hide()
|
2020-12-23 19:13:37 +01:00
|
|
|
}
|
2019-05-15 12:43:16 +02:00
|
|
|
}
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2019-05-15 12:43:16 +02:00
|
|
|
/**
|
|
|
|
* Init timeline tabs
|
|
|
|
*/
|
|
|
|
private fun setupTabs() {
|
|
|
|
// Setup the tabs and timeline pager.
|
2019-11-06 20:17:53 +01:00
|
|
|
adapter = AccountPagerAdapter(this, viewModel.accountId)
|
|
|
|
|
2023-01-13 19:51:09 +01:00
|
|
|
binding.accountFragmentViewPager.reduceSwipeSensitivity()
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFragmentViewPager.adapter = adapter
|
|
|
|
binding.accountFragmentViewPager.offscreenPageLimit = 2
|
2019-11-06 20:17:53 +01:00
|
|
|
|
2022-03-27 12:23:25 +02:00
|
|
|
val pageTitles = arrayOf(getString(R.string.title_posts), getString(R.string.title_posts_with_replies), getString(R.string.title_posts_pinned), getString(R.string.title_media))
|
2019-11-06 20:17:53 +01:00
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
TabLayoutMediator(binding.accountTabLayout, binding.accountFragmentViewPager) { tab, position ->
|
2019-11-06 20:17:53 +01:00
|
|
|
tab.text = pageTitles[position]
|
|
|
|
}.attach()
|
|
|
|
|
|
|
|
val pageMargin = resources.getDimensionPixelSize(R.dimen.tab_page_margin)
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFragmentViewPager.setPageTransformer(MarginPageTransformer(pageMargin))
|
2019-11-06 20:17:53 +01:00
|
|
|
|
2022-12-01 19:51:13 +01:00
|
|
|
val enableSwipeForTabs = preferences.getBoolean(PrefKeys.ENABLE_SWIPE_FOR_TABS, true)
|
|
|
|
binding.accountFragmentViewPager.isUserInputEnabled = enableSwipeForTabs
|
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountTabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
|
2019-05-15 12:43:16 +02:00
|
|
|
override fun onTabReselected(tab: TabLayout.Tab?) {
|
|
|
|
tab?.position?.let { position ->
|
|
|
|
(adapter.getFragment(position) as? ReselectableFragment)?.onReselect()
|
|
|
|
}
|
|
|
|
}
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2019-05-15 12:43:16 +02:00
|
|
|
override fun onTabUnselected(tab: TabLayout.Tab?) {}
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2019-05-15 12:43:16 +02:00
|
|
|
override fun onTabSelected(tab: TabLayout.Tab?) {}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-11-16 21:38:59 +01:00
|
|
|
private fun handleWindowInsets() {
|
2021-06-01 19:46:07 +02:00
|
|
|
ViewCompat.setOnApplyWindowInsetsListener(binding.accountCoordinatorLayout) { _, insets ->
|
|
|
|
val top = insets.getInsets(systemBars()).top
|
|
|
|
val toolbarParams = binding.accountToolbar.layoutParams as ViewGroup.MarginLayoutParams
|
2018-06-18 13:26:18 +02:00
|
|
|
toolbarParams.topMargin = top
|
2021-11-16 21:38:59 +01:00
|
|
|
|
2022-02-09 20:45:56 +01:00
|
|
|
val right = insets.getInsets(systemBars()).right
|
2021-11-16 21:38:59 +01:00
|
|
|
val bottom = insets.getInsets(systemBars()).bottom
|
2022-02-09 20:45:56 +01:00
|
|
|
val left = insets.getInsets(systemBars()).left
|
|
|
|
binding.accountCoordinatorLayout.updatePadding(right = right, bottom = bottom, left = left)
|
2021-11-16 21:38:59 +01:00
|
|
|
|
2021-06-01 19:46:07 +02:00
|
|
|
WindowInsetsCompat.CONSUMED
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
2021-11-16 21:38:59 +01:00
|
|
|
}
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2021-11-16 21:38:59 +01:00
|
|
|
private fun setupToolbar() {
|
2018-06-18 13:26:18 +02:00
|
|
|
// Setup the toolbar.
|
2021-03-07 19:05:51 +01:00
|
|
|
setSupportActionBar(binding.accountToolbar)
|
2019-10-01 18:49:34 +02:00
|
|
|
supportActionBar?.run {
|
|
|
|
setDisplayHomeAsUpEnabled(true)
|
|
|
|
setDisplayShowHomeEnabled(true)
|
|
|
|
setDisplayShowTitleEnabled(false)
|
|
|
|
}
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2019-10-12 20:00:29 +02:00
|
|
|
val appBarElevation = resources.getDimension(R.dimen.actionbar_elevation)
|
|
|
|
|
|
|
|
val toolbarBackground = MaterialShapeDrawable.createWithElevationOverlay(this, appBarElevation)
|
|
|
|
toolbarBackground.fillColor = ColorStateList.valueOf(Color.TRANSPARENT)
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountToolbar.background = toolbarBackground
|
2019-10-12 20:00:29 +02:00
|
|
|
|
2023-02-23 19:30:27 +01:00
|
|
|
// Provide a non-transparent background to the navigation and overflow icons to ensure
|
|
|
|
// they remain visible over whatever the profile background image might be.
|
|
|
|
val backgroundCircle = AppCompatResources.getDrawable(this, R.drawable.background_circle)!!
|
|
|
|
backgroundCircle.alpha = 210 // Any lower than this and the backgrounds interfere
|
|
|
|
binding.accountToolbar.navigationIcon = LayerDrawable(
|
|
|
|
arrayOf(
|
|
|
|
backgroundCircle,
|
|
|
|
binding.accountToolbar.navigationIcon
|
|
|
|
)
|
|
|
|
)
|
|
|
|
binding.accountToolbar.overflowIcon = LayerDrawable(
|
|
|
|
arrayOf(
|
|
|
|
backgroundCircle,
|
|
|
|
binding.accountToolbar.overflowIcon
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountHeaderInfoContainer.background = MaterialShapeDrawable.createWithElevationOverlay(this, appBarElevation)
|
2019-10-12 20:00:29 +02:00
|
|
|
|
|
|
|
val avatarBackground = MaterialShapeDrawable.createWithElevationOverlay(this, appBarElevation).apply {
|
|
|
|
fillColor = ColorStateList.valueOf(toolbarColor)
|
|
|
|
elevation = appBarElevation
|
|
|
|
shapeAppearanceModel = ShapeAppearanceModel.builder()
|
2021-06-28 21:13:24 +02:00
|
|
|
.setAllCornerSizes(resources.getDimension(R.dimen.account_avatar_background_radius))
|
|
|
|
.build()
|
2019-10-12 20:00:29 +02:00
|
|
|
}
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountAvatarImageView.background = avatarBackground
|
2019-10-12 20:00:29 +02:00
|
|
|
|
2018-06-18 13:26:18 +02:00
|
|
|
// Add a listener to change the toolbar icon color when it enters/exits its collapsed state.
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountAppBarLayout.addOnOffsetChangedListener(object : AppBarLayout.OnOffsetChangedListener {
|
2019-10-01 08:08:21 +02:00
|
|
|
|
2018-06-18 13:26:18 +02:00
|
|
|
override fun onOffsetChanged(appBarLayout: AppBarLayout, verticalOffset: Int) {
|
2019-12-19 19:09:40 +01:00
|
|
|
if (verticalOffset == oldOffset) {
|
2019-10-01 08:08:21 +02:00
|
|
|
return
|
|
|
|
}
|
2019-10-01 18:49:34 +02:00
|
|
|
oldOffset = verticalOffset
|
2019-10-01 08:08:21 +02:00
|
|
|
|
2020-01-30 21:37:28 +01:00
|
|
|
if (titleVisibleHeight + verticalOffset < 0) {
|
2019-06-05 21:35:29 +02:00
|
|
|
supportActionBar?.setDisplayShowTitleEnabled(true)
|
2018-06-18 13:26:18 +02:00
|
|
|
} else {
|
2019-06-05 21:35:29 +02:00
|
|
|
supportActionBar?.setDisplayShowTitleEnabled(false)
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
|
|
|
|
2022-12-30 11:22:01 +01:00
|
|
|
if (hideFab && !blocking) {
|
2018-06-18 13:26:18 +02:00
|
|
|
if (verticalOffset > oldOffset) {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFloatingActionButton.show()
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
|
|
|
if (verticalOffset < oldOffset) {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFloatingActionButton.hide()
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val scaledAvatarSize = (avatarSize + verticalOffset) / avatarSize
|
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountAvatarImageView.scaleX = scaledAvatarSize
|
|
|
|
binding.accountAvatarImageView.scaleY = scaledAvatarSize
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountAvatarImageView.visible(scaledAvatarSize > 0)
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2019-10-12 20:00:29 +02:00
|
|
|
val transparencyPercent = (abs(verticalOffset) / titleVisibleHeight.toFloat()).coerceAtMost(1f)
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2018-09-16 18:54:12 +02:00
|
|
|
window.statusBarColor = argbEvaluator.evaluate(transparencyPercent, statusBarColorTransparent, statusBarColorOpaque) as Int
|
2018-06-18 13:26:18 +02:00
|
|
|
|
|
|
|
val evaluatedToolbarColor = argbEvaluator.evaluate(transparencyPercent, Color.TRANSPARENT, toolbarColor) as Int
|
2019-10-12 20:00:29 +02:00
|
|
|
|
|
|
|
toolbarBackground.fillColor = ColorStateList.valueOf(evaluatedToolbarColor)
|
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.swipeToRefreshLayout.isEnabled = verticalOffset == 0
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
|
|
|
})
|
2019-05-15 12:43:16 +02:00
|
|
|
}
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2019-05-15 12:43:16 +02:00
|
|
|
private fun makeNotificationBarTransparent() {
|
2021-06-01 19:46:07 +02:00
|
|
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
2019-10-12 20:00:29 +02:00
|
|
|
window.statusBarColor = statusBarColorTransparent
|
2019-05-15 12:43:16 +02:00
|
|
|
}
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2019-05-15 12:43:16 +02:00
|
|
|
/**
|
|
|
|
* Subscribe to data loaded at the view model
|
|
|
|
*/
|
|
|
|
private fun subscribeObservables() {
|
2020-10-25 18:36:00 +01:00
|
|
|
viewModel.accountData.observe(this) {
|
2019-05-15 12:43:16 +02:00
|
|
|
when (it) {
|
|
|
|
is Success -> onAccountChanged(it.data)
|
|
|
|
is Error -> {
|
2021-03-07 19:05:51 +01:00
|
|
|
Snackbar.make(binding.accountCoordinatorLayout, R.string.error_generic, Snackbar.LENGTH_LONG)
|
2021-06-28 21:13:24 +02:00
|
|
|
.setAction(R.string.action_retry) { viewModel.refresh() }
|
|
|
|
.show()
|
2019-04-08 15:40:16 +02:00
|
|
|
}
|
2022-01-20 21:10:32 +01:00
|
|
|
is Loading -> { }
|
2019-04-08 15:40:16 +02:00
|
|
|
}
|
2020-10-25 18:36:00 +01:00
|
|
|
}
|
|
|
|
viewModel.relationshipData.observe(this) {
|
2019-05-15 12:43:16 +02:00
|
|
|
val relation = it?.data
|
|
|
|
if (relation != null) {
|
|
|
|
onRelationshipChanged(relation)
|
|
|
|
}
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2019-05-15 12:43:16 +02:00
|
|
|
if (it is Error) {
|
2021-03-07 19:05:51 +01:00
|
|
|
Snackbar.make(binding.accountCoordinatorLayout, R.string.error_generic, Snackbar.LENGTH_LONG)
|
2021-06-28 21:13:24 +02:00
|
|
|
.setAction(R.string.action_retry) { viewModel.refresh() }
|
|
|
|
.show()
|
2019-05-15 12:43:16 +02:00
|
|
|
}
|
2020-10-25 18:36:00 +01:00
|
|
|
}
|
2020-11-17 20:10:54 +01:00
|
|
|
viewModel.noteSaved.observe(this) {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.saveNoteInfo.visible(it, View.INVISIBLE)
|
2020-11-17 20:10:54 +01:00
|
|
|
}
|
2023-01-27 20:50:45 +01:00
|
|
|
|
|
|
|
// "Post failed" dialog should display in this activity
|
|
|
|
draftsAlert.observeInContext(this, true)
|
2019-05-15 12:43:16 +02:00
|
|
|
}
|
2018-06-18 13:26:18 +02:00
|
|
|
|
Add "Refresh" accessibility menu (#3121)
* Add "Refresh" accessibility menu to TimelineFragment
Per https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout
the layout does not provide accessibility events, and a menu item should be
provided as an alternative method for refreshing the content.
In `TimelineFragment`:
- Implement the `MenuProvider` interface so it can populate the action bar
menu in activities that host the fragment
- Create a "Refresh" menu item, and refresh the state when it is selected
`MainActivity` has to change how the menu is created, so that fragments
can add items to it.
In `MainActivity`:
- Call `setSupportActionBar` so `mainToolbar` participates in menus
- Implement the `MenuProvider` interface, and move menu creation there
- Set the title via supportActionBar
* Never show the refresh item as a menubar action
Per guidelines in https://developer.android.com/develop/ui/views/touch-and-input/swipe/add-swipe-interface#AddRefreshAction
* Add "Refresh" menu item for AccountMediaFragment
Also, fix the colour of the refresh progress indicator
* Implement "Refresh" for AnnouncementsActivity
* Add "Refresh" menu for ConversationsFragment
* Keep the tabs adapter over the life of the viewpager
Make `tabs` `var` instead of `val` in `MainPagerAdapter` so it can be updated
when tabs change.
Then detach the `tabLayoutMediator`, update the tabs, and call
`notifyItemRangeChanged` in `setupTabs()`.
This fixes a bug (not sure if it's this code, or in ViewPager2) where
assigning a new adapter to the view pager seemed to result in a leak of one
or more fragments. This wasn't user-visible, but it's a leak, and it becomes
user-visible when fragments want to display menus.
This also fixes two other bugs:
1. Be on the left-most tab. Scroll down a bit. Then modify the tabs at
"Account preferences > tabs", but keep the left-most tab as-is.
Then go back to MainActivity. Your reading position in the left-most
tab has been jumped to the top.
2. Be on any non-left-most tab. Then modify the tab list by reordering tabs
(adding/removing tabs is also OK).
Then go back to MainActivity. Your tab selection has been overridden,
and the left-most tab has been selected.
Because the fragments are not destroyed unnecessarily your reading position
is retained. And it remembers the tab you had selected, and as long as that
tab is still present you will be returned to it, even if it's changed
position in the list.
Fixes https://github.com/tuskyapp/Tusky/issues/3251
* Add "Refresh" menu for ScheduledStatusActivity
* Lint
* Add "Refresh" menu for SearchFragment / SearchActivity
* Explicitly set the searchview width
Using "collapseActionView" requires the user to press "Back" twice to exit
the activity, which is not acceptable.
* Move toolbar handling in to ViewThreadActivity
Previous code had the toolbar in the fragment's layout. Refactor to make
consistent with other activities, and move the toolbar in to the activity
layout.
Implement MenuProvider in ViewThreadFragment to adjust the menu in the
activity.
* Add "Refresh" menu to ViewThreadFragment
* Implement "Refresh" for ViewEditsFragment
* Lint
* Add "Refresh" menu to ReportStatusesFragment
* Add "Refresh" menu to NotificationsFragment
* Rename menu resource files
Be consistent with the layout resource files, which have an activity/fragment
prefix, then the lower_snake_case name of the activity or fragment it's for.
* Only enable refresh menu if swiptorefresh is enabled
Some timelines don't have swipetorefresh enabled (e.g., those shown on
AccountActivity). In those cases don't add the refresh menu, rely on the
hosting activity to provide it.
Update AccountActivity to provide the refresh menu item.
2023-03-01 19:58:18 +01:00
|
|
|
private fun onRefresh() {
|
|
|
|
viewModel.refresh()
|
|
|
|
adapter.refreshContent()
|
|
|
|
}
|
|
|
|
|
2019-05-15 12:43:16 +02:00
|
|
|
/**
|
|
|
|
* Setup swipe to refresh layout
|
|
|
|
*/
|
|
|
|
private fun setupRefreshLayout() {
|
Add "Refresh" accessibility menu (#3121)
* Add "Refresh" accessibility menu to TimelineFragment
Per https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout
the layout does not provide accessibility events, and a menu item should be
provided as an alternative method for refreshing the content.
In `TimelineFragment`:
- Implement the `MenuProvider` interface so it can populate the action bar
menu in activities that host the fragment
- Create a "Refresh" menu item, and refresh the state when it is selected
`MainActivity` has to change how the menu is created, so that fragments
can add items to it.
In `MainActivity`:
- Call `setSupportActionBar` so `mainToolbar` participates in menus
- Implement the `MenuProvider` interface, and move menu creation there
- Set the title via supportActionBar
* Never show the refresh item as a menubar action
Per guidelines in https://developer.android.com/develop/ui/views/touch-and-input/swipe/add-swipe-interface#AddRefreshAction
* Add "Refresh" menu item for AccountMediaFragment
Also, fix the colour of the refresh progress indicator
* Implement "Refresh" for AnnouncementsActivity
* Add "Refresh" menu for ConversationsFragment
* Keep the tabs adapter over the life of the viewpager
Make `tabs` `var` instead of `val` in `MainPagerAdapter` so it can be updated
when tabs change.
Then detach the `tabLayoutMediator`, update the tabs, and call
`notifyItemRangeChanged` in `setupTabs()`.
This fixes a bug (not sure if it's this code, or in ViewPager2) where
assigning a new adapter to the view pager seemed to result in a leak of one
or more fragments. This wasn't user-visible, but it's a leak, and it becomes
user-visible when fragments want to display menus.
This also fixes two other bugs:
1. Be on the left-most tab. Scroll down a bit. Then modify the tabs at
"Account preferences > tabs", but keep the left-most tab as-is.
Then go back to MainActivity. Your reading position in the left-most
tab has been jumped to the top.
2. Be on any non-left-most tab. Then modify the tab list by reordering tabs
(adding/removing tabs is also OK).
Then go back to MainActivity. Your tab selection has been overridden,
and the left-most tab has been selected.
Because the fragments are not destroyed unnecessarily your reading position
is retained. And it remembers the tab you had selected, and as long as that
tab is still present you will be returned to it, even if it's changed
position in the list.
Fixes https://github.com/tuskyapp/Tusky/issues/3251
* Add "Refresh" menu for ScheduledStatusActivity
* Lint
* Add "Refresh" menu for SearchFragment / SearchActivity
* Explicitly set the searchview width
Using "collapseActionView" requires the user to press "Back" twice to exit
the activity, which is not acceptable.
* Move toolbar handling in to ViewThreadActivity
Previous code had the toolbar in the fragment's layout. Refactor to make
consistent with other activities, and move the toolbar in to the activity
layout.
Implement MenuProvider in ViewThreadFragment to adjust the menu in the
activity.
* Add "Refresh" menu to ViewThreadFragment
* Implement "Refresh" for ViewEditsFragment
* Lint
* Add "Refresh" menu to ReportStatusesFragment
* Add "Refresh" menu to NotificationsFragment
* Rename menu resource files
Be consistent with the layout resource files, which have an activity/fragment
prefix, then the lower_snake_case name of the activity or fragment it's for.
* Only enable refresh menu if swiptorefresh is enabled
Some timelines don't have swipetorefresh enabled (e.g., those shown on
AccountActivity). In those cases don't add the refresh menu, rely on the
hosting activity to provide it.
Update AccountActivity to provide the refresh menu item.
2023-03-01 19:58:18 +01:00
|
|
|
binding.swipeToRefreshLayout.setOnRefreshListener { onRefresh() }
|
2021-06-28 21:13:24 +02:00
|
|
|
viewModel.isRefreshing.observe(
|
2022-04-15 13:20:27 +02:00
|
|
|
this
|
|
|
|
) { isRefreshing ->
|
|
|
|
binding.swipeToRefreshLayout.isRefreshing = isRefreshing == true
|
|
|
|
}
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.swipeToRefreshLayout.setColorSchemeResources(R.color.tusky_blue)
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun onAccountChanged(account: Account?) {
|
2019-05-15 12:43:16 +02:00
|
|
|
loadedAccount = account ?: return
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2022-03-27 12:23:25 +02:00
|
|
|
val usernameFormatted = getString(R.string.post_username_format, account.username)
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountUsernameTextView.text = usernameFormatted
|
|
|
|
binding.accountDisplayNameTextView.text = account.name.emojify(account.emojis, binding.accountDisplayNameTextView, animateEmojis)
|
2019-05-15 12:43:16 +02:00
|
|
|
|
2023-01-09 21:08:46 +01:00
|
|
|
// Long press on username to copy it to clipboard
|
|
|
|
for (view in listOf(binding.accountUsernameTextView, binding.accountDisplayNameTextView)) {
|
|
|
|
view.setOnLongClickListener {
|
|
|
|
loadedAccount?.let { loadedAccount ->
|
|
|
|
val fullUsername = getFullUsername(loadedAccount)
|
|
|
|
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
|
|
|
clipboard.setPrimaryClip(ClipData.newPlainText(null, fullUsername))
|
|
|
|
Snackbar.make(binding.root, getString(R.string.account_username_copied), Snackbar.LENGTH_SHORT)
|
|
|
|
.show()
|
|
|
|
}
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-15 13:20:27 +02:00
|
|
|
val emojifiedNote = account.note.parseAsMastodonHtml().emojify(account.emojis, binding.accountNoteTextView, animateEmojis)
|
2022-02-25 18:56:21 +01:00
|
|
|
setClickableText(binding.accountNoteTextView, emojifiedNote, emptyList(), null, this)
|
2019-05-15 12:43:16 +02:00
|
|
|
|
2023-03-01 21:06:55 +01:00
|
|
|
accountFieldAdapter.fields = account.fields.orEmpty()
|
|
|
|
accountFieldAdapter.emojis = account.emojis.orEmpty()
|
2019-05-15 12:43:16 +02:00
|
|
|
accountFieldAdapter.notifyDataSetChanged()
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountLockedImageView.visible(account.locked)
|
|
|
|
binding.accountBadgeTextView.visible(account.bot)
|
2019-05-15 12:43:16 +02:00
|
|
|
|
|
|
|
updateAccountAvatar()
|
|
|
|
updateToolbar()
|
|
|
|
updateMovedAccount()
|
|
|
|
updateRemoteAccount()
|
2022-05-17 19:49:42 +02:00
|
|
|
updateAccountJoinedDate()
|
2019-05-15 12:43:16 +02:00
|
|
|
updateAccountStats()
|
2019-07-10 06:52:51 +02:00
|
|
|
invalidateOptionsMenu()
|
2019-05-15 12:43:16 +02:00
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountMuteButton.setOnClickListener {
|
2020-07-27 10:28:59 +02:00
|
|
|
viewModel.unmuteAccount()
|
2019-05-15 12:43:16 +02:00
|
|
|
updateMuteButton()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-17 19:49:42 +02:00
|
|
|
private fun updateAccountJoinedDate() {
|
|
|
|
loadedAccount?.let { account ->
|
|
|
|
try {
|
|
|
|
binding.accountDateJoined.text = resources.getString(
|
|
|
|
R.string.account_date_joined,
|
|
|
|
SimpleDateFormat("MMMM, yyyy", Locale.getDefault()).format(account.createdAt)
|
|
|
|
)
|
|
|
|
binding.accountDateJoined.visibility = View.VISIBLE
|
|
|
|
} catch (e: ParseException) {
|
|
|
|
binding.accountDateJoined.visibility = View.GONE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-15 12:43:16 +02:00
|
|
|
/**
|
|
|
|
* Load account's avatar and header image
|
|
|
|
*/
|
|
|
|
private fun updateAccountAvatar() {
|
|
|
|
loadedAccount?.let { account ->
|
2019-05-26 08:46:08 +02:00
|
|
|
|
|
|
|
loadAvatar(
|
2021-06-28 21:13:24 +02:00
|
|
|
account.avatar,
|
|
|
|
binding.accountAvatarImageView,
|
|
|
|
resources.getDimensionPixelSize(R.dimen.avatar_radius_94dp),
|
|
|
|
animateAvatar
|
2019-05-26 08:46:08 +02:00
|
|
|
)
|
|
|
|
|
2019-04-16 21:39:12 +02:00
|
|
|
Glide.with(this)
|
2021-06-28 21:13:24 +02:00
|
|
|
.asBitmap()
|
|
|
|
.load(account.header)
|
|
|
|
.centerCrop()
|
|
|
|
.into(binding.accountHeaderImageView)
|
2019-05-15 12:43:16 +02:00
|
|
|
|
2023-02-20 20:06:50 +01:00
|
|
|
binding.accountAvatarImageView.setOnClickListener { view ->
|
|
|
|
viewImage(view, account.avatar)
|
|
|
|
}
|
|
|
|
binding.accountHeaderImageView.setOnClickListener { view ->
|
|
|
|
viewImage(view, account.header)
|
2018-07-30 15:42:45 +02:00
|
|
|
}
|
2019-05-15 12:43:16 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-30 15:42:45 +02:00
|
|
|
|
2023-02-20 20:06:50 +01:00
|
|
|
private fun viewImage(view: View, uri: String) {
|
|
|
|
view.transitionName = uri
|
|
|
|
startActivity(
|
|
|
|
ViewMediaActivity.newSingleImageIntent(view.context, uri),
|
|
|
|
ActivityOptionsCompat.makeSceneTransitionAnimation(this, view, uri).toBundle()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-05-15 12:43:16 +02:00
|
|
|
/**
|
|
|
|
* Update toolbar views for loaded account
|
|
|
|
*/
|
|
|
|
private fun updateToolbar() {
|
|
|
|
loadedAccount?.let { account ->
|
2022-05-03 19:15:59 +02:00
|
|
|
supportActionBar?.title = account.name.emojify(account.emojis, binding.accountToolbar, animateEmojis)
|
2022-03-27 12:23:25 +02:00
|
|
|
supportActionBar?.subtitle = String.format(getString(R.string.post_username_format), account.username)
|
2019-05-15 12:43:16 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2019-05-15 12:43:16 +02:00
|
|
|
/**
|
|
|
|
* Update moved account info
|
|
|
|
*/
|
|
|
|
private fun updateMovedAccount() {
|
|
|
|
loadedAccount?.moved?.let { movedAccount ->
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountMovedView.show()
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountMovedView.setOnClickListener {
|
2019-05-15 12:43:16 +02:00
|
|
|
onViewAccount(movedAccount.id)
|
|
|
|
}
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountMovedDisplayName.text = movedAccount.name
|
2022-03-27 12:23:25 +02:00
|
|
|
binding.accountMovedUsername.text = getString(R.string.post_username_format, movedAccount.username)
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2019-05-26 08:46:08 +02:00
|
|
|
val avatarRadius = resources.getDimensionPixelSize(R.dimen.avatar_radius_48dp)
|
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
loadAvatar(movedAccount.avatar, binding.accountMovedAvatar, avatarRadius, animateAvatar)
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountMovedText.text = getString(R.string.account_moved_description, movedAccount.name)
|
2019-05-15 12:43:16 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2019-05-15 12:43:16 +02:00
|
|
|
/**
|
|
|
|
* Check is account remote and update info if so
|
|
|
|
*/
|
|
|
|
private fun updateRemoteAccount() {
|
|
|
|
loadedAccount?.let { account ->
|
2018-10-03 21:53:31 +02:00
|
|
|
if (account.isRemote()) {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountRemoveView.show()
|
|
|
|
binding.accountRemoveView.setOnClickListener {
|
2022-02-25 18:56:21 +01:00
|
|
|
openLink(account.url)
|
2018-10-03 21:53:31 +02:00
|
|
|
}
|
|
|
|
}
|
2019-05-15 12:43:16 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-03 21:53:31 +02:00
|
|
|
|
2019-05-15 12:43:16 +02:00
|
|
|
/**
|
|
|
|
* Update account stat info
|
|
|
|
*/
|
|
|
|
private fun updateAccountStats() {
|
|
|
|
loadedAccount?.let { account ->
|
2018-06-18 13:26:18 +02:00
|
|
|
val numberFormat = NumberFormat.getNumberInstance()
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFollowersTextView.text = numberFormat.format(account.followersCount)
|
|
|
|
binding.accountFollowingTextView.text = numberFormat.format(account.followingCount)
|
|
|
|
binding.accountStatusesTextView.text = numberFormat.format(account.statusesCount)
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFloatingActionButton.setOnClickListener { mention() }
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFollowButton.setOnClickListener {
|
2019-05-15 12:43:16 +02:00
|
|
|
if (viewModel.isSelf) {
|
2018-06-18 13:26:18 +02:00
|
|
|
val intent = Intent(this@AccountActivity, EditProfileActivity::class.java)
|
2018-08-15 20:47:09 +02:00
|
|
|
startActivity(intent)
|
2018-06-18 13:26:18 +02:00
|
|
|
return@setOnClickListener
|
|
|
|
}
|
2019-05-15 12:43:16 +02:00
|
|
|
|
|
|
|
if (blocking) {
|
|
|
|
viewModel.changeBlockState()
|
|
|
|
return@setOnClickListener
|
|
|
|
}
|
|
|
|
|
2018-06-18 13:26:18 +02:00
|
|
|
when (followState) {
|
2019-05-15 12:43:16 +02:00
|
|
|
FollowState.NOT_FOLLOWING -> {
|
|
|
|
viewModel.changeFollowState()
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
2019-05-15 12:43:16 +02:00
|
|
|
FollowState.REQUESTED -> {
|
2018-06-18 13:26:18 +02:00
|
|
|
showFollowRequestPendingDialog()
|
|
|
|
}
|
2019-05-15 12:43:16 +02:00
|
|
|
FollowState.FOLLOWING -> {
|
2018-06-18 13:26:18 +02:00
|
|
|
showUnfollowWarningDialog()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateFollowButton()
|
2023-01-27 19:49:07 +01:00
|
|
|
updateSubscribeButton()
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun onRelationshipChanged(relation: Relationship) {
|
|
|
|
followState = when {
|
|
|
|
relation.following -> FollowState.FOLLOWING
|
|
|
|
relation.requested -> FollowState.REQUESTED
|
|
|
|
else -> FollowState.NOT_FOLLOWING
|
|
|
|
}
|
|
|
|
blocking = relation.blocking
|
|
|
|
muting = relation.muting
|
2020-06-23 19:59:49 +02:00
|
|
|
blockingDomain = relation.blockingDomain
|
2018-06-18 13:26:18 +02:00
|
|
|
showingReblogs = relation.showingReblogs
|
|
|
|
|
2020-12-23 19:13:37 +01:00
|
|
|
// If wellbeing mode is enabled, "follows you" text should not be visible
|
|
|
|
val preferences = PreferenceManager.getDefaultSharedPreferences(this)
|
|
|
|
val wellbeingEnabled = preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_PROFILE, false)
|
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFollowsYouTextView.visible(relation.followedBy && !wellbeingEnabled)
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2020-12-23 12:52:39 +01:00
|
|
|
// because subscribing is Pleroma extension, enable it __only__ when we have non-null subscribing field
|
|
|
|
// it's also now supported in Mastodon 3.3.0rc but called notifying and use different API call
|
2021-06-28 21:13:24 +02:00
|
|
|
if (!viewModel.isSelf && followState == FollowState.FOLLOWING &&
|
|
|
|
(relation.subscribing != null || relation.notifying != null)
|
|
|
|
) {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountSubscribeButton.show()
|
|
|
|
binding.accountSubscribeButton.setOnClickListener {
|
2020-12-23 12:52:39 +01:00
|
|
|
viewModel.changeSubscribingState()
|
|
|
|
}
|
2023-03-13 13:16:39 +01:00
|
|
|
if (relation.notifying != null) {
|
2020-12-23 12:52:39 +01:00
|
|
|
subscribing = relation.notifying
|
2023-03-13 13:16:39 +01:00
|
|
|
} else if (relation.subscribing != null) {
|
2020-12-23 12:52:39 +01:00
|
|
|
subscribing = relation.subscribing
|
2023-03-13 13:16:39 +01:00
|
|
|
}
|
2020-12-23 12:52:39 +01:00
|
|
|
}
|
|
|
|
|
2021-02-18 19:26:03 +01:00
|
|
|
// remove the listener so it doesn't fire on non-user changes
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountNoteTextInputLayout.editText?.removeTextChangedListener(noteWatcher)
|
2021-02-18 19:26:03 +01:00
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountNoteTextInputLayout.visible(relation.note != null)
|
|
|
|
binding.accountNoteTextInputLayout.editText?.setText(relation.note)
|
2020-11-17 20:10:54 +01:00
|
|
|
|
2023-03-10 20:27:24 +01:00
|
|
|
noteWatcher = binding.accountNoteTextInputLayout.editText?.doAfterTextChanged { s ->
|
2020-11-17 20:10:54 +01:00
|
|
|
viewModel.noteChanged(s.toString())
|
|
|
|
}
|
2023-03-10 20:27:24 +01:00
|
|
|
|
|
|
|
updateButtons()
|
2020-11-17 20:10:54 +01:00
|
|
|
}
|
|
|
|
|
2018-06-18 13:26:18 +02:00
|
|
|
private fun updateFollowButton() {
|
2019-05-15 12:43:16 +02:00
|
|
|
if (viewModel.isSelf) {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFollowButton.setText(R.string.action_edit_own_profile)
|
2018-06-18 13:26:18 +02:00
|
|
|
return
|
|
|
|
}
|
2019-05-15 12:43:16 +02:00
|
|
|
if (blocking) {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFollowButton.setText(R.string.action_unblock)
|
2019-05-15 12:43:16 +02:00
|
|
|
return
|
|
|
|
}
|
2018-06-18 13:26:18 +02:00
|
|
|
when (followState) {
|
2019-05-15 12:43:16 +02:00
|
|
|
FollowState.NOT_FOLLOWING -> {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFollowButton.setText(R.string.action_follow)
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
2019-05-15 12:43:16 +02:00
|
|
|
FollowState.REQUESTED -> {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFollowButton.setText(R.string.state_follow_requested)
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
2019-05-15 12:43:16 +02:00
|
|
|
FollowState.FOLLOWING -> {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFollowButton.setText(R.string.action_unfollow)
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-15 12:43:16 +02:00
|
|
|
private fun updateMuteButton() {
|
|
|
|
if (muting) {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountMuteButton.setIconResource(R.drawable.ic_unmute_24dp)
|
2019-05-15 12:43:16 +02:00
|
|
|
} else {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountMuteButton.hide()
|
2019-05-15 12:43:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-23 12:52:39 +01:00
|
|
|
private fun updateSubscribeButton() {
|
2021-06-28 21:13:24 +02:00
|
|
|
if (followState != FollowState.FOLLOWING) {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountSubscribeButton.hide()
|
2020-12-23 12:52:39 +01:00
|
|
|
}
|
|
|
|
|
2021-06-28 21:13:24 +02:00
|
|
|
if (subscribing) {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountSubscribeButton.setIconResource(R.drawable.ic_notifications_active_24dp)
|
|
|
|
binding.accountSubscribeButton.contentDescription = getString(R.string.action_unsubscribe_account)
|
2020-12-23 12:52:39 +01:00
|
|
|
} else {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountSubscribeButton.setIconResource(R.drawable.ic_notifications_24dp)
|
|
|
|
binding.accountSubscribeButton.contentDescription = getString(R.string.action_subscribe_account)
|
2020-12-23 12:52:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-18 13:26:18 +02:00
|
|
|
private fun updateButtons() {
|
|
|
|
invalidateOptionsMenu()
|
|
|
|
|
2019-05-15 12:43:16 +02:00
|
|
|
if (loadedAccount?.moved == null) {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFollowButton.show()
|
2018-06-18 13:26:18 +02:00
|
|
|
updateFollowButton()
|
2023-01-27 19:49:07 +01:00
|
|
|
updateSubscribeButton()
|
2018-06-18 13:26:18 +02:00
|
|
|
|
2022-12-30 11:22:01 +01:00
|
|
|
if (blocking) {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFloatingActionButton.hide()
|
|
|
|
binding.accountMuteButton.hide()
|
2018-06-18 13:26:18 +02:00
|
|
|
} else {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFloatingActionButton.show()
|
2023-01-27 19:49:07 +01:00
|
|
|
binding.accountMuteButton.visible(muting)
|
2019-05-15 12:43:16 +02:00
|
|
|
updateMuteButton()
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
|
|
|
} else {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFloatingActionButton.hide()
|
|
|
|
binding.accountFollowButton.hide()
|
|
|
|
binding.accountMuteButton.hide()
|
|
|
|
binding.accountSubscribeButton.hide()
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add "Refresh" accessibility menu (#3121)
* Add "Refresh" accessibility menu to TimelineFragment
Per https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout
the layout does not provide accessibility events, and a menu item should be
provided as an alternative method for refreshing the content.
In `TimelineFragment`:
- Implement the `MenuProvider` interface so it can populate the action bar
menu in activities that host the fragment
- Create a "Refresh" menu item, and refresh the state when it is selected
`MainActivity` has to change how the menu is created, so that fragments
can add items to it.
In `MainActivity`:
- Call `setSupportActionBar` so `mainToolbar` participates in menus
- Implement the `MenuProvider` interface, and move menu creation there
- Set the title via supportActionBar
* Never show the refresh item as a menubar action
Per guidelines in https://developer.android.com/develop/ui/views/touch-and-input/swipe/add-swipe-interface#AddRefreshAction
* Add "Refresh" menu item for AccountMediaFragment
Also, fix the colour of the refresh progress indicator
* Implement "Refresh" for AnnouncementsActivity
* Add "Refresh" menu for ConversationsFragment
* Keep the tabs adapter over the life of the viewpager
Make `tabs` `var` instead of `val` in `MainPagerAdapter` so it can be updated
when tabs change.
Then detach the `tabLayoutMediator`, update the tabs, and call
`notifyItemRangeChanged` in `setupTabs()`.
This fixes a bug (not sure if it's this code, or in ViewPager2) where
assigning a new adapter to the view pager seemed to result in a leak of one
or more fragments. This wasn't user-visible, but it's a leak, and it becomes
user-visible when fragments want to display menus.
This also fixes two other bugs:
1. Be on the left-most tab. Scroll down a bit. Then modify the tabs at
"Account preferences > tabs", but keep the left-most tab as-is.
Then go back to MainActivity. Your reading position in the left-most
tab has been jumped to the top.
2. Be on any non-left-most tab. Then modify the tab list by reordering tabs
(adding/removing tabs is also OK).
Then go back to MainActivity. Your tab selection has been overridden,
and the left-most tab has been selected.
Because the fragments are not destroyed unnecessarily your reading position
is retained. And it remembers the tab you had selected, and as long as that
tab is still present you will be returned to it, even if it's changed
position in the list.
Fixes https://github.com/tuskyapp/Tusky/issues/3251
* Add "Refresh" menu for ScheduledStatusActivity
* Lint
* Add "Refresh" menu for SearchFragment / SearchActivity
* Explicitly set the searchview width
Using "collapseActionView" requires the user to press "Back" twice to exit
the activity, which is not acceptable.
* Move toolbar handling in to ViewThreadActivity
Previous code had the toolbar in the fragment's layout. Refactor to make
consistent with other activities, and move the toolbar in to the activity
layout.
Implement MenuProvider in ViewThreadFragment to adjust the menu in the
activity.
* Add "Refresh" menu to ViewThreadFragment
* Implement "Refresh" for ViewEditsFragment
* Lint
* Add "Refresh" menu to ReportStatusesFragment
* Add "Refresh" menu to NotificationsFragment
* Rename menu resource files
Be consistent with the layout resource files, which have an activity/fragment
prefix, then the lower_snake_case name of the activity or fragment it's for.
* Only enable refresh menu if swiptorefresh is enabled
Some timelines don't have swipetorefresh enabled (e.g., those shown on
AccountActivity). In those cases don't add the refresh menu, rely on the
hosting activity to provide it.
Update AccountActivity to provide the refresh menu item.
2023-03-01 19:58:18 +01:00
|
|
|
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
|
2018-06-18 13:26:18 +02:00
|
|
|
menuInflater.inflate(R.menu.account_toolbar, menu)
|
|
|
|
|
2022-02-25 18:55:58 +01:00
|
|
|
val openAsItem = menu.findItem(R.id.action_open_as)
|
|
|
|
val title = openAsText
|
|
|
|
if (title == null) {
|
|
|
|
openAsItem.isVisible = false
|
|
|
|
} else {
|
|
|
|
openAsItem.title = title
|
|
|
|
}
|
|
|
|
|
2019-05-15 12:43:16 +02:00
|
|
|
if (!viewModel.isSelf) {
|
2018-06-18 13:26:18 +02:00
|
|
|
val block = menu.findItem(R.id.action_block)
|
|
|
|
block.title = if (blocking) {
|
|
|
|
getString(R.string.action_unblock)
|
|
|
|
} else {
|
|
|
|
getString(R.string.action_block)
|
|
|
|
}
|
|
|
|
|
|
|
|
val mute = menu.findItem(R.id.action_mute)
|
|
|
|
mute.title = if (muting) {
|
|
|
|
getString(R.string.action_unmute)
|
|
|
|
} else {
|
|
|
|
getString(R.string.action_mute)
|
|
|
|
}
|
|
|
|
|
2023-01-09 21:08:46 +01:00
|
|
|
loadedAccount?.let { loadedAccount ->
|
2019-06-11 15:56:27 +02:00
|
|
|
val muteDomain = menu.findItem(R.id.action_mute_domain)
|
2023-01-09 21:08:46 +01:00
|
|
|
domain = getDomain(loadedAccount.url)
|
2019-06-11 15:56:27 +02:00
|
|
|
if (domain.isEmpty()) {
|
|
|
|
// If we can't get the domain, there's no way we can mute it anyway...
|
|
|
|
menu.removeItem(R.id.action_mute_domain)
|
|
|
|
} else {
|
2020-06-23 19:59:49 +02:00
|
|
|
if (blockingDomain) {
|
|
|
|
muteDomain.title = getString(R.string.action_unmute_domain, domain)
|
|
|
|
} else {
|
|
|
|
muteDomain.title = getString(R.string.action_mute_domain, domain)
|
|
|
|
}
|
2019-06-11 15:56:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-18 13:26:18 +02:00
|
|
|
if (followState == FollowState.FOLLOWING) {
|
|
|
|
val showReblogs = menu.findItem(R.id.action_show_reblogs)
|
|
|
|
showReblogs.title = if (showingReblogs) {
|
|
|
|
getString(R.string.action_hide_reblogs)
|
|
|
|
} else {
|
|
|
|
getString(R.string.action_show_reblogs)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
menu.removeItem(R.id.action_show_reblogs)
|
|
|
|
}
|
|
|
|
} else {
|
2021-02-18 19:26:14 +01:00
|
|
|
// It shouldn't be possible to block, mute or report yourself.
|
2018-06-18 13:26:18 +02:00
|
|
|
menu.removeItem(R.id.action_block)
|
|
|
|
menu.removeItem(R.id.action_mute)
|
2019-06-11 15:56:27 +02:00
|
|
|
menu.removeItem(R.id.action_mute_domain)
|
2018-06-18 13:26:18 +02:00
|
|
|
menu.removeItem(R.id.action_show_reblogs)
|
2019-08-17 09:08:58 +02:00
|
|
|
menu.removeItem(R.id.action_report)
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
2019-02-27 20:03:38 +01:00
|
|
|
|
2022-11-12 22:05:55 +01:00
|
|
|
if (!viewModel.isSelf && followState != FollowState.FOLLOWING) {
|
|
|
|
menu.removeItem(R.id.action_add_or_remove_from_list)
|
|
|
|
}
|
|
|
|
|
Add "Refresh" accessibility menu (#3121)
* Add "Refresh" accessibility menu to TimelineFragment
Per https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout
the layout does not provide accessibility events, and a menu item should be
provided as an alternative method for refreshing the content.
In `TimelineFragment`:
- Implement the `MenuProvider` interface so it can populate the action bar
menu in activities that host the fragment
- Create a "Refresh" menu item, and refresh the state when it is selected
`MainActivity` has to change how the menu is created, so that fragments
can add items to it.
In `MainActivity`:
- Call `setSupportActionBar` so `mainToolbar` participates in menus
- Implement the `MenuProvider` interface, and move menu creation there
- Set the title via supportActionBar
* Never show the refresh item as a menubar action
Per guidelines in https://developer.android.com/develop/ui/views/touch-and-input/swipe/add-swipe-interface#AddRefreshAction
* Add "Refresh" menu item for AccountMediaFragment
Also, fix the colour of the refresh progress indicator
* Implement "Refresh" for AnnouncementsActivity
* Add "Refresh" menu for ConversationsFragment
* Keep the tabs adapter over the life of the viewpager
Make `tabs` `var` instead of `val` in `MainPagerAdapter` so it can be updated
when tabs change.
Then detach the `tabLayoutMediator`, update the tabs, and call
`notifyItemRangeChanged` in `setupTabs()`.
This fixes a bug (not sure if it's this code, or in ViewPager2) where
assigning a new adapter to the view pager seemed to result in a leak of one
or more fragments. This wasn't user-visible, but it's a leak, and it becomes
user-visible when fragments want to display menus.
This also fixes two other bugs:
1. Be on the left-most tab. Scroll down a bit. Then modify the tabs at
"Account preferences > tabs", but keep the left-most tab as-is.
Then go back to MainActivity. Your reading position in the left-most
tab has been jumped to the top.
2. Be on any non-left-most tab. Then modify the tab list by reordering tabs
(adding/removing tabs is also OK).
Then go back to MainActivity. Your tab selection has been overridden,
and the left-most tab has been selected.
Because the fragments are not destroyed unnecessarily your reading position
is retained. And it remembers the tab you had selected, and as long as that
tab is still present you will be returned to it, even if it's changed
position in the list.
Fixes https://github.com/tuskyapp/Tusky/issues/3251
* Add "Refresh" menu for ScheduledStatusActivity
* Lint
* Add "Refresh" menu for SearchFragment / SearchActivity
* Explicitly set the searchview width
Using "collapseActionView" requires the user to press "Back" twice to exit
the activity, which is not acceptable.
* Move toolbar handling in to ViewThreadActivity
Previous code had the toolbar in the fragment's layout. Refactor to make
consistent with other activities, and move the toolbar in to the activity
layout.
Implement MenuProvider in ViewThreadFragment to adjust the menu in the
activity.
* Add "Refresh" menu to ViewThreadFragment
* Implement "Refresh" for ViewEditsFragment
* Lint
* Add "Refresh" menu to ReportStatusesFragment
* Add "Refresh" menu to NotificationsFragment
* Rename menu resource files
Be consistent with the layout resource files, which have an activity/fragment
prefix, then the lower_snake_case name of the activity or fragment it's for.
* Only enable refresh menu if swiptorefresh is enabled
Some timelines don't have swipetorefresh enabled (e.g., those shown on
AccountActivity). In those cases don't add the refresh menu, rely on the
hosting activity to provide it.
Update AccountActivity to provide the refresh menu item.
2023-03-01 19:58:18 +01:00
|
|
|
menu.findItem(R.id.action_search)?.apply {
|
|
|
|
icon = IconicsDrawable(this@AccountActivity, GoogleMaterial.Icon.gmd_search).apply {
|
|
|
|
sizeDp = 20
|
|
|
|
colorInt = MaterialColors.getColor(binding.collapsingToolbar, android.R.attr.textColorPrimary)
|
|
|
|
}
|
|
|
|
}
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun showFollowRequestPendingDialog() {
|
|
|
|
AlertDialog.Builder(this)
|
2021-06-28 21:13:24 +02:00
|
|
|
.setMessage(R.string.dialog_message_cancel_follow_request)
|
|
|
|
.setPositiveButton(android.R.string.ok) { _, _ -> viewModel.changeFollowState() }
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.show()
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun showUnfollowWarningDialog() {
|
|
|
|
AlertDialog.Builder(this)
|
2021-06-28 21:13:24 +02:00
|
|
|
.setMessage(R.string.dialog_unfollow_warning)
|
|
|
|
.setPositiveButton(android.R.string.ok) { _, _ -> viewModel.changeFollowState() }
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.show()
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
|
|
|
|
2020-06-23 19:59:49 +02:00
|
|
|
private fun toggleBlockDomain(instance: String) {
|
2021-06-28 21:13:24 +02:00
|
|
|
if (blockingDomain) {
|
2020-06-23 19:59:49 +02:00
|
|
|
viewModel.unblockDomain(instance)
|
|
|
|
} else {
|
|
|
|
AlertDialog.Builder(this)
|
2021-06-28 21:13:24 +02:00
|
|
|
.setMessage(getString(R.string.mute_domain_warning, instance))
|
|
|
|
.setPositiveButton(getString(R.string.mute_domain_warning_dialog_ok)) { _, _ -> viewModel.blockDomain(instance) }
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.show()
|
2020-06-23 19:59:49 +02:00
|
|
|
}
|
2019-06-11 15:56:27 +02:00
|
|
|
}
|
|
|
|
|
2020-03-30 21:03:27 +02:00
|
|
|
private fun toggleBlock() {
|
|
|
|
if (viewModel.relationshipData.value?.data?.blocking != true) {
|
|
|
|
AlertDialog.Builder(this)
|
2021-06-28 21:13:24 +02:00
|
|
|
.setMessage(getString(R.string.dialog_block_warning, loadedAccount?.username))
|
|
|
|
.setPositiveButton(android.R.string.ok) { _, _ -> viewModel.changeBlockState() }
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.show()
|
2020-03-30 21:03:27 +02:00
|
|
|
} else {
|
|
|
|
viewModel.changeBlockState()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun toggleMute() {
|
|
|
|
if (viewModel.relationshipData.value?.data?.muting != true) {
|
2020-07-27 10:28:59 +02:00
|
|
|
loadedAccount?.let {
|
|
|
|
showMuteAccountDialog(
|
2021-06-28 21:13:24 +02:00
|
|
|
this,
|
|
|
|
it.username
|
2021-01-15 21:05:36 +01:00
|
|
|
) { notifications, duration ->
|
|
|
|
viewModel.muteAccount(notifications, duration)
|
2020-10-25 18:36:00 +01:00
|
|
|
}
|
2020-07-27 10:28:59 +02:00
|
|
|
}
|
2020-03-30 21:03:27 +02:00
|
|
|
} else {
|
2020-07-27 10:28:59 +02:00
|
|
|
viewModel.unmuteAccount()
|
2020-03-30 21:03:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-18 13:26:18 +02:00
|
|
|
private fun mention() {
|
|
|
|
loadedAccount?.let {
|
2022-12-30 11:22:01 +01:00
|
|
|
val options = if (viewModel.isSelf) {
|
Fix saving changes to statuses when editing (#3103)
* Fix saving changes to statuses when editing
With the previous code backing out of a status editing operation where changes
had been made (whether it was editing an existing status, a scheduled status,
or a draft) would prompt the user to save the changes as a new draft.
See https://github.com/tuskyapp/Tusky/issues/2704 and
https://github.com/tuskyapp/Tusky/issues/2705 for more detail.
The fix:
- Create an enum to represent the four different kinds of edits that can
happen
- Editing a new status (i.e., composing it for the first time)
- Editing a posted status
- Editing a draft
- Editing a scheduled status
- Store this in ComposeOptions, and set it appropriately everywhere
ComposeOptions is created.
- Check the edit kind when backing out of ComposeActivity, and use this to
show one of three different dialogs as appropriate so the user can:
- Save as new draft or discard changes
- Continue editing or discard changes
- Update existing draft or discard changes
Also fix ComposeViewModel.didChange(), which erroneously reported false if the
old text started with the new text (e.g., if the old text was "hello, world"
and it was edited to "hello", didChange() would not consider that to be a
change).
Fixes https://github.com/tuskyapp/Tusky/issues/2704,
https://github.com/tuskyapp/Tusky/issues/2705
* Use orEmpty extension function
2022-12-31 13:04:49 +01:00
|
|
|
ComposeActivity.ComposeOptions(kind = ComposeActivity.ComposeKind.NEW)
|
2022-12-30 11:22:01 +01:00
|
|
|
} else {
|
Fix saving changes to statuses when editing (#3103)
* Fix saving changes to statuses when editing
With the previous code backing out of a status editing operation where changes
had been made (whether it was editing an existing status, a scheduled status,
or a draft) would prompt the user to save the changes as a new draft.
See https://github.com/tuskyapp/Tusky/issues/2704 and
https://github.com/tuskyapp/Tusky/issues/2705 for more detail.
The fix:
- Create an enum to represent the four different kinds of edits that can
happen
- Editing a new status (i.e., composing it for the first time)
- Editing a posted status
- Editing a draft
- Editing a scheduled status
- Store this in ComposeOptions, and set it appropriately everywhere
ComposeOptions is created.
- Check the edit kind when backing out of ComposeActivity, and use this to
show one of three different dialogs as appropriate so the user can:
- Save as new draft or discard changes
- Continue editing or discard changes
- Update existing draft or discard changes
Also fix ComposeViewModel.didChange(), which erroneously reported false if the
old text started with the new text (e.g., if the old text was "hello, world"
and it was edited to "hello", didChange() would not consider that to be a
change).
Fixes https://github.com/tuskyapp/Tusky/issues/2704,
https://github.com/tuskyapp/Tusky/issues/2705
* Use orEmpty extension function
2022-12-31 13:04:49 +01:00
|
|
|
ComposeActivity.ComposeOptions(
|
|
|
|
mentionedUsernames = setOf(it.username),
|
|
|
|
kind = ComposeActivity.ComposeKind.NEW
|
|
|
|
)
|
2022-12-30 11:22:01 +01:00
|
|
|
}
|
|
|
|
val intent = ComposeActivity.startIntent(this, options)
|
2018-08-23 20:57:51 +02:00
|
|
|
startActivity(intent)
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onViewTag(tag: String) {
|
2022-02-25 18:57:31 +01:00
|
|
|
val intent = StatusListActivity.newHashtagIntent(this, tag)
|
2018-07-31 21:25:25 +02:00
|
|
|
startActivityWithSlideInAnimation(intent)
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onViewAccount(id: String) {
|
|
|
|
val intent = Intent(this, AccountActivity::class.java)
|
|
|
|
intent.putExtra("id", id)
|
2018-07-31 21:25:25 +02:00
|
|
|
startActivityWithSlideInAnimation(intent)
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onViewUrl(url: String) {
|
|
|
|
viewUrl(url)
|
|
|
|
}
|
|
|
|
|
Add "Refresh" accessibility menu (#3121)
* Add "Refresh" accessibility menu to TimelineFragment
Per https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout
the layout does not provide accessibility events, and a menu item should be
provided as an alternative method for refreshing the content.
In `TimelineFragment`:
- Implement the `MenuProvider` interface so it can populate the action bar
menu in activities that host the fragment
- Create a "Refresh" menu item, and refresh the state when it is selected
`MainActivity` has to change how the menu is created, so that fragments
can add items to it.
In `MainActivity`:
- Call `setSupportActionBar` so `mainToolbar` participates in menus
- Implement the `MenuProvider` interface, and move menu creation there
- Set the title via supportActionBar
* Never show the refresh item as a menubar action
Per guidelines in https://developer.android.com/develop/ui/views/touch-and-input/swipe/add-swipe-interface#AddRefreshAction
* Add "Refresh" menu item for AccountMediaFragment
Also, fix the colour of the refresh progress indicator
* Implement "Refresh" for AnnouncementsActivity
* Add "Refresh" menu for ConversationsFragment
* Keep the tabs adapter over the life of the viewpager
Make `tabs` `var` instead of `val` in `MainPagerAdapter` so it can be updated
when tabs change.
Then detach the `tabLayoutMediator`, update the tabs, and call
`notifyItemRangeChanged` in `setupTabs()`.
This fixes a bug (not sure if it's this code, or in ViewPager2) where
assigning a new adapter to the view pager seemed to result in a leak of one
or more fragments. This wasn't user-visible, but it's a leak, and it becomes
user-visible when fragments want to display menus.
This also fixes two other bugs:
1. Be on the left-most tab. Scroll down a bit. Then modify the tabs at
"Account preferences > tabs", but keep the left-most tab as-is.
Then go back to MainActivity. Your reading position in the left-most
tab has been jumped to the top.
2. Be on any non-left-most tab. Then modify the tab list by reordering tabs
(adding/removing tabs is also OK).
Then go back to MainActivity. Your tab selection has been overridden,
and the left-most tab has been selected.
Because the fragments are not destroyed unnecessarily your reading position
is retained. And it remembers the tab you had selected, and as long as that
tab is still present you will be returned to it, even if it's changed
position in the list.
Fixes https://github.com/tuskyapp/Tusky/issues/3251
* Add "Refresh" menu for ScheduledStatusActivity
* Lint
* Add "Refresh" menu for SearchFragment / SearchActivity
* Explicitly set the searchview width
Using "collapseActionView" requires the user to press "Back" twice to exit
the activity, which is not acceptable.
* Move toolbar handling in to ViewThreadActivity
Previous code had the toolbar in the fragment's layout. Refactor to make
consistent with other activities, and move the toolbar in to the activity
layout.
Implement MenuProvider in ViewThreadFragment to adjust the menu in the
activity.
* Add "Refresh" menu to ViewThreadFragment
* Implement "Refresh" for ViewEditsFragment
* Lint
* Add "Refresh" menu to ReportStatusesFragment
* Add "Refresh" menu to NotificationsFragment
* Rename menu resource files
Be consistent with the layout resource files, which have an activity/fragment
prefix, then the lower_snake_case name of the activity or fragment it's for.
* Only enable refresh menu if swiptorefresh is enabled
Some timelines don't have swipetorefresh enabled (e.g., those shown on
AccountActivity). In those cases don't add the refresh menu, rely on the
hosting activity to provide it.
Update AccountActivity to provide the refresh menu item.
2023-03-01 19:58:18 +01:00
|
|
|
override fun onMenuItemSelected(item: MenuItem): Boolean {
|
2018-06-18 13:26:18 +02:00
|
|
|
when (item.itemId) {
|
|
|
|
R.id.action_open_in_web -> {
|
|
|
|
// If the account isn't loaded yet, eat the input.
|
2023-01-09 21:08:46 +01:00
|
|
|
loadedAccount?.let { loadedAccount ->
|
|
|
|
openLink(loadedAccount.url)
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2022-02-25 18:55:58 +01:00
|
|
|
R.id.action_open_as -> {
|
2023-01-09 21:08:46 +01:00
|
|
|
loadedAccount?.let { loadedAccount ->
|
2022-02-25 18:55:58 +01:00
|
|
|
showAccountChooserDialog(
|
2023-03-13 13:16:39 +01:00
|
|
|
item.title,
|
|
|
|
false,
|
2022-02-25 18:55:58 +01:00
|
|
|
object : AccountSelectionListener {
|
|
|
|
override fun onAccountSelected(account: AccountEntity) {
|
2023-01-09 21:08:46 +01:00
|
|
|
openAsAccount(loadedAccount.url, account)
|
2022-02-25 18:55:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2023-01-09 21:08:46 +01:00
|
|
|
R.id.action_share_account_link -> {
|
|
|
|
// If the account isn't loaded yet, eat the input.
|
|
|
|
loadedAccount?.let { loadedAccount ->
|
|
|
|
val url = loadedAccount.url
|
|
|
|
val sendIntent = Intent()
|
|
|
|
sendIntent.action = Intent.ACTION_SEND
|
|
|
|
sendIntent.putExtra(Intent.EXTRA_TEXT, url)
|
|
|
|
sendIntent.type = "text/plain"
|
|
|
|
startActivity(Intent.createChooser(sendIntent, resources.getText(R.string.send_account_link_to)))
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
R.id.action_share_account_username -> {
|
|
|
|
// If the account isn't loaded yet, eat the input.
|
|
|
|
loadedAccount?.let { loadedAccount ->
|
|
|
|
val fullUsername = getFullUsername(loadedAccount)
|
|
|
|
val sendIntent = Intent()
|
|
|
|
sendIntent.action = Intent.ACTION_SEND
|
|
|
|
sendIntent.putExtra(Intent.EXTRA_TEXT, fullUsername)
|
|
|
|
sendIntent.type = "text/plain"
|
|
|
|
startActivity(Intent.createChooser(sendIntent, resources.getText(R.string.send_account_username_to)))
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2018-06-18 13:26:18 +02:00
|
|
|
R.id.action_block -> {
|
2020-03-30 21:03:27 +02:00
|
|
|
toggleBlock()
|
2018-06-18 13:26:18 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
R.id.action_mute -> {
|
2020-03-30 21:03:27 +02:00
|
|
|
toggleMute()
|
2018-06-18 13:26:18 +02:00
|
|
|
return true
|
|
|
|
}
|
2022-11-12 22:05:55 +01:00
|
|
|
R.id.action_add_or_remove_from_list -> {
|
|
|
|
ListsForAccountFragment.newInstance(viewModel.accountId).show(supportFragmentManager, null)
|
|
|
|
return true
|
|
|
|
}
|
2019-06-11 15:56:27 +02:00
|
|
|
R.id.action_mute_domain -> {
|
2020-06-23 19:59:49 +02:00
|
|
|
toggleBlockDomain(domain)
|
2019-06-11 15:56:27 +02:00
|
|
|
return true
|
|
|
|
}
|
2018-06-18 13:26:18 +02:00
|
|
|
R.id.action_show_reblogs -> {
|
2019-05-15 12:43:16 +02:00
|
|
|
viewModel.changeShowReblogsState()
|
2018-06-18 13:26:18 +02:00
|
|
|
return true
|
|
|
|
}
|
Add "Refresh" accessibility menu (#3121)
* Add "Refresh" accessibility menu to TimelineFragment
Per https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout
the layout does not provide accessibility events, and a menu item should be
provided as an alternative method for refreshing the content.
In `TimelineFragment`:
- Implement the `MenuProvider` interface so it can populate the action bar
menu in activities that host the fragment
- Create a "Refresh" menu item, and refresh the state when it is selected
`MainActivity` has to change how the menu is created, so that fragments
can add items to it.
In `MainActivity`:
- Call `setSupportActionBar` so `mainToolbar` participates in menus
- Implement the `MenuProvider` interface, and move menu creation there
- Set the title via supportActionBar
* Never show the refresh item as a menubar action
Per guidelines in https://developer.android.com/develop/ui/views/touch-and-input/swipe/add-swipe-interface#AddRefreshAction
* Add "Refresh" menu item for AccountMediaFragment
Also, fix the colour of the refresh progress indicator
* Implement "Refresh" for AnnouncementsActivity
* Add "Refresh" menu for ConversationsFragment
* Keep the tabs adapter over the life of the viewpager
Make `tabs` `var` instead of `val` in `MainPagerAdapter` so it can be updated
when tabs change.
Then detach the `tabLayoutMediator`, update the tabs, and call
`notifyItemRangeChanged` in `setupTabs()`.
This fixes a bug (not sure if it's this code, or in ViewPager2) where
assigning a new adapter to the view pager seemed to result in a leak of one
or more fragments. This wasn't user-visible, but it's a leak, and it becomes
user-visible when fragments want to display menus.
This also fixes two other bugs:
1. Be on the left-most tab. Scroll down a bit. Then modify the tabs at
"Account preferences > tabs", but keep the left-most tab as-is.
Then go back to MainActivity. Your reading position in the left-most
tab has been jumped to the top.
2. Be on any non-left-most tab. Then modify the tab list by reordering tabs
(adding/removing tabs is also OK).
Then go back to MainActivity. Your tab selection has been overridden,
and the left-most tab has been selected.
Because the fragments are not destroyed unnecessarily your reading position
is retained. And it remembers the tab you had selected, and as long as that
tab is still present you will be returned to it, even if it's changed
position in the list.
Fixes https://github.com/tuskyapp/Tusky/issues/3251
* Add "Refresh" menu for ScheduledStatusActivity
* Lint
* Add "Refresh" menu for SearchFragment / SearchActivity
* Explicitly set the searchview width
Using "collapseActionView" requires the user to press "Back" twice to exit
the activity, which is not acceptable.
* Move toolbar handling in to ViewThreadActivity
Previous code had the toolbar in the fragment's layout. Refactor to make
consistent with other activities, and move the toolbar in to the activity
layout.
Implement MenuProvider in ViewThreadFragment to adjust the menu in the
activity.
* Add "Refresh" menu to ViewThreadFragment
* Implement "Refresh" for ViewEditsFragment
* Lint
* Add "Refresh" menu to ReportStatusesFragment
* Add "Refresh" menu to NotificationsFragment
* Rename menu resource files
Be consistent with the layout resource files, which have an activity/fragment
prefix, then the lower_snake_case name of the activity or fragment it's for.
* Only enable refresh menu if swiptorefresh is enabled
Some timelines don't have swipetorefresh enabled (e.g., those shown on
AccountActivity). In those cases don't add the refresh menu, rely on the
hosting activity to provide it.
Update AccountActivity to provide the refresh menu item.
2023-03-01 19:58:18 +01:00
|
|
|
R.id.action_refresh -> {
|
|
|
|
binding.swipeToRefreshLayout.isRefreshing = true
|
|
|
|
onRefresh()
|
|
|
|
return true
|
|
|
|
}
|
2019-08-17 09:08:58 +02:00
|
|
|
R.id.action_report -> {
|
2023-01-09 21:08:46 +01:00
|
|
|
loadedAccount?.let { loadedAccount ->
|
|
|
|
startActivity(ReportActivity.getIntent(this, viewModel.accountId, loadedAccount.username))
|
2019-08-17 09:08:58 +02:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
Add "Refresh" accessibility menu (#3121)
* Add "Refresh" accessibility menu to TimelineFragment
Per https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout
the layout does not provide accessibility events, and a menu item should be
provided as an alternative method for refreshing the content.
In `TimelineFragment`:
- Implement the `MenuProvider` interface so it can populate the action bar
menu in activities that host the fragment
- Create a "Refresh" menu item, and refresh the state when it is selected
`MainActivity` has to change how the menu is created, so that fragments
can add items to it.
In `MainActivity`:
- Call `setSupportActionBar` so `mainToolbar` participates in menus
- Implement the `MenuProvider` interface, and move menu creation there
- Set the title via supportActionBar
* Never show the refresh item as a menubar action
Per guidelines in https://developer.android.com/develop/ui/views/touch-and-input/swipe/add-swipe-interface#AddRefreshAction
* Add "Refresh" menu item for AccountMediaFragment
Also, fix the colour of the refresh progress indicator
* Implement "Refresh" for AnnouncementsActivity
* Add "Refresh" menu for ConversationsFragment
* Keep the tabs adapter over the life of the viewpager
Make `tabs` `var` instead of `val` in `MainPagerAdapter` so it can be updated
when tabs change.
Then detach the `tabLayoutMediator`, update the tabs, and call
`notifyItemRangeChanged` in `setupTabs()`.
This fixes a bug (not sure if it's this code, or in ViewPager2) where
assigning a new adapter to the view pager seemed to result in a leak of one
or more fragments. This wasn't user-visible, but it's a leak, and it becomes
user-visible when fragments want to display menus.
This also fixes two other bugs:
1. Be on the left-most tab. Scroll down a bit. Then modify the tabs at
"Account preferences > tabs", but keep the left-most tab as-is.
Then go back to MainActivity. Your reading position in the left-most
tab has been jumped to the top.
2. Be on any non-left-most tab. Then modify the tab list by reordering tabs
(adding/removing tabs is also OK).
Then go back to MainActivity. Your tab selection has been overridden,
and the left-most tab has been selected.
Because the fragments are not destroyed unnecessarily your reading position
is retained. And it remembers the tab you had selected, and as long as that
tab is still present you will be returned to it, even if it's changed
position in the list.
Fixes https://github.com/tuskyapp/Tusky/issues/3251
* Add "Refresh" menu for ScheduledStatusActivity
* Lint
* Add "Refresh" menu for SearchFragment / SearchActivity
* Explicitly set the searchview width
Using "collapseActionView" requires the user to press "Back" twice to exit
the activity, which is not acceptable.
* Move toolbar handling in to ViewThreadActivity
Previous code had the toolbar in the fragment's layout. Refactor to make
consistent with other activities, and move the toolbar in to the activity
layout.
Implement MenuProvider in ViewThreadFragment to adjust the menu in the
activity.
* Add "Refresh" menu to ViewThreadFragment
* Implement "Refresh" for ViewEditsFragment
* Lint
* Add "Refresh" menu to ReportStatusesFragment
* Add "Refresh" menu to NotificationsFragment
* Rename menu resource files
Be consistent with the layout resource files, which have an activity/fragment
prefix, then the lower_snake_case name of the activity or fragment it's for.
* Only enable refresh menu if swiptorefresh is enabled
Some timelines don't have swipetorefresh enabled (e.g., those shown on
AccountActivity). In those cases don't add the refresh menu, rely on the
hosting activity to provide it.
Update AccountActivity to provide the refresh menu item.
2023-03-01 19:58:18 +01:00
|
|
|
return false
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun getActionButton(): FloatingActionButton? {
|
2022-12-30 11:22:01 +01:00
|
|
|
return if (!blocking) {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountFloatingActionButton
|
2023-03-13 13:16:39 +01:00
|
|
|
} else {
|
|
|
|
null
|
|
|
|
}
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
|
|
|
|
2023-01-09 21:08:46 +01:00
|
|
|
private fun getFullUsername(account: Account): String {
|
2023-02-20 19:58:37 +01:00
|
|
|
return if (account.isRemote()) {
|
|
|
|
"@" + account.username
|
2023-01-09 21:08:46 +01:00
|
|
|
} else {
|
|
|
|
val localUsername = account.localUsername
|
|
|
|
// Note: !! here will crash if this pane is ever shown to a logged-out user. With AccountActivity this is believed to be impossible.
|
|
|
|
val domain = accountManager.activeAccount!!.domain
|
2023-02-20 19:58:37 +01:00
|
|
|
"@$localUsername@$domain"
|
2023-01-09 21:08:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-09 19:48:04 +02:00
|
|
|
override fun androidInjector() = dispatchingAndroidInjector
|
2018-06-18 13:26:18 +02:00
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
private const val KEY_ACCOUNT_ID = "id"
|
|
|
|
private val argbEvaluator = ArgbEvaluator()
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
fun getIntent(context: Context, accountId: String): Intent {
|
|
|
|
val intent = Intent(context, AccountActivity::class.java)
|
|
|
|
intent.putExtra(KEY_ACCOUNT_ID, accountId)
|
|
|
|
return intent
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|