This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Add these lines inside your MainActivity. | |
if (Build.VERSION.SDK_INT >= 30) { | |
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { view, windowInsets -> | |
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) | |
// Apply the insets as a margin to the view. Here the system is setting | |
// only the bottom, left, and right dimensions, but apply whichever insets are | |
// appropriate to your layout. You can also update the view padding | |
// if that's more appropriate. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val words = "H,e,l,l,o w,o,r,l,d,H,e,l,l,o w,o,r,l,d".split(',') | |
val frequenciesofChars = words.groupingBy { it }.eachCount() | |
println("Counting frequencies letters:") | |
println(frequenciesofChars) | |
//Counting frequencies letters:: | |
//{H=2, e=2, l=6, o w=2, o=2, r=2, d=2} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MutableStack<E>(vararg items: E) { | |
private var elements = items.toMutableList() | |
fun push(element: E) = elements.add(element) | |
fun peek(): E = elements.last() | |
fun pop(index: Int): E = elements.removeAt(index) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val intList = mutableListOf(1, 2, 3, 4, 5, 6, 7) | |
val filtered = intList.filter { | |
it % 2 == 0 | |
} | |
println(filtered)///[2, 4, 6] | |
val mapped = intList.map { | |
it * it | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
val sumResult = calculate(4, 5, ::sum) //sumResult 9, | |
val mulResult = calculate(4, 5) { a, b -> a * b } // mulResult 20 | |
println("sumResult $sumResult, mulResult $mulResult") | |
} | |
fun calculate(x: Int, y: Int, operation: (Int, Int) -> Int): Int { | |
return operation(x, y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
printMessage("Hello") | |
printMessageWithPrefix("Hello", "World") | |
sum(4, 5) | |
multiply(4, 5) | |
} | |
fun printMessage(message: String) { | |
println(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
//var can be reassigned | |
var varInt: Int = 1 | |
var varString: String = "Hello" | |
var varDouble: Double = 24.0 | |
var varLong: Long = 30L | |
//val can't be reassigned | |
val valInt: Int = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//interface | |
interface CoroutineDispatcherProvider { | |
val main: CoroutineDispatcher | |
val io: CoroutineDispatcher | |
val default: CoroutineDispatcher | |
val unconfirmed: CoroutineDispatcher | |
} | |
//initialization using "by lazy" | |
open class RealCoroutineDispatcherProvider : CoroutineDispatcherProvider { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.util.Log | |
import com.currency.domain.CurrencyConverter | |
import io.ktor.client.* | |
import io.ktor.client.engine.android.* | |
import io.ktor.client.plugins.* | |
import io.ktor.client.plugins.contentnegotiation.* | |
import io.ktor.client.plugins.logging.* | |
import io.ktor.client.plugins.observer.* | |
import io.ktor.serialization.kotlinx.json.* | |
import kotlinx.serialization.json.Json |
OlderNewer