Unverified Commit b53054f2 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito Committed by GitHub

Merge branch 'develop' into strings

parents 1c0f9b61 a8d9ec30
import android.content.Context import android.content.Context
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.view.View
import android.widget.TextView import android.widget.TextView
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.DrawableCompat import androidx.core.graphics.drawable.DrawableCompat
...@@ -60,7 +61,7 @@ object DrawableHelper { ...@@ -60,7 +61,7 @@ object DrawableHelper {
/** /**
* Tints a Drawable. * 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 drawable The Drawable to tint.
* @param context The context. * @param context The context.
...@@ -72,58 +73,74 @@ object DrawableHelper { ...@@ -72,58 +73,74 @@ object DrawableHelper {
DrawableCompat.setTint(drawable, ContextCompat.getColor(context, resId)) DrawableCompat.setTint(drawable, ContextCompat.getColor(context, resId))
/** /**
* Compounds an array of Drawable (to appear to the left of the text) into an array of TextView. * Compounds an array of Drawable (to appear on the start side of a 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 arrays of Drawable and TextView MUST be equal.
* *
* @param textView The array of TextView. * @param textView The array of TextView.
* @param drawables The array of Drawable. * @param drawables The array of Drawable.
* @see compoundLeftDrawable * @see compoundStartDrawable
*/ */
fun compoundDrawables(textView: Array<TextView>, drawables: Array<Drawable>) { fun compoundDrawables(textView: Array<TextView>, drawables: Array<Drawable>) {
if (textView.size != drawables.size) { if (textView.size != drawables.size) {
return return
} else { } else {
for (i in textView.indices) { 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)
}
} }
} }
} }
/** /**
* Compounds a Drawable (to appear on the left side of a text) into a TextView. * Compounds a Drawable (to appear on the start side of a text) into a TextView.
* *
* @param textView The TextView. * @param textView The TextView.
* @param drawable The Drawable. * @param drawable The Drawable.
* @see compoundDrawables * @see compoundDrawables
*/ */
fun compoundLeftDrawable(textView: TextView, drawable: Drawable) = fun compoundStartDrawable(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. * Compounds a Drawable (to appear on the end side of a text) into a TextView.
* *
* @param textView The TextView. * @param textView The TextView.
* @param drawable The Drawable. * @param drawable The Drawable.
* @see compoundLeftDrawable * @see compoundStartDrawable
*/ */
fun compoundRightDrawable(textView: TextView, drawable: Drawable) = fun compoundEndDrawable(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. * Compounds a Drawable (to appear on the start and end side of a text) into a TextView.
* *
* @param textView The TextView. * @param textView The TextView.
* @param leftDrawable The left Drawable. * @param startDrawable The start Drawable.
* @param rightDrawable The right Drawable. * @param endDrawable The end Drawable.
* @see compoundLeftDrawable * @see compoundStartDrawable
*/ */
fun compoundLeftAndRightDrawable( fun compoundStartAndEndDrawable(
textView: TextView, textView: TextView,
leftDrawable: Drawable, startDrawable: Drawable,
rightDrawable: Drawable endDrawable: Drawable
) = ) =
textView.setCompoundDrawablesWithIntrinsicBounds(leftDrawable, null, rightDrawable, null) if (textView.resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_LTR) {
textView.setCompoundDrawablesWithIntrinsicBounds(startDrawable, null, endDrawable, null)
} else {
textView.setCompoundDrawablesWithIntrinsicBounds(endDrawable, null, startDrawable, null)
}
/** /**
* Returns the user status drawable. * Returns the user status drawable.
...@@ -141,4 +158,4 @@ object DrawableHelper { ...@@ -141,4 +158,4 @@ object DrawableHelper {
else -> getDrawableFromId(R.drawable.ic_status_invisible_12dp, context) else -> getDrawableFromId(R.drawable.ic_status_invisible_12dp, context)
} }
} }
} }
\ No newline at end of file
...@@ -140,7 +140,7 @@ class RegisterUsernameFragment : Fragment(), RegisterUsernameView { ...@@ -140,7 +140,7 @@ class RegisterUsernameFragment : Fragment(), RegisterUsernameView {
val atDrawable = DrawableHelper.getDrawableFromId(R.drawable.ic_at_black_20dp, it) val atDrawable = DrawableHelper.getDrawableFromId(R.drawable.ic_at_black_20dp, it)
DrawableHelper.wrapDrawable(atDrawable) DrawableHelper.wrapDrawable(atDrawable)
DrawableHelper.tintDrawable(atDrawable, it, R.color.colorDrawableTintGrey) DrawableHelper.tintDrawable(atDrawable, it, R.color.colorDrawableTintGrey)
DrawableHelper.compoundLeftDrawable(text_username, atDrawable) DrawableHelper.compoundStartDrawable(text_username, atDrawable)
} }
} }
......
...@@ -195,7 +195,7 @@ class ChatDetailsFragment : Fragment(), ChatDetailsView { ...@@ -195,7 +195,7 @@ class ChatDetailsFragment : Fragment(), ChatDetailsView {
val wrappedDrawable = DrawableHelper.wrapDrawable(it) val wrappedDrawable = DrawableHelper.wrapDrawable(it)
val mutableDrawable = wrappedDrawable.mutate() val mutableDrawable = wrappedDrawable.mutate()
DrawableHelper.tintDrawable(mutableDrawable, context!!, R.color.colorPrimary) DrawableHelper.tintDrawable(mutableDrawable, context!!, R.color.colorPrimary)
DrawableHelper.compoundLeftDrawable(name, mutableDrawable) DrawableHelper.compoundStartDrawable(name, mutableDrawable)
} }
} }
......
...@@ -139,7 +139,7 @@ class ChatRoomActivity : AppCompatActivity(), HasSupportFragmentInjector { ...@@ -139,7 +139,7 @@ class ChatRoomActivity : AppCompatActivity(), HasSupportFragmentInjector {
} }
fun setupExpandMoreForToolbar(listener: (View) -> Unit) { fun setupExpandMoreForToolbar(listener: (View) -> Unit) {
DrawableHelper.compoundRightDrawable( DrawableHelper.compoundEndDrawable(
text_toolbar_title, text_toolbar_title,
DrawableHelper.getDrawableFromId(R.drawable.ic_chatroom_toolbar_expand_more_20dp, this) DrawableHelper.getDrawableFromId(R.drawable.ic_chatroom_toolbar_expand_more_20dp, this)
) )
......
...@@ -233,14 +233,14 @@ class DirectoryFragment : Fragment(), DirectoryView { ...@@ -233,14 +233,14 @@ class DirectoryFragment : Fragment(), DirectoryView {
private fun updateSortByTitle() { private fun updateSortByTitle() {
if (isSortByChannels) { if (isSortByChannels) {
text_sort_by.text = getString(R.string.msg_channels) text_sort_by.text = getString(R.string.msg_channels)
DrawableHelper.compoundLeftAndRightDrawable( DrawableHelper.compoundStartAndEndDrawable(
text_sort_by, text_sort_by,
hashtagDrawable, hashtagDrawable,
arrowDownDrawable arrowDownDrawable
) )
} else { } else {
text_sort_by.text = getString(R.string.msg_users) text_sort_by.text = getString(R.string.msg_users)
DrawableHelper.compoundLeftAndRightDrawable( DrawableHelper.compoundStartAndEndDrawable(
text_sort_by, text_sort_by,
userDrawable, userDrawable,
arrowDownDrawable arrowDownDrawable
......
...@@ -100,21 +100,21 @@ class DirectorySortingBottomSheetFragment : BottomSheetDialogFragment() { ...@@ -100,21 +100,21 @@ class DirectorySortingBottomSheetFragment : BottomSheetDialogFragment() {
} }
} }
private fun checkSelection(textView: TextView, leftDrawable: Drawable) { private fun checkSelection(textView: TextView, startDrawable: Drawable) {
context?.let { context?.let {
DrawableHelper.compoundLeftAndRightDrawable( DrawableHelper.compoundStartAndEndDrawable(
textView, textView,
leftDrawable, startDrawable,
checkDrawable checkDrawable
) )
} }
} }
private fun uncheckSelection(textView: TextView, leftDrawable: Drawable) { private fun uncheckSelection(textView: TextView, startDrawable: Drawable) {
context?.let { context?.let {
DrawableHelper.compoundLeftDrawable( DrawableHelper.compoundStartDrawable(
textView, textView,
leftDrawable startDrawable
) )
} }
} }
......
...@@ -143,21 +143,21 @@ class SortingAndGroupingBottomSheetFragment : BottomSheetDialogFragment(), Sorti ...@@ -143,21 +143,21 @@ class SortingAndGroupingBottomSheetFragment : BottomSheetDialogFragment(), Sorti
text_sort_by.text = getString(R.string.msg_sort_by_placeholder, text.toLowerCase()) text_sort_by.text = getString(R.string.msg_sort_by_placeholder, text.toLowerCase())
} }
private fun checkSelection(textView: TextView, @DrawableRes leftDrawable: Int) { private fun checkSelection(textView: TextView, @DrawableRes startDrawable: Int) {
context?.let { context?.let {
DrawableHelper.compoundLeftAndRightDrawable( DrawableHelper.compoundStartAndEndDrawable(
textView, textView,
DrawableHelper.getDrawableFromId(leftDrawable, it), DrawableHelper.getDrawableFromId(startDrawable, it),
DrawableHelper.getDrawableFromId(R.drawable.ic_check, it) DrawableHelper.getDrawableFromId(R.drawable.ic_check, it)
) )
} }
} }
private fun uncheckSelection(textView: TextView, @DrawableRes leftDrawable: Int) { private fun uncheckSelection(textView: TextView, @DrawableRes startDrawable: Int) {
context?.let { context?.let {
DrawableHelper.compoundLeftDrawable( DrawableHelper.compoundStartDrawable(
textView, textView,
DrawableHelper.getDrawableFromId(leftDrawable, it) DrawableHelper.getDrawableFromId(startDrawable, it)
) )
} }
} }
......
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