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 {
}
@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> {
return suspendCancellableCoroutine { cont ->
val signal = CancellationSignal()
cont.invokeOnCancellation { signal.cancel() }
// 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>> {
override fun onAnswer(answer: Collection<InetAddress>, rcode: Int) =
cont.resume(answer.toTypedArray())
......
......@@ -55,13 +55,14 @@ class ServiceNotification(private val service: BaseService.Interface, profileNam
override fun stateChanged(state: Int, profileName: String?, msg: String?) { } // ignore
override fun trafficUpdated(profileId: Long, stats: TrafficStats) {
if (profileId != 0L) return
service as Context
val txr = service.getString(R.string.speed, Formatter.formatFileSize(service, stats.txRate))
val rxr = service.getString(R.string.speed, Formatter.formatFileSize(service, stats.rxRate))
builder.setContentText("$txr↑\t$rxr↓")
style.bigText(service.getString(R.string.stat_summary, txr, rxr,
builder.apply {
setContentText((service as Context).getString(R.string.traffic,
service.getString(R.string.speed, Formatter.formatFileSize(service, stats.txRate)),
service.getString(R.string.speed, Formatter.formatFileSize(service, stats.rxRate))))
setSubText(service.getString(R.string.traffic,
Formatter.formatFileSize(service, stats.txTotal),
Formatter.formatFileSize(service, stats.rxTotal)))
}
show()
}
override fun trafficPersisted(profileId: Long) { }
......@@ -77,7 +78,7 @@ class ServiceNotification(private val service: BaseService.Interface, profileNam
.setContentTitle(profileName)
.setContentIntent(Core.configureIntent(service))
.setSmallIcon(R.drawable.ic_service_active)
private val style = NotificationCompat.BigTextStyle(builder).bigText("")
.setCategory(NotificationCompat.CATEGORY_SERVICE)
private var isVisible = true
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