Prefer SnackBars
This commit is contained in:
@@ -10,6 +10,7 @@ import android.os.IBinder
|
|||||||
import android.support.customtabs.CustomTabsIntent
|
import android.support.customtabs.CustomTabsIntent
|
||||||
import android.support.design.internal.BottomNavigationMenuView
|
import android.support.design.internal.BottomNavigationMenuView
|
||||||
import android.support.design.widget.BottomNavigationView
|
import android.support.design.widget.BottomNavigationView
|
||||||
|
import android.support.design.widget.Snackbar
|
||||||
import android.support.v4.app.Fragment
|
import android.support.v4.app.Fragment
|
||||||
import android.support.v4.content.ContextCompat
|
import android.support.v4.content.ContextCompat
|
||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
@@ -32,6 +33,7 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
|
|||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
fun launchUrl(url: Uri) = customTabsIntent.launchUrl(this, url)
|
fun launchUrl(url: Uri) = customTabsIntent.launchUrl(this, url)
|
||||||
|
fun snackbar(text: CharSequence = "") = Snackbar.make(binding.fragmentHolder, text, Snackbar.LENGTH_LONG)
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import android.os.Build
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v4.content.FileProvider
|
import android.support.v4.content.FileProvider
|
||||||
import android.support.v7.preference.Preference
|
import android.support.v7.preference.Preference
|
||||||
import android.widget.Toast
|
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
import be.mygod.vpnhotspot.net.Routing
|
import be.mygod.vpnhotspot.net.Routing
|
||||||
import be.mygod.vpnhotspot.net.UpstreamMonitor
|
import be.mygod.vpnhotspot.net.UpstreamMonitor
|
||||||
@@ -27,10 +26,10 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
|
|||||||
override fun onCreatePreferencesFix(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferencesFix(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
preferenceManager.preferenceDataStore = SharedPreferenceDataStore(app.pref)
|
preferenceManager.preferenceDataStore = SharedPreferenceDataStore(app.pref)
|
||||||
addPreferencesFromResource(R.xml.pref_settings)
|
addPreferencesFromResource(R.xml.pref_settings)
|
||||||
|
val mainActivity = activity as MainActivity
|
||||||
findPreference("service.clean").setOnPreferenceClickListener {
|
findPreference("service.clean").setOnPreferenceClickListener {
|
||||||
if (Routing.clean() == null) {
|
if (Routing.clean() == null) mainActivity.snackbar().setText(R.string.root_unavailable).show()
|
||||||
Toast.makeText(requireContext(), R.string.root_unavailable, Toast.LENGTH_SHORT).show()
|
else app.cleanRoutings()
|
||||||
} else app.cleanRoutings()
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
findPreference("misc.logcat").setOnPreferenceClickListener {
|
findPreference("misc.logcat").setOnPreferenceClickListener {
|
||||||
@@ -90,7 +89,7 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
findPreference("misc.source").setOnPreferenceClickListener {
|
findPreference("misc.source").setOnPreferenceClickListener {
|
||||||
(activity as MainActivity).launchUrl(Uri.parse("https://github.com/Mygod/VPNHotspot"))
|
mainActivity.launchUrl(Uri.parse("https://github.com/Mygod/VPNHotspot"))
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
findPreference("misc.donate").setOnPreferenceClickListener {
|
findPreference("misc.donate").setOnPreferenceClickListener {
|
||||||
|
|||||||
@@ -16,11 +16,8 @@ import android.support.v7.widget.RecyclerView
|
|||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import be.mygod.vpnhotspot.App
|
import be.mygod.vpnhotspot.*
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
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.databinding.ListitemRepeaterBinding
|
||||||
import be.mygod.vpnhotspot.net.wifi.P2pSupplicantConfiguration
|
import be.mygod.vpnhotspot.net.wifi.P2pSupplicantConfiguration
|
||||||
import be.mygod.vpnhotspot.net.wifi.WifiP2pDialog
|
import be.mygod.vpnhotspot.net.wifi.WifiP2pDialog
|
||||||
@@ -104,21 +101,23 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
|||||||
val binder = binder
|
val binder = binder
|
||||||
val group = binder?.service?.group
|
val group = binder?.service?.group
|
||||||
val ssid = group?.networkName
|
val ssid = group?.networkName
|
||||||
val context = parent.requireContext()
|
val mainActivity = parent.activity as MainActivity
|
||||||
if (ssid != null) {
|
if (ssid != null) {
|
||||||
val wifi = WifiConfiguration()
|
val wifi = WifiConfiguration()
|
||||||
val conf = P2pSupplicantConfiguration()
|
val conf = P2pSupplicantConfiguration()
|
||||||
wifi.SSID = ssid
|
wifi.SSID = ssid
|
||||||
wifi.preSharedKey = group.passphrase
|
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) {
|
if (wifi.preSharedKey != null) {
|
||||||
var dialog: WifiP2pDialog? = null
|
var dialog: WifiP2pDialog? = null
|
||||||
dialog = WifiP2pDialog(context, DialogInterface.OnClickListener { _, which ->
|
dialog = WifiP2pDialog(mainActivity, DialogInterface.OnClickListener { _, which ->
|
||||||
when (which) {
|
when (which) {
|
||||||
DialogInterface.BUTTON_POSITIVE -> when (conf.update(dialog!!.config!!)) {
|
DialogInterface.BUTTON_POSITIVE -> when (conf.update(dialog!!.config!!)) {
|
||||||
true -> App.app.handler.postDelayed(binder::requestGroupUpdate, 1000)
|
true -> app.handler.postDelayed(binder::requestGroupUpdate, 1000)
|
||||||
false -> Toast.makeText(context, R.string.noisy_su_failure, Toast.LENGTH_SHORT).show()
|
false -> mainActivity.snackbar().setText(R.string.noisy_su_failure).show()
|
||||||
null -> Toast.makeText(context, R.string.root_unavailable, Toast.LENGTH_SHORT).show()
|
null -> mainActivity.snackbar().setText(R.string.root_unavailable).show()
|
||||||
}
|
}
|
||||||
DialogInterface.BUTTON_NEUTRAL -> binder.resetCredentials()
|
DialogInterface.BUTTON_NEUTRAL -> binder.resetCredentials()
|
||||||
}
|
}
|
||||||
@@ -127,7 +126,7 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
|||||||
return
|
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.annotation.RequiresApi
|
||||||
import android.support.v7.widget.RecyclerView
|
import android.support.v7.widget.RecyclerView
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.Toast
|
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
|
import be.mygod.vpnhotspot.MainActivity
|
||||||
import be.mygod.vpnhotspot.R
|
import be.mygod.vpnhotspot.R
|
||||||
import be.mygod.vpnhotspot.databinding.ListitemInterfaceBinding
|
import be.mygod.vpnhotspot.databinding.ListitemInterfaceBinding
|
||||||
import be.mygod.vpnhotspot.net.TetherType
|
import be.mygod.vpnhotspot.net.TetherType
|
||||||
@@ -43,10 +43,10 @@ abstract class TetherManager private constructor(protected val parent: Tethering
|
|||||||
|
|
||||||
override fun onClick(v: View?) {
|
override fun onClick(v: View?) {
|
||||||
val manager = manager!!
|
val manager = manager!!
|
||||||
val context = manager.parent.requireContext()
|
val mainActivity = manager.parent.activity as MainActivity
|
||||||
if (Build.VERSION.SDK_INT >= 23 && !Settings.System.canWrite(context)) try {
|
if (Build.VERSION.SDK_INT >= 23 && !Settings.System.canWrite(mainActivity)) try {
|
||||||
manager.parent.startActivity(Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS,
|
manager.parent.startActivity(Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS,
|
||||||
Uri.parse("package:${context.packageName}")))
|
Uri.parse("package:${mainActivity.packageName}")))
|
||||||
return
|
return
|
||||||
} catch (exc: ActivityNotFoundException) {
|
} catch (exc: ActivityNotFoundException) {
|
||||||
exc.printStackTrace()
|
exc.printStackTrace()
|
||||||
@@ -62,7 +62,7 @@ abstract class TetherManager private constructor(protected val parent: Tethering
|
|||||||
while (cause != null) {
|
while (cause != null) {
|
||||||
cause = cause.cause
|
cause = cause.cause
|
||||||
if (cause != null && cause !is InvocationTargetException) {
|
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)
|
ManageBar.start(itemView.context)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -90,11 +90,8 @@ abstract class TetherManager private constructor(protected val parent: Tethering
|
|||||||
protected abstract fun stop()
|
protected abstract fun stop()
|
||||||
|
|
||||||
override fun onTetheringStarted() = data.notifyChange()
|
override fun onTetheringStarted() = data.notifyChange()
|
||||||
override fun onTetheringFailed() {
|
override fun onTetheringFailed() =
|
||||||
app.handler.post {
|
(parent.activity as MainActivity).snackbar().setText(R.string.tethering_manage_failed).show()
|
||||||
Toast.makeText(parent.requireContext(), R.string.tethering_manage_failed, Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun bindTo(viewHolder: RecyclerView.ViewHolder) {
|
override fun bindTo(viewHolder: RecyclerView.ViewHolder) {
|
||||||
(viewHolder as ViewHolder).manager = this
|
(viewHolder as ViewHolder).manager = this
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package be.mygod.vpnhotspot.net.wifi
|
|||||||
import android.net.wifi.WifiConfiguration
|
import android.net.wifi.WifiConfiguration
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.Toast
|
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
import be.mygod.vpnhotspot.util.loggerSu
|
import be.mygod.vpnhotspot.util.loggerSu
|
||||||
import be.mygod.vpnhotspot.util.noisySu
|
import be.mygod.vpnhotspot.util.noisySu
|
||||||
@@ -28,7 +27,7 @@ class P2pSupplicantConfiguration {
|
|||||||
|
|
||||||
private val content by lazy { loggerSu("cat /data/misc/wifi/p2p_supplicant.conf") }
|
private val content by lazy { loggerSu("cat /data/misc/wifi/p2p_supplicant.conf") }
|
||||||
|
|
||||||
fun readPsk(): String? {
|
fun readPsk(handler: ((RuntimeException) -> Unit)? = null): String? {
|
||||||
return try {
|
return try {
|
||||||
val match = pskParser.findAll(content ?: return null).single()
|
val match = pskParser.findAll(content ?: return null).single()
|
||||||
if (match.groups[2] == null && match.groups[3] == null) "" else {
|
if (match.groups[2] == null && match.groups[3] == null) "" else {
|
||||||
@@ -37,13 +36,13 @@ class P2pSupplicantConfiguration {
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
} catch (e: NoSuchElementException) {
|
} catch (e: NoSuchElementException) {
|
||||||
Toast.makeText(app, e.message, Toast.LENGTH_LONG).show()
|
handler?.invoke(e)
|
||||||
null
|
null
|
||||||
} catch (e: RuntimeException) {
|
} catch (e: RuntimeException) {
|
||||||
Crashlytics.log(Log.WARN, TAG, content)
|
Crashlytics.log(Log.WARN, TAG, content)
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
Crashlytics.logException(e)
|
Crashlytics.logException(e)
|
||||||
Toast.makeText(app, e.message, Toast.LENGTH_LONG).show()
|
handler?.invoke(e)
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,14 +16,20 @@
|
|||||||
app:title="@string/app_name"
|
app:title="@string/app_name"
|
||||||
android:id="@+id/toolbar"/>
|
android:id="@+id/toolbar"/>
|
||||||
|
|
||||||
<FrameLayout
|
<android.support.design.widget.CoordinatorLayout
|
||||||
android:id="@+id/fragmentHolder"
|
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/navigation"
|
app:layout_constraintBottom_toTopOf="@+id/navigation"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/toolbar"/>
|
app:layout_constraintTop_toBottomOf="@+id/toolbar">
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/fragmentHolder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
|
</android.support.design.widget.CoordinatorLayout>
|
||||||
|
|
||||||
<android.support.design.widget.BottomNavigationView
|
<android.support.design.widget.BottomNavigationView
|
||||||
android:id="@+id/navigation"
|
android:id="@+id/navigation"
|
||||||
|
|||||||
Reference in New Issue
Block a user