Skip to content

Commit

Permalink
Merge pull request #10 from erkutaras/develop
Browse files Browse the repository at this point in the history
add attributes for state
  • Loading branch information
erkutaras authored Dec 1, 2018
2 parents a9d97c3 + f52fac3 commit 4dd3984
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ allprojects {
**Step 2.** Add the library dependency to your project build.gradle:
```
dependencies {
implementation 'com.github.erkutaras:StateLayout:1.1.1'
implementation 'com.github.erkutaras:StateLayout:1.1.2'
}
```

Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
defaultConfig {
minSdkVersion 17
targetSdkVersion 27
versionCode 12
versionName "1.1.1"
versionCode 13
versionName "1.1.2"

vectorDrawables.useSupportLibrary = true
}
Expand Down
14 changes: 14 additions & 0 deletions library/src/main/java/com/erkutaras/statelayout/StateLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ class StateLayout @JvmOverloads constructor(context: Context,

private var state: State = NONE

init {
context.theme.obtainStyledAttributes(
attrs,
R.styleable.StateLayout,
0, 0).apply {

try {
state = State.values()[getInteger(R.styleable.StateLayout_state, NONE.ordinal)]
} finally {
recycle()
}
}
}

override fun onFinishInflate() {
super.onFinishInflate()
setupContentState()
Expand Down
14 changes: 14 additions & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="StateLayout">
<attr name="state" format="enum">
<enum name="loading" value="0"/>
<enum name="content" value="1"/>
<enum name="info" value="2"/>
<enum name="loading_with_content" value="3"/>
<enum name="error" value="4"/>
<enum name="empty" value="5"/>
<enum name="none" value="6"/>
</attr>
</declare-styleable>
</resources>
3 changes: 2 additions & 1 deletion sample/src/main/res/layout/activity_state_layout_sample.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp">
android:layout_marginTop="8dp"
app:state="content">

<WebView
android:id="@+id/webView"
Expand Down

0 comments on commit 4dd3984

Please sign in to comment.