Skip to content

Commit

Permalink
Merge pull request #5128 from Bnyro/master
Browse files Browse the repository at this point in the history
refactor: create a custom view for expendable text views
  • Loading branch information
Bnyro authored Nov 7, 2023
2 parents 08b223d + 25e3665 commit 9e783c9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,6 @@ class ChannelFragment : Fragment() {
binding.channelDescription.text = response.description.orEmpty().trim()
}

binding.channelDescription.setOnClickListener {
(it as TextView).apply {
it.maxLines = if (it.maxLines == Int.MAX_VALUE) 2 else Int.MAX_VALUE
}
}

ImageHelper.loadImage(response.bannerUrl, binding.channelBanner)
ImageHelper.loadImage(response.avatarUrl, binding.channelImage)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.core.text.parseAsHtml
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.view.updatePadding
Expand Down Expand Up @@ -139,11 +140,6 @@ class PlaylistFragment : Fragment() {
binding.playlistProgress.isGone = true
binding.playlistName.text = response.name

binding.playlistName.setOnClickListener {
binding.playlistName.maxLines =
if (binding.playlistName.maxLines == 2) Int.MAX_VALUE else 2
}

binding.playlistInfo.text = getChannelAndVideoString(response, response.videos)
binding.playlistInfo.setOnClickListener {
(context as MainActivity).navController.navigate(
Expand All @@ -156,13 +152,6 @@ class PlaylistFragment : Fragment() {
// hide playlist description text view if not provided
binding.playlistDescription.isGone = response.description.orEmpty().isBlank()

binding.playlistDescription.let { textView ->
textView.setOnClickListener {
textView.maxLines =
if (textView.maxLines == Int.MAX_VALUE) 3 else Int.MAX_VALUE
}
}

showPlaylistVideos(response)

// show playlist options
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.github.libretube.ui.views

import android.content.Context
import android.text.TextUtils
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView
import com.github.libretube.R

class ExpandableTextView(context: Context, attributeSet: AttributeSet? = null) :
AppCompatTextView(context, attributeSet) {

init {
maxLines = DEFAULT_MAX_LINES
ellipsize = TextUtils.TruncateAt.END
setBackgroundResource(R.drawable.rounded_ripple)

setOnClickListener {
maxLines = if (maxLines == DEFAULT_MAX_LINES) Int.MAX_VALUE else DEFAULT_MAX_LINES
}
}

companion object {
private const val DEFAULT_MAX_LINES = 2
}
}
5 changes: 1 addition & 4 deletions app/src/main/res/layout/fragment_channel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,12 @@

</LinearLayout>

<TextView
<com.github.libretube.ui.views.ExpandableTextView
android:id="@+id/channel_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="5dp"
android:autoLink="web"
android:background="@drawable/rounded_ripple"
android:ellipsize="end"
android:maxLines="2"
android:padding="10dp" />

<HorizontalScrollView
Expand Down
10 changes: 2 additions & 8 deletions app/src/main/res/layout/fragment_playlist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@
android:layout_marginTop="8dp"
android:orientation="horizontal">

<TextView
<com.github.libretube.ui.views.ExpandableTextView
android:id="@+id/playlist_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_weight="1"
android:background="@drawable/rounded_ripple"
android:ellipsize="end"
android:maxLines="2"
android:paddingHorizontal="5dp"
android:paddingVertical="2dp"
android:textSize="20sp"
Expand Down Expand Up @@ -100,15 +97,12 @@
android:paddingBottom="5dp"
android:textStyle="bold" />

<TextView
<com.github.libretube.ui.views.ExpandableTextView
android:id="@+id/playlistDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="5dp"
android:autoLink="web"
android:background="@drawable/rounded_ripple"
android:ellipsize="end"
android:maxLines="3"
android:paddingHorizontal="10dp"
android:paddingTop="5dp"
android:paddingBottom="10dp" />
Expand Down

0 comments on commit 9e783c9

Please sign in to comment.