Skip to content

dutchmanbd/materialutils

Repository files navigation

MaterialUtils

Build Status Codacy Badge GitHub issues Version

Material Util Project For Kotlin

Get Started

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

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

Add the dependency

dependencies {
	implementation "com.github.dutchmanbd:materialutils:<latest_version>"
}

View Extensions

How to use

Suppose you have some views like as TextView, ProgressBar. If TextView ID is tvName and ProgressBar ID is pbMain. Then you can easily show and hide those views using following code:

Show views:

tvName.show()
pbMain.show()

Hide views:

tvName.hide()
pbMain.hide()

Show keyboard:

etName.showKeyboard()

Hide keyboard:

etName.hideKeyboard()

Context Extension

Show toast from activity

toast("Your message here")

Show Toast from fragment

context?.toast("Your message here")

findNavigationController in activity

findNavController(binding.navMainFragment.id)

start and startAndFinish activity

start(Intent(this, AuthActivity::class.java))
startAndFinish(Intent(this, AuthActivity::class.java))

SharedPreference

Init SharedPref

val sharedPref = SharedPref(context)

Read data from sharedPref

val name = sharedPref.read(YOUR_KEY, DEFAULT_VALUE)

DEFAULT_VALUE must be String, Int, Boolean

Example

String
val name: String = sharedPref.read(YOUR_KEY, "")
Int
val id: Int = sharedPref.read(YOUR_KEY, 0)
Boolean
val isAvailable: Boolean = sharedPref.read(YOUR_KEY, false)

Write data to sharedPref

sharedPref.write(YOUR_KEY, "dutchman")

Example

String
sharedPref.write(YOUR_KEY, "dutchman")
Int
sharedPref.write(YOUR_KEY, 704)
Boolean
sharedPref.write(YOUR_KEY, true)

Network Connection

observe network connection realtime in activity or fragment

Example

private var netConnection: NetworkConnection? = null
override fun onCreate(savedInstanceState: Bundle?) {
    netConnection = NetworkConnection(applicationContext)
    netConnection?.observe(this, Observer { hasConnected ->
        if(hasConnected){
            toast("connected")
        } else {
            toast("disconnected")
        }
    })
}

About

Material Util Project Demo

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages