Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: create a custom view for expendable text views #5128

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.View
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.core.text.parseAsHtml

Check failure on line 10 in app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Unused import Raw Output: app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt:10:1: error: Unused import (standard:no-unused-imports)
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.view.updatePadding
Expand Down Expand Up @@ -139,11 +140,6 @@
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 @@
// 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

Check failure on line 1 in app/src/main/java/com/github/libretube/ui/views/ExpandableTextView.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 File must end with a newline (\n) Raw Output: app/src/main/java/com/github/libretube/ui/views/ExpandableTextView.kt:1:1: error: File must end with a newline (\n) (standard:final-newline)

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
Loading