package com.example.basecore.widget
|
|
import android.content.Context
|
import android.provider.ContactsContract.CommonDataKinds
|
import android.util.AttributeSet
|
import android.view.LayoutInflater
|
import android.view.View
|
import android.widget.FrameLayout
|
import android.widget.LinearLayout
|
import android.widget.TextView
|
import androidx.annotation.DrawableRes
|
import com.example.basecore.R
|
|
|
class LoadingLayout @JvmOverloads constructor(
|
context: Context,
|
attrs: AttributeSet? = null,
|
defStyleAttr: Int = 0,
|
) : FrameLayout(context, attrs, defStyleAttr) {
|
|
|
private val mErrorLayout: View
|
private val mEmptyLayout: View
|
private val mLoadingLayout: LinearLayout
|
private val retryBtn: TextView
|
|
private var loadEvent: LoadEvent? = null
|
|
init {
|
|
LayoutInflater.from(context).inflate(R.layout.common_layout_loading, this)
|
|
mErrorLayout = findViewById(R.id.error_layout)
|
mEmptyLayout = findViewById(R.id.empty_layout)
|
mLoadingLayout = findViewById(R.id.loading_container)
|
|
retryBtn = findViewById(R.id.retry_button)
|
|
retryBtn.setOnClickListener {
|
loadEvent?.onRetryLoad()
|
}
|
|
mEmptyLayout.setOnClickListener {
|
loadEvent?.onRetryLoad()
|
}
|
}
|
|
|
fun loadError() {
|
mEmptyLayout.visibility = GONE
|
mErrorLayout.visibility = VISIBLE
|
mLoadingLayout.visibility = GONE
|
visibility = VISIBLE
|
}
|
|
fun loadingData() {
|
mEmptyLayout.visibility = GONE
|
mErrorLayout.visibility = GONE
|
mLoadingLayout.visibility = VISIBLE
|
visibility = VISIBLE
|
}
|
|
|
fun loadEmpty() {
|
mEmptyLayout.visibility = VISIBLE
|
mErrorLayout.visibility = GONE
|
mLoadingLayout.visibility = GONE
|
visibility = VISIBLE
|
}
|
|
fun loadNull() {
|
mEmptyLayout.visibility = GONE
|
mErrorLayout.visibility = GONE
|
mLoadingLayout.visibility = GONE
|
visibility = GONE
|
|
}
|
|
|
|
fun bindEvent(event: LoadEvent) {
|
this.loadEvent = event
|
}
|
|
interface LoadEvent {
|
|
fun onRetryLoad()
|
}
|
}
|