js使用专属的toast,防止显示不全
This commit is contained in:
@@ -41,12 +41,12 @@ import io.legato.kazusa.utils.externalCache
|
|||||||
import io.legato.kazusa.utils.fromJsonObject
|
import io.legato.kazusa.utils.fromJsonObject
|
||||||
import io.legato.kazusa.utils.isAbsUrl
|
import io.legato.kazusa.utils.isAbsUrl
|
||||||
import io.legato.kazusa.utils.isMainThread
|
import io.legato.kazusa.utils.isMainThread
|
||||||
import io.legato.kazusa.utils.longToastOnUi
|
import io.legato.kazusa.utils.longToastForJs
|
||||||
import io.legato.kazusa.utils.mapAsync
|
import io.legato.kazusa.utils.mapAsync
|
||||||
import io.legato.kazusa.utils.stackTraceStr
|
import io.legato.kazusa.utils.stackTraceStr
|
||||||
import io.legato.kazusa.utils.startActivity
|
import io.legato.kazusa.utils.startActivity
|
||||||
import io.legato.kazusa.utils.toStringArray
|
import io.legato.kazusa.utils.toStringArray
|
||||||
import io.legato.kazusa.utils.toastOnUi
|
import io.legato.kazusa.utils.toastForJs
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.flow.asFlow
|
import kotlinx.coroutines.flow.asFlow
|
||||||
import kotlinx.coroutines.flow.flowOn
|
import kotlinx.coroutines.flow.flowOn
|
||||||
@@ -937,7 +937,7 @@ interface JsExtensions : JsEncodeUtils {
|
|||||||
*/
|
*/
|
||||||
fun toast(msg: Any?) {
|
fun toast(msg: Any?) {
|
||||||
rhinoContext.ensureActive()
|
rhinoContext.ensureActive()
|
||||||
appCtx.toastOnUi("${getSource()?.getTag()}: ${msg.toString()}")
|
appCtx.toastForJs("${getSource()?.getTag()}: ${msg.toString()}")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -945,7 +945,7 @@ interface JsExtensions : JsEncodeUtils {
|
|||||||
*/
|
*/
|
||||||
fun longToast(msg: Any?) {
|
fun longToast(msg: Any?) {
|
||||||
rhinoContext.ensureActive()
|
rhinoContext.ensureActive()
|
||||||
appCtx.longToastOnUi("${getSource()?.getTag()}: ${msg.toString()}")
|
appCtx.longToastForJs("${getSource()?.getTag()}: ${msg.toString()}")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,8 +6,11 @@ import android.content.Context
|
|||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import io.legato.kazusa.BuildConfig
|
import io.legato.kazusa.BuildConfig
|
||||||
|
import io.legato.kazusa.databinding.ViewToastBinding
|
||||||
import io.legato.kazusa.help.config.AppConfig
|
import io.legato.kazusa.help.config.AppConfig
|
||||||
|
import splitties.systemservices.layoutInflater
|
||||||
|
|
||||||
|
private var toastForJs: Toast? = null
|
||||||
private var toast: Toast? = null
|
private var toast: Toast? = null
|
||||||
private var toastLegacy: Toast? = null
|
private var toastLegacy: Toast? = null
|
||||||
|
|
||||||
@@ -61,6 +64,43 @@ fun Context.longToastOnUiLegacy(message: CharSequence) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JS 专用弹窗,短时间显示
|
||||||
|
*/
|
||||||
|
|
||||||
|
fun Context.toastForJs(message: CharSequence?, duration: Int = Toast.LENGTH_SHORT) {
|
||||||
|
runOnUI {
|
||||||
|
kotlin.runCatching {
|
||||||
|
toastForJs?.cancel()
|
||||||
|
toastForJs = Toast(this)
|
||||||
|
ViewToastBinding.inflate(layoutInflater).run {
|
||||||
|
toastForJs?.view = root
|
||||||
|
tvText.text = message
|
||||||
|
}
|
||||||
|
toastForJs?.duration = duration
|
||||||
|
toastForJs?.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Context.toastForJs(message: Int, duration: Int = Toast.LENGTH_SHORT) {
|
||||||
|
toastForJs(getString(message), duration)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Context.longToastForJs(message: CharSequence?) {
|
||||||
|
toastForJs(message, Toast.LENGTH_LONG)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Context.longToastForJs(message: Int) {
|
||||||
|
toastForJs(message, Toast.LENGTH_LONG)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fragment 调用代理
|
||||||
|
fun Fragment.toastForJs(message: CharSequence?) = requireContext().toastForJs(message)
|
||||||
|
fun Fragment.toastForJs(message: Int) = requireContext().toastForJs(message)
|
||||||
|
fun Fragment.longToastForJs(message: CharSequence?) = requireContext().longToastForJs(message)
|
||||||
|
fun Fragment.longToastForJs(message: Int) = requireContext().longToastForJs(message)
|
||||||
|
|
||||||
fun Fragment.toastOnUi(message: Int) = requireActivity().toastOnUi(message)
|
fun Fragment.toastOnUi(message: Int) = requireActivity().toastOnUi(message)
|
||||||
|
|
||||||
fun Fragment.toastOnUi(message: CharSequence) = requireActivity().toastOnUi(message)
|
fun Fragment.toastOnUi(message: CharSequence) = requireActivity().toastOnUi(message)
|
||||||
|
|||||||
@@ -25,11 +25,13 @@
|
|||||||
android:id="@+id/flexbox"
|
android:id="@+id/flexbox"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:clipToPadding="false"
|
android:clipToPadding="false"
|
||||||
android:paddingVertical="8dp"
|
android:layout_marginTop="8dp"
|
||||||
|
android:overScrollMode="never"
|
||||||
|
app:dividerDrawable="@drawable/shape_space_divider"
|
||||||
app:flexDirection="row"
|
app:flexDirection="row"
|
||||||
app:flexWrap="wrap" />
|
app:flexWrap="wrap"
|
||||||
|
app:showDivider="middle" />
|
||||||
|
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<androidx.cardview.widget.CardView
|
||||||
|
android:id="@+id/cv_toast"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:cardCornerRadius="12dp"
|
||||||
|
app:cardElevation="2dp"
|
||||||
|
app:cardUseCompatPadding="true">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_text"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:paddingHorizontal="16dp"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
android:paddingBottom="10dp" />
|
||||||
|
|
||||||
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user