Skip to content

Commit

Permalink
Merge pull request #606 from atsuko-fukui/feature/support_rtl
Browse files Browse the repository at this point in the history
Feature/support rtl
  • Loading branch information
jmatsu committed Feb 5, 2018
2 parents 252be01 + b870783 commit 451042a
Show file tree
Hide file tree
Showing 23 changed files with 141 additions and 52 deletions.
Expand Up @@ -17,6 +17,7 @@ import android.view.Menu
import android.view.MenuItem
import android.widget.TextView
import io.github.droidkaigi.confsched2018.R
import io.github.droidkaigi.confsched2018.util.ext.isLayoutDirectionRtl
import io.github.droidkaigi.confsched2018.util.ext.selectedText
import io.github.droidkaigi.confsched2018.util.ext.toReadableDateTimeString
import io.github.droidkaigi.confsched2018.util.ext.toReadableTimeString
Expand Down Expand Up @@ -45,8 +46,11 @@ 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
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 @@ -11,6 +11,7 @@ import android.text.TextPaint
import android.text.TextUtils
import android.view.View
import io.github.droidkaigi.confsched2018.R
import io.github.droidkaigi.confsched2018.util.ext.isLayoutDirectionRtl

/**
* Created by e10dokup on 2018/01/18.
Expand Down Expand Up @@ -53,7 +54,11 @@ class StickyHeaderItemDecoration constructor(
return
}

outRect.left = contentMargin
if (view.isLayoutDirectionRtl()) {
outRect.right = contentMargin
} else {
outRect.left = contentMargin
}
}

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

val textX = if (view.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 +96,7 @@ class StickyHeaderItemDecoration constructor(
textY = viewBottom - lineHeight
}
}
c.drawText(textLine, labelPadding.toFloat(), textY, textPaint)
c.drawText(textLine, textX, textY, textPaint)
}
}

Expand Down
Expand Up @@ -7,6 +7,7 @@ import android.support.design.widget.CoordinatorLayout
import android.support.design.widget.Snackbar
import android.util.AttributeSet
import android.view.View
import io.github.droidkaigi.confsched2018.util.ext.setPaddingWithLayoutDirction

/**
* Behavior to show Snackbar above BottomNavigationView
Expand Down Expand Up @@ -53,7 +54,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)
setPaddingWithLayoutDirction(paddingStart, paddingTop, paddingEnd, translateY)
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,13 @@ var View.elevationForPostLollipop: Float
elevation = value
}
}

fun View.setPaddingWithLayoutDirction(start: Int, top: Int, end: Int, bottom: Int) =
if (isLayoutDirectionRtl()) {
setPadding(end, top, start, bottom)
} else {
setPadding(start, top, end, bottom)
}

fun View.isLayoutDirectionRtl() =
resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_RTL
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 @@ -33,8 +33,8 @@
android:layout_height="0dp"
android:clipChildren="false"
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

0 comments on commit 451042a

Please sign in to comment.