Skip to content

Commit

Permalink
Merge pull request #18 from erkutaras/develop
Browse files Browse the repository at this point in the history
add loading message
  • Loading branch information
erkutaras authored Jan 6, 2019
2 parents a1fd3d5 + b84891f commit a48e51a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 41 deletions.
4 changes: 2 additions & 2 deletions 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.2.1'
implementation 'com.github.erkutaras:StateLayout:1.2.2'
}
```

Expand All @@ -41,7 +41,7 @@ _If you don't migrate your project with AndroidX yet, you may need to exclude an

```
dependencies {
implementation ('com.github.erkutaras:StateLayout:1.2.1') {
implementation ('com.github.erkutaras:StateLayout:1.2.2') {
exclude group: 'androidx.appcompat'
}
}
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 14
targetSdkVersion 28
versionCode 16
versionName "1.2.1"
versionCode 17
versionName "1.2.2"

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

fun loadingMessage(message: String): StateLayout {
loadingLayout?.findViewById<TextView>(R.id.textView_state_layout_loading_message)?.let {
it.text = message
it.visibility = View.VISIBLE
}
return loading()
}

fun loading(): StateLayout {
state = LOADING
loadingLayout?.visibility = View.VISIBLE
Expand All @@ -132,6 +140,13 @@ class StateLayout @JvmOverloads constructor(context: Context,
return this
}

fun loading(@LayoutRes layoutId: Int) {
this.loadingLayoutRes = layoutId
removeView(loadingLayout)
setupLoadingState()
showState(provideLoadingStateInfo())
}

fun content(): StateLayout {
state = CONTENT
loadingLayout?.visibility = View.GONE
Expand Down Expand Up @@ -205,6 +220,13 @@ class StateLayout @JvmOverloads constructor(context: Context,
return this
}

fun info(@LayoutRes layoutId: Int) {
this.infoLayoutRes = layoutId
removeView(infoLayout)
setupInfoState()
showState(provideInfoStateInfo())
}

fun loadingWithContent(): StateLayout {
state = LOADING_WITH_CONTENT
loadingLayout?.visibility = View.GONE
Expand All @@ -214,19 +236,11 @@ class StateLayout @JvmOverloads constructor(context: Context,
return this
}

fun showState(stateInfo: StateInfo?) {
when (stateInfo?.state) {
LOADING -> loading()
CONTENT -> content()
LOADING_WITH_CONTENT -> loadingWithContent()
INFO, ERROR, EMPTY -> {
stateInfo.infoImage?.let { infoImage(it) }
stateInfo.infoTitle?.let { infoTitle(it) }
stateInfo.infoMessage?.let { infoMessage(it) }
stateInfo.infoButtonText?.let { infoButtonText(it) }
}
null, NONE -> hideAll()
}
fun loadingWithContent(@LayoutRes layoutId: Int) {
this.loadingWithContentLayoutRes = layoutId
removeView(loadingWithContentLayout)
setupLoadingWithContentState()
showState(provideLoadingWithContentStateInfo())
}

fun showLoading(stateInfo: StateInfo?) {
Expand All @@ -245,25 +259,19 @@ class StateLayout @JvmOverloads constructor(context: Context,
showState(stateInfo)
}

fun loading(@LayoutRes layoutId: Int) {
this.loadingLayoutRes = layoutId
removeView(loadingLayout)
setupLoadingState()
showState(provideLoadingStateInfo())
}

fun info(@LayoutRes layoutId: Int) {
this.infoLayoutRes = layoutId
removeView(infoLayout)
setupInfoState()
showState(provideInfoStateInfo())
}

fun loadingWithContent(@LayoutRes layoutId: Int) {
this.loadingWithContentLayoutRes = layoutId
removeView(loadingWithContentLayout)
setupLoadingWithContentState()
showState(provideLoadingWithContentStateInfo())
fun showState(stateInfo: StateInfo?) {
when (stateInfo?.state) {
LOADING -> loading()
CONTENT -> content()
LOADING_WITH_CONTENT -> loadingWithContent()
INFO, ERROR, EMPTY -> {
stateInfo.infoImage?.let { infoImage(it) }
stateInfo.infoTitle?.let { infoTitle(it) }
stateInfo.infoMessage?.let { infoMessage(it) }
stateInfo.infoButtonText?.let { infoButtonText(it) }
}
null, NONE -> hideAll()
}
}

companion object {
Expand Down
22 changes: 18 additions & 4 deletions library/src/main/res/layout/layout_state_loading.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:colorBackground">
android:background="?android:colorBackground"
android:gravity="center"
android:orientation="vertical">

<TextView
android:id="@+id/textView_state_layout_loading_message"
style="@android:style/TextAppearance.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:gravity="center_horizontal"
android:textStyle="normal"
android:visibility="gone"
tools:text="Loading..."
tools:visibility="visible"/>

<ProgressBar
android:id="@+id/progressBar_state_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:tint="?colorAccent"/>

</RelativeLayout>
</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class StateLayoutSampleActivity : AppCompatActivity(), StateLayout.OnStateLayout
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
hasError = false
if (url.equals(WEB_URL)) stateLayout.loading()
if (url.equals(WEB_URL)) stateLayout.loadingMessage("Loading...")
else stateLayout.loadingWithContent()
}

Expand Down

0 comments on commit a48e51a

Please sign in to comment.