View StandardFunctionWith.kt
// having "with" | |
with(viewModel){ | |
val balanceText = this.balanceText | |
val category = this.category.run { | |
value = false | |
} | |
} | |
// without using "with" | |
val balanceText = viewmodel.balanceText |
View StandardFunctionRun.kt
// Without run | |
fun printPersonName(person : Person){ | |
print(person.name) | |
} | |
// With run | |
fun printPersonName(person : Person) = person.run{ | |
print(name) | |
} |
View StandardFunctionWithOrWithoutLet.kt
// Without Let | |
if(person!=null){ | |
doSomething() | |
} | |
// With Let | |
person?.let{ | |
doSomething() | |
} |
View StandardFunctionApplyAlso.kt
val person = Person().apply{ | |
name = "aveek" | |
tel = "+98234552344" | |
}.also{ | |
Log.d("test",it.name) | |
} |
View ScopingFunctionsApplyAlso.kt
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") |
View InlineFunctions.kt
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 { |
View SampleDocumentationClass.kt
/** 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 |
View BaseStrategy.kt
interface IBaseStrategy { | |
fun isEnable(enable : Boolean) | |
} | |
interface IPendingStrategy : IBaseStrategy{ | |
} | |
interface IErrorStrategy : IBaseStrategy{ | |
var OnReUpload : (result : Result)-> Unit | |
} | |
interface IManageStrategy : IBaseStrategy{ |
View BaseContext.kt
class BaseContext(private var state: IBaseState) { | |
fun getState(): IBaseState { | |
return state | |
} | |
} | |
interface IBaseState { | |
fun setPackageExpiryVisibility() | |
} | |
interface IState1 : IBaseState { |
View StateClass.kt
class State1 : IState1 { | |
var featureAvailable = false | |
private set | |
get() = field | |
var totalFeature = "" | |
private set | |
get() = field | |
var consumedFeature = "" | |
private set |
NewerOlder