Skip to content

Instantly share code, notes, and snippets.

View balsikandar's full-sized avatar
💭
Working on React native and Android as the Team Lead of Carwale

BAL SIKANDAR balsikandar

💭
Working on React native and Android as the Team Lead of Carwale
View GitHub Profile
@balsikandar
balsikandar / StudentDSL.kt
Created January 19, 2020 19:59
Kotlin DSL an improvement over Builder pattern
class Student(
val name: String?,
val standard: Int,
val rollNumber: Int
) {
private constructor(builder: Builder) : this(builder.name, builder.standard, builder.rollNumber)
companion object {
inline fun student(block: Student.Builder.() -> Unit) = Student.Builder().apply(block).build()
fun main() {
val carDealer = CarDealer()
println(carDealer.getSpeed(VehicleTypes.BUS))
}
class CarDealer {
val map = HashMap<VehicleTypes, Vehicle>()
init {
map.put(VehicleTypes.CAR, Car())
if (pickupSelected && dropSelected) return gotoNextPage()
var msg: String? = "Please select pickup location"
if (selectedTab === "PICKUP_POINT" && pickupSelected) {
goToDrop()
msg = null
}
msg = msg ?: "Please select drop location"
if (selectedTab === "DROP_POINT" && dropSelected) {
if (pickupSelected && dropSelected) return gotoNextPage()
if (selectedTab === "PICKUP_POINT") {
if (pickupSelected) {
goToDrop();
} else {
toast("Please select pickup location")
}
}
fun main() {
if (pickupSelected && dropSelected) return gotoNextPage()
if (selectedTab === "PICKUP_POINT") {
verifyPickup(pickupSelected)
}
if (selectedTab === "DROP_POINT") {
verifyDropOff(dropSelected)
}
if (pickupSelected && dropSelected) {
return gotoNextPage();
}
if (selectedTab === "PICKUP_POINT") {
if (pickupSelected) {
goToDrop();
} else {
toast("Please select pickup location")
}
if (pickupSelected && dropSelected) {
gotoNextPage();
} else if (selectedTab === "PICKUP_POINT") {
if (pickupSelected) {
goToDrop();
} else {
toast("Please select pickup location")
}
} else {
if (dropSelected) {
getCurrencyNameOf("UK")
fun getCurrencyNameOf(country: String): String {
return if (country == "India") {
"Rupee"
} else if (country == "USA") {
"Dollars"
} else if (country == "UK") {
"Euro"
} else if (country == "Japan") {
class Currency {
val map = HashMap<String, String>();
init {
map.put("India", "Rupee")
map.put("UK", "Euro")
map.put("Japan", "Yen")
map.put("USA", "Dollar")
map.put("China", "Yuan")
}
try {
val intent = Intent()
val manufacturer = Build.MANUFACTURER
if ("xiaomi".equals(manufacturer, ignoreCase = true)) {
intent.component = ComponentName(
"com.miui.securitycenter",
"com.miui.permcenter.autostart.AutoStartManagementActivity"
)
} else if ("oppo".equals(manufacturer, ignoreCase = true)) {
intent.component = ComponentName(