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