Skip to content

Commit

Permalink
Implement design using RecyclerView
Browse files Browse the repository at this point in the history
  • Loading branch information
e10dokup committed Jan 1, 2019
1 parent 7f29b78 commit 77bac78
Show file tree
Hide file tree
Showing 16 changed files with 497 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.droidkaigi.confsched2019.about.fixeddata

sealed class AboutThisApp(
open val id: Int,
open val name: Int,
open val description: Int,
open val navigationUrl: String?
) {
data class Item(
override val id: Int,
override val name: Int,
override val description: Int,
override val navigationUrl: String?
) : AboutThisApp(id, name, description, navigationUrl)

// TODO: Determine headers link
data class HeadItem(
override val id: Int,
override val name: Int,
override val description: Int,
override val navigationUrl: String?
) : AboutThisApp(id, name, description, navigationUrl)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package io.github.droidkaigi.confsched2019.about.fixeddata

import io.github.droidkaigi.confsched2019.about.R

class AboutThisApps {

companion object {
fun getThisApps(): List<AboutThisApp> {
var index = 0
return listOf(
// Head Item
AboutThisApp.HeadItem(
10000 + index++,
R.string.what_is_droidkaigi,
R.string.description_droidkaigi,
""
),
// Access Item
AboutThisApp.Item(
10000 + index++,
R.string.access_to_place,
R.string.check_map,
""
),
// StaffList Item
AboutThisApp.Item(
10000 + index++,
R.string.staff_list,
R.string.check,
""
),
// Privacy Policy Item
AboutThisApp.Item(
10000 + index++,
R.string.privacy_policy,
R.string.check,
""
),
// License Item
AboutThisApp.Item(
10000 + index++,
R.string.license,
R.string.check,
""
),
// App Version Item
AboutThisApp.Item(
10000 + index++,
R.string.app_version,
R.string.version_name,
""
)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,26 @@ import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Lifecycle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.SimpleItemAnimator
import com.xwray.groupie.GroupAdapter
import com.xwray.groupie.ViewHolder
import dagger.Module
import dagger.Provides
import io.github.droidkaigi.confsched2019.about.R
import io.github.droidkaigi.confsched2019.about.databinding.FragmentAboutBinding
import io.github.droidkaigi.confsched2019.about.fixeddata.AboutThisApps
import io.github.droidkaigi.confsched2019.about.ui.item.AboutSection
import io.github.droidkaigi.confsched2019.about.ui.widget.DaggerFragment
import io.github.droidkaigi.confsched2019.about.ui.widget.DottedItemDecoration
import io.github.droidkaigi.confsched2019.di.PageScope

class AboutFragment : DaggerFragment() {

private lateinit var binding: FragmentAboutBinding
private val aboutSection = AboutSection()


override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -30,6 +40,37 @@ class AboutFragment : DaggerFragment() {
)
return binding.root
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)

setupRecyclerView()
}

private fun setupRecyclerView() {
val groupAdapter = GroupAdapter<ViewHolder>().apply {
add(aboutSection)
}
binding.aboutRecycler.apply {
layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, false)
adapter = groupAdapter
addItemDecoration(
DottedItemDecoration.from(
context,
R.color.gray3,
R.dimen.divider_padding,
R.dimen.divider_padding,
R.dimen.divider_width,
R.dimen.divider_gap
)
)
(itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false
}
aboutSection.updateAboutThisApps(
AboutThisApps.getThisApps()
)
}

}

@Module
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.github.droidkaigi.confsched2019.about.ui.item

import android.view.View
import androidx.databinding.DataBindingUtil
import com.xwray.groupie.Item
import com.xwray.groupie.databinding.BindableItem
import com.xwray.groupie.databinding.ViewHolder
import io.github.droidkaigi.confsched2019.about.R
import io.github.droidkaigi.confsched2019.about.databinding.HeaderAboutBinding
import io.github.droidkaigi.confsched2019.about.fixeddata.AboutThisApp

class AboutHeaderItem(
private val headItem: AboutThisApp.HeadItem
) : BindableItem<HeaderAboutBinding>() {

override fun createViewHolder(itemView: View): ViewHolder<HeaderAboutBinding> {
return ViewHolder(DataBindingUtil.bind(itemView)!!)
}

override fun getLayout(): Int = R.layout.header_about

override fun bind(binding: HeaderAboutBinding, position: Int) {
binding.headItem = headItem
}

override fun isSameAs(other: Item<*>?): Boolean =
other is AboutHeaderItem

override fun equals(other: Any?): Boolean =
headItem == (other as? AboutHeaderItem?)?.headItem

override fun hashCode(): Int = headItem.hashCode()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.github.droidkaigi.confsched2019.about.ui.item

import android.view.View
import androidx.core.content.ContextCompat
import androidx.databinding.DataBindingUtil
import com.xwray.groupie.Item
import com.xwray.groupie.databinding.BindableItem
import com.xwray.groupie.databinding.ViewHolder
import io.github.droidkaigi.confsched2019.about.R
import io.github.droidkaigi.confsched2019.about.databinding.ItemAboutBinding
import io.github.droidkaigi.confsched2019.about.fixeddata.AboutThisApp

class AboutItem(
private val item: AboutThisApp.Item
) : BindableItem<ItemAboutBinding>() {

override fun createViewHolder(itemView: View): ViewHolder<ItemAboutBinding> {
return ViewHolder(DataBindingUtil.bind(itemView)!!)
}

override fun getLayout(): Int = R.layout.item_about

override fun bind(binding: ItemAboutBinding, position: Int) {
binding.item = item
if (item.navigationUrl.isNullOrEmpty()) {
binding.checkText.setTextColor(
ContextCompat.getColor(binding.root.context, R.color.gray2)
)
}
}

override fun isSameAs(other: Item<*>?): Boolean =
other is AboutItem

override fun equals(other: Any?): Boolean =
item == (other as? AboutItem?)?.item

override fun hashCode(): Int = item.hashCode()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.droidkaigi.confsched2019.about.ui.item

import com.xwray.groupie.Item
import com.xwray.groupie.Section
import io.github.droidkaigi.confsched2019.about.fixeddata.AboutThisApp

class AboutSection : Section() {

fun updateAboutThisApps(
aboutThisApps: List<AboutThisApp>
) {
val headItem = aboutThisApps.first { it is AboutThisApp.HeadItem } as AboutThisApp.HeadItem
val header = AboutHeaderItem(
headItem
)
val list = mutableListOf<Item<*>>(header)
aboutThisApps.filter { it is AboutThisApp.Item }
.mapTo(list) {
AboutItem(it as AboutThisApp.Item)
}
update(list)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package io.github.droidkaigi.confsched2019.about.ui.widget

import android.content.Context
import android.graphics.*
import android.view.View
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView

class DottedItemDecoration private constructor(
private val color: Int,
private val paddingLeft: Int,
private val paddingRight: Int,
private val width: Int,
private val gap: Int
) : RecyclerView.ItemDecoration() {

companion object {
fun from(
context: Context,
colorRes: Int,
paddingLeftRes: Int,
paddingRightRes: Int,
widthRes: Int,
gapRes: Int
): DottedItemDecoration {
val color = ContextCompat.getColor(context, colorRes)
val paddingLeftPx = context.resources.getDimensionPixelSize(paddingLeftRes)
val paddingRightPx = context.resources.getDimensionPixelSize(paddingRightRes)
val widthPx = context.resources.getDimensionPixelSize(widthRes)
val gapPx = context.resources.getDimensionPixelSize(gapRes)
return DottedItemDecoration(
color,
paddingLeftPx,
paddingRightPx,
widthPx,
gapPx
)
}
}

private val paint: Paint = Paint()

init {
paint.apply {
color = this@DottedItemDecoration.color
style = Paint.Style.STROKE
strokeWidth = this@DottedItemDecoration.width.toFloat()
pathEffect = DashPathEffect(
floatArrayOf(
this@DottedItemDecoration.gap.toFloat(),
this@DottedItemDecoration.gap.toFloat()
),
0f)
}
}

override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
super.getItemOffsets(outRect, view, parent, state)
if (parent.getChildAdapterPosition(view) < 1) return

outRect.bottom = width
}

override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
val left = paddingLeft.toFloat()
val right = (parent.width - paddingRight).toFloat()

val childCount = parent.childCount
val path = Path()
for (i in 0 until childCount) {
val child = parent.getChildAt(i)
val top = (child.bottom + width / 2).toFloat()

path.moveTo(left, top)
path.lineTo(right, top)
}
c.drawPath(path, paint)
}
}
29 changes: 11 additions & 18 deletions feature/about/src/main/res/drawable/dotted_line_gray3.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:bottom="-2dp"
android:left="-2dp"
android:right="-2dp"
android:top="0dp">

<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="@color/gray3"
android:dashWidth="3dp"
android:dashGap="3dp" />
</shape>
</item>
</layer-list>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:width="1dp"
android:color="@color/gray3"
android:dashWidth="5dp"
android:dashGap="5dp" />
<size
android:width="1dp"/>
</shape>
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
android:id="@+id/description_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/logo_layout">
Expand All @@ -23,7 +20,7 @@
android:textSize="16sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

z
<TextView
android:id="@+id/description_droidkaigi_text"
android:layout_width="wrap_content"
Expand Down
3 changes: 0 additions & 3 deletions feature/about/src/main/res/layout/about_links_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
android:id="@+id/links_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/description_layout">
Expand Down
Loading

0 comments on commit 77bac78

Please sign in to comment.