Android
-
[Android] Kotlin Coroutines Flow 2주차 (1/2)Android 2021. 8. 11. 17:58
Asynchronous Flow suspend 함수는 비동기적으로 동작하고 단일 값을 반환합니다. Flow는 비동기적으로 여러 개의 값을 반환받고 싶을 때 사용하는 코루틴 빌더입니다. Representing multiple values Collections을 사용하여 여러 개의 값을 반환할 수 있습니다. fun simple(): List = listOf(1, 2, 3) fun main() { simple().forEach { value -> println(value) } } // 1 // 2 // 3 Sequences kotlin builder인 sequence를 사용하여 100ms 간격으로 숫자를 찍습니다. Thread.sleep을 사용하기 때문에 Thread가 blocking 됩니다. fun simp..
-
[Android] Kotlin Coroutines 1주차Android 2021. 7. 28. 17:14
Asynchronous programming techniques 사용자가 사용할 때 기다리거나 병목현상이 발생하는 것을 피하고 싶습니다. 위와 같은 문제를 해결하기 위해서 다음과 같은 방식이 있습니다. Threading 제일 보편적인 방식입니다. fun postItem(item: Item) { val token = preparePost() val post = submitPost(token, item) processPost(post) } fun preparePost(): Token { // makes a request and consequently blocks the main thread return token } 함수가 UI를 차단한다고 한다면 별도의 스레드를 실행해 UI가 차단되는 것을 막을 수 있습니..
-
[Android] Clean Architecture 학습기Android 2021. 6. 7. 11:10
[프로젝트] https://github.com/Minoyam/Clean_Coroutines_Hilt_Sample Minoyam/Clean_Coroutines_Hilt_Sample Contribute to Minoyam/Clean_Coroutines_Hilt_Sample development by creating an account on GitHub. github.com Clean Architecture를 배워보기 위해 간단한 Sample 하나를 만들어 봤습니다. 동작 방식은 Github에 들어가면 확인하실 수 있습니다. p.s : Coroutine flow까지 학습하여 적용을 해보는 것이 목표입니다. Clean Architecture 구조 Clean Architecture를 검색을 하시면 이러한 모양의 ..
-
설계 원칙 - SOLIDAndroid 2021. 3. 30. 13:40
1. SRP (단일 책임의 원칙: Single Responsibility Principle) 소프트웨어 시스템이 가질 수 있는 최적의 구조는 시스템을 만드는 조직의 사회적 구조에 커다란 영향을 받는다. 따라서 각 소프트웨어 모듈은 변경의 이유가 하나, 단 하나여야만 한다. -> 하나의 모듈은 하나의 액터에 대해서만 책임져야 한다. 액터 - 변경을 요청하는 한 명 이상의 사람 징후 1 : 우발적 중복 class Employee(){ fun calculatePay(){ /* 회계팀에서 기능을 정의, CFO 보고를 위해 사용 regularHours() 메서드 사용 */ } fun reportHours(){ /* 인사팀에서 기능을 정의, COO 보고를 위해 사용 regularHours() 메서드 사용 */ } ..
-
[Android] 카카오 로그인 v2 API with kotlin - 2Android 2020. 12. 24. 16:05
https://omod.tistory.com/94 [Android] 카카오 로그인 v2 API with kotlin - 1 카카오 로그인을 공부하면서 사용하는 방법을 정리 해볼까 합니다. 일단 카카오 내어플리케이션에 들어가서 앱을 등록 해줘야합니다. 앱 아이콘에는 앱에 사용할 아이콘 이미지를 넣어 주시면 omod.tistory.com 로그인 구현 부분 입니다. class LoginActivity : BaseActivity(R.layout.activity_login) { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val callback: (OAuthToken?, Throwable?) -> Un..
-
[Android] TextView 부분 글자 바꾸기 (Span)Android 2020. 12. 14. 16:59
* 부분 글자 색상 바꾸기 fun TextView.textColorSomeChange(changeText: String, @ColorRes color: Int) { val index = text.toString().indexOf(changeText) if (index != -1) { val ssb = SpannableString(text) ssb.setSpan( ForegroundColorSpan( ContextCompat.getColor( App.instance.context(), color ) ), index, index + changeText.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE ) text = ssb } } * 부분 글자 사이즈 바꾸기 fun TextView..
-
Retrofit2 + RxJava 에서 Header 가져오기Android 2020. 12. 6. 17:16
서버와 통신을 할때 header에 있는 토큰을 가져와야 할때가 있다. POST("/register") fun registerUser(@Body registerPostData: RegistrationForm): Single 보통 통신을 할때 반환을 보통 위에 처럼 하는데 POST("/register") fun registerUser(@Body registerPostData: RegistrationForm): Single 반환 타입에 Response로 감싸주면 header를 가져 올 수 있게 된다.