From bef916010d81e7e6c6dc610204ddb5c9a7ba9199 Mon Sep 17 00:00:00 2001 From: Levi Bard Date: Fri, 4 Dec 2020 17:35:51 +0100 Subject: [PATCH] Fix links in announcements. (#2011) Fixes #2008 --- .../announcements/AnnouncementAdapter.kt | 7 +++--- .../announcements/AnnouncementsActivity.kt | 24 +++++++++++++++---- .../res/layout/activity_announcements.xml | 2 ++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/announcements/AnnouncementAdapter.kt b/app/src/main/java/com/keylesspalace/tusky/components/announcements/AnnouncementAdapter.kt index c4fa93f2..29b57a2e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/announcements/AnnouncementAdapter.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/announcements/AnnouncementAdapter.kt @@ -27,10 +27,12 @@ import com.google.android.material.chip.ChipGroup import com.keylesspalace.tusky.R import com.keylesspalace.tusky.entity.Announcement import com.keylesspalace.tusky.entity.Emoji +import com.keylesspalace.tusky.interfaces.LinkListener +import com.keylesspalace.tusky.util.LinkHelper import com.keylesspalace.tusky.util.emojify import kotlinx.android.synthetic.main.item_announcement.view.* -interface AnnouncementActionListener { +interface AnnouncementActionListener: LinkListener { fun openReactionPicker(announcementId: String, target: View) fun addReaction(announcementId: String, name: String) fun removeReaction(announcementId: String, name: String) @@ -59,13 +61,12 @@ class AnnouncementAdapter( } inner class AnnouncementViewHolder(private val view: View) : RecyclerView.ViewHolder(view) { - private val text: TextView = view.text private val chips: ChipGroup = view.chipGroup private val addReactionChip: Chip = view.addReactionChip fun bind(item: Announcement) { - text.text = item.content + LinkHelper.setClickableText(text, item.content, null, listener) item.reactions.forEachIndexed { i, reaction -> (chips.getChildAt(i)?.takeUnless { it.id == R.id.addReactionChip } as Chip? diff --git a/app/src/main/java/com/keylesspalace/tusky/components/announcements/AnnouncementsActivity.kt b/app/src/main/java/com/keylesspalace/tusky/components/announcements/AnnouncementsActivity.kt index 5bfd17bc..1f86a0ab 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/announcements/AnnouncementsActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/announcements/AnnouncementsActivity.kt @@ -22,11 +22,9 @@ import android.view.MenuItem import android.view.View import android.widget.PopupWindow import androidx.activity.viewModels -import androidx.lifecycle.Observer import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager -import com.keylesspalace.tusky.BaseActivity -import com.keylesspalace.tusky.R +import com.keylesspalace.tusky.* import com.keylesspalace.tusky.adapter.EmojiAdapter import com.keylesspalace.tusky.adapter.OnEmojiSelectedListener import com.keylesspalace.tusky.di.Injectable @@ -37,7 +35,7 @@ import kotlinx.android.synthetic.main.activity_announcements.* import kotlinx.android.synthetic.main.toolbar_basic.* import javax.inject.Inject -class AnnouncementsActivity : BaseActivity(), AnnouncementActionListener, OnEmojiSelectedListener, Injectable { +class AnnouncementsActivity : BottomSheetActivity(), AnnouncementActionListener, OnEmojiSelectedListener, Injectable { @Inject lateinit var viewModelFactory: ViewModelFactory @@ -147,6 +145,24 @@ class AnnouncementsActivity : BaseActivity(), AnnouncementActionListener, OnEmoj viewModel.removeReaction(announcementId, name) } + override fun onViewTag(tag: String?) { + val intent = Intent(this, ViewTagActivity::class.java) + intent.putExtra("hashtag", tag) + startActivityWithSlideInAnimation(intent) + } + + override fun onViewAccount(id: String?) { + if (id != null) { + viewAccount(id) + } + } + + override fun onViewUrl(url: String?) { + if (url != null) { + viewUrl(url) + } + } + companion object { fun newIntent(context: Context) = Intent(context, AnnouncementsActivity::class.java) } diff --git a/app/src/main/res/layout/activity_announcements.xml b/app/src/main/res/layout/activity_announcements.xml index c0504b83..9e40e9df 100644 --- a/app/src/main/res/layout/activity_announcements.xml +++ b/app/src/main/res/layout/activity_announcements.xml @@ -36,4 +36,6 @@ tools:src="@drawable/elephant_error" tools:visibility="visible" /> + +