-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from muddassir235/gh_issue_1
Resolve Issue#1
- Loading branch information
Showing
11 changed files
with
261 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 40 additions & 7 deletions
47
app/src/main/java/com/muddassir/connection_checker_app/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,61 @@ | ||
package com.muddassir.connection_checker_app | ||
|
||
import android.content.Intent | ||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import com.muddassir.connection_checker.ConnectionChecker | ||
import com.muddassir.connection_checker.ConnectionState | ||
import com.muddassir.connection_checker.ConnectivityListener | ||
import com.muddassir.connection_checker.checkConnection | ||
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) | ||
checkConnectionFunctionAndInterface() | ||
} | ||
|
||
fun checkConnectionClassAndInterface() { | ||
val connectionChecker = ConnectionChecker(this) | ||
connectionChecker.connectivityListener = this | ||
} | ||
|
||
fun checkConnectionFunctionAndInterface() { | ||
checkConnection(this) | ||
} | ||
|
||
fun checkConnectionFunctionAndLambda() { | ||
checkConnection(this) { | ||
onConnectionState(it) | ||
} | ||
} | ||
|
||
override fun onConnectionState(state: ConnectionState) { | ||
connection_status_tv.text = if(state == ConnectionState.CONNECTED) { | ||
"Connected" | ||
} else if(state == ConnectionState.SLOW) { | ||
"Slow Internet Connection" | ||
} else { | ||
"Disconnected" | ||
connection_status_tv.text = when (state) { | ||
ConnectionState.CONNECTED -> { | ||
"Connected" | ||
} | ||
ConnectionState.SLOW -> { | ||
"Slow Internet Connection" | ||
} | ||
else -> { | ||
"Disconnected" | ||
} | ||
} | ||
|
||
// Test Lifecycle | ||
// if(state == ConnectionState.DISCONNECTED) { | ||
// startActivity(Intent(this, OtherActivity::class.java)) | ||
// finish() | ||
// } | ||
} | ||
} | ||
|
||
class OtherActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.muddassir.connection_checker"> | ||
|
||
/ | ||
<uses-permission android:name="android.permission.INTERNET"/> | ||
</manifest> |
Oops, something went wrong.