Skip to content

NitinPraksash9911/floating-loader-button

Repository files navigation


Generic badge Generic badge made-with-kotlin Generic badge Github Downloads (total) GitHub license contributions welcome

Floating Loader Button

Android library to show circular loader within floating button

Requirements

  • Android Studio
  • MinSdk 16

Integration

Step.1 add jitpack to project level build.gradle

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

Step.2 add dependency to module level build.gradle

dependencies {
    implementation 'com.github.NitinPraksash9911:floating-loader-button:1.x.x'
}

Create view in xml

  <in.nitin.library.FloatingLoaderButton
        android:id="@+id/floatingLoaderBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:loaderBackgroundColor="#50CCDF"
        app:loaderFabSize="Medium"
        app:loadingIconColor="#FFD600"
        app:loadingStatus="None" />

Attrs

Name Values
app:loaderBackgroundColor to change the FloatingLoaderButton background color & by default background color is black
app:loaderFabSize to change the size of FloatingLoaderButton & it's available in three sizes Medium, Small, & Large choose one from these
app:loadingIconColor to change the arrow-icon color and by default arrow-icon color is white
app:loadingStatus use to define the state of loader & it has three states 1. None for initial stage when doing nothing, 2. Loading to start circular loading, 3. Finish to stop circular loading (recommended to use None in xml and set the loader state programmatically) and you can use these states to change the loader state in xml when using data binding

Size

Large Medium Small

Kotlin

This below example shows only how you can use FloatingLoaderButton when calling an api and you can also use this anywhere where something going to take some time in andorid application such as Background Task, Database Operation, Network Operation etc...

 val floatingLoaderButton: FloatingLoaderButton = findViewById<FloatingLoaderButton>(R.id.floatingLoaderBtn)
    
        floatingLoaderButton.setOnClickListener {

            // to start circular animation when api call starts
            floatingLoaderButton.setLoadingStatus(FloatingLoaderButton.LoaderStatus.LOADING)

            val apiInterface = ApiInterface.create().getData()
            
            apiInterface.enqueue(object : Callback<List<Data>> {
            
                override fun onResponse(call: Call<List<Data>>?, response: Response<List<Data>>?) {

                    if (response?.body() != null)
                        recyclerAdapter.setData(response.body()!!)
                       
                    // to stop circular animation when api call success
                    floatingLoaderButton.setLoadingStatus(FloatingLoaderButton.LoaderStatus.FINISH)
                }

                override fun onFailure(call: Call<List<Data>>?, t: Throwable?) {

                    //to stop circular animation when api call fails
                    floatingLoaderButton.setLoadingStatus(FloatingLoaderButton.LoaderStatus.FINISH)

                }
            })
        }

Proguard

In order to use this library with proguard you need to add this line to your proguard.cfg:

-keep class `in`.nitin.library.FloatingLoaderButton.** { *; }

Developed By

📄 License

Floating Loader Button is released under the Apache 2.0 license. See LICENSE for details.

Copyright 2020 Nitin Prakash

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.