NetworkX

Additional

Language
Kotlin
Version
4.2.0 (Nov 25, 2022)
Created
Jul 26, 2020
Updated
Nov 27, 2022 (Retired)
Owner
Romman Sabbir (rommansabbir)
Contributors
Romman Sabbir (rommansabbir)
Saeid Lotfi (saeed-lotfi)
2
Activity
Badge
Generate
Download
Source code

⚡ 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.