Skip to content

Instantly share code, notes, and snippets.

@dandvl
dandvl / SnackbarSample.kt
Created January 5, 2023 18:57
SnackBar with Jetpack Compose
import android.util.Log
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Scaffold
import androidx.compose.material.SnackbarResult
import androidx.compose.material.rememberScaffoldState
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
@dandvl
dandvl / MainActivity.kt
Created December 22, 2022 06:00
Async on Android
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.system.measureTimeMillis
class MainActivity : AppCompatActivity() {
@dandvl
dandvl / MainActivity.kt
Last active December 22, 2022 06:01
CR Launch Android
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.system.measureTimeMillis
class MainActivity : AppCompatActivity() {
@dandvl
dandvl / MainActivity.kt
Last active December 21, 2022 00:04
Foreground Services w WorkManager
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val constraints = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.setRequiresStorageNotLow(true)
.build()
@dandvl
dandvl / MainActivity.kt
Created December 20, 2022 22:03
Simplest WorkManager
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.work.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
@dandvl
dandvl / Async.kt
Last active December 12, 2022 02:53
fun main() = runBlocking(Dispatchers.Default) {
val j = GlobalScope.launch {
val m = measureTimeMillis {
val answer1 = async { networkCall() }
val answer2 = async { networkCall2() }
println(answer1.await())
println(answer2.await())
}
println("m: $m")
@dandvl
dandvl / Description.md
Last active April 11, 2022 03:42
Setting up a Toolbar

In the begging android had the Action Bar as an App bar (that's why remove on the manifest) but more features were added to the Toolbar. available now in this library. 'androidx.appcompat:appcompat:1.4.1'

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import com.google.android.material.snackbar.Snackbar
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
class MyViewModel {
val result = liveData {
emit(doComputation)
}
}
//implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0"
@dandvl
dandvl / clean_code.md
Created December 9, 2020 03:48 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules