From 4ca9c27f3dd5402978ee06fd01e28e4e8ee6550a Mon Sep 17 00:00:00 2001 From: Muddassir Khan Date: Sat, 29 Aug 2020 03:55:28 +0500 Subject: [PATCH] Setup example --- app/build.gradle | 2 ++ app/src/main/AndroidManifest.xml | 11 ++++++- .../connection_checker_app/MainActivity.kt | 30 +++++++++++++++++++ app/src/main/res/layout/activity_main.xml | 9 ++++++ app/src/main/res/values/strings.xml | 1 + 5 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/muddassir/connection_checker_app/MainActivity.kt create mode 100644 app/src/main/res/layout/activity_main.xml diff --git a/app/build.gradle b/app/build.gradle index dd446ea..7e7323e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,10 +24,12 @@ android { } dependencies { + implementation project(":connection_checker") implementation fileTree(dir: "libs", include: ["*.jar"]) implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation 'androidx.core:core-ktx:1.3.1' implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.1' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8b1fa95..27d7a5e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,3 +1,4 @@ + @@ -7,6 +8,14 @@ android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" - android:theme="@style/AppTheme" /> + android:theme="@style/AppTheme"> + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/muddassir/connection_checker_app/MainActivity.kt b/app/src/main/java/com/muddassir/connection_checker_app/MainActivity.kt new file mode 100644 index 0000000..42691ed --- /dev/null +++ b/app/src/main/java/com/muddassir/connection_checker_app/MainActivity.kt @@ -0,0 +1,30 @@ +package com.muddassir.connection_checker_app + +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import com.muddassir.connection_checker.ConnectionChecker +import com.muddassir.connection_checker.ConnectivityListener +import kotlinx.android.synthetic.main.activity_main.* + +class MainActivity : AppCompatActivity(), ConnectivityListener { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + val connectionChecker = ConnectionChecker(this, lifecycle) + connectionChecker.connectivityListener = this + connectionChecker.startChecking() + } + + override fun onConnected() { + connection_status_tv.text = "Connected" + } + + override fun onConnectionSlow() { + connection_status_tv.text = "Slow Internet Connection" + } + + override fun onDisconnected() { + connection_status_tv.text = "Disconnected" + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..d65ebdc --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,9 @@ + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bcdfb44..a6ef059 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,4 @@ Connection Checker + Connected \ No newline at end of file