Version 2 of Oops! No Internet! library released!

Md. Mahmudul Hasan Shohag
3 min readJan 21, 2021

I am very excited to introduce version 2 of the Oops! No Internet! Android library.

Photo by brandon siu on Unsplash

In this new version, we’ve restructured and refactored the whole library. The library is now using a lifecycle-aware component to show & hide the dialogs and snackbars, which will reduce code and many unexpected crashes. We’ve also introduced a ready-to-use lifecycle-aware component. Which will make it easy to create any new components/elements to automatically do things based on the Internet connectivity change. The library also now dark-mode ☀️ 🌘 ready.

A short introduction… 🚀

Dialogs

As the entire library has been restructured, we’ve changed NoInternetDialog to NoInternetDialogPendulum . We’ve created a brand new dialog called NoInternetDialogSignal . Both are dark-mode ready 😃.

Preview of NoInternetDialogPendulum
Preview of NoInternetDialogSignal

Snackbar

We’ve added a new snackbar named NoInternetSnackbarFire .

Preview of NoInternetSnackbarFire

Lifecycle-Aware Component

We’ve created NoInternetObserveComponent , which is a lifecycle-aware component. It can be used to create any custom no internet alert component like dialog, snackbar, etc. with ease. So, the components will show-hide automatically and will be created and destroy based on the application lifecycle.

We’ve also provided a ready to use BaseNoInternetDialog class, so anyone can quickly create custom no internet dialog without any complexity.

We are now using the Maven repository for our library 😎 Yeaaa…

No extra repository is required for using the library! We hosted our library at the Maven repository. So you can use the library just by adding the library as a dependency.

How to use… 🤨

As we are now using a lifecycle-aware component, the usage of the library is super ⚡ simple.

First, add the dependency in your project-level build.gradle file:

android {

// ...

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

}

dependencies {
// ...

// Material Components for Android. Replace the version with the latest version of Material Components library.
implementation 'com.google.android.material:material:x.x.x'

implementation 'org.imaginativeworld.oopsnointernet:oopsnointernet:x.x.x'
}

Replace x.x.x with the latest versions.

Notes:

  • 0. Minimum SDK for this library is API 21 (Android 5.0 Lollipop).
  • 1. Your application has to use AndroidX to use this library.
  • 2. You have to use *.MaterialComponents.* in your styles.

Finally, Just initialize any of the NoInternetDialog* and/or NoInternetSnackbar* using the builder in onCreate(), that's all! 😃

The NoInternetDialog* and/or NoInternetSnackbar* will then automatically appear when no active Internet connection found and disappear otherwise.

// Kotlin
class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// ...

// No Internet Dialog: Pendulum
NoInternetDialogPendulum.Builder(
this,
lifecycle
).build()


// No Internet Dialog: Signal
NoInternetDialogSignal.Builder(
this,
lifecycle
).build()


// No Internet Snackbar: Fire
NoInternetSnackbarFire.Builder(
binding.mainContainer,
lifecycle
).build()

}
}

Details short examples with customizable attributes can be found here and The sample project can be found here.

The examples for custom dialog and tutorial for NoInternetObserveComponent are coming soon. Though for now, you can check out the library source code for detailed usage 😉.

What next… 🤔

Use it… Clone it… Fork it… Check out the library source-code… Give suggestions, ideas, PRs...

Finally, share the library with your friends and colleagues 😁.

--

--