Refine error messages in general

This commit is contained in:
Mygod
2019-02-23 23:00:14 +08:00
parent 664913a2ff
commit 317e2121c2
4 changed files with 13 additions and 8 deletions

View File

@@ -9,6 +9,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.util.readableMessage
import com.google.android.material.snackbar.Snackbar
import com.topjohnwu.superuser.NoShellException
@@ -18,17 +19,17 @@ sealed class SmartSnackbar {
private var holder: View? = null
fun make(@StringRes text: Int): SmartSnackbar = make(app.getText(text))
fun make(text: CharSequence? = ""): SmartSnackbar {
fun make(text: CharSequence = ""): SmartSnackbar {
val holder = holder
return if (holder == null) @SuppressLint("ShowToast") {
if (Looper.myLooper() == null) Looper.prepare()
ToastWrapper(Toast.makeText(app, text, Toast.LENGTH_LONG))
} else SnackbarWrapper(Snackbar.make(holder, text ?: null.toString(), Snackbar.LENGTH_LONG))
} else SnackbarWrapper(Snackbar.make(holder, text, Snackbar.LENGTH_LONG))
}
fun make(e: Throwable) = make(when (e) {
is NoShellException -> e.cause ?: e
else -> e
}.localizedMessage)
}.readableMessage)
}
class Register(lifecycle: Lifecycle, private val view: View) : LifecycleObserver {