Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
[] Add advanced button
Browse files Browse the repository at this point in the history
           high-level explanation of what the changes do.

[](https://fivestars.atlassian.net/browse/)
  • Loading branch information
darran-kelinske-fivestars committed Jun 3, 2019
1 parent 29d0287 commit a5d8aa6
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 69 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
Expand All @@ -44,4 +44,4 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.gms.google-services'
14 changes: 8 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fivestars.wifihealthcheck">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<application
android:allowBackup="true"
Expand All @@ -15,7 +15,9 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".advanced.AdvancedActivity">
</activity>
<activity android:name=".main.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
package com.fivestars.wifihealthcheck
package com.fivestars.wifihealthcheck.main

import android.Manifest
import android.content.pm.PackageManager
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.annotation.FloatRange
import androidx.appcompat.app.AppCompatActivity
import com.fivestars.wifihealthcheck.R
import com.fivestars.wifihealthcheck.usecase.WifiScanData
import com.github.mikephil.charting.components.AxisBase
import com.github.mikephil.charting.data.BarData
import com.github.mikephil.charting.data.BarDataSet
import com.github.mikephil.charting.data.BarEntry
import com.github.mikephil.charting.formatter.IAxisValueFormatter
import com.github.mikephil.charting.formatter.ValueFormatter
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet
import com.github.mikephil.charting.utils.ColorTemplate
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import java.util.*
import kotlin.coroutines.CoroutineContext

Expand All @@ -34,6 +37,10 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
setContentView(R.layout.activity_main)
presenter = WifiHealthPresenter(this)
requestWifiPermission()
advanced_button.setOnClickListener {
advanced_results_layout.visibility = View.VISIBLE
advanced_button.visibility = View.GONE
}
}

override fun onDestroy() {
Expand Down Expand Up @@ -68,9 +75,14 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
presenter.execute()
}

fun updateProgress(progress: Int) {
progress_bar.progress = progress
}

fun showResults(wifiScanData: WifiScanData, pass: Boolean) {
progress_frame_layout.visibility = View.GONE
results_layout.visibility = View.VISIBLE
pass_fail_view.visibility = View.VISIBLE
advanced_button.visibility = View.VISIBLE

pass_fail_view.text = when {
pass -> "Pass"
Expand All @@ -79,6 +91,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
showChart(wifiScanData)
}


fun getRandomColor(): Int {
val rnd = Random()
return Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package com.fivestars.wifihealthcheck
package com.fivestars.wifihealthcheck.main

import android.net.wifi.WifiManager
import android.content.Context.WIFI_SERVICE
import android.net.wifi.WifiInfo
import com.fivestars.wifihealthcheck.model.NetworkInfo
import com.fivestars.wifihealthcheck.usecase.*

data class AllTheData(
val networkInfo: NetworkInfo,
val wifiInfo: WifiInfo,
val wifiScanData: WifiScanData,
val speedTestResults: SpeedTestResults?
)


class WifiHealthPresenter(private val mainActivity: MainActivity) {

Expand All @@ -23,9 +17,13 @@ class WifiHealthPresenter(private val mainActivity: MainActivity) {
private val speedTestUseCase = SpeedTestUseCase()

suspend fun execute() {
mainActivity.updateProgress(10)
val beforeNetworkInfo = networkInfoUseCase.getNetworkInfo()
// val speedResults = speedTestUseCase.speedTest()
mainActivity.updateProgress(33)
val speedResults = speedTestUseCase.speedTest()
mainActivity.updateProgress(70)
val afterNetworkInfo = networkInfoUseCase.getNetworkInfo()
mainActivity.updateProgress(95)

val packetLoss = calculatePacketLoss(beforeNetworkInfo, afterNetworkInfo)

Expand All @@ -39,16 +37,16 @@ class WifiHealthPresenter(private val mainActivity: MainActivity) {
// Link Rate > 43 Mbps

var pass = true
/*

if (wifiInfo.rssi < -60 || speedResults.download < 5 || speedResults.upload < 2 || wifiInfo.linkSpeed < 42 || packetLoss > .05) {
pass = false
}*/
}

mainActivity.showResults(wifiScanData, pass)

}

fun calculatePacketLoss(before: NetworkInfo, after: NetworkInfo): Double {
private fun calculatePacketLoss(before: NetworkInfo, after: NetworkInfo): Double {
val rxPackets = after.rxData.getValue("packets") - before.rxData.getValue("packets")
val txPackets = after.txData.getValue("packets") - before.txData.getValue("packets")

Expand All @@ -61,5 +59,4 @@ class WifiHealthPresenter(private val mainActivity: MainActivity) {
fun shutDown() {
wifiScanUseCase.shutdown(mainActivity)
}

}
11 changes: 11 additions & 0 deletions app/src/main/java/com/fivestars/wifihealthcheck/model/Models.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.fivestars.wifihealthcheck.model

import android.net.wifi.WifiInfo
import com.fivestars.wifihealthcheck.usecase.SpeedTestResults
import com.fivestars.wifihealthcheck.usecase.WifiScanData

data class NetworkInfo(
val interfaceFlags: List<String>,
val macAddress: String,
Expand All @@ -12,3 +16,10 @@ data class Network(
val ssid: String,
val rssi: Int
)

data class AllTheData(
val networkInfo: NetworkInfo,
val wifiInfo: WifiInfo,
val wifiScanData: WifiScanData,
val speedTestResults: SpeedTestResults?
)
113 changes: 70 additions & 43 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,66 +1,93 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".main.MainActivity">

<LinearLayout
android:id="@+id/progress_frame_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">

<FrameLayout
android:id="@+id/progress_frame_layout"
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:id="@+id/progress_bar"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:indeterminate="false"
android:progress="5"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
android:layout_marginTop="8dp"
android:layout_gravity="center_horizontal"
android:textSize="18sp"
android:text="Running Diagnostic Tests"/>
</LinearLayout>

<ProgressBar android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="progress"/>
</FrameLayout>
<TextView
android:id="@+id/pass_fail_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="top"
android:textSize="24sp"
android:visibility="gone"/>

<LinearLayout
android:id="@+id/results_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="top"
android:gravity="top"
android:visibility="gone">
<Button
android:id="@+id/advanced_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_gravity="center_horizontal"
android:textSize="24sp"
android:text="Advanced"
android:visibility="gone"/>

<TextView
android:id="@+id/pass_fail_view"
android:layout_width="80dp"
android:layout_height="80dp"/>
<LinearLayout
android:id="@+id/advanced_results_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="top"
android:gravity="top"
android:visibility="gone">

<!--<TextView-->
<!--android:id="@+id/wifi_info"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content" />-->
<!--android:id="@+id/wifi_info"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content" />-->

<!--<TextView-->
<!--android:id="@+id/network_info"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content" />-->
<!--android:id="@+id/network_info"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content" />-->

<!--<TextView-->
<!--android:id="@+id/wifi_scan"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"/>-->
<!--android:id="@+id/wifi_scan"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"/>-->

<!--<TextView-->
<!--android:id="@+id/speed_results"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"/>-->
<!--android:id="@+id/speed_results"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"/>-->

<!--<TextView-->
<!--android:id="@+id/link_speed_text_view"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content" />-->
<!--android:id="@+id/link_speed_text_view"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content" />-->

<com.github.mikephil.charting.charts.BarChart
android:id="@+id/chart1"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:id="@+id/chart1"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</LinearLayout>

</FrameLayout>

0 comments on commit a5d8aa6

Please sign in to comment.