Skip to content

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

Notifications You must be signed in to change notification settings

rommansabbir/NetworkX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

50 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

NetworkX

-----------------------------------------------------

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.

-----------------------------------------------------

Installation

➀ Step 1:

Add the JitPack repository to your build file .

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

➀ Step 2:

Add the dependency.

    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}"
    }

-----------------------------------------------------

NoInternetDialogV2

  • Show Dialog
    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)
    NoInternetDialogV2.forceClose()
  • Determine if the NoInternetDialogV2 is currently visible or not.
    NoInternetDialogV2.isVisible
  • Show Dialog (Compose Version)
    val ui = defaultNoInternetUI()
    NoInternetDialogCompose(
      true,
      ui,
      { /*Dialog Cancelled*/ },
      { /*Dialog closed by user, by pressing action button*/ }
    )

-----------------------------------------------------

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.

-----------------------------------------------------

Contact me

βœ” LinkedIn

βœ” Website

-----------------------------------------------------

License

Apache Version 2.0

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.

About

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

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages