Skip to content

Commit

Permalink
Make links in bios of follow request and follow notifications work (#…
Browse files Browse the repository at this point in the history
…3646)

* make links in bios of follow request and follow notifications work
* use ClickableSpanTextView to display account notes
  • Loading branch information
connyduck authored May 13, 2023
1 parent ad9e57c commit 74a00c0
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@ import com.keylesspalace.tusky.components.notifications.NotificationsPagingAdapt
import com.keylesspalace.tusky.databinding.ItemFollowRequestBinding
import com.keylesspalace.tusky.entity.TimelineAccount
import com.keylesspalace.tusky.interfaces.AccountActionListener
import com.keylesspalace.tusky.interfaces.LinkListener
import com.keylesspalace.tusky.util.StatusDisplayOptions
import com.keylesspalace.tusky.util.emojify
import com.keylesspalace.tusky.util.hide
import com.keylesspalace.tusky.util.loadAvatar
import com.keylesspalace.tusky.util.parseAsMastodonHtml
import com.keylesspalace.tusky.util.setClickableText
import com.keylesspalace.tusky.util.show
import com.keylesspalace.tusky.util.unicodeWrap
import com.keylesspalace.tusky.util.visible
import com.keylesspalace.tusky.viewdata.NotificationViewData

class FollowRequestViewHolder(
private val binding: ItemFollowRequestBinding,
private val accountActionListener: AccountActionListener,
private val linkListener: LinkListener,
private val showHeader: Boolean
) : NotificationsPagingAdapter.ViewHolder, RecyclerView.ViewHolder(binding.root) {

Expand Down Expand Up @@ -92,9 +96,11 @@ class FollowRequestViewHolder(
if (account.note.isEmpty()) {
binding.accountNote.hide()
} else {
binding.accountNote.text =
account.note.parseAsMastodonHtml()
.emojify(account.emojis, binding.accountNote, animateEmojis)
binding.accountNote.show()

val emojifiedNote = account.note.parseAsMastodonHtml()
.emojify(account.emojis, binding.accountNote, animateEmojis)
setClickableText(binding.accountNote, emojifiedNote, emptyList(), null, linkListener)
}
val avatarRadius = binding.avatar.context.resources.getDimensionPixelSize(R.dimen.avatar_radius_48dp)
loadAvatar(account.avatar, binding.avatar, avatarRadius, animateAvatar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.commit
import com.keylesspalace.tusky.BaseActivity
import com.keylesspalace.tusky.BottomSheetActivity
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.databinding.ActivityAccountListBinding
import dagger.android.DispatchingAndroidInjector
import dagger.android.HasAndroidInjector
import javax.inject.Inject

class AccountListActivity : BaseActivity(), HasAndroidInjector {
class AccountListActivity : BottomSheetActivity(), HasAndroidInjector {

@Inject
lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Any>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ import autodispose2.androidx.lifecycle.AndroidLifecycleScopeProvider.from
import autodispose2.autoDispose
import com.google.android.material.snackbar.Snackbar
import com.keylesspalace.tusky.BaseActivity
import com.keylesspalace.tusky.BottomSheetActivity
import com.keylesspalace.tusky.PostLookupFallbackBehavior
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.StatusListActivity
import com.keylesspalace.tusky.components.account.AccountActivity
import com.keylesspalace.tusky.components.accountlist.AccountListActivity.Type
import com.keylesspalace.tusky.components.accountlist.adapter.AccountAdapter
Expand All @@ -47,6 +50,7 @@ import com.keylesspalace.tusky.di.Injectable
import com.keylesspalace.tusky.entity.Relationship
import com.keylesspalace.tusky.entity.TimelineAccount
import com.keylesspalace.tusky.interfaces.AccountActionListener
import com.keylesspalace.tusky.interfaces.LinkListener
import com.keylesspalace.tusky.network.MastodonApi
import com.keylesspalace.tusky.settings.PrefKeys
import com.keylesspalace.tusky.util.HttpHeaderLink
Expand All @@ -60,7 +64,11 @@ import retrofit2.Response
import java.io.IOException
import javax.inject.Inject

class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountActionListener, Injectable {
class AccountListFragment :
Fragment(R.layout.fragment_account_list),
AccountActionListener,
LinkListener,
Injectable {

@Inject
lateinit var api: MastodonApi
Expand Down Expand Up @@ -107,7 +115,7 @@ class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountAct
instanceName = accountManager.activeAccount!!.domain,
accountLocked = arguments?.getBoolean(ARG_ACCOUNT_LOCKED) == true
)
val followRequestsAdapter = FollowRequestsAdapter(this, animateAvatar, animateEmojis, showBotOverlay)
val followRequestsAdapter = FollowRequestsAdapter(this, this, animateAvatar, animateEmojis, showBotOverlay)
binding.recyclerView.adapter = ConcatAdapter(headerAdapter, followRequestsAdapter)
followRequestsAdapter
}
Expand All @@ -131,13 +139,22 @@ class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountAct
fetchAccounts()
}

override fun onViewTag(tag: String) {
(activity as BaseActivity?)
?.startActivityWithSlideInAnimation(StatusListActivity.newHashtagIntent(requireContext(), tag))
}

override fun onViewAccount(id: String) {
(activity as BaseActivity?)?.let {
val intent = AccountActivity.getIntent(it, id)
it.startActivityWithSlideInAnimation(intent)
}
}

override fun onViewUrl(url: String) {
(activity as BottomSheetActivity?)?.viewUrl(url, PostLookupFallbackBehavior.OPEN_IN_BROWSER)
}

override fun onMute(mute: Boolean, id: String, position: Int, notifications: Boolean) {
viewLifecycleOwner.lifecycleScope.launch {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import android.view.ViewGroup
import com.keylesspalace.tusky.adapter.FollowRequestViewHolder
import com.keylesspalace.tusky.databinding.ItemFollowRequestBinding
import com.keylesspalace.tusky.interfaces.AccountActionListener
import com.keylesspalace.tusky.interfaces.LinkListener

/** Displays a list of follow requests with accept/reject buttons. */
class FollowRequestsAdapter(
accountActionListener: AccountActionListener,
private val linkListener: LinkListener,
animateAvatar: Boolean,
animateEmojis: Boolean,
showBotOverlay: Boolean
Expand All @@ -43,6 +45,7 @@ class FollowRequestsAdapter(
return FollowRequestViewHolder(
binding,
accountActionListener,
linkListener,
showHeader = false
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.databinding.ItemFollowBinding
import com.keylesspalace.tusky.entity.Notification
import com.keylesspalace.tusky.entity.TimelineAccount
import com.keylesspalace.tusky.interfaces.LinkListener
import com.keylesspalace.tusky.util.StatusDisplayOptions
import com.keylesspalace.tusky.util.emojify
import com.keylesspalace.tusky.util.loadAvatar
import com.keylesspalace.tusky.util.parseAsMastodonHtml
import com.keylesspalace.tusky.util.setClickableText
import com.keylesspalace.tusky.util.unicodeWrap
import com.keylesspalace.tusky.viewdata.NotificationViewData

class FollowViewHolder(
private val binding: ItemFollowBinding,
private val notificationActionListener: NotificationActionListener
private val notificationActionListener: NotificationActionListener,
private val linkListener: LinkListener
) : NotificationsPagingAdapter.ViewHolder, RecyclerView.ViewHolder(binding.root) {
private val avatarRadius42dp = itemView.context.resources.getDimensionPixelSize(
R.dimen.avatar_radius_42dp
Expand Down Expand Up @@ -94,11 +97,12 @@ class FollowViewHolder(
animateAvatars
)

binding.notificationAccountNote.text = account.note.parseAsMastodonHtml().emojify(
val emojifiedNote = account.note.parseAsMastodonHtml().emojify(
account.emojis,
binding.notificationAccountNote,
animateEmojis
)
setClickableText(binding.notificationAccountNote, emojifiedNote, emptyList(), null, linkListener)
}

private fun setupButtons(listener: NotificationActionListener, accountId: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,15 @@ class NotificationsPagingAdapter(
NotificationViewKind.FOLLOW -> {
FollowViewHolder(
ItemFollowBinding.inflate(inflater, parent, false),
notificationActionListener
notificationActionListener,
statusActionListener
)
}
NotificationViewKind.FOLLOW_REQUEST -> {
FollowRequestViewHolder(
ItemFollowRequestBinding.inflate(inflater, parent, false),
accountActionListener,
statusActionListener,
showHeader = true
)
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/layout/activity_account_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
<include layout="@layout/item_status_bottom_sheet" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_follow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
app:layout_constraintTop_toTopOf="@+id/notification_display_name"
tools:text="\@testuser" />

<TextView
<com.keylesspalace.tusky.view.ClickableSpanTextView
android:id="@+id/notification_account_note"
android:layout_width="0dp"
android:layout_height="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_follow_request.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
app:layout_constraintTop_toTopOf="@+id/rejectButton"
app:srcCompat="@drawable/ic_check_24dp" />

<TextView
<com.keylesspalace.tusky.view.ClickableSpanTextView
android:id="@+id/account_note"
android:layout_width="0dp"
android:layout_height="wrap_content"
Expand Down

0 comments on commit 74a00c0

Please sign in to comment.