1414 * limitations under the License.
1515 */
1616
17- @file:Suppress(" unused" )
18-
1917package com.dylanc.loadingstateview
2018
2119import android.app.Activity
@@ -45,7 +43,7 @@ class LoadingStateView @JvmOverloads constructor(
4543 private val viewCashes: HashMap <Any , View > = HashMap ()
4644
4745 /* *
48- * Constructs a LoadingStateView with an activity
46+ * Constructs a LoadingStateView with an activity and listener.
4947 */
5048 @JvmOverloads
5149 constructor (activity: Activity , listener: OnReloadListener ? = null ) :
@@ -63,11 +61,7 @@ class LoadingStateView @JvmOverloads constructor(
6361 *
6462 * @param delegates the view delegates of creating view
6563 */
66- fun setHeaders (vararg delegates : ViewDelegate ) =
67- setDecorView(LinearDecorViewDelegate (delegates.map {
68- register(it)
69- getView(it.viewType)
70- }))
64+ fun setHeaders (vararg delegates : ViewDelegate ) = setDecorView(LinearDecorViewDelegate (* delegates))
7165
7266 /* *
7367 * Sets an view delegate for decorating content view.
@@ -98,11 +92,7 @@ class LoadingStateView @JvmOverloads constructor(
9892 *
9993 * @param delegates the view delegates of creating view
10094 */
101- fun addChildHeaders (vararg delegates : ViewDelegate ) =
102- addChildDecorView(LinearDecorViewDelegate (delegates.map {
103- register(it)
104- getView(it.viewType)
105- }))
95+ fun addChildHeaders (vararg delegates : ViewDelegate ) = addChildDecorView(LinearDecorViewDelegate (* delegates))
10696
10797 /* *
10898 * Adds child decorative view between the content and the decorative view.
@@ -128,9 +118,7 @@ class LoadingStateView @JvmOverloads constructor(
128118 *
129119 * @param delegates the view delegate of creating view
130120 */
131- fun register (vararg delegates : ViewDelegate ) {
132- delegates.forEach { viewDelegates[it.viewType] = it }
133- }
121+ fun register (vararg delegates : ViewDelegate ) = delegates.forEach { viewDelegates[it.viewType] = it }
134122
135123 @JvmOverloads
136124 fun showLoadingView (animation : Animation ? = null) = showView(ViewType .LOADING , animation)
@@ -215,9 +203,14 @@ class LoadingStateView @JvmOverloads constructor(
215203 abstract fun getContentParent (decorView : View ): ViewGroup
216204 }
217205
218- private class LinearDecorViewDelegate (private val views : List <View >) : DecorViewDelegate() {
206+ private inner class LinearDecorViewDelegate (private val views : List <View >) : DecorViewDelegate() {
219207 private lateinit var contentParent: FrameLayout
220208
209+ constructor (vararg delegates: ViewDelegate ) : this (delegates.map {
210+ register(it)
211+ getView(it.viewType)
212+ })
213+
221214 override fun onCreateDecorView (inflater : LayoutInflater ) =
222215 LinearLayout (inflater.context).apply {
223216 orientation = LinearLayout .VERTICAL
0 commit comments