Skip to content

Commit

Permalink
Merge branch 'release/v0.0.16'
Browse files Browse the repository at this point in the history
  • Loading branch information
sangcomz committed Jan 25, 2018
2 parents 0437436 + 2b45bac commit edd3df3
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 28 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

StickyTimeLine is timeline view for android.

## What's New in 0.0.15?
## What's New in 0.0.16?
- Fix Problems when recycler view is not added to dependency [#5](https://github.com/sangcomz/StickyTimeLine/issues/5)

## How to Use
Expand All @@ -16,7 +16,7 @@ StickyTimeLine is timeline view for android.
}
dependencies {
compile 'com.github.sangcomz:StickyTimeLine:v0.0.15'
compile 'com.github.sangcomz:StickyTimeLine:v0.0.16'
}
```
### Usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ import xyz.sangcomz.stickytimelineview.ext.DP
import xyz.sangcomz.stickytimelineview.model.RecyclerViewAttr
import xyz.sangcomz.stickytimelineview.model.SectionInfo

/*
*/

/**
* Copyright 2017 Timothy Paetz
* Copyright 2017 SeokWon Jeong
* thanks to @tim.paetz
* I was inspired by his code. And I used some of his code in the library.
* https://github.com/paetztm/recycler_view_headers
Expand All @@ -36,6 +40,10 @@ class RecyclerSectionItemDecoration(context: Context,
private var headerOffset = defaultOffset * 8


/**
* Get the offset for each Item.
* There is a difference in top offset between sections and not sections.
*/
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State?) {
super.getItemOffsets(outRect,
view,
Expand All @@ -49,7 +57,6 @@ class RecyclerSectionItemDecoration(context: Context,
outRect.top = defaultOffset / 2
}


val leftMargin = defaultOffset * 6
val rightMargin = defaultOffset * 2

Expand All @@ -59,26 +66,15 @@ class RecyclerSectionItemDecoration(context: Context,

}

override fun onDraw(c: Canvas?, parent: RecyclerView?, state: RecyclerView.State?) {
super.onDraw(c, parent, state)
// c?.let {
// parent?.let {
// val leftMargin = defaultOffset * 6
// val rightMargin = defaultOffset * 2
// val topMargin = defaultOffset
// (0 until parent.childCount)
// .map { parent.getChildAt(it) }
// .forEach {
// val params = it.layoutParams
// if (params is RecyclerView.LayoutParams && params.leftMargin != leftMargin) {
// params.setMargins(leftMargin, 0, rightMargin, topMargin)
// it.layoutParams = params
// }
// }
// }
// }
}

/**
* Draw any appropriate decorations into the Canvas supplied to the RecyclerView.
* Any content drawn by this method will be drawn after the item views are drawn
* and will thus appear over the views.
*
* @param c Canvas to draw into
* @param parent RecyclerView this ItemDecoration is drawing into
* @param state The current state of RecyclerView.
*/
override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State?) {
super.onDrawOver(c,
parent,
Expand Down Expand Up @@ -126,6 +122,9 @@ class RecyclerSectionItemDecoration(context: Context,
}
}

/**
* First create a header view.
*/
private fun getHeaderView(parent: RecyclerView) {
headerView = inflateHeaderView(parent)
headerView?.let { headerView ->
Expand Down Expand Up @@ -154,6 +153,9 @@ class RecyclerSectionItemDecoration(context: Context,
}
}

/**
* Set a header view for section info.
*/
private fun setHeaderView(sectionInfo: SectionInfo) {
headerTitle?.text = sectionInfo.title
headerSubTitle?.apply {
Expand All @@ -167,13 +169,19 @@ class RecyclerSectionItemDecoration(context: Context,

}

/**
* Draw a line in the timeline.
*/
private fun drawLine(c: Canvas, parent: RecyclerView) {
val paint = Paint()
paint.color = recyclerViewAttr.sectionLineColor
paint.strokeWidth = recyclerViewAttr.sectionLineWidth
c.drawLines(floatArrayOf(defaultOffset * 3f, 0f, defaultOffset * 3f, parent.height.toFloat()), paint)
}

/**
*
*/
private fun getChildInContact(parent: RecyclerView, contactPoint: Int): View? =
(0 until parent.childCount)
.map {
Expand All @@ -183,6 +191,9 @@ class RecyclerSectionItemDecoration(context: Context,
it.top in contactPoint / 2..contactPoint
}

/**
* Returns the oval drawable of the timeline.
*/
private fun getOvalDrawable(): Drawable {
val strokeWidth = defaultOffset / 2
val roundRadius = defaultOffset * 2
Expand All @@ -197,13 +208,19 @@ class RecyclerSectionItemDecoration(context: Context,
return gd
}

/**
* Moving parts when headers meet
*/
private fun moveHeader(c: Canvas, topHeader: View, offset: Float) {
c.save()
c.translate(0f, offset)
topHeader.draw(c)
c.restore()
}

/**
* Draw a header
*/
private fun drawHeader(c: Canvas, child: View, headerView: View) {
c.save()
if (sticky) {
Expand Down Expand Up @@ -251,6 +268,9 @@ class RecyclerSectionItemDecoration(context: Context,
view.measuredHeight)
}

/**
* To check if section is
*/
private fun getIsSection(position: Int): Boolean = when (position) {
0 -> {
true
Expand All @@ -264,10 +284,20 @@ class RecyclerSectionItemDecoration(context: Context,

}


/**
* Section-specific callback interface
*/
interface SectionCallback {

/**
* To check if section is
*/
fun isSection(position: Int): Boolean

/**
* Functions that return a section header in a section
*/
fun getSectionHeader(position: Int): SectionInfo?
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@ import android.util.AttributeSet
import xyz.sangcomz.stickytimelineview.model.RecyclerViewAttr


/**
* Created by seokwon.jeong on 16/11/2017.
/*
* Copyright 2018 SeokWon Jeong.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

class TimeLineRecyclerView(context: Context?, attrs: AttributeSet?) : RecyclerView(context, attrs) {
Expand Down Expand Up @@ -47,15 +59,17 @@ class TimeLineRecyclerView(context: Context?, attrs: AttributeSet?) : RecyclerVi
}
}

/**
* Add RecyclerSectionItemDecoration for Sticky TimeLineView
*
* @param callback SectionCallback
*/
fun addItemDecoration(callback: RecyclerSectionItemDecoration.SectionCallback) {
recyclerViewAttr?.let {
this.addItemDecoration(RecyclerSectionItemDecoration(context,
true,
callback,
it))
}


}

}

0 comments on commit edd3df3

Please sign in to comment.