NetworkPro

Additional

Language
Java
Version
1.2 (Mar 16, 2018)
Created
Jan 19, 2018
Updated
Mar 16, 2018
Owner
Periyanayagam
Contributor
Periyanayagam
1
Activity
Badge
Generate
Download
Source code
APK file

Blurb

NetworkPro

Simple library to handle network connections in different views in just few lines of code. Primary goal of this library is to simplify the overall process in few lines of code. More options and customization available in code.

Usage

First and foremost in AndroidManifest file register broadcast receiver

<receiver
         android:name="com.perusudroid.networkchecker.broadcast.NetworkManager"
         android:enabled="true"
         android:exported="true">
         <intent-filter>
             <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
             <action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
         </intent-filter>
     </receiver>

Make sure to use permission

   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
   <uses-permission android:name="android.permission.INTERNET" />

To handle network connections within activity

new NetworkManager.Builder()
                      .callback(this) // INetworkListener methods will be trigged on network connection/disconnection
                      .build();

To show toast message

         new NetworkManager.Builder()
             .showMessage()  // show default toast message to user
              .build();

To show toast with custom message

new NetworkManager.Builder()
           .showCustomMessage(getString(R.string.tst_network_connected), getString(R.string.tst_netword_disconnected)) 
           .build();

To show snackbar

         new NetworkManager.Builder()
              .showSnack(this) // show default snackbar message
              .build();

To show snackbar with custom message

          new NetworkManager.Builder()
           .showCustomSnack(this, getString(R.string.snk_network_connected), getString(R.string.snk_netword_disconnected), Color.WHITE, Color.BLACK, Color.RED, Color.GREEN) 
            .build();

To show alert dialog

        new NetworkManager.Builder()
            .showAlert(this, this) // show default alert message
             .build();

To show alert dialog with custom message and actions

         new NetworkManager.Builder()
           .showCustomAlert(this, "Network has been disconnected", this) // show custom alert
           .build();

To load activity with default message and action

      new NetworkManager.Builder()
            .loadPage() // load activity
            .build();

To load activity with custom message and action

          new NetworkManager.Builder()
             .loadCustomPage(Constants.networkMsg.DISCONNECTED_PAGE, false, true) //load activity with custom message
            .build();

Download

Step 1. Add the JitPack repository to your build file 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.Periyanayagam:NetworkPro:1.1'
}

Kindly check in your device and if any issues, post in issue section. Will be fixed and updated.