Fix links in announcements. (#2011)

Fixes #2008
main
Levi Bard 4 years ago committed by Alibek Omarov
parent 3d0c5a47d3
commit bef916010d
  1. 7
      app/src/main/java/com/keylesspalace/tusky/components/announcements/AnnouncementAdapter.kt
  2. 24
      app/src/main/java/com/keylesspalace/tusky/components/announcements/AnnouncementsActivity.kt
  3. 2
      app/src/main/res/layout/activity_announcements.xml

@ -27,10 +27,12 @@ import com.google.android.material.chip.ChipGroup
import com.keylesspalace.tusky.R import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.entity.Announcement import com.keylesspalace.tusky.entity.Announcement
import com.keylesspalace.tusky.entity.Emoji 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 com.keylesspalace.tusky.util.emojify
import kotlinx.android.synthetic.main.item_announcement.view.* import kotlinx.android.synthetic.main.item_announcement.view.*
interface AnnouncementActionListener { interface AnnouncementActionListener: LinkListener {
fun openReactionPicker(announcementId: String, target: View) fun openReactionPicker(announcementId: String, target: View)
fun addReaction(announcementId: String, name: String) fun addReaction(announcementId: String, name: String)
fun removeReaction(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) { inner class AnnouncementViewHolder(private val view: View) : RecyclerView.ViewHolder(view) {
private val text: TextView = view.text private val text: TextView = view.text
private val chips: ChipGroup = view.chipGroup private val chips: ChipGroup = view.chipGroup
private val addReactionChip: Chip = view.addReactionChip private val addReactionChip: Chip = view.addReactionChip
fun bind(item: Announcement) { fun bind(item: Announcement) {
text.text = item.content LinkHelper.setClickableText(text, item.content, null, listener)
item.reactions.forEachIndexed { i, reaction -> item.reactions.forEachIndexed { i, reaction ->
(chips.getChildAt(i)?.takeUnless { it.id == R.id.addReactionChip } as Chip? (chips.getChildAt(i)?.takeUnless { it.id == R.id.addReactionChip } as Chip?

@ -22,11 +22,9 @@ import android.view.MenuItem
import android.view.View import android.view.View
import android.widget.PopupWindow import android.widget.PopupWindow
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.keylesspalace.tusky.BaseActivity import com.keylesspalace.tusky.*
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.adapter.EmojiAdapter import com.keylesspalace.tusky.adapter.EmojiAdapter
import com.keylesspalace.tusky.adapter.OnEmojiSelectedListener import com.keylesspalace.tusky.adapter.OnEmojiSelectedListener
import com.keylesspalace.tusky.di.Injectable 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 kotlinx.android.synthetic.main.toolbar_basic.*
import javax.inject.Inject import javax.inject.Inject
class AnnouncementsActivity : BaseActivity(), AnnouncementActionListener, OnEmojiSelectedListener, Injectable { class AnnouncementsActivity : BottomSheetActivity(), AnnouncementActionListener, OnEmojiSelectedListener, Injectable {
@Inject @Inject
lateinit var viewModelFactory: ViewModelFactory lateinit var viewModelFactory: ViewModelFactory
@ -147,6 +145,24 @@ class AnnouncementsActivity : BaseActivity(), AnnouncementActionListener, OnEmoj
viewModel.removeReaction(announcementId, name) 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 { companion object {
fun newIntent(context: Context) = Intent(context, AnnouncementsActivity::class.java) fun newIntent(context: Context) = Intent(context, AnnouncementsActivity::class.java)
} }

@ -36,4 +36,6 @@
tools:src="@drawable/elephant_error" tools:src="@drawable/elephant_error"
tools:visibility="visible" /> tools:visibility="visible" />
<include layout="@layout/item_status_bottom_sheet" />
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

Loading…
Cancel
Save