From 57fedd65f301b56ce7871b3c84e0960b24a952cf Mon Sep 17 00:00:00 2001 From: Jeremy Jao Date: Sun, 13 Aug 2017 21:30:41 -0400 Subject: [PATCH] #319: interface wrapper around Android Wifi state Not quite finished. We should edit the unit tests in PatternDataManager, move it to PatternDataManagerTestKt, then rename this to patternDataManagerTest.kt --- app/build.gradle | 7 +++- .../pattrack/wrappers/AndroidWifiChecker.kt | 23 ++++++++++++ build.gradle | 10 +++++- pat-static/build.gradle | 7 ++++ .../patstatic/wrappers/WifiChecker.kt | 13 +++++++ .../patterns/PatternDataManagerTestKt.kt | 36 +++++++++++++++++++ 6 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 app/src/main/kotlin/com/rectanglel/pattrack/wrappers/AndroidWifiChecker.kt create mode 100644 pat-static/src/main/kotlin/com/rectanglel/patstatic/wrappers/WifiChecker.kt create mode 100644 pat-static/src/test/kotlin/com/rectanglel/patstatic/patterns/PatternDataManagerTestKt.kt diff --git a/app/build.gradle b/app/build.gradle index 55614c4e..d1512c0f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' apply plugin: 'me.tatarka.retrolambda' apply plugin: 'com.github.ben-manes.versions' @@ -19,7 +20,7 @@ android { applicationId "rectangledbmi.com.pittsburghrealtimetracker" minSdkVersion versions.android.minSdk targetSdkVersion versions.android.targetSdk - versionCode 160080001 + versionCode 160080002 versionName "8.0.1-beta" } lintOptions { @@ -40,6 +41,9 @@ android { sourceCompatibility versions.java.target targetCompatibility versions.java.target } + sourceSets { + main.java.srcDirs += "src/main/kotlin" + } } @@ -83,6 +87,7 @@ dependencies { testCompile "junit:junit:${versions.test.junit}" testCompile "org.mockito:mockito-core:${versions.test.mockito}" + compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" } buildscript { diff --git a/app/src/main/kotlin/com/rectanglel/pattrack/wrappers/AndroidWifiChecker.kt b/app/src/main/kotlin/com/rectanglel/pattrack/wrappers/AndroidWifiChecker.kt new file mode 100644 index 00000000..e1c4746d --- /dev/null +++ b/app/src/main/kotlin/com/rectanglel/pattrack/wrappers/AndroidWifiChecker.kt @@ -0,0 +1,23 @@ +package com.rectanglel.pattrack.wrappers + +import android.content.Context +import android.net.ConnectivityManager +import com.rectanglel.patstatic.wrappers.WifiChecker + +/** + *

Android implementation of checking to see if wifi is on. + *

Created by epicstar on 8/13/17. + * @author Jeremy Jao + * @since 160080002 + */ +class AndroidWifiChecker constructor(context: Context): WifiChecker { + + private val connectivityManager : ConnectivityManager = + context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager + + override fun isOnWifi(): Boolean { + val networkInfo = connectivityManager.activeNetworkInfo + return networkInfo.type == ConnectivityManager.TYPE_WIFI + } + +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 18694698..990d89f7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,16 +1,19 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext.kotlin_version = '1.1.3-2' repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } +apply plugin: 'kotlin' allprojects { repositories { @@ -59,7 +62,6 @@ ext { // versions for all dependencies versions = [ - kotlin: '1.1.0', java: [ annotation: '10.0-b28', target: JavaVersion.VERSION_1_8, @@ -102,3 +104,9 @@ ext { ] ] } +repositories { + mavenCentral() +} +dependencies { + compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" +} diff --git a/pat-static/build.gradle b/pat-static/build.gradle index d8861d48..37bbb1b3 100644 --- a/pat-static/build.gradle +++ b/pat-static/build.gradle @@ -1,8 +1,10 @@ apply plugin: 'java' +apply plugin: 'kotlin' apply plugin: 'me.tatarka.retrolambda' buildscript { + ext.kotlin_version = '1.1.3-2' repositories { jcenter() mavenCentral() @@ -14,6 +16,7 @@ buildscript { // check for updates of 3rd party libs: // `./gradlew dependencyUpdates -Drevision=release` classpath "com.github.ben-manes:gradle-versions-plugin:${versions.gradleVersions}" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -32,6 +35,7 @@ dependencies { testCompile "junit:junit:${versions.test.junit}" testCompile "org.mockito:mockito-core:${versions.test.mockito}" + compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" } sourceSets { @@ -55,3 +59,6 @@ task cleanCachedRoutes(type: Delete) { } jar.dependsOn cacheRoutes +repositories { + mavenCentral() +} diff --git a/pat-static/src/main/kotlin/com/rectanglel/patstatic/wrappers/WifiChecker.kt b/pat-static/src/main/kotlin/com/rectanglel/patstatic/wrappers/WifiChecker.kt new file mode 100644 index 00000000..32b6bc62 --- /dev/null +++ b/pat-static/src/main/kotlin/com/rectanglel/patstatic/wrappers/WifiChecker.kt @@ -0,0 +1,13 @@ +package com.rectanglel.patstatic.wrappers + +/** + *

Checks if + *

Created by epicstar on 8/13/17. + * @author Jeremy Jao + */ +public interface WifiChecker { + /** + * Checks if wifi is on. + */ + fun isOnWifi() : Boolean +} \ No newline at end of file diff --git a/pat-static/src/test/kotlin/com/rectanglel/patstatic/patterns/PatternDataManagerTestKt.kt b/pat-static/src/test/kotlin/com/rectanglel/patstatic/patterns/PatternDataManagerTestKt.kt new file mode 100644 index 00000000..252e7b29 --- /dev/null +++ b/pat-static/src/test/kotlin/com/rectanglel/patstatic/patterns/PatternDataManagerTestKt.kt @@ -0,0 +1,36 @@ +package com.rectanglel.patstatic.patterns + +import com.rectanglel.patstatic.mock.PatApiMock +import com.rectanglel.patstatic.model.RetrofitPatApi +import com.rectanglel.patstatic.model.StaticData +import com.rectanglel.patstatic.wrappers.WifiChecker +import org.junit.Before +import org.mockito.Mockito +import java.io.File + +/** + * Created by epicstar on 8/13/17. + */ +class PatternDataManagerTestKt { // TODO: rename this to PatternDataManagerTest + private lateinit var dir : File + private lateinit var patternDataManager : PatternDataManager + private lateinit var patapi : RetrofitPatApi + private lateinit var staticData : StaticData + private lateinit var wifiChecker : WifiChecker + + @Before + fun setUp() { + dir = File ("testDirectory") + dir.mkdirs() + patapi = PatApiMock.getPatApiMock() + staticData = Mockito.mock(StaticData::class.java) + wifiChecker = Mockito.mock(WifiChecker::class.java) + patternDataManager = Mockito.spy(PatternDataManager( + dir, + patapi, + staticData + )) + } + + +} \ No newline at end of file