Better RTL support in manga details and library

This commit is contained in:
Jay 2020-04-24 17:09:08 -04:00
parent 024b075330
commit 9586b564ed
7 changed files with 31 additions and 25 deletions

View File

@ -54,6 +54,7 @@ import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
import eu.kanade.tachiyomi.ui.migration.manga.design.PreMigrationController import eu.kanade.tachiyomi.ui.migration.manga.design.PreMigrationController
import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.dpToPxEnd
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.system.launchUI
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
@ -169,7 +170,7 @@ class LibraryController(
text_view_m.translationY = view.height * text_view_m.translationY = view.height *
(index.toFloat() / (adapter.headerItems.size + 1)) (index.toFloat() / (adapter.headerItems.size + 1))
- text_view_m.height / 2 + 16.dpToPx - text_view_m.height / 2 + 16.dpToPx
text_view_m.translationX = 45f.dpToPx text_view_m.translationX = 45f.dpToPxEnd
text_view_m.alpha = 1f text_view_m.alpha = 1f
text_view_m.text = headerItem.category.name text_view_m.text = headerItem.category.name
} }
@ -189,7 +190,7 @@ class LibraryController(
} }
RecyclerView.SCROLL_STATE_IDLE -> { RecyclerView.SCROLL_STATE_IDLE -> {
scrollAnim = fast_scroller.animate().setStartDelay(1000).setDuration(250) scrollAnim = fast_scroller.animate().setStartDelay(1000).setDuration(250)
.translationX(25f.dpToPx) .translationX(25f.dpToPxEnd)
scrollAnim?.start() scrollAnim?.start()
} }
} }
@ -199,7 +200,8 @@ class LibraryController(
private fun hideScroller(duration: Long = 1000) { private fun hideScroller(duration: Long = 1000) {
if (alwaysShowScroller) return if (alwaysShowScroller) return
scrollAnim = scrollAnim =
fast_scroller.animate().setStartDelay(duration).setDuration(250).translationX(25f.dpToPx) fast_scroller.animate().setStartDelay(duration).setDuration(250)
.translationX(25f.dpToPxEnd)
scrollAnim?.start() scrollAnim?.start()
} }
@ -219,7 +221,7 @@ class LibraryController(
super.onViewCreated(view) super.onViewCreated(view)
view.applyWindowInsetsForRootController(activity!!.bottom_nav) view.applyWindowInsetsForRootController(activity!!.bottom_nav)
if (!::presenter.isInitialized) presenter = LibraryPresenter(this) if (!::presenter.isInitialized) presenter = LibraryPresenter(this)
if (!alwaysShowScroller) fast_scroller.translationX = 25f.dpToPx if (!alwaysShowScroller) fast_scroller.translationX = 25f.dpToPxEnd
setFastScrollBackground() setFastScrollBackground()
adapter = LibraryCategoryAdapter(this) adapter = LibraryCategoryAdapter(this)

View File

@ -93,6 +93,7 @@ import eu.kanade.tachiyomi.ui.webview.WebViewActivity
import eu.kanade.tachiyomi.util.storage.getUriCompat import eu.kanade.tachiyomi.util.storage.getUriCompat
import eu.kanade.tachiyomi.util.system.ThemeUtil import eu.kanade.tachiyomi.util.system.ThemeUtil
import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.dpToPxEnd
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.system.launchUI
import eu.kanade.tachiyomi.util.system.pxToDp import eu.kanade.tachiyomi.util.system.pxToDp
@ -293,7 +294,7 @@ class MangaDetailsController : BaseController,
showScroll = show showScroll = show
scrollAnim?.cancel() scrollAnim?.cancel()
scrollAnim = fast_scroller.animate().setDuration(100).translationX( scrollAnim = fast_scroller.animate().setDuration(100).translationX(
if (show) 0f else 25f.dpToPx) if (show) 0f else 25f.dpToPxEnd)
scrollAnim?.start() scrollAnim?.start()
} }
if (fPosition > 0 && !showScroll) { if (fPosition > 0 && !showScroll) {
@ -312,7 +313,7 @@ class MangaDetailsController : BaseController,
} }
private fun setFastScroller() { private fun setFastScroller() {
fast_scroller.translationX = if (showScroll || isTablet) 0f else 25f.dpToPx fast_scroller.translationX = if (showScroll || isTablet) 0f else 25f.dpToPxEnd
fast_scroller.setupWithRecyclerView(recycler, { position -> fast_scroller.setupWithRecyclerView(recycler, { position ->
val letter = adapter?.getSectionText(position) val letter = adapter?.getSectionText(position)
when { when {

View File

@ -20,6 +20,7 @@ import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.isLTR
import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.invisible import eu.kanade.tachiyomi.util.view.invisible
import eu.kanade.tachiyomi.util.view.resetStrokeColor import eu.kanade.tachiyomi.util.view.resetStrokeColor
@ -56,6 +57,8 @@ class MangaHeaderHolder(
true true
false false
} }
if (!itemView.resources.isLTR)
more_bg_gradient.rotation = 180f
less_button.setOnClickListener { collapseDesc() } less_button.setOnClickListener { collapseDesc() }
manga_genres_tags.setOnTagClickListener { manga_genres_tags.setOnTagClickListener {
adapter.delegate.tagClicked(it) adapter.delegate.tagClicked(it)

View File

@ -9,14 +9,13 @@ import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.res.Resources import android.content.res.Resources
import android.graphics.drawable.Drawable
import android.net.ConnectivityManager import android.net.ConnectivityManager
import android.net.Uri import android.net.Uri
import android.os.PowerManager import android.os.PowerManager
import android.view.View
import android.widget.Toast import android.widget.Toast
import androidx.annotation.AttrRes import androidx.annotation.AttrRes
import androidx.annotation.ColorRes import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.browser.customtabs.CustomTabsIntent import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
@ -101,15 +100,6 @@ fun Context.contextCompatColor(@ColorRes resource: Int): Int {
return ContextCompat.getColor(this, resource) return ContextCompat.getColor(this, resource)
} }
/**
* Returns the color from ContextCompat
*
* @param resource the color.
*/
fun Context.contextCompatDrawable(@DrawableRes resource: Int): Drawable? {
return ContextCompat.getDrawable(this, resource)
}
/** /**
* Converts to dp. * Converts to dp.
*/ */
@ -125,6 +115,14 @@ val Int.dpToPx: Int
val Float.dpToPx: Float val Float.dpToPx: Float
get() = (this * Resources.getSystem().displayMetrics.density) get() = (this * Resources.getSystem().displayMetrics.density)
/** Converts to px and takes into account LTR/RTL layout */
val Float.dpToPxEnd: Float
get() = (this * Resources.getSystem().displayMetrics.density *
if (Resources.getSystem().isLTR) 1 else -1)
val Resources.isLTR
get() = configuration.layoutDirection == View.LAYOUT_DIRECTION_LTR
/** /**
* Property to get the notification manager from the context. * Property to get the notification manager from the context.
*/ */

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item <item
android:left="0dp" android:start="0dp"
android:right="4dp" android:end="4dp"
android:bottom="4dp" android:bottom="4dp"
android:top="4dp"> android:top="4dp">
<shape android:shape="rectangle"> <shape android:shape="rectangle">
@ -14,7 +14,7 @@
</shape> </shape>
</item> </item>
<item <item
android:left="10dp" android:start="10dp"
android:bottom="4dp" android:bottom="4dp"
android:top="4dp"> android:top="4dp">
<shape android:shape="rectangle"> <shape android:shape="rectangle">

View File

@ -117,7 +117,7 @@
<com.google.android.material.textview.MaterialTextView <com.google.android.material.textview.MaterialTextView
style="@style/TextAppearance.MaterialComponents.Headline6" style="@style/TextAppearance.MaterialComponents.Headline6"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:paddingStart="16dp" android:paddingStart="16dp"
@ -128,7 +128,7 @@
android:id="@+id/sort_method_group" android:id="@+id/sort_method_group"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="horizontal"
android:paddingStart="12dp" android:paddingStart="12dp"
android:paddingEnd="12dp"> android:paddingEnd="12dp">

View File

@ -49,9 +49,9 @@
android:id="@+id/top_view" android:id="@+id/top_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="100dp" android:layout_height="100dp"
android:layout_marginTop="0dp"
app:layout_constraintBottom_toTopOf="@id/cover_card" app:layout_constraintBottom_toTopOf="@id/cover_card"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -116,11 +116,13 @@
<TextView <TextView
android:id="@+id/manga_status" android:id="@+id/manga_status"
style="@style/TextAppearance.Regular.Body1.Secondary" style="@style/TextAppearance.Regular.Body1.Secondary"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="4dp" android:layout_marginTop="4dp"
android:layout_marginEnd="16dp"
android:text="@string/unknown_status" android:text="@string/unknown_status"
android:textIsSelectable="false" android:textIsSelectable="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/title" app:layout_constraintStart_toStartOf="@id/title"
app:layout_constraintTop_toBottomOf="@+id/manga_author" /> app:layout_constraintTop_toBottomOf="@+id/manga_author" />
@ -268,7 +270,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:text="@string/more" android:text="@string/more"
android:textAlignment="textEnd" android:textAlignment="viewEnd"
app:layout_constraintBottom_toBottomOf="@id/more_guide" app:layout_constraintBottom_toBottomOf="@id/more_guide"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:rippleColor="@null" /> app:rippleColor="@null" />