Unverified Commit 3d40cb71 authored by Hussein El Feky's avatar Hussein El Feky Committed by GitHub

Let drawables be set correctly in RTL languages

parent 5ceacaf2
import android.content.Context
import android.graphics.drawable.Drawable
import android.view.View
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.DrawableCompat
......@@ -60,7 +61,7 @@ object DrawableHelper {
/**
* Tints a Drawable.
*
* REMARK: you MUST always wrap the Drawable before tint it.
* REMARK: you MUST always wrap the Drawable before tinting it.
*
* @param drawable The Drawable to tint.
* @param context The context.
......@@ -74,7 +75,7 @@ object DrawableHelper {
/**
* Compounds an array of Drawable (to appear to the left of the text) into an array of TextView.
*
* REMARK: the number of elements in both array of Drawable and EditText MUST be equal.
* REMARK: the number of elements in both array of Drawable and TextView MUST be equal.
*
* @param textView The array of TextView.
* @param drawables The array of Drawable.
......@@ -85,7 +86,11 @@ object DrawableHelper {
return
} else {
for (i in textView.indices) {
textView[i].setCompoundDrawablesWithIntrinsicBounds(drawables[i], null, null, null)
if (textView[i].resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_LTR) {
textView[i].setCompoundDrawablesWithIntrinsicBounds(drawables[i], null, null, null)
} else {
textView[i].setCompoundDrawablesWithIntrinsicBounds(null, null, drawables[i], null)
}
}
}
}
......@@ -98,7 +103,11 @@ object DrawableHelper {
* @see compoundDrawables
*/
fun compoundLeftDrawable(textView: TextView, drawable: Drawable) =
textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
if (textView.resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_LTR) {
textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
} else {
textView.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null)
}
/**
* Compounds a Drawable (to appear on the right side of a text) into a TextView.
......@@ -108,7 +117,11 @@ object DrawableHelper {
* @see compoundLeftDrawable
*/
fun compoundRightDrawable(textView: TextView, drawable: Drawable) =
textView.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null)
if (textView.resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_LTR) {
textView.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null)
} else {
textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
}
/**
* Compounds a Drawable (to appear on the left and right side of a text) into a TextView.
......@@ -123,7 +136,11 @@ object DrawableHelper {
leftDrawable: Drawable,
rightDrawable: Drawable
) =
textView.setCompoundDrawablesWithIntrinsicBounds(leftDrawable, null, rightDrawable, null)
if (textView.resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_LTR) {
textView.setCompoundDrawablesWithIntrinsicBounds(leftDrawable, null, rightDrawable, null)
} else {
textView.setCompoundDrawablesWithIntrinsicBounds(rightDrawable, null, leftDrawable, null)
}
/**
* Returns the user status drawable.
......@@ -141,4 +158,4 @@ object DrawableHelper {
else -> getDrawableFromId(R.drawable.ic_status_invisible_12dp, context)
}
}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment