Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rommansabbir/NetworkX

πŸ…½πŸ…΄πŸ†ƒπŸ††πŸ…ΎπŸ†πŸ…ΊπŸ†‡ An easy & handy library to monitor device internet connection status.
https://github.com/rommansabbir/NetworkX

coroutines coroutines-android internet-connection networkx

Last synced: 8 days ago
JSON representation

πŸ…½πŸ…΄πŸ†ƒπŸ††πŸ…ΎπŸ†πŸ…ΊπŸ†‡ An easy & handy library to monitor device internet connection status.

Awesome Lists containing this project

README

        

![NetworkX](https://user-images.githubusercontent.com/25950083/185731068-480fd969-f18d-439c-938a-6285a50c2be2.png)

[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png)](#getting-started-quick)


Maintained


Maintained


JitPack

⚑ Latest Version: 4.2.0 | Change Logs πŸ”°

- NetworkX now works with both __Activity__ or __Application__ Scope (NetworkX lifecycle is bounded to `NetworkXLifecycle.Activity` or `NetworkXLifecycle.Application`).
- Introduced `SmartConfig` to replace old config [`NetworkXConfig` has been deprecated].
- New __API__ to initialize `NetworkX`, enabled smart refactoring to replace old __API__ with new one.
- New __API__ [`NoInternetDialogV2.forceClose()`] added to close `Dialog` forcefully.
- Added support for custom _Drawable_ to be shown in `NoInternetDialogV2`.
- Added support for _No Internet Dialog_ `JetPack Compose` version.
- Several __Classes__, __APIs__ has been deprecated.
- Removed unused classes/packages.

[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png)](#getting-started-quick)

Installation

## ➀ Step 1:

Add the JitPack repository to your build file .

```gradle
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
```

## ➀ Step 2:

Add the dependency.

```gradle
dependencies {
implementation 'com.github.rommansabbir:NetworkX:4.2.0'
}
```

## ➀ Step 3:
Initialize `NetworkX` from your `Application.onCreate()`
````
//Deprecated way
val builder = NetworkXConfig.Builder()
.withApplication(this)
// You can disable speed meter if not required
.withEnableSpeedMeter(true)
.build()
NetworkXProvider.enable(builder)

//New smart way
NetworkXProvider.enable(SmartConfig(this, true, NetworkXLifecycle.Application))
````

## ➀ Step 4:
- To check Internet Connection status, simply call extension variable
`isInternetConnected` or `isInternetConnectedLiveData` or `isInternetConnectedFlow`.
````
isInternetConnectedFlow.collectLatest {
lifecycleScope.launch {
textView.text = "Internet connection status: $it"
}
}
````

- To get connected network speed/last known speed [`LastKnownSpeed`] call extension variable
`lastKnownSpeed` or `lastKnownSpeedLiveData` or `lastKnownSpeedFlow`

````
lastKnownSpeed?.let {
textView2.text ="S-${it.speed}|T-${it.networkTypeNetwork}|SS-${it.simplifiedSpeed}"
}
````

[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png)](#getting-started-quick)

NoInternetDialogV2

- Show Dialog
```kotlin
NoInternetDialogV2(
activity = WeakReference(this@MainActivity),
title = "No Internet Bro",
message = "This is just a dummy message",
buttonTitle = "Okay",
isCancelable = true
) { /* Button Presses */ }
```
- Close Dialog (Forcefully)

```kotlin
NoInternetDialogV2.forceClose()
```
- Determine if the `NoInternetDialogV2` is currently visible or not.

```kotlin
NoInternetDialogV2.isVisible
```

- Show Dialog (Compose Version)

```kotlin
val ui = defaultNoInternetUI()
NoInternetDialogCompose(
true,
ui,
{ /*Dialog Cancelled*/ },
{ /*Dialog closed by user, by pressing action button*/ }
)
```

[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png)](#getting-started-quick)

Notes:

- **NetworkX** (including **Speed Meter**) can work on both **Application** scope or **Activity** scope. If scope is **Activity**, NetworkX will *start/release* it's components based on _ActivityLifecycleCallback_ (**onCreate - onDestroy**). Else, it will *start* it's components only once and there will be no components *release* event.
- To emit (**`MutableStateFlow`**) **Last Known Speed** or **Internet Connection Status**,required **`CoroutineScope`** works under a **`Dispatchers.IO`** context.
- The default value for **Internet Connection Status** is `false`.
- The default value for **LastKnownSpeed** is `NONE`.

[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png)](#getting-started-quick)

## Contact me

βœ” [LinkedIn](https://www.linkedin.com/in/rommansabbir/)

βœ” [Website](https://rommansabbir.com)

[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png)](#getting-started-quick)

### License

[Apache Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html)

````html
Copyright (C) 2022 Romman Sabbir

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
````