Manage title visibility on DetailsActivity
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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<AppCompatActivity>? = 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
|
||||
}
|
||||
}
|
||||
@@ -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">
|
||||
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/button_read"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -47,6 +43,47 @@
|
||||
tools:enabled="true"
|
||||
tools:icon="@drawable/ic_read" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/button_dropdown"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:background="?selectableItemBackgroundBorderless"
|
||||
android:contentDescription="@string/translations"
|
||||
android:padding="@dimen/margin_small"
|
||||
android:src="@drawable/ic_expand_more" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/group_header"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginHorizontal="@dimen/toolbar_button_margin"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?textAppearanceTitleMedium"
|
||||
tools:ignore="InconsistentLayout"
|
||||
tools:text="@string/chapter_d_of_d" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView_subtitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?textAppearanceTitleSmall"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:visibility="gone"
|
||||
tools:text="English"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.appbar.MaterialToolbar>
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
@@ -63,69 +100,18 @@
|
||||
app:layout_constraintWidth_percent="0.5"
|
||||
tools:layout="@layout/fragment_details" />
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/group_header"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toEndOf="@id/card_chapters"
|
||||
app:layout_constraintStart_toStartOf="@id/card_chapters"
|
||||
app:layout_constraintTop_toBottomOf="@id/appbar">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignWithParentIfMissing="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_toStartOf="@id/button_dropdown"
|
||||
android:paddingHorizontal="@dimen/margin_normal"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?textAppearanceTitleMedium"
|
||||
tools:ignore="InconsistentLayout"
|
||||
tools:text="@string/chapter_d_of_d" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView_subtitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignWithParentIfMissing="true"
|
||||
android:layout_below="@id/textView_title"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_toStartOf="@id/button_dropdown"
|
||||
android:paddingHorizontal="@dimen/margin_normal"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?textAppearanceTitleSmall"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:visibility="gone"
|
||||
tools:text="English"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/button_dropdown"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginBottom="1dp"
|
||||
android:background="?selectableItemBackgroundBorderless"
|
||||
android:padding="@dimen/margin_small"
|
||||
android:src="@drawable/ic_expand_more" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/card_chapters"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginStart="@dimen/side_card_offset"
|
||||
android:layout_marginTop="2dp"
|
||||
android:layout_marginEnd="@dimen/side_card_offset"
|
||||
android:layout_marginBottom="@dimen/side_card_offset"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/container_details"
|
||||
app:layout_constraintTop_toBottomOf="@id/group_header">
|
||||
app:layout_constraintTop_toBottomOf="@id/appbar">
|
||||
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/container_chapters"
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/scrollView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
|
||||
@@ -24,17 +24,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/margin_normal"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toStartOf="@id/guideline"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<include
|
||||
android:id="@+id/layout_sync"
|
||||
layout="@layout/layout_synchronization"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/guideline"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
@@ -46,7 +35,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toStartOf="@id/guideline"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/card_update" />
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<com.google.android.material.materialswitch.MaterialSwitch
|
||||
android:id="@+id/switch_incognito"
|
||||
@@ -63,7 +52,7 @@
|
||||
android:textColor="?attr/colorControlNormal"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/guideline"
|
||||
app:layout_constraintTop_toBottomOf="@id/layout_sync"
|
||||
app:layout_constraintTop_toBottomOf="@id/card_update"
|
||||
app:layout_goneMarginTop="8dp" />
|
||||
|
||||
<org.koitharu.kotatsu.core.ui.widgets.ListItemTextView
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/scrollView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
|
||||
@@ -19,14 +19,6 @@
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<include
|
||||
android:id="@+id/layout_sync"
|
||||
layout="@layout/layout_synchronization"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<com.google.android.material.divider.MaterialDivider
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
Reference in New Issue
Block a user