Skip to content

ma-za-kpe/LiveDataNetworkUtil

Repository files navigation

LiveDataNetworkUtil

A simple Android Livedata network library.

Android CI License

Modules

The networkUtil module is the fundamental module that you need in order to use this library.

Please note that this library only supports Kotlin.

Step 1: Add it in your root build.gradle at the end of repositories:

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

Step 2: Add the dependency

    dependencies {
	        implementation 'com.github.ma-za-kpe:LiveDataNetworkUtil:0.2.1'
	}

Example

   private fun handleNetwork() {
        NetworkUtil.getNetworkLiveData(applicationContext).observe(this, { isConnected ->
            if (!isConnected) {
                Toast.makeText(this, "no internet", Toast.LENGTH_SHORT).show()
            } else {
                Toast.makeText(this, "internet available", Toast.LENGTH_SHORT).show()
            }
        })
    }
  • An implementation from the example project can be found here

Article can be found here Network Util