diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsFragment.kt index 28c79fc75..7c581df2b 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsFragment.kt @@ -83,6 +83,7 @@ class DetailsFragment : binding.infoLayout.textViewSource.setOnClickListener(this) binding.textViewDescription.movementMethod = LinkMovementMethod.getInstance() binding.chipsTags.onChipClickListener = this + TitleScrollCoordinator(binding.textViewTitle).attach(binding.scrollView) viewModel.manga.filterNotNull().observe(viewLifecycleOwner, ::onMangaUpdated) viewModel.isLoading.observe(viewLifecycleOwner, ::onLoadingStateChanged) viewModel.historyInfo.observe(viewLifecycleOwner, ::onHistoryChanged) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/TitleScrollCoordinator.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/TitleScrollCoordinator.kt new file mode 100644 index 000000000..364357531 --- /dev/null +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/TitleScrollCoordinator.kt @@ -0,0 +1,45 @@ +package org.koitharu.kotatsu.details.ui + +import android.content.Context +import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.doOnLayout +import androidx.core.widget.NestedScrollView +import org.koitharu.kotatsu.core.util.ext.findActivity +import java.lang.ref.WeakReference + +class TitleScrollCoordinator( + private val titleView: TextView, +) : NestedScrollView.OnScrollChangeListener { + + private val location = IntArray(2) + private var activityRef: WeakReference? = null + + override fun onScrollChange(v: NestedScrollView, scrollX: Int, scrollY: Int, oldScrollX: Int, oldScrollY: Int) { + val actionBar = getActivity(v.context)?.supportActionBar ?: return + titleView.getLocationOnScreen(location) + var top = location[1] + titleView.height + v.getLocationOnScreen(location) + top -= location[1] + actionBar.setDisplayShowTitleEnabled(top < 0) + } + + fun attach(scrollView: NestedScrollView) { + scrollView.setOnScrollChangeListener(this) + scrollView.doOnLayout { + onScrollChange(scrollView, 0, 0, 0, 0) + } + } + + private fun getActivity(context: Context): AppCompatActivity? { + activityRef?.get()?.let { + if (!it.isDestroyed) return it + } + val activity = context.findActivity() as? AppCompatActivity + if (activity == null || activity.isDestroyed) { + return null + } + activityRef = WeakReference(activity) + return activity + } +} diff --git a/app/src/main/res/layout-w600dp/activity_details.xml b/app/src/main/res/layout-w600dp/activity_details.xml index 9221f7ed0..03faa2f1f 100644 --- a/app/src/main/res/layout-w600dp/activity_details.xml +++ b/app/src/main/res/layout-w600dp/activity_details.xml @@ -24,13 +24,9 @@ android:id="@id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" - android:background="@drawable/m3_tabs_background" - android:theme="?attr/actionBarTheme" app:layout_scrollFlags="noScroll" - tools:ignore="PrivateResource" tools:menu="@menu/opt_details"> - + + + + + + + + + + @@ -63,69 +100,18 @@ app:layout_constraintWidth_percent="0.5" tools:layout="@layout/fragment_details" /> - - - - - - - - - - + app:layout_constraintTop_toBottomOf="@id/appbar"> - - + app:layout_constraintTop_toTopOf="parent" /> - -