Skip to content

Commit

Permalink
Merge pull request #3 from daniel-stoneuk/master
Browse files Browse the repository at this point in the history
Add paddingStartItem and previousItemCharacters attributes
  • Loading branch information
adrielcafe authored Mar 28, 2020
2 parents 7f7b071 + 12e44fb commit f8bab45
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 420 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
/.idea
.externalNativeBuild
.DS_Store
.gradle
.gradle
*.iml
19 changes: 0 additions & 19 deletions KrumbsView.iml

This file was deleted.

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ dependencies {
<cafe.adriel.krumbsview.KrumbsView
...
app:krumbsStartItem="[string]"
app:krumbsPaddingStartItem="[dimension]"
app:krumbsPreviousItemCharacters="[integer]"
app:krumbsTypeface="[string|font]"
app:krumbsTextSize="[dimension]"
app:krumbsBoldText="[true|false]"
Expand Down Expand Up @@ -100,6 +102,8 @@ with(krumbsView){
setTextSizeSp(20f)
setTextSizePx(40f)
setBoldText(true)
setPaddingStartItem(10f)
setPreviousItemCharacters(2)
setCurrentItemTextColor(Color.WHITE)
setPreviousItemTextColor(color(R.color.transparent_white))
setSeparatorTintColor(color(R.color.transparent_white))
Expand All @@ -110,6 +114,7 @@ with(krumbsView){
```

You can also use your custom Krumb implementation:

```kotlin
data class MyKrumb(val id: Int,
val folderName: String,
Expand Down
200 changes: 0 additions & 200 deletions app/app.iml

This file was deleted.

7 changes: 5 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
android:id="@+id/vDefaultBreadcrumbs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/gray"
android:paddingTop="50dp"
android:paddingBottom="50dp"
android:background="@color/gray"
app:krumbsStartItem="Home"/>
app:krumbsPaddingStartItem="16dp"
app:krumbsStartItem="Home" />

<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
Expand All @@ -39,6 +40,8 @@
app:krumbsSeparatorTintColor="@color/colorPrimaryDark"
app:krumbsSeparatorIcon="@drawable/ic_play_arrow"
app:krumbsAnimationType="growShrink"
app:krumbsPreviousItemCharacters="2"
app:krumbsPaddingStartItem="8dp"
app:krumbsAnimationDuration="longDuration"/>

<androidx.appcompat.widget.AppCompatTextView
Expand Down
185 changes: 0 additions & 185 deletions library/library.iml

This file was deleted.

38 changes: 34 additions & 4 deletions library/src/main/java/cafe/adriel/krumbsview/KrumbsView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ open class KrumbsView(context: Context, attrs: AttributeSet? = null) : LinearLay
}

protected val items = ArrayDeque<Krumb>()

protected var _paddingStartItem: Int = 0
var paddingStartItem: Int
get () {
return _paddingStartItem
}
set (padding) {
_paddingStartItem = padding
updateState()
}

protected var _previousItemCharacters: Int = 3
var previousItemCharacters: Int
get () {
return _previousItemCharacters
}
set (previousItemCharacters) {
_previousItemCharacters = previousItemCharacters
updateState()
}

protected var listener: (() -> Unit)? = null

val size: Int
Expand All @@ -49,6 +70,8 @@ open class KrumbsView(context: Context, attrs: AttributeSet? = null) : LinearLay
init {
val styleAttrs = context.theme.obtainStyledAttributes(attrs, R.styleable.KrumbsView, 0, 0)
val startItem = styleAttrs.getString(R.styleable.KrumbsView_krumbsStartItem)
_paddingStartItem = styleAttrs.getDimensionPixelSize(R.styleable.KrumbsView_krumbsPaddingStartItem, 0)
_previousItemCharacters = styleAttrs.getInt(R.styleable.KrumbsView_krumbsPreviousItemCharacters, 3)
val typefaceStr = styleAttrs.getString(R.styleable.KrumbsView_krumbsTypeface)
val typefaceResId = styleAttrs.getResourceId(R.styleable.KrumbsView_krumbsTypeface, -1)
val textSize = styleAttrs.getDimension(R.styleable.KrumbsView_krumbsTextSize, -1f)
Expand Down Expand Up @@ -153,7 +176,9 @@ open class KrumbsView(context: Context, attrs: AttributeSet? = null) : LinearLay
protected fun updateState(){
if(items.isEmpty()) {
vBreadcrumbCurrentItemSwitcher.setCurrentText("")

with (vBreadcrumbCurrentItemSwitcher) {
setPadding(_paddingStartItem, paddingTop, paddingRight, paddingBottom)
}
vBreadcrumbPreviousItemSwitcher.setCurrentText("")
vBreadcrumbPreviousItemSwitcher.visibility = View.GONE

Expand All @@ -162,14 +187,19 @@ open class KrumbsView(context: Context, attrs: AttributeSet? = null) : LinearLay
val currentItem = items.peek()
if (items.size > 1) {
vBreadcrumbCurrentItemSwitcher.setText(currentItem?.title)

with (vBreadcrumbCurrentItemSwitcher) {
setPadding(0, paddingTop, paddingRight, paddingBottom)
}
val previousItem = items.elementAt(1)
vBreadcrumbPreviousItemSwitcher.setText(previousItem.title.takeLast(3))
vBreadcrumbPreviousItemSwitcher.setText(previousItem.title.takeLast(_previousItemCharacters))
vBreadcrumbPreviousItemSwitcher.visibility = View.VISIBLE

vBreadcrumbSeparator.visibility = View.VISIBLE
} else {
vBreadcrumbCurrentItemSwitcher.setCurrentText(currentItem?.title)
with (vBreadcrumbCurrentItemSwitcher) {
setPadding(_paddingStartItem, paddingTop, paddingRight, paddingBottom)
}

vBreadcrumbPreviousItemSwitcher.setCurrentText("")
vBreadcrumbPreviousItemSwitcher.visibility = View.GONE
Expand Down Expand Up @@ -371,4 +401,4 @@ open class KrumbsView(context: Context, attrs: AttributeSet? = null) : LinearLay
outAnimation?.duration = duration.duration
}
}
}
}
18 changes: 11 additions & 7 deletions library/src/main/res/layout/view_krumbs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="0dp"
Expand All @@ -15,22 +15,26 @@
<TextSwitcher
android:id="@+id/vBreadcrumbPreviousItemSwitcher"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:minWidth="50dp"
android:visibility="gone"/>

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/vBreadcrumbSeparator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:visibility="gone"
app:tint="?colorControlHighlight"
app:srcCompat="@drawable/krumbs_ic_arrow_right"/>
android:paddingLeft="4dp"
android:paddingStart="4dp"
android:paddingRight="4dp"
android:paddingEnd="4dp"
app:srcCompat="@drawable/krumbs_ic_arrow_right"
app:tint="?colorControlHighlight" />

<TextSwitcher
android:id="@+id/vBreadcrumbCurrentItemSwitcher"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
android:layout_height="wrap_content"/>

</androidx.appcompat.widget.LinearLayoutCompat>
2 changes: 2 additions & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<attr name="krumbsStartItem" format="string"/>
<attr name="krumbsTypeface" format="string|reference"/>
<attr name="krumbsTextSize" format="dimension"/>
<attr name="krumbsPaddingStartItem" format="dimension"/>
<attr name="krumbsPreviousItemCharacters" format="integer"/>
<attr name="krumbsBoldText" format="boolean"/>
<attr name="krumbsCurrentItemTextColor" format="color"/>
<attr name="krumbsPreviousItemTextColor" format="color"/>
Expand Down
2 changes: 0 additions & 2 deletions library/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

<style name="KrumbsStyle.CurrentItem">
<item name="android:background">@null</item>
<item name="android:paddingLeft">15dp</item>
<item name="android:paddingStart">15dp</item>
<item name="android:textColor">?android:textColorPrimary</item>
</style>

Expand Down

0 comments on commit f8bab45

Please sign in to comment.