분류 전체보기(80)
-
자주 까먹는 compose modifiers
1). border Modifier@Composable fun MakeBorder( modifier: Modifier = Modifier ) { Box(modifier = modifier.fillMaxSize(), contentAlignment = Alignment.Center) { Spacer( modifier = Modifier .border( color = Color.Red, width = 2.dp, shape = CircleShape ) .size(100.dp) ) } }2). horizontalScroll Modifier@Composable fun HorizontalScroll( modifier: Modifier = Modifier ) { val scrollState = rememberScrol..
2023.10.23 -
Data store vs Shared preference
DataStoreSharedPreference는 동기적으로 동작. 특히 이의 apply()는 ui스레드를 차단하여 잠재적인 성능 문제를야기할 수 있음 → 대안책 Dispatchers.IO 옵션을 사용하면 ui스레드 안전성을 보장받을 수 있음Proto DataStore코루틴과 플로우를 활용함Preferences DataStore키-밸류 쌍 관리sharedPreferencs의 완벽한 대응책 Interface DataStoreAPIinterface DataStoreAPI { suspend fun getPreferenceValue(key: Preferences.Key,defaultValue: T):T suspend fun putPreferenceValue(key: Preferences.Key,value:T) s..
2023.10.23 -
to clean code (in Kotlin)
Kotlin ContractsCallsInPlace컴파일러가 람다 함수가 호출되는 방식과 해당 매개변수와 상호작용 하는 방식을 이해하는데 도움이 됨AT_MOST_ONCEAT_LEAST_ONCEEXACTLY_ONCEUNKNOWNinline fun customRun(block: () -> T): T { contract { callsInPlace(block, AT_MOST_ONCE) } return block() } InvocationKind호출시 함수가 작동하는 방식을 지정. 옵션은 아래 두 개returns(true)implies(this ≠ null)fun getUserById(id: Int?): User? { contract { returns(true) implies (id != null) } // Yo..
2023.10.23 -
Android APK 크기 줄이기
ProGuard 또는 R8 사용: ProGuard 또는 R8을 사용하여 사용하지 않는 코드를 제거하고 클래스 이름을 바꾸고 APK 크기를 줄입니다.이미지 최적화:품질 저하 없이 이미지를 압축합니다. 예를 들어 OptiPNG, PNGOUT 및 TinyPNG와 같은 도구를 사용하여 PNG 이미지를 최적화하고 JPEGmini를 사용하여 JPEG 이미지를 최적화할 수 있습니다.벡터 그래픽 사용:비트맵 이미지 대신 벡터 그래픽을 사용하여 APK의 크기를 줄입니다. 예를 들어 Android Studio의 Vector Asset Studio를 사용하여 벡터 그래픽을 만듭니다.웹 글꼴 사용:앱에 글꼴을 포함하는 대신 웹 글꼴을 사용합니다. 이렇게 하면 APK 크기를 크게 줄일 수 있습니다. 예를 들어 Google 글꼴..
2023.10.23 -
Deligation을 통한 상태관리 단순화
솔루션: Delegate Classes 🛠️ 우려 사항 분리: 각 기능에 대한 delegate 클래스를 제작함으로써 각 구성 요소를 개별적으로 작업할 수 있어, 테스트 및 개발이 더 쉬워진다 🛠️ 공유 상태 관리: 메인 ViewModel이 중재자 역할을 하고. 분리된 부분을 연결하여 퍼즐을 완성할 수 있다는 것을 알고있음. 이를 통해 오래된 데이터를 무효화하거나, 대규모 저장소를 구축하는 것에 대한 걱정 없이 상태 데이터를 공유할 수 있음 classInRideViewModel ( privateval rideDelegate: RideDelegate, privateval NavigationDelegate: NavigationDelegate ) : ViewModel(), NavigationDelegateby ..
2023.10.23 -
Viewmodel / manage string res
Solution! stringres를 사용하는 방법sealed class AppString{ data class Res(@StringRes val resId: Int, vararg val arguments: Any): AppString() data class Quantity(@StringRes val quantityResId: Int, quantity): AppString data class Text(val value: String): AppString() } 이제 새 AppString클래스는 단일 인터페이스를 제공하여 ViewModel에서 View까지 다양한 유형의 문자열을 정의하는 데 도움이 되며, AppString클래스와 해당 내용이 POJO(또는 POKO)이므로 리소스를 포함할 필요 없이 단위 테..
2023.10.23