Skip to content

Commit 2643913

Browse files
authored
Merge pull request #434 from openziti/remove-up-down-stats
Remove network speed indicators from dashboard
2 parents 652129d + bb6eece commit 2643913

File tree

3 files changed

+14
-159
lines changed

3 files changed

+14
-159
lines changed

app/src/main/java/org/openziti/mobile/ZitiMobileEdgeActivity.kt

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ package org.openziti.mobile
77
import android.animation.AnimatorSet
88
import android.animation.ObjectAnimator
99
import android.content.ComponentName
10-
import android.content.Context
1110
import android.content.Intent
1211
import android.content.ServiceConnection
1312
import android.content.SharedPreferences
1413
import android.content.res.Resources
15-
import android.net.Uri
1614
import android.net.VpnService
1715
import android.os.Build
1816
import android.os.Bundle
@@ -23,11 +21,9 @@ import android.os.VibratorManager
2321
import android.view.View
2422
import android.view.WindowManager
2523
import android.view.animation.DecelerateInterpolator
26-
import android.widget.TextView
2724
import androidx.activity.OnBackPressedCallback
2825
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
2926
import androidx.appcompat.app.AppCompatActivity
30-
import androidx.core.os.ConfigurationCompat
3127
import androidx.core.os.bundleOf
3228
import androidx.fragment.app.add
3329
import androidx.fragment.app.commit
@@ -39,6 +35,7 @@ import org.openziti.mobile.fragments.IdentityDetailFragment
3935
import org.openziti.mobile.model.TunnelModel
4036
import java.util.Timer
4137
import java.util.TimerTask
38+
import androidx.core.net.toUri
4239

4340
class ZitiMobileEdgeActivity : AppCompatActivity() {
4441

@@ -61,10 +58,6 @@ class ZitiMobileEdgeActivity : AppCompatActivity() {
6158
private val HamburgerLabel by lazy { binding.HamburgerLabel }
6259
private val IdentityListing by lazy { binding.IdentityListing }
6360
private val StateButton by lazy { binding.StateButton }
64-
private val DownloadSpeed by lazy { binding.DownloadSpeed }
65-
private val DownloadMbps by lazy { binding.DownloadMbps }
66-
private val UploadMbps by lazy { binding.UploadMbps }
67-
private val UploadSpeed by lazy { binding.UploadSpeed }
6861
private val TimeConnected by lazy { binding.TimeConnected }
6962
private val MainLogo by lazy { binding.MainLogo }
7063

@@ -93,7 +86,7 @@ class ZitiMobileEdgeActivity : AppCompatActivity() {
9386

9487
fun launchUrl(url:String) {
9588
val openURL = Intent(Intent.ACTION_VIEW)
96-
openURL.data = Uri.parse(url)
89+
openURL.data = url.toUri()
9790
startActivity(openURL)
9891
}
9992

@@ -165,10 +158,10 @@ class ZitiMobileEdgeActivity : AppCompatActivity() {
165158
})
166159

167160
val vb = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
168-
val vbm = getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
161+
val vbm = getSystemService(VIBRATOR_MANAGER_SERVICE) as VibratorManager
169162
vbm.defaultVibrator
170163
} else {
171-
getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
164+
getSystemService(VIBRATOR_SERVICE) as Vibrator
172165
}
173166

174167
val vpnPrepare = registerForActivityResult(StartActivityForResult()) {
@@ -283,7 +276,7 @@ class ZitiMobileEdgeActivity : AppCompatActivity() {
283276
}
284277

285278

286-
prefs = getSharedPreferences("ziti-vpn", Context.MODE_PRIVATE)
279+
prefs = getSharedPreferences("ziti-vpn", MODE_PRIVATE)
287280
}
288281

289282
override fun onPause() {
@@ -293,15 +286,11 @@ class ZitiMobileEdgeActivity : AppCompatActivity() {
293286

294287
override fun onResume() {
295288
super.onResume()
296-
bindService(Intent(applicationContext, ZitiVPNService::class.java), serviceConnection, Context.BIND_AUTO_CREATE)
289+
bindService(Intent(applicationContext, ZitiVPNService::class.java), serviceConnection,
290+
BIND_AUTO_CREATE
291+
)
297292

298293
updateTunnelState()
299-
300-
model.stats().observe(this) {
301-
setSpeed(it.down, DownloadSpeed, DownloadMbps)
302-
setSpeed(it.up, UploadSpeed, UploadMbps)
303-
}
304-
305294
}
306295

307296
private fun updateTunnelState() {
@@ -314,32 +303,6 @@ class ZitiMobileEdgeActivity : AppCompatActivity() {
314303
OffButton.visibility = if (on) View.GONE else View.VISIBLE
315304
}
316305

317-
val MB = 1024 * 1024
318-
val KB = 1024
319-
320-
fun setSpeed(rate: Double, speed: TextView, label: TextView) {
321-
val r: Double
322-
val l: String
323-
when {
324-
rate * 8 > MB -> {
325-
r = (rate * 8) / (1024 * 1024)
326-
l = "Mbps"
327-
}
328-
rate * 8 > KB -> {
329-
r = (rate * 8) / KB
330-
l = "Kbps"
331-
}
332-
else -> {
333-
r = rate * 8
334-
l = "bps"
335-
}
336-
}
337-
338-
speed.text = String.format(
339-
ConfigurationCompat.getLocales(resources.configuration)[0], "%.1f", r)
340-
label.text = l
341-
}
342-
343306
private fun stopZitiVPN() {
344307
startService(Intent(this, ZitiVPNService::class.java).setAction("stop"))
345308
}

app/src/main/java/org/openziti/mobile/model/TunnelModel.kt

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ import androidx.datastore.preferences.preferencesDataStore
1414
import androidx.lifecycle.LiveData
1515
import androidx.lifecycle.MutableLiveData
1616
import androidx.lifecycle.ViewModel
17-
import androidx.lifecycle.asLiveData
1817
import androidx.lifecycle.viewModelScope
19-
import kotlinx.coroutines.delay
2018
import kotlinx.coroutines.flow.first
21-
import kotlinx.coroutines.flow.flow
2219
import kotlinx.coroutines.flow.map
2320
import kotlinx.coroutines.launch
2421
import kotlinx.coroutines.runBlocking
@@ -45,13 +42,13 @@ import org.openziti.tunnel.ZitiConfig
4542
import org.openziti.tunnel.ZitiID
4643
import org.openziti.tunnel.toPEM
4744
import java.io.File
48-
import timber.log.Timber as Log
4945
import java.net.URI
5046
import java.security.KeyStore.PrivateKeyEntry
5147
import java.security.cert.X509Certificate
5248
import java.time.Clock
5349
import java.time.Duration
5450
import java.util.concurrent.CompletableFuture
51+
import timber.log.Timber as Log
5552

5653
class TunnelModel(
5754
val tunnel: Tunnel,
@@ -74,14 +71,6 @@ class TunnelModel(
7471
}
7572
}
7673

77-
data class NetworkStats(val up: Double, val down: Double)
78-
fun stats() = flow {
79-
while (true) {
80-
emit(NetworkStats(tunnel.getUpRate(), tunnel.getDownRate()))
81-
delay(1_000)
82-
}
83-
}.asLiveData()
84-
8574
fun identities(): LiveData<List<Identity>> = identitiesData
8675
private val identitiesData = MutableLiveData<List<Identity>>()
8776
private val identities = mutableMapOf<String, Identity>()
@@ -177,7 +166,7 @@ class TunnelModel(
177166
tunnel.processCmd(cmd).handleAsync { json: JsonElement? , ex: Throwable? ->
178167
idModel.start()
179168
if (ex != null) {
180-
Log.w("failed to execute", ex)
169+
Log.w(ex, "failed to execute")
181170
} else {
182171
identitiesData.postValue(identities.values.toList())
183172
Log.d("load result[$id]: $json")

app/src/main/res/layout/dashboard.xml

Lines changed: 4 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -401,109 +401,12 @@
401401
app:layout_constraintTop_toTopOf="parent" />
402402
</androidx.constraintlayout.widget.ConstraintLayout>
403403

404-
<LinearLayout
405-
android:id="@+id/LabelArea"
406-
android:layout_width="match_parent"
407-
android:layout_height="20dp"
408-
android:layout_weight=".1"
409-
android:gravity="center_horizontal|center_vertical"
410-
android:orientation="horizontal"
411-
android:visibility="visible">
412-
413-
<TextView
414-
android:id="@+id/DownloadSpeedLabel"
415-
android:layout_width="wrap_content"
416-
android:layout_height="wrap_content"
417-
android:layout_marginEnd="8dp"
418-
android:text="@string/download"
419-
android:textColor="@color/colorTitle" />
420-
421-
<ImageView
422-
android:id="@+id/DownIcon"
423-
android:layout_width="20dp"
424-
android:layout_height="20dp"
425-
android:background="@drawable/down"
426-
android:contentDescription="@string/download"
427-
tools:srcCompat="@drawable/down" />
428-
429-
<TextView
430-
android:id="@+id/UploadSpeedLabel"
431-
android:layout_width="wrap_content"
432-
android:layout_height="wrap_content"
433-
android:layout_marginStart="8dp"
434-
android:layout_marginEnd="8dp"
435-
android:text="@string/upload"
436-
android:textColor="@color/colorTitle" />
437-
438-
<ImageView
439-
android:id="@+id/UpIcon"
440-
android:layout_width="20dp"
441-
android:layout_height="20dp"
442-
android:contentDescription="@string/upload"
443-
app:srcCompat="@drawable/up" />
444-
</LinearLayout>
445-
446-
<LinearLayout
447-
android:id="@+id/CountArea"
448-
android:layout_width="match_parent"
449-
android:layout_height="0dp"
450-
android:layout_weight=".15"
451-
android:gravity="center_horizontal"
452-
android:orientation="horizontal"
453-
android:visibility="visible">
454-
455-
<TextView
456-
android:id="@+id/DownloadSpeed"
457-
android:layout_width="wrap_content"
458-
android:layout_height="match_parent"
459-
android:layout_marginEnd="10dp"
460-
android:text="@string/defults"
461-
android:textColor="@color/download"
462-
android:textSize="60sp"
463-
android:autoSizeTextType="uniform"
464-
tools:text="@string/defults" />
465-
466-
<TextView
467-
android:id="@+id/UploadSpeed"
468-
android:layout_width="wrap_content"
469-
android:layout_height="match_parent"
470-
android:layout_marginStart="10dp"
471-
android:text="@string/defults"
472-
android:textColor="@color/upload"
473-
android:autoSizeTextType="uniform"
474-
android:textSize="60sp" />
475-
</LinearLayout>
476-
477-
<LinearLayout
478-
android:id="@+id/CountLabelArea"
479-
android:layout_width="match_parent"
480-
android:layout_height="match_parent"
481-
android:gravity="center_horizontal"
482-
android:layout_weight=".05"
483-
android:weightSum="2"
484-
android:orientation="horizontal"
485-
android:visibility="visible">
486-
487-
<TextView
488-
android:id="@+id/DownloadMbps"
489-
android:layout_width="wrap_content"
490-
android:layout_height="match_parent"
491-
android:text="@string/speed"
492-
android:layout_marginEnd="10dp"
493-
android:textColor="@color/subTitle" />
494-
<TextView
495-
android:id="@+id/UploadMbps"
496-
android:layout_width="wrap_content"
497-
android:layout_height="match_parent"
498-
android:text="@string/speed"
499-
android:layout_marginStart="10dp"
500-
android:textColor="@color/subTitle" />
501-
</LinearLayout>
502404
<ScrollView
503405
android:layout_width="fill_parent"
504-
android:layout_height="0dp"
505-
android:contentDescription="@string/identities"
506-
android:layout_weight=".5">
406+
android:layout_height="wrap_content"
407+
android:layout_weight=".5"
408+
android:contentDescription="@string/identities">
409+
507410
<LinearLayout
508411
android:id="@+id/IdentityListing"
509412
android:layout_width="match_parent"

0 commit comments

Comments
 (0)