Skip to content

Instantly share code, notes, and snippets.

View MortezaNedaei's full-sized avatar
🏠
Working from home

MoNe MortezaNedaei

🏠
Working from home
View GitHub Profile
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Build;
import android.text.Editable;
import android.util.AttributeSet;
import android.util.TypedValue;
@MortezaNedaei
MortezaNedaei / Context-Receiver.md
Last active March 29, 2022 09:31
Android Context Receivers

❓ What is Context Receiver? ✅ Context-registered receivers, receive broadcasts as long as their registering context is valid. For an example, if you register within an Activity context, you receive broadcasts as long as the activity is not destroyed. If you register with the Application context, you receive broadcasts as long as the app is running.

❓ What is Multiple Receiver concept? ✅ With Kotlin 1.6.20-M1, you are no longer limited to having one receiver. If you need more, you can make functions, properties, and classes context-dependent (or contextual) by adding context receivers to their declaration.

❓ Can you explain more? ✅ Visit Jetbrains

@MortezaNedaei
MortezaNedaei / Backing-Field.md
Created April 1, 2022 07:45
Kotlin Backing Field

❓ What is Kotlin Backing Field? :white_check_mark: A Backing Field is just a field that will be generated automatically for a property in a class only if it uses the default implementation of at least one of the accessors(getter/setter). :question: Can you give me an example? 🐝 Consider this Kotlin class:

class DummyClass {
    var size = 0;
    var isEmpty
        get() = size == 0
        set(value) {
@MortezaNedaei
MortezaNedaei / Kotlin-SAM-Conversion.md
Last active April 14, 2022 09:08
Kotlin SAM Conversion (SAM Interface)

❓ What is Kotlin SAM and fun interface?

✅ fun interface is Kotlin definition of Java functional interface. Kotlin can sugarize any Java Functional interfaces (interfaces with only one abstract member) into lambdas to leverage interoperability. This process is called SAM Conversion.

⁉️ Usage: It can help make your code more concise and readable by using lambda expressions.

⚠️ Tip: suspend function cannot be used as a SAM

⚡️ Examples: Comparator, ReadOnlyProperty, PropertyDelegateProvider interfaces

@MortezaNedaei
MortezaNedaei / OkHttp-NewBuilder.md
Created April 17, 2022 14:23
How to change already existed OkHttp Client instance for other purposes?

❓ How to change already existed OkHttp Client instance for other purposes?

✅ You can customize a shared OkHttpClient instance with newBuilder().

This builds a client that shares the same connection pool, thread pools, and configuration. Use the builder methods to configure the derived client for a specific purpose.

👀 Sample:

OkHttpClient eagerClient = client.newBuilder()
 .readTimeout(500, TimeUnit.MILLISECONDS)