Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/support rtl #606

Merged
merged 11 commits into from Feb 5, 2018
Expand Up @@ -15,6 +15,7 @@ import android.text.style.StyleSpan
import android.view.ActionMode
import android.view.Menu
import android.view.MenuItem
import android.view.View

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Unused import

import android.widget.TextView
import io.github.droidkaigi.confsched2018.R
import io.github.droidkaigi.confsched2018.util.ext.selectedText
Expand Down Expand Up @@ -45,8 +46,12 @@ fun TextView.setPeriodText(startDate: Date?, endDate: Date?) {
@BindingAdapter(value = ["prefix", "roomName"])
fun TextView.setRoomText(prefix: String?, roomName: String?) {
prefix ?: return
text = when (roomName) { null -> ""
else -> context.getString(R.string.room_format, prefix, roomName)
roomName ?: return
val isLayoutDirectionRtl = resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_RTL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you extract this comparison as an extension method of View?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done with 5937050

text = if (isLayoutDirectionRtl) {
context.getString(R.string.room_format_rtl, prefix, roomName)
} else {
context.getString(R.string.room_format, prefix, roomName)
}
}

Expand Down
Expand Up @@ -53,7 +53,11 @@ class StickyHeaderItemDecoration constructor(
return
}

outRect.left = contentMargin
if (view.context.resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_RTL) {
outRect.right = contentMargin
} else {
outRect.left = contentMargin
}
}

override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
Expand All @@ -77,6 +81,14 @@ class StickyHeaderItemDecoration constructor(
val textLine = callback.getGroupFirstLine(position)
if (TextUtils.isEmpty(textLine)) continue

val isLayoutDirectionRtl =
view.resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_RTL
val textX = if (isLayoutDirectionRtl) {
labelPadding.toFloat() + view.width.toFloat()
} else {
labelPadding.toFloat()
}

val viewBottom = view.bottom + view.paddingBottom
var textY = Math.max(view.height, viewBottom) - lineHeight
if (position + 1 < totalItemCount) {
Expand All @@ -85,7 +97,7 @@ class StickyHeaderItemDecoration constructor(
textY = viewBottom - lineHeight
}
}
c.drawText(textLine, labelPadding.toFloat(), textY, textPaint)
c.drawText(textLine, textX, textY, textPaint)
}
}

Expand Down
Expand Up @@ -53,7 +53,7 @@ open class BottomNavigationBehavior : CoordinatorLayout.Behavior<BottomNavigatio
internal fun updateSnackBarPaddingBottomByBottomNavigationView(view: BottomNavigationView) {
snackbar?.apply {
val translateY = (view.height - view.translationY).toInt()
setPadding(paddingLeft, paddingTop, paddingRight, translateY)
setPadding(paddingEnd, paddingTop, paddingStart, translateY)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀 I guess here should be setPaddingWithLayoutDirction(paddingStart, paddingTop, paddingEnd, translateY)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂

requestLayout()
}
}
Expand Down
Expand Up @@ -29,7 +29,7 @@ class FeedContentTextView
var x = event.x.toInt()
var y = event.y.toInt()

x -= totalPaddingLeft
x -= totalPaddingStart
y -= totalPaddingTop
x += scrollX
y += scrollY
Expand Down
Expand Up @@ -5,6 +5,7 @@ import android.support.annotation.LayoutRes
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.View
import io.github.droidkaigi.confsched2018.util.ext.setPaddingWithLayoutDirction

class SponsorsItemDecoration(@LayoutRes private val sponsorItemViewType: Int)
: RecyclerView.ItemDecoration() {
Expand All @@ -30,21 +31,22 @@ class SponsorsItemDecoration(@LayoutRes private val sponsorItemViewType: Int)
val sidePadding = 16 * density
val middlePadding = 8 * density

val leftPadding = when {
val startPadding = when {
isStart -> sidePadding
isEnd && spanSize == 2 -> 0f
isEnd && spanSize == 3 -> middlePadding / 2
else -> middlePadding
}.toInt()

val rightPadding = when {
val endPadding = when {
isEnd -> sidePadding
isStart && spanSize == 2 -> 0f
isStart && spanSize == 3 -> middlePadding / 2
else -> middlePadding
}.toInt()

view.setPadding(leftPadding, view.paddingTop, rightPadding, view.paddingBottom)
view.setPaddingWithLayoutDirction(
startPadding, view.paddingTop, endPadding, view.paddingBottom)
}

private fun isSponsorItem(child: View, parent: RecyclerView): Boolean =
Expand Down
Expand Up @@ -34,3 +34,10 @@ var View.elevationForPostLollipop: Float
elevation = value
}
}

fun View.setPaddingWithLayoutDirction(start: Int, top: Int, end: Int, bottom: Int) =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if (resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_RTL) {
setPadding(end, top, start, bottom)
} else {
setPadding(start, top, end, bottom)
}
1 change: 1 addition & 0 deletions app/src/main/res/drawable/ic_access_black_24dp.xml
Expand Up @@ -3,6 +3,7 @@
android:height="24dp"
android:viewportHeight="20.0"
android:viewportWidth="20.0"
android:autoMirrored="true"
>
<path
android:fillAlpha="0.58"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/drawable/ic_contributor_black_24dp.xml
Expand Up @@ -3,6 +3,7 @@
android:height="24dp"
android:viewportHeight="20.0"
android:viewportWidth="20.0"
android:autoMirrored="true"
>
<path
android:fillAlpha="0.58"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/layout/fragment_map.xml
Expand Up @@ -34,6 +34,7 @@
android:layout_margin="16dp"
android:lineSpacingExtra="7.2sp"
android:text="@string/map_place_name"
android:textAlignment="viewStart"
android:textColor="#ffffff"
android:textIsSelectable="true"
android:textSize="18sp"
Expand Down Expand Up @@ -85,6 +86,7 @@
android:layout_marginStart="72dp"
android:lineSpacingExtra="9.6sp"
android:text="@string/map_address"
android:textAlignment="viewStart"
android:textIsSelectable="true"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down Expand Up @@ -121,6 +123,7 @@
android:layout_marginTop="8dp"
android:lineSpacingExtra="9.6sp"
android:text="@string/map_nearby_stations"
android:textAlignment="viewStart"
android:textIsSelectable="true"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout/fragment_search.xml
Expand Up @@ -20,8 +20,8 @@
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:targetApi="lollipop"
/>
Expand All @@ -31,8 +31,8 @@
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/tab_layout"
/>

Expand Down
22 changes: 16 additions & 6 deletions app/src/main/res/layout/fragment_session_detail.xml
Expand Up @@ -69,6 +69,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:textAlignment="viewStart"
android:textIsSelectable="true"
android:text="@{session.title}"
android:textColor="@color/app_bar_text_color"
Expand All @@ -85,6 +86,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:paddingTop="8dp"
android:textAlignment="viewStart"
android:textColor="@color/app_bar_text_color"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/session_title"
Expand Down Expand Up @@ -187,7 +189,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/finished_session_check"
/>

<View
android:id="@+id/divider_finished_session"
android:layout_width="match_parent"
Expand All @@ -209,10 +210,19 @@
android:layout_marginEnd="16dp"
android:layout_marginStart="12dp"
android:layout_marginTop="24dp"
android:text='@{"DAY"+session.dayNumber+" / "}'
android:text='@{"DAY"+session.dayNumber}'
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/divider_finished_session"
tools:text="DAY1 / "
tools:text="DAY1"
/>
<TextView
android:id="@+id/divider_day_and_period"
style="@style/TextStyle.App.Caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/session_header_divider"
app:layout_constraintStart_toEndOf="@+id/session_day_number"
app:layout_constraintTop_toTopOf="@id/session_day_number"
/>
<TextView
android:id="@+id/session_period"
Expand All @@ -221,8 +231,8 @@
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
app:endDate="@{session.endTime}"
app:layout_constraintStart_toEndOf="@id/session_day_number"
app:layout_constraintTop_toTopOf="@id/session_day_number"
app:layout_constraintStart_toEndOf="@id/divider_day_and_period"
app:layout_constraintTop_toTopOf="@id/divider_day_and_period"
app:layout_goneMarginStart="12dp"
app:layout_goneMarginTop="16dp"
app:startDate="@{session.startTime}"
Expand Down Expand Up @@ -250,8 +260,8 @@
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:gravity="top"
android:text="@{session.desc}"
android:textAlignment="viewStart"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout/fragment_sessions.xml
Expand Up @@ -20,8 +20,8 @@
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tabMode="scrollable"
tools:targetApi="lollipop"
Expand All @@ -32,8 +32,8 @@
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/tab_layout"
/>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_sessions_feedback.xml
Expand Up @@ -257,6 +257,7 @@
android:layout_marginTop="16dp"
android:hint="@string/session_feedback_comment_hint"
android:text="@{sessionFeedback.comment}"
android:textAlignment="viewStart"
android:textAppearance="@style/TextAppearance.App.Subhead"
android:textColor="@color/black"
android:textColorHint="#757575"
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/layout/item_about_this_app.xml
Expand Up @@ -22,7 +22,6 @@
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:fontFamily="sans-serif"
android:paddingLeft="24dp"
android:paddingStart="24dp"
android:text="@{aboutThisApp.name}"
android:textColor="#de000000"
Expand All @@ -39,9 +38,10 @@
android:layout_marginTop="8dp"
android:fontFamily="sans-serif"
android:lineSpacingExtra="4.8sp"
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:paddingStart="24dp"
android:paddingEnd="24dp"
android:text="@{aboutThisApp.description}"
android:textAlignment="viewStart"
android:textColor="#8b000000"
android:textSize="12sp"
android:textStyle="normal"
Expand Down
26 changes: 13 additions & 13 deletions app/src/main/res/layout/item_about_this_app_header.xml
Expand Up @@ -21,14 +21,13 @@
android:id="@+id/about_this_app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:fontFamily="sans-serif-light"
android:text="@string/about_what_is_prefix"
android:textColor="#de000000"
android:textSize="23sp"
android:textStyle="normal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintLeft_toLeftOf="@id/conference_name"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

app:layout_constraintTop_toTopOf="parent"
/>

Expand All @@ -54,7 +53,7 @@
android:textColor="#de000000"
android:textSize="23sp"
android:textStyle="normal"
app:layout_constraintEnd_toEndOf="@id/conference_name"
app:layout_constraintRight_toRightOf="@id/conference_name"
app:layout_constraintTop_toTopOf="parent"
/>

Expand All @@ -68,6 +67,7 @@
android:fontFamily="sans-serif"
android:lineSpacingExtra="9.6sp"
android:text="@{headItem.description}"
android:textAlignment="viewStart"
android:textColor="#000000"
android:textSize="12sp"
android:textStyle="normal"
Expand All @@ -85,8 +85,8 @@
android:contentDescription="@string/about_content_description_facebook"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/about_this_app_twitter"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/about_this_app_twitter"
app:layout_constraintTop_toBottomOf="@id/about_this_app_description"
app:srcCompat="@drawable/ic_facebook_purple_24dp"
/>
Expand All @@ -96,8 +96,8 @@
style="@style/SocialMediaButton"
android:contentDescription="@string/about_content_description_twitter"
app:layout_constraintBottom_toBottomOf="@id/about_this_app_facebook"
app:layout_constraintLeft_toRightOf="@+id/about_this_app_facebook"
app:layout_constraintRight_toLeftOf="@+id/about_this_app_github"
app:layout_constraintStart_toEndOf="@+id/about_this_app_facebook"
app:layout_constraintEnd_toStartOf="@+id/about_this_app_github"
app:layout_constraintTop_toTopOf="@id/about_this_app_facebook"
app:srcCompat="@drawable/ic_twitter_blue_24dp"
/>
Expand All @@ -107,8 +107,8 @@
style="@style/SocialMediaButton"
android:contentDescription="@string/about_content_description_github"
app:layout_constraintBottom_toBottomOf="@id/about_this_app_twitter"
app:layout_constraintLeft_toRightOf="@+id/about_this_app_twitter"
app:layout_constraintRight_toLeftOf="@+id/about_this_app_youtube"
app:layout_constraintStart_toEndOf="@+id/about_this_app_twitter"
app:layout_constraintEnd_toStartOf="@+id/about_this_app_youtube"
app:layout_constraintTop_toTopOf="@id/about_this_app_twitter"
app:srcCompat="@drawable/ic_github_black_24dp"
/>
Expand All @@ -118,8 +118,8 @@
style="@style/SocialMediaButton"
android:contentDescription="@string/about_content_description_youtube"
app:layout_constraintBottom_toBottomOf="@id/about_this_app_github"
app:layout_constraintLeft_toRightOf="@+id/about_this_app_github"
app:layout_constraintRight_toLeftOf="@+id/about_this_app_Medium"
app:layout_constraintStart_toEndOf="@+id/about_this_app_github"
app:layout_constraintEnd_toStartOf="@+id/about_this_app_Medium"
app:layout_constraintTop_toTopOf="@id/about_this_app_github"
app:srcCompat="@drawable/ic_youtube_24dp"
/>
Expand All @@ -129,8 +129,8 @@
style="@style/SocialMediaButton"
android:contentDescription="@string/about_content_description_medium"
app:layout_constraintBottom_toBottomOf="@id/about_this_app_youtube"
app:layout_constraintLeft_toRightOf="@+id/about_this_app_youtube"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toEndOf="@+id/about_this_app_youtube"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/about_this_app_youtube"
app:srcCompat="@drawable/ic_medium_24dp"
/>
Expand Down