Skip to content

Instantly share code, notes, and snippets.

View NsAveek's full-sized avatar
🏠
Working from home

Aveek NsAveek

🏠
Working from home
View GitHub Profile
// having "with"
with(viewModel){
val balanceText = this.balanceText
val category = this.category.run {
value = false
}
}
// without using "with"
val balanceText = viewmodel.balanceText
// Without run
fun printPersonName(person : Person){
print(person.name)
}
// With run
fun printPersonName(person : Person) = person.run{
print(name)
}
// Without Let
if(person!=null){
doSomething()
}
// With Let
person?.let{
doSomething()
}
val person = Person().apply{
name = "aveek"
tel = "+98234552344"
}.also{
Log.d("test",it.name)
}
activity.setResult(Activity.RESULT_OK, Intent().apply { // this:intent
putExtra("response", true)
putExtra("message", "success")
putExtra("result", "ok")
})
activity.setResult(Activity.RESULT_OK, Intent().also { // it:intent
it.putExtra("response", true)
it.putExtra("message", "success")
it.putExtra("result", "ok")
const val addFragment = 1
const val replaceFragment = 2
private inline fun generateFragmentTransaction(fragmentToReplaceOrAdd : Fragment, addOrReplace: Int) : FragmentTransaction {
return when(addOrReplace) {
addFragment -> supportFragmentManager.beginTransaction().add(R.id.container_frame, fragmentToReplaceOrAdd)
else -> supportFragmentManager.beginTransaction().replace(R.id.container_frame, fragmentToReplaceOrAdd)
}
}
private fun fragmentAddOrReplacer(name : String, transaction : ()-> FragmentTransaction){
transaction().apply {
/** Represents Module for Test Management
* @author Aveek
* @author www.myproject.com
* @version 1
* @since 4.4.0 - Version
*/
@Module
internal class TestModule (val context : TestManagement) {
/**
* provides viewModel of the XML
@NsAveek
NsAveek / BaseStrategy.kt
Last active March 6, 2019 15:01
Interface for Strategy Design Pattern
interface IBaseStrategy {
fun isEnable(enable : Boolean)
}
interface IPendingStrategy : IBaseStrategy{
}
interface IErrorStrategy : IBaseStrategy{
var OnReUpload : (result : Result)-> Unit
}
interface IManageStrategy : IBaseStrategy{
@NsAveek
NsAveek / BaseContext.kt
Created March 2, 2019 16:28
A class that contains the Base Context and interfaces for handling the States
class BaseContext(private var state: IBaseState) {
fun getState(): IBaseState {
return state
}
}
interface IBaseState {
fun setPackageExpiryVisibility()
}
interface IState1 : IBaseState {
@NsAveek
NsAveek / StateClass.kt
Last active March 2, 2019 16:24
State Classes that extends from Base interface
class State1 : IState1 {
var featureAvailable = false
private set
get() = field
var totalFeature = ""
private set
get() = field
var consumedFeature = ""
private set