Refactor details title expansion
This commit is contained in:
@@ -23,11 +23,16 @@ class SelectableTextView @JvmOverloads constructor(
|
|||||||
private fun fixSelectionRange() {
|
private fun fixSelectionRange() {
|
||||||
if (selectionStart < 0 || selectionEnd < 0) {
|
if (selectionStart < 0 || selectionEnd < 0) {
|
||||||
val spannableText = text as? Spannable ?: return
|
val spannableText = text as? Spannable ?: return
|
||||||
Selection.setSelection(spannableText, text.length)
|
Selection.setSelection(spannableText, spannableText.length)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun scrollTo(x: Int, y: Int) {
|
override fun scrollTo(x: Int, y: Int) {
|
||||||
super.scrollTo(0, 0)
|
super.scrollTo(0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun selectAll() {
|
||||||
|
val spannableText = text as? Spannable ?: return
|
||||||
|
Selection.selectAll(spannableText)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,6 @@ package org.koitharu.kotatsu.details.ui
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.view.MotionEvent
|
|
||||||
import android.content.ClipData
|
|
||||||
import android.content.ClipboardManager
|
|
||||||
import android.view.GestureDetector
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.style.DynamicDrawableSpan
|
import android.text.style.DynamicDrawableSpan
|
||||||
import android.text.style.ForegroundColorSpan
|
import android.text.style.ForegroundColorSpan
|
||||||
@@ -128,7 +123,6 @@ class DetailsActivity :
|
|||||||
lateinit var tagHighlighter: ListExtraProvider
|
lateinit var tagHighlighter: ListExtraProvider
|
||||||
|
|
||||||
private val viewModel: DetailsViewModel by viewModels()
|
private val viewModel: DetailsViewModel by viewModels()
|
||||||
private lateinit var gestureDetector: GestureDetector
|
|
||||||
private lateinit var menuProvider: DetailsMenuProvider
|
private lateinit var menuProvider: DetailsMenuProvider
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
@@ -162,32 +156,7 @@ class DetailsActivity :
|
|||||||
viewBinding.containerBottomSheet?.let { sheet ->
|
viewBinding.containerBottomSheet?.let { sheet ->
|
||||||
onBackPressedDispatcher.addCallback(BottomSheetCollapseCallback(sheet))
|
onBackPressedDispatcher.addCallback(BottomSheetCollapseCallback(sheet))
|
||||||
}
|
}
|
||||||
gestureDetector = GestureDetector(this, object : GestureDetector.SimpleOnGestureListener() {
|
TitleExpandListener(viewBinding.textViewTitle).attach()
|
||||||
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
|
|
||||||
val tv = viewBinding.textViewTitle
|
|
||||||
TransitionManager.beginDelayedTransition(tv.parent as ViewGroup)
|
|
||||||
if (tv.maxLines == 5) {
|
|
||||||
tv.maxLines = 20 // Expand text
|
|
||||||
} else {
|
|
||||||
tv.maxLines = 5 // Collapse text
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onLongPress(e: MotionEvent) {
|
|
||||||
val clipboardManager = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
|
||||||
val clip = ClipData.newPlainText("copied text", viewBinding.textViewTitle.text)
|
|
||||||
clipboardManager.setPrimaryClip(clip)
|
|
||||||
Toast.makeText(this@DetailsActivity, "Text copied", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
viewBinding.textViewTitle.setOnTouchListener { _, motionEvent ->
|
|
||||||
gestureDetector.onTouchEvent(motionEvent)
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
viewModel.details.filterNotNull().observe(this, ::onMangaUpdated)
|
viewModel.details.filterNotNull().observe(this, ::onMangaUpdated)
|
||||||
viewModel.onMangaRemoved.observeEvent(this, ::onMangaRemoved)
|
viewModel.onMangaRemoved.observeEvent(this, ::onMangaRemoved)
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package org.koitharu.kotatsu.details.ui
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.transition.TransitionManager
|
||||||
|
import android.view.GestureDetector
|
||||||
|
import android.view.MotionEvent
|
||||||
|
import android.view.View
|
||||||
|
import android.view.View.OnTouchListener
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.core.ui.widgets.SelectableTextView
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
||||||
|
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
|
class TitleExpandListener(
|
||||||
|
private val textView: SelectableTextView,
|
||||||
|
) : GestureDetector.SimpleOnGestureListener(), OnTouchListener {
|
||||||
|
|
||||||
|
private val gestureDetector = GestureDetector(textView.context, this)
|
||||||
|
private val linesExpanded = textView.resources.getInteger(R.integer.details_description_lines)
|
||||||
|
private val linesCollapsed = textView.resources.getInteger(R.integer.details_title_lines)
|
||||||
|
|
||||||
|
override fun onTouch(v: View?, event: MotionEvent) = gestureDetector.onTouchEvent(event)
|
||||||
|
|
||||||
|
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
|
||||||
|
if (textView.context.isAnimationsEnabled) {
|
||||||
|
TransitionManager.beginDelayedTransition(textView.parent as ViewGroup)
|
||||||
|
}
|
||||||
|
if (textView.maxLines in 1 until Integer.MAX_VALUE) {
|
||||||
|
textView.maxLines = Integer.MAX_VALUE
|
||||||
|
} else {
|
||||||
|
textView.maxLines = linesCollapsed
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLongPress(e: MotionEvent) {
|
||||||
|
textView.maxLines = Integer.MAX_VALUE
|
||||||
|
textView.selectAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun attach() {
|
||||||
|
textView.setOnTouchListener(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -84,7 +84,7 @@
|
|||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="5"
|
android:maxLines="@integer/details_title_lines"
|
||||||
android:textAppearance="?attr/textAppearanceHeadlineSmall"
|
android:textAppearance="?attr/textAppearanceHeadlineSmall"
|
||||||
android:textIsSelectable="true"
|
android:textIsSelectable="true"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
<integer name="manga_badge_max_character_count">3</integer>
|
<integer name="manga_badge_max_character_count">3</integer>
|
||||||
<integer name="explore_buttons_columns">2</integer>
|
<integer name="explore_buttons_columns">2</integer>
|
||||||
<integer name="details_description_lines">4</integer>
|
<integer name="details_description_lines">4</integer>
|
||||||
|
<integer name="details_title_lines">4</integer>
|
||||||
|
|
||||||
<integer name="splash_screen_duration">450</integer>
|
<integer name="splash_screen_duration">450</integer>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user