|
@@ -2,12 +2,16 @@ package eu.kanade.tachiyomi.widget
|
|
|
|
|
|
import android.content.Context
|
|
|
import android.util.AttributeSet
|
|
|
+import android.view.View
|
|
|
+import android.widget.Button
|
|
|
+import android.widget.LinearLayout
|
|
|
import android.widget.RelativeLayout
|
|
|
import androidx.annotation.StringRes
|
|
|
import eu.kanade.tachiyomi.R
|
|
|
import eu.kanade.tachiyomi.util.view.gone
|
|
|
import eu.kanade.tachiyomi.util.view.visible
|
|
|
import kotlin.random.Random
|
|
|
+import kotlinx.android.synthetic.main.common_view_empty.view.actions_container
|
|
|
import kotlinx.android.synthetic.main.common_view_empty.view.text_face
|
|
|
import kotlinx.android.synthetic.main.common_view_empty.view.text_label
|
|
|
|
|
@@ -29,24 +33,50 @@ class EmptyView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
|
|
|
* Show the information view
|
|
|
* @param textResource text of information view
|
|
|
*/
|
|
|
- fun show(@StringRes textResource: Int) {
|
|
|
+ fun show(@StringRes textResource: Int, actions: List<Action>? = null) {
|
|
|
+ show(context.getString(textResource), actions)
|
|
|
+ }
|
|
|
+
|
|
|
+ fun show(message: String, actions: List<Action>? = null) {
|
|
|
text_face.text = getRandomErrorFace()
|
|
|
- text_label.text = context.getString(textResource)
|
|
|
+ text_label.text = message
|
|
|
+
|
|
|
+ actions_container.removeAllViews()
|
|
|
+ if (!actions.isNullOrEmpty()) {
|
|
|
+ actions.forEach {
|
|
|
+ val button = Button(context).apply {
|
|
|
+ layoutParams = LinearLayout.LayoutParams(
|
|
|
+ LinearLayout.LayoutParams.WRAP_CONTENT,
|
|
|
+ LinearLayout.LayoutParams.WRAP_CONTENT)
|
|
|
+
|
|
|
+ setText(it.resId)
|
|
|
+ setOnClickListener(it.listener)
|
|
|
+ }
|
|
|
+
|
|
|
+ actions_container.addView(button)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
this.visible()
|
|
|
}
|
|
|
|
|
|
companion object {
|
|
|
private val ERROR_FACES = listOf(
|
|
|
- "(・o・;)",
|
|
|
- "Σ(ಠ_ಠ)",
|
|
|
- "ಥ_ಥ",
|
|
|
- "(˘・_・˘)",
|
|
|
- "(; ̄Д ̄)",
|
|
|
- "(・Д・。"
|
|
|
+ "(・o・;)",
|
|
|
+ "Σ(ಠ_ಠ)",
|
|
|
+ "ಥ_ಥ",
|
|
|
+ "(˘・_・˘)",
|
|
|
+ "(; ̄Д ̄)",
|
|
|
+ "(・Д・。"
|
|
|
)
|
|
|
|
|
|
fun getRandomErrorFace(): String {
|
|
|
return ERROR_FACES[Random.nextInt(ERROR_FACES.size)]
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ data class Action(
|
|
|
+ @StringRes val resId: Int,
|
|
|
+ val listener: View.OnClickListener
|
|
|
+ )
|
|
|
}
|