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
|
2018-06-18 13:26:18 +02:00
|
|
|
import android.os.Bundle
|
2020-11-17 20:10:54 +01:00
|
|
|
import android.text.Editable
|
2019-01-21 08:37:25 +01:00
|
|
|
import android.view.Menu
|
|
|
|
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
|
2018-12-17 15:25:35 +01:00
|
|
|
import androidx.core.app.ActivityOptionsCompat
|
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
|
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.AccountListActivity
|
|
|
|
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
|
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
|
2021-06-28 21:13:24 +02:00
|
|
|
import com.keylesspalace.tusky.util.DefaultTextWatcher
|
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
|
|
|
|
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
|
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
|
|
|
|
2019-06-09 19:48:04 +02:00
|
|
|
class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInjector, LinkListener {
|
2018-06-18 13:26:18 +02:00
|
|
|
|
|
|
|
@Inject
|
2019-06-09 19:48:04 +02:00
|
|
|
lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Any>
|
2018-06-18 13:26:18 +02:00
|
|
|
@Inject
|
|
|
|
lateinit var viewModelFactory: ViewModelFactory
|
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
|
|
|
|
2022-12-01 19:51:13 +01:00
|
|
|
private val preferences by lazy { PreferenceManager.getDefaultSharedPreferences(this) }
|
|
|
|
|
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
|
|
|
|
@ColorInt
|
|
|
|
private var toolbarColor: Int = 0
|
|
|
|
@ColorInt
|
|
|
|
private var statusBarColorTransparent: Int = 0
|
|
|
|
@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
|
|
|
|
@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
|
|
|
|
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)
|
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() {
|
2022-12-31 13:01:35 +01:00
|
|
|
toolbarColor = MaterialColors.getColor(this, R.attr.colorSurface, Color.BLACK)
|
2022-08-04 16:48:26 +02:00
|
|
|
statusBarColorTransparent = getColor(R.color.transparent_statusbar_background)
|
2022-12-31 13:01:35 +01:00
|
|
|
statusBarColorOpaque = MaterialColors.getColor(this, 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
|
|
|
|
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
|
|
|
|
2019-05-15 12:43:16 +02:00
|
|
|
/**
|
|
|
|
* Setup swipe to refresh layout
|
|
|
|
*/
|
|
|
|
private fun setupRefreshLayout() {
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.swipeToRefreshLayout.setOnRefreshListener {
|
2019-05-15 12:43:16 +02:00
|
|
|
viewModel.refresh()
|
|
|
|
adapter.refreshContent()
|
2018-06-18 13:26:18 +02:00
|
|
|
}
|
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
|
|
|
|
2022-04-27 19:58:39 +02:00
|
|
|
accountFieldAdapter.fields = account.fields ?: emptyList()
|
2019-05-15 12:43:16 +02:00
|
|
|
accountFieldAdapter.emojis = account.emojis ?: emptyList()
|
|
|
|
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
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountAvatarImageView.setOnClickListener { avatarView ->
|
2022-01-11 19:55:17 +01:00
|
|
|
val intent =
|
|
|
|
ViewMediaActivity.newSingleImageIntent(avatarView.context, account.avatar)
|
2018-07-30 15:42:45 +02:00
|
|
|
|
2018-12-03 11:22:57 +01:00
|
|
|
avatarView.transitionName = account.avatar
|
2018-07-30 15:42:45 +02:00
|
|
|
val options = ActivityOptionsCompat.makeSceneTransitionAnimation(this, avatarView, account.avatar)
|
|
|
|
|
|
|
|
startActivity(intent, options.toBundle())
|
|
|
|
}
|
2019-05-15 12:43:16 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-30 15:42:45 +02:00
|
|
|
|
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()
|
|
|
|
}
|
2021-06-28 21:13:24 +02:00
|
|
|
if (relation.notifying != null)
|
2020-12-23 12:52:39 +01:00
|
|
|
subscribing = relation.notifying
|
2021-06-28 21:13:24 +02:00
|
|
|
else if (relation.subscribing != null)
|
2020-12-23 12:52:39 +01:00
|
|
|
subscribing = relation.subscribing
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2021-03-07 19:05:51 +01:00
|
|
|
binding.accountNoteTextInputLayout.editText?.addTextChangedListener(noteWatcher)
|
2020-11-17 20:10:54 +01:00
|
|
|
|
2018-06-18 13:26:18 +02:00
|
|
|
updateButtons()
|
|
|
|
}
|
|
|
|
|
2021-06-28 21:13:24 +02:00
|
|
|
private val noteWatcher = object : DefaultTextWatcher() {
|
2020-11-17 20:10:54 +01:00
|
|
|
override fun afterTextChanged(s: Editable) {
|
|
|
|
viewModel.noteChanged(s.toString())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
2018-06-18 13:26:18 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2019-02-27 20:03:38 +01:00
|
|
|
return super.onCreateOptionsMenu(menu)
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
|
|
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(
|
|
|
|
item.title, false,
|
|
|
|
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
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item)
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2018-06-18 13:26:18 +02:00
|
|
|
} else null
|
|
|
|
}
|
|
|
|
|
2023-01-09 21:08:46 +01:00
|
|
|
private fun getFullUsername(account: Account): String {
|
|
|
|
if (account.isRemote()) {
|
|
|
|
return "@" + account.username
|
|
|
|
} 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
|
|
|
|
return "@$localUsername@$domain"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|