mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
refactor: create a custom view for expendable text views
This commit is contained in:
parent
992ba1f78d
commit
25e36659dc
@ -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)
|
||||
|
||||
|
@ -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
|
||||
@ -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(
|
||||
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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"
|
||||
@ -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" />
|
||||
|
Loading…
Reference in New Issue
Block a user