Coder Social home page Coder Social logo

netlistener's Introduction

NetListener

An android library to implement listener for network and internet connection.

Demo app photos and video

Screen.Recording.2021-03-08.at.14.01.17.mov

Screenshot 2021-03-08 at 14 00 35

Screenshot 2021-03-08 at 14 00 00

Screenshot 2021-03-08 at 13 59 32

Implementation

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.hansaray:NetListener:0.1.0'
}

Usage

Listener usage:

Step1: Ideally initialize observer in onResume or onStart methods.

    NetListener.observer(MainActivity.this)
            .setSnackBarEnabled(true)
            .setCallBack(this)
            .setSensitivity(4)
            .
            .
            .
            .build();

Step2: Unregister the NetListener onDestroy method.

    NetListener.unregister(MainActivity.this);

Step3: Implement the interface for listener.

   public class MainActivity extends AppCompatActivity implements InternetConnectionListener

Step4: Implement override methods.

   @Override
    public void onConnected(int source) {
    
   }

   @Override
   public View onDisconnected() {
       return layout_you_want_to_show_the_snackbar_on;
   }

Checking the connection once:

   boolean connected = NetListener.isInternetConnected(getApplicationContext());

Settings and methods

   .setSnackBarEnabled(true) //While instant listening, you can enable/disable snackbar, by default it's enabled.
   .setBackground(snackbar_shape) //You can set snackbar background, by default it's red,rectangle with rounded corners.
   .setTextColor(white) //You can set text color, by default it's white.
   .setIcon(ic_no_internet) //You can set icon for snackbar when there is no internet.
   .setLogsEnabled(false) //You can enable/disable logs for testing, by default it's false.
   .setSnackBarCancelable(false) //You can set snackbar cancelable or not, by default it's false.
   .setSnackBarDuration(Snackbar.LENGTH_INDEFINITE) //You can set snackbar duration, by default it's indefinite.
   .setCallBack(this) //Setting call back activity which implemented the interface.
   .setSensitivity(4) //Setting ping sending sensitivity to determine internet connection.
   .setMessage(R.string.no_internet) //You can set message to show on snackbar when there is no internet.
   
   NetListener.isInternetConnected(context) //Returns internet connection status at the moment
   NetListener.isActive(context) //Returns status of NetListener if it's active or not
   NetListener.getConnectionType(context) //Returns internet connection type at the moment. Wifi,Cellular or Vpn.

netlistener's People

Contributors

hansaray avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.