Material Util Project For Kotlin
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>"
}
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:
tvName.show()
pbMain.show()
tvName.hide()
pbMain.hide()
etName.showKeyboard()
etName.hideKeyboard()
toast("Your message here")
context?.toast("Your message here")
findNavController(binding.navMainFragment.id)
start(Intent(this, AuthActivity::class.java))
startAndFinish(Intent(this, AuthActivity::class.java))
val sharedPref = SharedPref(context)
val name = sharedPref.read(YOUR_KEY, DEFAULT_VALUE)
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)
sharedPref.write(YOUR_KEY, "dutchman")
String
sharedPref.write(YOUR_KEY, "dutchman")
Int
sharedPref.write(YOUR_KEY, 704)
Boolean
sharedPref.write(YOUR_KEY, true)
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")
}
})
}