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

Add option to scroll long scene details text #123

Merged
merged 1 commit into from
Feb 20, 2024
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 @@ -21,6 +21,7 @@ import com.github.damontecres.stashapp.presenters.StashPresenter
import com.github.damontecres.stashapp.util.QueryEngine
import com.github.damontecres.stashapp.util.ageInYears
import com.github.damontecres.stashapp.util.createGlideUrl
import com.github.damontecres.stashapp.util.onlyScrollIfNeeded
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.launch
import kotlin.math.floor
Expand Down Expand Up @@ -130,14 +131,7 @@ class PerformerFragment : Fragment(R.layout.performer_view) {
override fun onResume() {
super.onResume()
val scrollView = requireView().findViewById<ScrollView>(R.id.performer_scrollview)

scrollView.viewTreeObserver.addOnGlobalLayoutListener {
val childHeight = scrollView.getChildAt(0).height
val isScrollable =
scrollView.height < childHeight + scrollView.paddingTop + scrollView.paddingBottom
Log.v(TAG, "isScrollable=$isScrollable")
scrollView.isFocusable = isScrollable
}
scrollView.onlyScrollIfNeeded()
}

private fun addRow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import android.view.View
import android.widget.RatingBar
import android.widget.SeekBar
import android.widget.TextView
import androidx.core.widget.NestedScrollView
import androidx.leanback.widget.AbstractDetailsDescriptionPresenter
import androidx.preference.PreferenceManager
import com.github.damontecres.stashapp.R
import com.github.damontecres.stashapp.StashOnFocusChangeListener
import com.github.damontecres.stashapp.api.fragment.SlimSceneData
import com.github.damontecres.stashapp.util.Constants
import com.github.damontecres.stashapp.util.ServerPreferences
import com.github.damontecres.stashapp.util.concatIfNotBlank
import com.github.damontecres.stashapp.util.onlyScrollIfNeeded
import com.github.damontecres.stashapp.util.titleOrFilename

class DetailsDescriptionPresenter(val ratingCallback: RatingCallback) :
Expand All @@ -25,6 +28,17 @@ class DetailsDescriptionPresenter(val ratingCallback: RatingCallback) :
viewHolder.title.text = scene.titleOrFilename
viewHolder.body.text = scene.details

val scrollView = viewHolder.view.findViewById<NestedScrollView>(R.id.description_scrollview)
val useScrollbar =
PreferenceManager.getDefaultSharedPreferences(viewHolder.view.context)
.getBoolean("scrollSceneDetails", true)
if (useScrollbar) {
scrollView.onlyScrollIfNeeded()
} else {
scrollView.isFocusable = false
scrollView.isVerticalScrollBarEnabled = false
}

val file = scene.files.firstOrNull()
if (file != null) {
val resolution = "${file.videoFileData.height}P"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import android.os.Build
import android.text.TextUtils
import android.util.Log
import android.util.TypedValue
import android.widget.ScrollView
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.core.widget.NestedScrollView
import androidx.preference.PreferenceManager
import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.api.Optional
Expand Down Expand Up @@ -394,3 +396,21 @@ val PerformerData.ageInYears: Int?
} else {
null
}

fun ScrollView.onlyScrollIfNeeded() {
viewTreeObserver.addOnGlobalLayoutListener {
val childHeight = getChildAt(0).height
val isScrollable =
height < childHeight + paddingTop + paddingBottom
isFocusable = isScrollable
}
}

fun NestedScrollView.onlyScrollIfNeeded() {
viewTreeObserver.addOnGlobalLayoutListener {
val childHeight = getChildAt(0).height
val isScrollable =
height < childHeight + paddingTop + paddingBottom
isFocusable = isScrollable
}
}
25 changes: 17 additions & 8 deletions app/src/main/res/layout/lb_details_description.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>

Expand Down Expand Up @@ -45,13 +45,22 @@
android:id="@+id/lb_details_description_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?attr/detailsDescriptionSubtitleStyle"
/>
style="?attr/detailsDescriptionSubtitleStyle" />

<TextView
android:id="@+id/lb_details_description_body"
android:layout_width="wrap_content"
<androidx.core.widget.NestedScrollView
android:id="@+id/description_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?attr/detailsDescriptionBodyStyle"
/>
android:paddingBottom="25dp"
android:fadeScrollbars="false"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarThumbVertical="@color/focus_color">

<TextView
android:id="@+id/lb_details_description_body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?attr/detailsDescriptionBodyStyle" />
</androidx.core.widget.NestedScrollView>
</LinearLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<integer tools:override="true" name="lb_details_description_body_max_lines">18</integer>
<integer tools:override="true" name="lb_details_description_body_max_lines">1000</integer>
<dimen name="title_bar_height">60dp</dimen>
<dimen name="title_bar_margin">10dp</dimen>
<dimen name="table_text_size">13sp</dimen>
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,13 @@
app:key="scrollToNextResult"
app:title="Scroll to next on View All"
app:summary="Automatically scroll down to the 'next' results when clicking View All on main page"
app:defaultValue="true"
/>
app:defaultValue="true" />
<SwitchPreference
app:key="scrollSceneDetails"
app:title="Long scene details behavior"
app:summaryOn="Scroll if needed"
app:summaryOff="Truncate details"
app:defaultValue="true" />
</PreferenceCategory>

<PreferenceCategory app:title="Playback">
Expand Down
Loading