Skip to content

Instantly share code, notes, and snippets.

View magdamiu's full-sized avatar

Magda Miu magdamiu

View GitHub Profile
@magdamiu
magdamiu / build.gradle
Created December 28, 2020 21:41
Add swiperefreshlayout dependency
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
@magdamiu
magdamiu / RecyclerViewClickAndLongClick.java
Created May 20, 2023 11:02
RecyclerView Click and LongClick Handling
// STEP 1 - create new file
public interface ClickListener {
public void onClick(View view, int position);
public void onLongClick(View view, int position);
}
// STEP 2 - create new file
import android.content.Context;
@magdamiu
magdamiu / UsersRepository.java
Last active May 6, 2023 09:46
Repository for the users
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class UsersRepository {
@magdamiu
magdamiu / gradient.xml
Last active February 19, 2023 17:43
Gradient with Animation
// gradients
// gradient_1.xml in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="225"
android:endColor="#1a2980"
android:startColor="#26d0ce" />
</shape>
@magdamiu
magdamiu / CameraXSample.kt
Created August 8, 2020 19:04
Smile, it’s CameraX! [preview and capture] | Capture - Step 1: create ImageCapture reference
val imageCapture = ImageCapture.Builder().build()
// SETUP CAPTURE MODE
// to optimize photo capture for quality
val captureMode = ImageCapture.CAPTURE_MODE_MAXIMIZE_QUALITY
// to optimize photo capture for latency (default)
val captureMode = ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY
imageCapture = ImageCapture.Builder()
@magdamiu
magdamiu / CameraXSample.kt
Last active August 9, 2022 11:14
Setup FPS for ImageAnalysis
fun applyFrameRateOnImageAnalysis(): ImageAnalysis {
val imageAnalysisBuilder = ImageAnalysis.Builder()
val camera2InterOp = Camera2Interop.Extender(imageAnalysisBuilder)
camera2InterOp.setCaptureRequestOption(
CaptureRequest.CONTROL_AE_MODE,
CaptureRequest.CONTROL_AE_MODE_OFF
)
camera2InterOp.setCaptureRequestOption(
CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE,
Range(60, 60)
@magdamiu
magdamiu / CollectionsVsSequences.kt
Created December 17, 2021 14:54
Collections vs Sequences
var someNumbers = listOf(1, 4, 5, 6, 7, 8, 2323, 5456, 343, 2)
someNumbers
.filter { it % 2 == 0 }
.map { it * 3 }
.sum()
someNumbers
.asSequence()
.filter { it % 2 == 0 }
.map { it * 2 }
@magdamiu
magdamiu / SealedClass.kt
Created December 17, 2021 14:48
Sealed class in Kotlin
sealed class Fruit(val name: String) {
class Apple : Fruit("Apple")
class Mango : Fruit("Mango")
}
class Pomegranate : Fruit("Pomegranate")
fun display(fruit: Fruit) {
when (fruit) {
is Fruit.Apple -> println("${fruit.name} is good for iron")
@magdamiu
magdamiu / StringTemplates.kt
Created December 17, 2021 13:56
String templates | High performance with idiomatic Kotlin
val displayContentWithTemplate = "Hello $firstName! Please confirm that $email is your email address."
@magdamiu
magdamiu / UseFunction.kt
Created December 17, 2021 13:50
Disposable pattern to avoid resource leaks | High performance with idiomatic Kotlin
inputStream.use {
outputStream.use {
// do something with the streams
outputStream.write(inputStream.read())
}
}
// improved option
arrayOf(inputStream, outputStream).use {
// do something with the streams