Skip to content

Latest commit

 

History

History
143 lines (109 loc) · 4.02 KB

File metadata and controls

143 lines (109 loc) · 4.02 KB

Download API Licence

StateLayout

  • built on 2022.1.1 Patch 2 with AndroidX.
  • Please read also issuesreleases.

[ 中文 ]

Screenshot

Characteristics

  • good scalability
  • using the class as the status code
  • fully customizable states
  • support for custom parameters
  • support for animation
  • fully customizable animation
  • support for child view visibility strategy
  • support for AppBarLayout Lift
  • low coupling

Setup

Gradle

On your module's build.gradle file add this implementation statement to the dependencies section:

dependencies {
    implementation "com.chooongg.widget:statelayout:$version"
}

How to use

1. Used in layout XML

adding a state layout to layout xml

<com.chooongg.widget.stateLayout.StateLayout 
    android:id="@+id/stateLayout"
    android:layout_width="match_parent" 
    android:layout_height="match_parent">
    <!-- ChildView -->
    <!-- ChildView -->
    <!-- ChildView -->
</com.chooongg.widget.stateLayout.StateLayout>

ChildView supports configuring the visibilityStrategy attribute, which is used to control the display and hide policies during state switching

<com.chooongg.widget.stateLayout.StateLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent" 
    android:layout_height="match_parent">
        <!-- show when the state is ContentState, default -->
        <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_visibilityStrategy="content"/>
        <!-- show as long as the status is non ContentState -->
        <View
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_visibilityStrategy="other"/>
        <!-- show as long as the ContentState exists -->
        <View
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_visibilityStrategy="otherIgnoreContent"/>
        <!-- always show regardless of any status -->
        <View
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_visibilityStrategy="always"/>
</com.chooongg.widget.stateLayout.StateLayout>

The show method can be used to switch the state of StateLayout

// show ProgressState
stateLayout.show(ProgressState::class)
// show Content
stateLayout.ShowContent()

set the on retry event listener

stateLayout.setOnRetryEventListener { currentState: KClass<out AbstractState> ->
    // do something
}

set the on state changed listener

stateLayout.setOnStateChangedListener { currentState: KClass<out AbstractState> ->
    // do something
}

2. Used in code

// bind Activity
val stateLayout = StateLayout.bind(activity)
// bind Fragment
val stateLayout = StateLayout.bind(fragment)
// bind View
val stateLayout = StateLayout.bind(view)

R8 / ProGuard

If you are using R8 the shrinking and obfuscation rules are included automatically.

ProGuard users must manually add the options from[consumer-rules.pro].

License

Licensed under the Apache License, Version 2.0, click here for the full license.