Commit 554a9b1b authored by Mygod's avatar Mygod

Make service notification more compact

This also fixes styling issue on Android Q beta 1 thru 4.
parent 2f7f9310
...@@ -54,20 +54,18 @@ sealed class DnsResolverCompat { ...@@ -54,20 +54,18 @@ sealed class DnsResolverCompat {
} }
@TargetApi(29) @TargetApi(29)
private object DnsResolverCompat29 : DnsResolverCompat() { private object DnsResolverCompat29 : DnsResolverCompat(), Executor {
/** /**
* This executor will run on its caller directly. On Q beta 3, this results in calling in main thread. * This executor will run on its caller directly. On Q beta 3 thru 4, this results in calling in main thread.
*/ */
private object InPlaceExecutor : Executor { override fun execute(command: Runnable) = command.run()
override fun execute(command: Runnable?) = command!!.run()
}
override suspend fun resolve(network: Network, host: String): Array<InetAddress> { override suspend fun resolve(network: Network, host: String): Array<InetAddress> {
return suspendCancellableCoroutine { cont -> return suspendCancellableCoroutine { cont ->
val signal = CancellationSignal() val signal = CancellationSignal()
cont.invokeOnCancellation { signal.cancel() } cont.invokeOnCancellation { signal.cancel() }
// retry should be handled by client instead // retry should be handled by client instead
DnsResolver.getInstance().query(network, host, DnsResolver.FLAG_NO_RETRY, InPlaceExecutor, DnsResolver.getInstance().query(network, host, DnsResolver.FLAG_NO_RETRY, this,
signal, object : DnsResolver.Callback<Collection<InetAddress>> { signal, object : DnsResolver.Callback<Collection<InetAddress>> {
override fun onAnswer(answer: Collection<InetAddress>, rcode: Int) = override fun onAnswer(answer: Collection<InetAddress>, rcode: Int) =
cont.resume(answer.toTypedArray()) cont.resume(answer.toTypedArray())
......
...@@ -55,13 +55,14 @@ class ServiceNotification(private val service: BaseService.Interface, profileNam ...@@ -55,13 +55,14 @@ class ServiceNotification(private val service: BaseService.Interface, profileNam
override fun stateChanged(state: Int, profileName: String?, msg: String?) { } // ignore override fun stateChanged(state: Int, profileName: String?, msg: String?) { } // ignore
override fun trafficUpdated(profileId: Long, stats: TrafficStats) { override fun trafficUpdated(profileId: Long, stats: TrafficStats) {
if (profileId != 0L) return if (profileId != 0L) return
service as Context builder.apply {
val txr = service.getString(R.string.speed, Formatter.formatFileSize(service, stats.txRate)) setContentText((service as Context).getString(R.string.traffic,
val rxr = service.getString(R.string.speed, Formatter.formatFileSize(service, stats.rxRate)) service.getString(R.string.speed, Formatter.formatFileSize(service, stats.txRate)),
builder.setContentText("$txr↑\t$rxr↓") service.getString(R.string.speed, Formatter.formatFileSize(service, stats.rxRate))))
style.bigText(service.getString(R.string.stat_summary, txr, rxr, setSubText(service.getString(R.string.traffic,
Formatter.formatFileSize(service, stats.txTotal), Formatter.formatFileSize(service, stats.txTotal),
Formatter.formatFileSize(service, stats.rxTotal))) Formatter.formatFileSize(service, stats.rxTotal)))
}
show() show()
} }
override fun trafficPersisted(profileId: Long) { } override fun trafficPersisted(profileId: Long) { }
...@@ -77,7 +78,7 @@ class ServiceNotification(private val service: BaseService.Interface, profileNam ...@@ -77,7 +78,7 @@ class ServiceNotification(private val service: BaseService.Interface, profileNam
.setContentTitle(profileName) .setContentTitle(profileName)
.setContentIntent(Core.configureIntent(service)) .setContentIntent(Core.configureIntent(service))
.setSmallIcon(R.drawable.ic_service_active) .setSmallIcon(R.drawable.ic_service_active)
private val style = NotificationCompat.BigTextStyle(builder).bigText("") .setCategory(NotificationCompat.CATEGORY_SERVICE)
private var isVisible = true private var isVisible = true
init { init {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment