Merge branch 'master' into q-beta
This commit is contained in:
@@ -67,11 +67,10 @@ class ClientsFragment : Fragment(), MainScope by MainScope.Supervisor() {
|
||||
override fun onClick(dialog: DialogInterface?, which: Int) {
|
||||
when (which) {
|
||||
DialogInterface.BUTTON_POSITIVE -> {
|
||||
val newNickname = this.dialog!!.findViewById<EditText>(android.R.id.edit).text
|
||||
MacLookup.abort(arg.mac)
|
||||
GlobalScope.launch(Dispatchers.Unconfined) {
|
||||
AppDatabase.instance.clientRecordDao.upsert(arg.mac) {
|
||||
nickname = this@NicknameDialogFragment.dialog!!.findViewById<EditText>(android.R.id.edit).text
|
||||
}
|
||||
AppDatabase.instance.clientRecordDao.upsert(arg.mac) { nickname = newNickname }
|
||||
}
|
||||
}
|
||||
DialogInterface.BUTTON_NEUTRAL -> MacLookup.perform(arg.mac, true)
|
||||
|
||||
@@ -79,10 +79,7 @@ class LocalOnlyHotspotManager(private val parent: TetheringFragment) : Manager()
|
||||
private inner class Data : be.mygod.vpnhotspot.manage.Data() {
|
||||
private val lookup: Map<String, NetworkInterface> get() = parent.ifaceLookup
|
||||
|
||||
override val icon: Int get() {
|
||||
val iface = binder?.iface
|
||||
return (if (iface.isNullOrBlank()) TetherType.WIFI else TetherType.ofInterface(iface)).icon
|
||||
}
|
||||
override val icon get() = R.drawable.ic_action_perm_scan_wifi
|
||||
override val title: CharSequence get() {
|
||||
val configuration = binder?.configuration ?: return parent.getString(R.string.tethering_temp_hotspot)
|
||||
return SpannableStringBuilder("${configuration.SSID} - ").apply {
|
||||
|
||||
@@ -15,7 +15,7 @@ import be.mygod.vpnhotspot.util.stopAndUnbind
|
||||
|
||||
@RequiresApi(26)
|
||||
class LocalOnlyHotspotTileService : KillableTileService() {
|
||||
private val tile by lazy { Icon.createWithResource(application, R.drawable.ic_device_wifi_tethering) }
|
||||
private val tile by lazy { Icon.createWithResource(application, R.drawable.ic_action_perm_scan_wifi) }
|
||||
|
||||
private var binder: LocalOnlyHotspotService.Binder? = null
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import be.mygod.vpnhotspot.net.TetheringManager.localOnlyTetheredIfaces
|
||||
import be.mygod.vpnhotspot.net.TetheringManager.tetheredIfaces
|
||||
import be.mygod.vpnhotspot.util.ServiceForegroundConnector
|
||||
import be.mygod.vpnhotspot.util.broadcastReceiver
|
||||
import be.mygod.vpnhotspot.util.isNotGone
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import timber.log.Timber
|
||||
import java.net.NetworkInterface
|
||||
@@ -102,18 +103,11 @@ class TetheringFragment : Fragment(), ServiceConnection, MenuItem.OnMenuItemClic
|
||||
}
|
||||
|
||||
private fun updateMonitorList(canMonitor: List<String> = emptyList()) {
|
||||
val toolbar = requireActivity().toolbar
|
||||
val menu = toolbar.menu
|
||||
if (canMonitor.isEmpty()) menu.removeItem(R.id.monitor) else {
|
||||
var item = menu.findItem(R.id.monitor)
|
||||
if (item == null) {
|
||||
toolbar.inflateMenu(R.menu.toolbar_monitor)
|
||||
item = menu.findItem(R.id.monitor)!!
|
||||
}
|
||||
item.subMenu.apply {
|
||||
clear()
|
||||
canMonitor.sorted().forEach { add(it).setOnMenuItemClickListener(this@TetheringFragment) }
|
||||
}
|
||||
val item = requireActivity().toolbar.menu.findItem(R.id.monitor) ?: return // assuming no longer foreground
|
||||
item.isNotGone = canMonitor.isNotEmpty()
|
||||
item.subMenu.apply {
|
||||
clear()
|
||||
canMonitor.sorted().forEach { add(it).setOnMenuItemClickListener(this@TetheringFragment) }
|
||||
}
|
||||
}
|
||||
override fun onMenuItemClick(item: MenuItem?): Boolean {
|
||||
@@ -130,9 +124,15 @@ class TetheringFragment : Fragment(), ServiceConnection, MenuItem.OnMenuItemClic
|
||||
binding.interfaces.adapter = adapter
|
||||
adapter.update(emptyList(), emptyList(), emptyList())
|
||||
ServiceForegroundConnector(this, this, TetheringService::class)
|
||||
requireActivity().toolbar.inflateMenu(R.menu.toolbar_tethering)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
requireActivity().toolbar.menu.clear()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (Build.VERSION.SDK_INT >= 27) ManageBar.Data.notifyChange()
|
||||
@@ -177,9 +177,4 @@ class TetheringFragment : Fragment(), ServiceConnection, MenuItem.OnMenuItemClic
|
||||
binder = null
|
||||
requireContext().unregisterReceiver(receiver)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
updateMonitorList()
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.os.Build
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import androidx.annotation.DrawableRes
|
||||
@@ -94,6 +95,13 @@ fun Context.stopAndUnbind(connection: ServiceConnection) {
|
||||
unbindService(connection)
|
||||
}
|
||||
|
||||
var MenuItem.isNotGone: Boolean
|
||||
get() = isVisible || isEnabled
|
||||
set(value) {
|
||||
isVisible = value
|
||||
isEnabled = value
|
||||
}
|
||||
|
||||
fun <K, V> MutableMap<K, V>.computeIfAbsentCompat(key: K, value: () -> V) = if (Build.VERSION.SDK_INT >= 24)
|
||||
computeIfAbsent(key) { value() } else this[key] ?: value().also { put(key, it) }
|
||||
fun <K, V> MutableMap<K, V>.putIfAbsentCompat(key: K, value: V) = if (Build.VERSION.SDK_INT >= 24)
|
||||
|
||||
Reference in New Issue
Block a user