View SOLID Principle by example
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
Single Responsibility principle | |
------------------------------- | |
class Invoice(){ | |
fun AddInvoice(){} | |
fun DeleteInvoice(){} | |
fun GenerateReport(){} | |
fun otherReportRelatedTask(){} | |
fun EmailReport(){} | |
fun otherEmailRelatedTask(){} | |
} |
View Room relation
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
//one-to-many relation | |
@Entity(tableName = "TicketGroup") | |
data class TicketGroup( | |
@PrimaryKey(autoGenerate = false) | |
val groupId: Int, | |
val groupName: String, | |
) | |
@Entity(tableName = "Ticket") | |
data class Ticket( |
View validation using custom annotation
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 MainActivity : AppCompatActivity(), ConstraintValidatorContext { | |
lateinit var edt: EditText | |
lateinit var btn: Button | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
edt = findViewById(R.id.edt) |
View rememberSaveable
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
************************************************************************************************************************************ | |
restore state of list of Int, String using rememberSaveable | |
************************************************************************************************************************************ | |
import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.saveable.listSaver | |
import androidx.compose.runtime.saveable.rememberSaveable | |
import androidx.compose.runtime.snapshots.SnapshotStateList | |
import androidx.compose.runtime.toMutableStateList | |
View Multi-Device Preview
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
@Preview(group = "phone", name = "light", device = Devices.PIXEL_4_XL, showSystemUi = true) | |
@Preview( | |
group = "phone", | |
name = "dark", | |
uiMode = UI_MODE_NIGHT_YES, | |
device = Devices.PIXEL_4_XL, | |
showSystemUi = true, | |
showBackground = true | |
) | |
annotation class Phone |
View Flow Demo
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
*********************************************************StateFlow Demo************************************************************** | |
Step-1) build.gradle | |
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.6" | |
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.6" | |
Step-2) data class | |
data class Resource<out T>(val status: Status, val data: T?, val message: String?) { | |
companion object { |
View Interceptors
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
Gzip interceptors = for data compression | |
public class GzipRequestInterceptor implements Interceptor { | |
@Override | |
public Response intercept(Chain chain) throws IOException { | |
Request originalRequest = chain.request(); | |
if (originalRequest.body() == null || originalRequest.header("Content-Encoding") != null) { | |
return chain.proceed(originalRequest); | |
} | |
Request compressedRequest = originalRequest.newBuilder() |
View to get foldable postures
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
//WindowStateUtils.kt | |
/** | |
* Information about the posture of the device | |
*/ | |
sealed interface DevicePosture { | |
object NormalPosture : DevicePosture | |
data class BookPosture( | |
val hingePosition: Rect | |
) : DevicePosture |
View App.kt
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 sharedApplicationContext: Context get() = sharedApplicationContextBackingProperty | |
?: throw IllegalStateException( | |
"Application context not initialized yet." | |
) | |
private var sharedApplicationContextBackingProperty: Context? = null | |
class App : Application() { | |
override fun onCreate() { | |
super.onCreate() |
View interview programs
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
************************************************************************************************************************************** | |
Sort without sort function | |
************************************************************************************************************************************** | |
val numbers = mutableListOf(4, 8, 32, 2, 5, 8) | |
var temp: Int | |
for (i in 0 until numbers.size) { | |
for (j in i + 1 until numbers.size) { | |
if (numbers[i] > numbers[j]) { | |
temp = numbers[i] |
NewerOlder