Prefer SnackBars
This commit is contained in:
@@ -16,11 +16,8 @@ import android.support.v7.widget.RecyclerView
|
||||
import android.view.WindowManager
|
||||
import android.widget.EditText
|
||||
import android.widget.Toast
|
||||
import be.mygod.vpnhotspot.App
|
||||
import be.mygod.vpnhotspot.*
|
||||
import be.mygod.vpnhotspot.App.Companion.app
|
||||
import be.mygod.vpnhotspot.BR
|
||||
import be.mygod.vpnhotspot.R
|
||||
import be.mygod.vpnhotspot.RepeaterService
|
||||
import be.mygod.vpnhotspot.databinding.ListitemRepeaterBinding
|
||||
import be.mygod.vpnhotspot.net.wifi.P2pSupplicantConfiguration
|
||||
import be.mygod.vpnhotspot.net.wifi.WifiP2pDialog
|
||||
@@ -104,21 +101,23 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
||||
val binder = binder
|
||||
val group = binder?.service?.group
|
||||
val ssid = group?.networkName
|
||||
val context = parent.requireContext()
|
||||
val mainActivity = parent.activity as MainActivity
|
||||
if (ssid != null) {
|
||||
val wifi = WifiConfiguration()
|
||||
val conf = P2pSupplicantConfiguration()
|
||||
wifi.SSID = ssid
|
||||
wifi.preSharedKey = group.passphrase
|
||||
if (wifi.preSharedKey == null) wifi.preSharedKey = conf.readPsk()
|
||||
if (wifi.preSharedKey == null) {
|
||||
wifi.preSharedKey = conf.readPsk { mainActivity.snackbar(it.message.toString()).show() }
|
||||
}
|
||||
if (wifi.preSharedKey != null) {
|
||||
var dialog: WifiP2pDialog? = null
|
||||
dialog = WifiP2pDialog(context, DialogInterface.OnClickListener { _, which ->
|
||||
dialog = WifiP2pDialog(mainActivity, DialogInterface.OnClickListener { _, which ->
|
||||
when (which) {
|
||||
DialogInterface.BUTTON_POSITIVE -> when (conf.update(dialog!!.config!!)) {
|
||||
true -> App.app.handler.postDelayed(binder::requestGroupUpdate, 1000)
|
||||
false -> Toast.makeText(context, R.string.noisy_su_failure, Toast.LENGTH_SHORT).show()
|
||||
null -> Toast.makeText(context, R.string.root_unavailable, Toast.LENGTH_SHORT).show()
|
||||
true -> app.handler.postDelayed(binder::requestGroupUpdate, 1000)
|
||||
false -> mainActivity.snackbar().setText(R.string.noisy_su_failure).show()
|
||||
null -> mainActivity.snackbar().setText(R.string.root_unavailable).show()
|
||||
}
|
||||
DialogInterface.BUTTON_NEUTRAL -> binder.resetCredentials()
|
||||
}
|
||||
@@ -127,7 +126,7 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
||||
return
|
||||
}
|
||||
}
|
||||
Toast.makeText(context, R.string.repeater_configure_failure, Toast.LENGTH_LONG).show()
|
||||
mainActivity.snackbar().setText(R.string.repeater_configure_failure).show()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ import android.provider.Settings
|
||||
import android.support.annotation.RequiresApi
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import be.mygod.vpnhotspot.App.Companion.app
|
||||
import be.mygod.vpnhotspot.MainActivity
|
||||
import be.mygod.vpnhotspot.R
|
||||
import be.mygod.vpnhotspot.databinding.ListitemInterfaceBinding
|
||||
import be.mygod.vpnhotspot.net.TetherType
|
||||
@@ -43,10 +43,10 @@ abstract class TetherManager private constructor(protected val parent: Tethering
|
||||
|
||||
override fun onClick(v: View?) {
|
||||
val manager = manager!!
|
||||
val context = manager.parent.requireContext()
|
||||
if (Build.VERSION.SDK_INT >= 23 && !Settings.System.canWrite(context)) try {
|
||||
val mainActivity = manager.parent.activity as MainActivity
|
||||
if (Build.VERSION.SDK_INT >= 23 && !Settings.System.canWrite(mainActivity)) try {
|
||||
manager.parent.startActivity(Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS,
|
||||
Uri.parse("package:${context.packageName}")))
|
||||
Uri.parse("package:${mainActivity.packageName}")))
|
||||
return
|
||||
} catch (exc: ActivityNotFoundException) {
|
||||
exc.printStackTrace()
|
||||
@@ -62,7 +62,7 @@ abstract class TetherManager private constructor(protected val parent: Tethering
|
||||
while (cause != null) {
|
||||
cause = cause.cause
|
||||
if (cause != null && cause !is InvocationTargetException) {
|
||||
Toast.makeText(context, cause.message, Toast.LENGTH_LONG).show()
|
||||
mainActivity.snackbar(cause.message.toString()).show()
|
||||
ManageBar.start(itemView.context)
|
||||
break
|
||||
}
|
||||
@@ -90,11 +90,8 @@ abstract class TetherManager private constructor(protected val parent: Tethering
|
||||
protected abstract fun stop()
|
||||
|
||||
override fun onTetheringStarted() = data.notifyChange()
|
||||
override fun onTetheringFailed() {
|
||||
app.handler.post {
|
||||
Toast.makeText(parent.requireContext(), R.string.tethering_manage_failed, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
override fun onTetheringFailed() =
|
||||
(parent.activity as MainActivity).snackbar().setText(R.string.tethering_manage_failed).show()
|
||||
|
||||
override fun bindTo(viewHolder: RecyclerView.ViewHolder) {
|
||||
(viewHolder as ViewHolder).manager = this
|
||||
|
||||
Reference in New Issue
Block a user