|
|
@@ -7,12 +7,18 @@ import android.view.ViewGroup
|
|
|
import android.widget.FrameLayout
|
|
|
import io.legado.app.R
|
|
|
import io.legado.app.databinding.ViewLoadMoreBinding
|
|
|
+import io.legado.app.lib.dialogs.alert
|
|
|
import io.legado.app.utils.invisible
|
|
|
import io.legado.app.utils.visible
|
|
|
|
|
|
@Suppress("unused")
|
|
|
class LoadMoreView(context: Context, attrs: AttributeSet? = null) : FrameLayout(context, attrs) {
|
|
|
private val binding = ViewLoadMoreBinding.inflate(LayoutInflater.from(context), this)
|
|
|
+ private var errorMsg = ""
|
|
|
+
|
|
|
+ var isLoading = false
|
|
|
+ private set
|
|
|
+
|
|
|
var hasMore = true
|
|
|
private set
|
|
|
|
|
|
@@ -22,23 +28,26 @@ class LoadMoreView(context: Context, attrs: AttributeSet? = null) : FrameLayout(
|
|
|
}
|
|
|
|
|
|
fun startLoad() {
|
|
|
+ isLoading = true
|
|
|
binding.tvText.invisible()
|
|
|
binding.rotateLoading.show()
|
|
|
}
|
|
|
|
|
|
fun stopLoad() {
|
|
|
+ isLoading = false
|
|
|
binding.rotateLoading.hide()
|
|
|
}
|
|
|
|
|
|
fun hasMore() {
|
|
|
+ errorMsg = ""
|
|
|
hasMore = true
|
|
|
- binding.tvText.invisible()
|
|
|
- binding.rotateLoading.show()
|
|
|
+ startLoad()
|
|
|
}
|
|
|
|
|
|
fun noMore(msg: String? = null) {
|
|
|
+ stopLoad()
|
|
|
+ errorMsg = ""
|
|
|
hasMore = false
|
|
|
- binding.rotateLoading.hide()
|
|
|
if (msg != null) {
|
|
|
binding.tvText.text = msg
|
|
|
} else {
|
|
|
@@ -48,10 +57,21 @@ class LoadMoreView(context: Context, attrs: AttributeSet? = null) : FrameLayout(
|
|
|
}
|
|
|
|
|
|
fun error(msg: String) {
|
|
|
+ stopLoad()
|
|
|
hasMore = false
|
|
|
- binding.rotateLoading.hide()
|
|
|
- binding.tvText.text = msg
|
|
|
+ errorMsg = msg
|
|
|
+ binding.tvText.text = context.getString(R.string.error_load_msg, "点击查看详情")
|
|
|
binding.tvText.visible()
|
|
|
}
|
|
|
|
|
|
+ fun showErrorDialog(): Boolean {
|
|
|
+ if (errorMsg.isBlank()) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ context.alert(R.string.error) {
|
|
|
+ setMessage(errorMsg)
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
}
|