Tell user when blocking won't work

This commit is contained in:
Mygod
2018-10-03 14:16:31 +08:00
parent 249474abb2
commit a4e69c5a9b
4 changed files with 12 additions and 0 deletions

View File

@@ -32,6 +32,7 @@ import be.mygod.vpnhotspot.net.monitor.TrafficRecorder
import be.mygod.vpnhotspot.room.*
import be.mygod.vpnhotspot.util.ServiceForegroundConnector
import be.mygod.vpnhotspot.util.toPluralInt
import be.mygod.vpnhotspot.widget.SmartSnackbar
import java.text.NumberFormat
class ClientsFragment : Fragment(), ServiceConnection {
@@ -118,10 +119,14 @@ class ClientsFragment : Fragment(), ServiceConnection {
}
R.id.block, R.id.unblock -> {
val client = binding.client ?: return false
val wasWorking = TrafficRecorder.isWorking(client.mac.macToLong())
client.record.apply {
AppDatabase.instance.clientRecordDao.update(ClientRecord(mac, nickname, !blocked))
}
IpNeighbourMonitor.instance?.flush()
if (!wasWorking && item.itemId == R.id.block) {
SmartSnackbar.make(R.string.clients_popup_block_service_inactive).show()
}
true
}
R.id.stats -> {

View File

@@ -146,4 +146,9 @@ object TrafficRecorder {
unscheduleUpdateLocked()
records.clear()
}
/**
* Possibly inefficient. Don't call this too often.
*/
fun isWorking(mac: Long) = records.values.any { it.mac == mac }
}

View File

@@ -59,6 +59,7 @@
<string name="clients_popup_nickname">昵称…</string>
<string name="clients_popup_block">拉黑</string>
<string name="clients_popup_block_service_inactive">拉黑需要为该接口打开服务。</string>
<string name="clients_popup_unblock">洗白</string>
<string name="clients_popup_stats">流量…</string>
<string name="clients_nickname_title">%s 的昵称</string>

View File

@@ -63,6 +63,7 @@
<string name="clients_popup_nickname">Nickname…</string>
<string name="clients_popup_block">Block</string>
<string name="clients_popup_block_service_inactive">Turn on service for this interface to block the client.</string>
<string name="clients_popup_unblock">Unblock</string>
<string name="clients_popup_stats">Stats…</string>
<string name="clients_nickname_title">Nickname for %s</string>