<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hanmolee on Medium]]></title>
        <description><![CDATA[Stories by Hanmolee on Medium]]></description>
        <link>https://medium.com/@Hanmolee?source=rss-17e4893dc857------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*SKTnodK7ZiTm_HBD.</url>
            <title>Stories by Hanmolee on Medium</title>
            <link>https://medium.com/@Hanmolee?source=rss-17e4893dc857------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 17:00:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Hanmolee/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Kotlin + DI + MVP + Retrofit2 - Part1]]></title>
            <link>https://medium.com/@Hanmolee/kotlin-di-mvp-retrofit2-part1-bc0f070fd9fd?source=rss-17e4893dc857------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc0f070fd9fd</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[mvp]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[dagger-2]]></category>
            <category><![CDATA[retrofit2]]></category>
            <dc:creator><![CDATA[Hanmolee]]></dc:creator>
            <pubDate>Mon, 17 Dec 2018 10:03:54 GMT</pubDate>
            <atom:updated>2018-12-17T10:03:54.866Z</atom:updated>
            <content:encoded><![CDATA[<p>Github API를 사용해 리스트를 보여주는 MVP와 Dagger2를 적용한 예제입니다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/234/1*7zOFP2e8CL27sB0n_nUcxw.gif" /><figcaption>예제 동작 시연</figcaption></figure><p><strong>기존에 포스팅한 두 예제를 응용하여</strong></p><p><strong>MVP와 Dagger2를 사용해 개념 이해를 돕기 위한 예제입니다.</strong></p><p><strong>Rest Api를 위해 Github Api를 사용하였습니다.</strong></p><h4>MVP 기본 예제 :</h4><p><a href="https://medium.com/@dlgksah/mvp-kotlin-example-2de93add4c82">MVP + Kotlin Example</a></p><h4>Dagger2 기본예제 :</h4><p><a href="https://medium.com/@dlgksah/dagger2-kotlin-example-4c90d3d56edc">Dagger2 + Kotlin Example</a></p><blockquote>유저 시나리오</blockquote><ol><li>검색하고자 하는 이름을 입력한다.</li><li>버튼을 클릭 한다.</li><li>검색한 사용자의 정보가 보인다.</li><li>사용자 정보를 클릭 한다.</li><li>사용자의 레포지토리 리스트가 보인다.</li></ol><h4><em>버튼 클릭 이벤트로 Rest Api 통신을 한 후 리스트를 뿌려주는 아주 간단한 예제입니다.</em></h4><blockquote>개발 시나리오</blockquote><ol><li>Gradle 설정</li><li>재사용성을 줄여줄 Base를 만든다.</li><li>의존성 주입을 위해 Component와 Module을 만든다.</li><li>API 통신을 위한 모델과 인터페이스를 만든다.</li><li>UI(MVP)를 만든다.</li><li>의존성을 주입한다.</li></ol><h3>1. Gradle 설정</h3><ul><li>Project</li></ul><pre>ext {<br>    retrofit_version = &#39;2.3.0&#39;<br>    rxjava2_version = &#39;2.1.8&#39;<br>    rxandroid_version = &#39;2.1.0&#39;<br>    dagger2_version = &#39;2.18&#39;<br>    support_version = &#39;27.1.1&#39;<br>    rxbinding_version = &#39;2.2.0&#39;<br>    anko_version = &#39;0.10.7&#39;<br>    glide_version = &#39;4.8.0&#39;<br><br>}</pre><ul><li>App</li></ul><pre>// retrofit + gson<br>implementation &quot;com.squareup.retrofit2:retrofit:$retrofit_version&quot;<br>implementation &quot;com.squareup.retrofit2:adapter-rxjava2:$retrofit_version&quot;<br>implementation &quot;com.squareup.retrofit2:converter-gson:$retrofit_version&quot;<br>implementation &quot;com.squareup.retrofit2:converter-moshi:$retrofit_version&quot;<br><br>// rx<br>implementation &quot;io.reactivex.rxjava2:rxjava:$rxjava2_version&quot;<br>implementation &quot;io.reactivex.rxjava2:rxandroid:$rxandroid_version&quot;<br>implementation &quot;com.jakewharton.rxbinding2:rxbinding-kotlin:$rxbinding_version&quot;<br><br><br>// dependency injection<br>// Dagger 2<br>implementation &quot;com.google.dagger:dagger:$dagger2_version&quot;<br>kapt &quot;com.google.dagger:dagger-compiler:$dagger2_version&quot;<br>compileOnly &quot;org.glassfish:javax.annotation:3.1.1&quot;<br>implementation &#39;javax.inject:javax.inject:1&#39;<br><br>// ui<br>implementation &#39;com.android.support.constraint:constraint-layout:1.1.3&#39;<br>implementation &quot;com.android.support:recyclerview-v7:$support_version&quot;<br>implementation &quot;com.android.support:cardview-v7:$support_version&quot;<br>implementation &quot;com.android.support:design:$support_version&quot;<br><br>//anko<br>implementation &quot;org.jetbrains.anko:anko-commons:$anko_version&quot;<br><br>//glide<br>implementation &quot;com.github.bumptech.glide:glide:$glide_version&quot;</pre><h3>2. Base</h3><h4>- BaseView</h4><pre>interface BaseView {<br><br>    fun getContext() : Context<br><br>    fun showError(error : String)<br><br>    fun showError(@StringRes errorResId : Int) {<br>        this.showError(getContext().getString(errorResId))<br>    }<br><br>}</pre><ul><li>Context, Toast 등 View에서 자주 사용할 듯한 메서드를 만든다.</li></ul><h4>- BasePresenter</h4><pre>abstract class BasePresenter&lt;T&gt; {<br><br>    init {<br>        inject()<br>    }<br><br>    open fun onViewCreated(view: T) {}<br><br>    open fun onViewDestroyed() {}<br><br>    private fun inject() {<br>        when(this) {<br>            is SearchPresenter -&gt; {<br>                DaggerNetworkComponent.builder().networkModule(NetworkModule).build().inject(this)<br>            }<br><br>            is RepoPresenter -&gt; {<br>                DaggerNetworkComponent.builder().networkModule(NetworkModule).build().inject(this)<br>            }<br>        }<br>    }<br><br>}</pre><ul><li>뷰가 생성되고 제거되는 부분을 메서드로 만들었습니다.</li><li>매번 Presenter 에서 네트워크 의존성 주입하는 부분을 BasePresenter의 init 부분에서 처리를 하도록 하였습니다.</li></ul><h4>- BaseActivity</h4><pre>abstract class BaseActivity : AppCompatActivity() {<br><br>    init {<br>        inject()<br>    }<br><br>    private fun inject() {<br>        when(this) {<br>            is SearchActivity -&gt; {<br>                DaggerActivityComponent.builder()<br>                        .activityModule(ActivityModule)<br>                        .build()<br>                        .inject(this)<br>            }<br><br>            is RepoActivity -&gt; {<br>                DaggerActivityComponent.builder()<br>                        .activityModule(ActivityModule)<br>                        .build()<br>                        .inject(this)<br>            }<br>        }<br>    }<br><br>}</pre><ul><li>매번 Activity에서 Presenter 의존성 주입하는 부분을 BaseActivity의 init 부분에서 처리하도록 하였습니다.</li></ul><h3>3. 의존성 주입을 위해 Module, Component를 만든다.</h3><h4>- ContextModule</h4><pre>@Module<br>object ContextModule {<br><br>    @Provides<br>    fun provideContext(baseView: BaseView) : Context {<br>        return baseView.getContext()<br>    }<br><br>    @Provides<br>    fun provideApplication(context: Context) : Application {<br>        return context.<em>applicationContext </em>as Application<br>    }<br><br>}</pre><ul><li>앱의 컨텍스트를 가져올 수있는 모듈을 생성해줍니다.</li></ul><h4>- NetworkModule</h4><pre>@Module<br>object NetworkModule {<br><br>    @Provides<br>    internal fun provideApiService(retrofit: Retrofit) : ApiService {<br>        return retrofit.create(ApiService::class.<em>java</em>)<br>    }<br><br>    @Provides<br>    internal fun provideRetrofitInterface() : Retrofit {<br>        return Retrofit.Builder()<br>                .baseUrl(<em>BASE_URL</em>)<br>                .addConverterFactory(MoshiConverterFactory.create())<br>                .addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))<br>                .build()<br>    }<br>}</pre><ul><li>Retrofit을 사용하기 위한 모듈을 생성해줍니다.</li></ul><h4>- ActivityModule</h4><pre>@Module<br>object ActivityModule {<br><br>    @Provides<br>    internal fun provideSearchPresenter() : SearchPresenter {<br>        return SearchPresenter()<br>    }<br><br>    @Provides<br>    internal fun provideRepoPresenter() : RepoPresenter {<br>        return RepoPresenter()<br>    }<br>}</pre><ul><li>각 Activity에서 Presenter를 주입할 수 있는 모듈을 만들어 줍니다.</li></ul><h4>- ActivityComponent</h4><pre>@Singleton<br>@Component(modules = [ContextModule::class, ActivityModule::class])<br>interface ActivityComponent {<br><br>    fun inject(searchActivity: SearchActivity)<br>    fun inject(repoActivity: RepoActivity)<br>}</pre><ul><li>만들어 놓은 Context, Activity 모듈을 컴포넌트에 연결해 줍니다.</li><li>BaseActivity에서 ActivityComponent를 빌드하여 각 Activity에 따른 Presenter를 주입시켜 줍니다.</li></ul><h4>- NetworkComponent</h4><pre>@Singleton<br>@Component(modules = [NetworkModule::class])<br>interface NetworkComponent {<br><br>    fun inject(searchPresenter: SearchPresenter)<br>    fun inject(repoPresenter: RepoPresenter)<br>}</pre><ul><li>만들어 놓은 Network Moduled을 컴포넌트에 연결해 줍니다.</li><li>Presenter에서 API Call을 할 것이기 때문에 BasePresenter에서 네트워크 모듈을 주입시켜 줍니다.</li></ul><h3>4. API 통신을 위한 모델과 인터페이스를 만든다.</h3><h4>- ApiService</h4><pre>interface ApiService {<br><br>    @GET(&quot;/users/{username}&quot;)<br>    fun getUserInfo(@Path(&quot;username&quot;) userName: String): Single&lt;UserInfo&gt;<br><br>    @GET(&quot;/users/{username}/repos&quot;)<br>    fun getRepo(@Path(&quot;username&quot;) userName: String): Single&lt;List&lt;Repo&gt;&gt;<br><br>}</pre><ul><li>Github Api를 사용하기 위한 Api 인터페이스를 만들어 줍니다.</li></ul><h4>- data model</h4><pre>data class UserInfo(<br>        val login : String,<br>        val name : String?,<br>        val avatar_url : String?,<br>        val blog : String?<br>)</pre><pre>data class Repo(<br>        val name : String?,<br>        val stargazers_count : Int?,<br>        val description : String?<br>)</pre><ul><li>Api Response를 위한 데이터 모델을 만들어줍니다.(@SerializedName은 사용하지 않았습니다.)</li></ul><h3>5. UI(MVP)를 만든다. / 6. 의존성을 주입한다.</h3><ul><li><strong><em>유저의 이름을 입력하여 검색하는 UI를 만듭니다. (Search)</em></strong></li></ul><h4>- SearchView</h4><pre>interface SearchView : BaseView {<br><br>    fun initButton() //버튼클릭 이벤트를 정의<br><br>    fun showUserInfo(userInfo: UserInfo) //Api 응답을 보여주기 위해<br><br>    fun showLoading() // 프로그레스를 보인다.<br><br>    fun hideLoading() // 프로그레스를 숨긴다.<br><br>    fun showNotResult() // Api 응답이 없을 경우 결과 없음을 보여주기 위해<br><br>    fun startNextActivity(userName : String) <br>    // 검색한 사용자의 레포 리스트를 보여주기 위해<br>}</pre><h4>- SearchPresenter</h4><pre>class SearchPresenter : BasePresenter&lt;SearchView&gt;() {<br><br>    @Inject<br>    lateinit var apiService : ApiService<br><br>    private var searchView : SearchView? = null<br><br>    private var userName : String? = null<br><br>    val compositeDisposable : CompositeDisposable by <em>lazy </em><strong>{ </strong>CompositeDisposable() <strong>}<br><br>    </strong>override fun onViewCreated(view: SearchView) {<br>        searchView = view<br><br>        searchView?.initButton()<br>    }<br><br>    fun searchUserInfo(userNameText : String) {<br>        searchView?.showLoading()<br>        apiService.getUserInfo(userNameText)<br>                .observeOn(AndroidSchedulers.mainThread())<br>                .subscribeOn(Schedulers.io())<br>                .doOnError <strong>{<br>                    </strong>searchView?.hideLoading()<br>                    userName = null<br>                <strong>}<br>                </strong>.doOnSuccess <strong>{ </strong>searchView?.hideLoading() <strong>}<br>                </strong>.subscribe(<br>                        <strong>{ </strong>userInfo <strong>-&gt;<br>                            </strong>userInfo?.<em>run </em><strong>{<br>                                </strong>searchView?.showUserInfo(userInfo)<br>                                userName = userInfo.login<br>                            <strong>} </strong>?: kotlin.<em>run </em><strong>{<br>                                </strong>searchView?.showNotResult()<br>                                userName = null<br>                            <strong>}<br>                        }</strong>, <strong>{ </strong>error <strong>-&gt; </strong>searchView?.showError(error.toString()) <strong>}<br>                </strong>)<br>                .<em>apply </em><strong>{ </strong>compositeDisposable.add(this) <strong>}<br>    </strong>}<br><br>    fun clickUserInfo() {<br>        userName?.<em>let </em><strong>{ </strong>userName <strong>-&gt;<br>            </strong>searchView?.startNextActivity(userName)<br>        <strong>}<br>    </strong>}<br><br>    override fun onViewDestroyed() {<br>        searchView = null<br>        compositeDisposable.clear()<br>    }<br>}</pre><ul><li>@Inject lateinit var apiService : ApiService : BasePresenter에서 네트워크 컴포넌트를 빌드하여 네크워크 모듈을 의존성 주입하여 사용한다.</li><li>view의 생성과 제거를 정의한다.</li><li>view 생성시에 버튼이벤트를 정의한다.</li><li>Button의 Rxbinding을 관리하기 위한 CompositeDisposable을 관리 한다.</li><li>사용자 이름을 입력하고 검색 버튼이벤트가 발생하면 Api Request를 요청한다.</li><li>Api 응답을 받아 사용자의 정보를 보여준다.</li><li>view가 제거될때 Disposable을 clear 해준다.</li></ul><h4>- SearchActivity</h4><pre>class SearchActivity : BaseActivity(), SearchView {<br><br>    @Inject<br>    lateinit var searchPresenter: SearchPresenter<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.<em>activity_search</em>)<br><br>        searchPresenter.onViewCreated(this)<br>    }<br><br>    override fun initButton() {<br>        searchButton.<em>clicks</em>()<br>                .throttleFirst(500, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())<br>                .filter <strong>{ </strong>inputUserName.<em>text</em>.<em>isNotEmpty</em>() <strong>}<br>                </strong>.subscribe <strong>{<br>                    </strong>searchPresenter.searchUserInfo(inputUserName.<em>text</em>.toString())<br>                <strong>}<br>                </strong>.<em>apply </em><strong>{ </strong>searchPresenter.compositeDisposable.add(this) <strong>}<br><br>        </strong>userInfoForm.<em>clicks</em>()<br>                .throttleFirst(500, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())<br>                .filter <strong>{ </strong>userInfoForm.<em>visibility </em>== View.<em>VISIBLE </em><strong>}<br>                </strong>.subscribe <strong>{<br>                    </strong>searchPresenter.clickUserInfo()<br>                <strong>}<br>                </strong>.<em>apply </em><strong>{ </strong>searchPresenter.compositeDisposable.add(this) <strong>}<br>    </strong>}<br><br><br>    override fun showUserInfo(userInfo: UserInfo) {<br>        notResultText.<em>visibility </em>= View.<em>GONE<br>        </em>userInfoForm.<em>visibility </em>= View.<em>VISIBLE<br><br>        </em>Glide.with(getContext()).load(userInfo.avatar_url).into(profileImg)<br>        userNameText.<em>text </em>= userInfo.name<br>        userBlogText.<em>text </em>= userInfo.blog<br>    }<br><br>    override fun showLoading() {<br>        progressBar.<em>visibility </em>= View.<em>VISIBLE<br>    </em>}<br><br>    override fun hideLoading() {<br>        progressBar.<em>visibility </em>= View.<em>GONE<br>    </em>}<br><br>    override fun showNotResult() {<br>        notResultText.<em>visibility </em>= View.<em>VISIBLE<br>        </em>userInfoForm.<em>visibility </em>= View.<em>GONE<br>    </em>}<br><br>    override fun startNextActivity(userName: String) {<br>        val nextActivity = RepoActivity.newIntent(getContext(), userName)<br>        startActivity(nextActivity)<br>    }<br><br>    override fun onDestroy() {<br>        searchPresenter.onViewDestroyed()<br>        super.onDestroy()<br>    }<br><br>    override fun getContext(): Context {<br>        return this<br>    }<br><br>    override fun showError(error: String) {<br>        <em>toast</em>(error)<br>    }<br><br>}</pre><ul><li>@Inject lateinit var searchPresenter: SearchPresenter : BaseActivity에서 SearchPresenter를 의존성 주입하여 사용한다.</li><li>SearchView의 메서드를 재정의하여 SearchPresenter와 상호작용을 한다.</li><li><strong><em>입력한 유저의 레포지토리 리스트를 보여준다. (Repo)</em></strong></li></ul><h4>- RepoView</h4><pre>interface RepoView : BaseView {<br><br>    fun updateRepo(repo : List&lt;Repo&gt;) // Repo list Api request요청<br><br>    fun showRefreshing() // progress 보인다.<br><br>    fun hideRefreshing() // progress 숨긴다.<br><br>    fun getUserName() : String <br>    // SearchActivity에서 검색한 유저의 이름을 가져온다.<br>}</pre><h4>- RepoPresenter</h4><pre>class RepoPresenter : BasePresenter&lt;RepoView&gt;() {<br><br>    @Inject<br>    lateinit var apiService: ApiService<br><br>    private var repoView : RepoView? = null<br><br>    val compositeDisposable : CompositeDisposable by <em>lazy </em><strong>{ </strong>CompositeDisposable() <strong>}<br><br>    </strong>override fun onViewCreated(view: RepoView) {<br>        repoView = view<br>        view.showRefreshing()<br>        loadRepo()<br>    }<br><br><br>    fun loadRepo() {<br>        apiService.getRepo(repoView?.getUserName()!!)<br>                .observeOn(AndroidSchedulers.mainThread())<br>                .subscribeOn(Schedulers.io())<br>                .doOnSuccess <strong>{ </strong>repoView?.hideRefreshing() <strong>}<br>                </strong>.doOnError <strong>{ </strong>repoView?.hideRefreshing() <strong>}<br>                </strong>.subscribe(<br>                        <strong>{ </strong>repoList <strong>-&gt;<br>                            </strong>repoList?.<em>run </em><strong>{<br>                                </strong>repoView?.updateRepo(repoList)<br>                            <strong>}<br>                        }</strong>, <strong>{ </strong>repoView?.showError(R.string.<em>error</em>) <strong>}<br>                </strong>)<br>                .<em>apply </em><strong>{ </strong>compositeDisposable.add(this) <strong>}<br>    </strong>}<br><br>    override fun onViewDestroyed() {<br>        repoView = null<br>        compositeDisposable.clear()<br>    }<br>}</pre><ul><li>@Inject lateinit var apiService : ApiService : BasePresenter에서 네트워크 컴포넌트를 빌드하여 네크워크 모듈을 의존성 주입하여 사용한다.</li><li>Api Requset를 요청하여 사용자의 레포지토리 정보를 가져온다.</li><li>요청에 대한 응답이 올 경우 리스트를 보여준다.</li></ul><h4>- RepoAdapter</h4><pre>class RepoAdapter : RecyclerView.Adapter&lt;RepoAdapter.RepoHolder&gt;() {<br><br>    private var repo : List&lt;Repo&gt; = <em>listOf</em>()<br><br>    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RepoHolder {<br>        val view = LayoutInflater.from(parent.<em>context</em>).inflate(R.layout.<em>item_repo</em>, parent, false);<br>        return RepoHolder(view)<br>    }<br><br>    override fun getItemCount(): Int {<br>        return repo.size<br>    }<br><br>    override fun onBindViewHolder(holder: RepoHolder, position: Int) {<br>        holder.bind(repo[position])<br>    }<br><br>    fun updateRepo(repo: List&lt;Repo&gt;) {<br>        this.repo = repo<br>        notifyDataSetChanged()<br>    }<br><br>    class RepoHolder(private val view: View) : RecyclerView.ViewHolder(view) {<br><br>        fun bind(repo: Repo) {<br>            view.repoNameText.<em>text </em>= repo.name<br>            view.repoDescriptionText.<em>text </em>= repo.description<br>            view.repoStarText.<em>text </em>= repo.stargazers_count.<em>toString</em>()<br>        }<br>    }<br><br>}</pre><ul><li>RepoList를 보여주기위한 Adapter를 만들어준다.</li></ul><h4>- RepoActivity</h4><pre>class RepoActivity : BaseActivity(), RepoView {<br><br>    @Inject<br>    lateinit var repoPresenter: RepoPresenter<br><br>    private val repoAdapter = RepoAdapter()<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.<em>activity_repo</em>)<br><br>        initRecyclerView()<br>        setRefresh()<br><br>        repoPresenter.onViewCreated(this)<br>    }<br><br>    private fun initRecyclerView() {<br>        <em>with</em>(repoList) <strong>{<br>            </strong><em>adapter </em>= repoAdapter<br>        <strong>}<br>    </strong>}<br><br>    private fun setRefresh() {<br>        refreshLayout.setOnRefreshListener <strong>{<br>            </strong>repoPresenter.loadRepo()<br>        <strong>}<br>    </strong>}<br><br>    override fun onDestroy() {<br>        repoPresenter.onViewDestroyed()<br>        super.onDestroy()<br>    }<br><br>    override fun showRefreshing() {<br>        refreshLayout.<em>isRefreshing </em>= true<br>    }<br><br>    override fun hideRefreshing() {<br>        refreshLayout.<em>isRefreshing </em>= false<br>    }<br><br>    override fun showError(error: String) {<br>        <em>toast</em>(error)<br>    }<br><br>    override fun updateRepo(repo: List&lt;Repo&gt;) {<br>        repoAdapter.updateRepo(repo)<br>    }<br><br>    override fun getUserName(): String {<br>        return <em>intent</em>.getStringExtra(<em>USER_NAME</em>)<br>    }<br><br>    override fun getContext(): Context {<br>        return this<br>    }<br><br>    companion object {<br>        fun newIntent(context: Context, userName : String) : Intent {<br><br>            val repoIntent = Intent(context, RepoActivity::class.<em>java</em>)<br>            repoIntent.putExtra(<em>USER_NAME</em>, userName)<br><br>            return repoIntent<br>        }<br>    }<br><br>}</pre><ul><li>@Inject lateinit var repoPresenter: repoPresenter : BaseActivity에서 RepoPresenter를 의존성 주입하여 사용한다.</li><li>RepoView의 메서드를 재정의하여 RepoPresenter와 상호작용을 한다.</li><li>Intent로 전달받은 입력한 사용자의 이름을 받아서 사용한다.</li><li>RecyclerView에 Adapter를 정의하여 사용한다.</li></ul><h4>지금까지 MVP와 Dagger2, Retrofit2를 사용하여 API 통신을 하는 예제를 만들어 보았습니다.</h4><h4>이후에 만들 예제는 현재 만든 예제를 Android에 적합한 Dagger2 방식을 사용하여 변환하여 만든 예제를 만들어 보도록 하겠습니다.</h4><p>Ex &gt;</p><p><em>@ActivityScope @ContributesAndroidInjector(modules = [SearchActivityModule::class])</em></p><p><em>@Inject constructor(private val searchRepository: SearchRepository)</em></p><h4>이것은 제가 예제를 만들 기 전 스터디한 코드입니다. 참고하셔도 좋습니다.</h4><p><a href="https://github.com/hanmolee/GitHubExample/tree/UseDagger2_Old">hanmolee/GitHubExample</a></p><h4>포스트한 예제 모든 코드는 이곳에서 확인하실 수 있습니다.</h4><p><a href="https://github.com/hanmolee/MVP_Dagger2">hanmolee/MVP_Dagger2</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc0f070fd9fd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MVP + Kotlin Example]]></title>
            <link>https://medium.com/@Hanmolee/mvp-kotlin-example-2de93add4c82?source=rss-17e4893dc857------2</link>
            <guid isPermaLink="false">https://medium.com/p/2de93add4c82</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[mvp]]></category>
            <dc:creator><![CDATA[Hanmolee]]></dc:creator>
            <pubDate>Fri, 23 Nov 2018 10:15:38 GMT</pubDate>
            <atom:updated>2018-11-23T10:15:38.600Z</atom:updated>
            <content:encoded><![CDATA[<p>MVP 패턴의 기본 구현 예제입니다.</p><p>회사 프로젝트에 테스트 코드를 도입하기 위해 가장 안정적인 패턴을 찾던 중</p><p>프로젝트와 알맞은 패턴으로 MVP를 적용하게 되었습니다.</p><p>앞서 작성한 Dagger2와 함께 Presenter를 주입하기 위한 예제를 만들기 전에 필요한 학습인 MVP 패턴에 대한 예제를 만들어 보았습니다.</p><h3>MVP란?</h3><p>Model-View-Presenter로 이루어진 상호 의존성을 떨어뜨려 결합도를 낮출 수 있는 디자인 패턴입니다.</p><h4>Model :</h4><p>DB, REST API 등 비즈니스 로직 및 데이터와 관련된 처리역할을 하는 부분입니다.</p><h4>View :</h4><p>Activity 와 Fragment 같이 View를 담당하는 사용자 인터페이스 역할을 하는 부분입니다.</p><h4>Presenter :</h4><p>View에서 이벤트를 받아서 데이터를 가공하여 View 에 전달하는 역할을 하는 부분입니다. View와 Model의 다리 역할을 해줍니다.</p><h3><strong>Model, View, Presenter가 각각 어떤 역할을 하는지 예제로 확인해 보겠습니다.</strong></h3><h4>예제 시나리오는 간단합니다.</h4><ul><li>사용자가 버튼을 누르면 Dog List의 이름과 나이가 보여야 한다.</li></ul><h4>이때 각자의 역할의 흐름을 살펴보면</h4><h4>1. 사용자가 버튼을 누른다.</h4><p>→ View에서 클릭 이벤트가 발생</p><p>→ View에서 발생한 클릭 이벤트를 Presenter로 전달.</p><h4>2. Dog List를 가져온다.</h4><p>(이때 Dog List를 가져온다는 것을 DB 혹은 REST API를 호출한다고 생각하면 좀 더 이해하기 쉬울거 같습니다.)</p><p>→ Presenter가 Model에 데이터를 요청한다.</p><p>→ Model이 Presenter에 요청한 데이터를 전달한다. (서버,디비에서 가져온 데이터)</p><p>→ Presenter가 Model에서 전달 받은 데이터를 정제한다.</p><p>→ Presenter가 정제한 데이터를 View에 전달한다.</p><h4>3. Dog List의 이름과 나이가 보여야 한다.</h4><p>→ View가 Presenter에서 전달받은 데이터를 사용자에게 보여준다.</p><h3>저 흐름대로 구현한 예제를 보겠습니다.</h3><ul><li>이 예제는 View, Presenter가 구현해야할 인터페이스를 정의하는 Contract 인터페이스를 사용하였습니다.</li></ul><h3>먼저 MVP에 공통적으로 들어가기 때문에 재사용성이 높은 부분을 만들어 줍니다.</h3><h4>BaseView</h4><pre>interface BaseView {<br><br>    fun showError(error : String)<br><br>}</pre><ul><li>showError : Error를 출력하는 부분이 공통적으로 쓰인다는 가정하에 함수를 생성.</li></ul><h4>BasePresenter</h4><pre>interface BasePresenter&lt;T&gt; {<br><br>    fun takeView(view: T)<br>    fun dropView()<br><br>}</pre><ul><li>takeView : View가 생성 혹은 bind 될 때를 Presenter에 전달</li><li>dropView : View가 제거되거나 unBind 될 때를 Presenter에 전달</li></ul><h4>BaseActivity</h4><pre>abstract class BaseActivity : AppCompatActivity() {<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        initPresenter()<br>    }<br><br>    abstract fun initPresenter()<br><br>}</pre><ul><li>initPresenter : View와 상호작용할 Presenter를 주입하기 위해</li></ul><h3>Model역할을 하는 Dog, DogList를 구현해 줍니다.</h3><h4>dog (ex : data model)</h4><pre>data class Dog(<br>        val name : String,<br>        val age : Int<br>)</pre><h4>DogList (ex : GET Response)</h4><pre>object DogListData {<br><br>    fun getDoglistData(): List&lt;Dog&gt; {<br>        return <em>listOf</em>(<br>                Dog(&quot;Maltese&quot;,3),<br>                Dog(&quot;Golden Retriever&quot;,5),<br>                Dog(&quot;Siberian Husky&quot;,2)<br>        )<br>    }<br>}</pre><h3>View와 Presenter가 구현해야할 인터페이스를 정의 하는 Contract를 구현한다.</h3><h4>Contract</h4><pre>interface SearchContract {<br><br>    interface View : BaseView {<br>        fun showLoading()<br>        fun hideLoading()<br>        fun showDogList(dogList : List&lt;Dog&gt;)<br>    }<br><br>    interface Presenter : BasePresenter&lt;View&gt; {<br>        fun getDogList()<br>    }<br><br>}</pre><ul><li>showLoading, hideLoading : 데이터를 받아서 정제 하는동안 보일 ProgressBar관리하는 함수</li><li>showDogList : 정제한 데이터를 Presenter에서 전달받을 함수</li><li>getDogList : Model로 부터 데이터를 받아오기(정제하기) 위한 함수</li></ul><h3>View와 1 : 1 관계를 유지할 Presenter를 구현한다.</h3><pre>class SearchPresenter : SearchContract.Presenter {<br><br>    private var searchView : SearchContract.View? = null<br><br>    override fun takeView(view: SearchContract.View) {<br>        searchView = view<br>    }<br><br>    override fun getDogList() {<br>        searchView?.showLoading()<br><br>        Handler().postDelayed(<strong>{<br>            </strong>val dogList = DogListData.getDoglistData()<br>            searchView?.showDogList(dogList)<br>            searchView?.hideLoading()<br>        <strong>}</strong>, 1000)<br>    }<br><br>    override fun dropView() {<br>        searchView = null<br>    }<br><br>}</pre><ul><li>takeView : View와 Presenter를 연결해준다. (searchView = view)</li><li>getDogList :</li></ul><blockquote>1. searchView?.showLoading() : 1초간 네트워크와 통신하는 척을 해주었다. (View에 프로그레스바를 보여주도록 요청한다.)</blockquote><blockquote>2. DogListData.getDoglistData() : Model에서 DogList를 전달 받는다. (정제는 해줄필요가 없었다… 억지로 넣었다가 코드가 지저분해져서 뺏다.)</blockquote><blockquote>3. searchView?.showDogList(dogList) : Model에서 전달받은 데이터를 View에게 전달한다.</blockquote><blockquote>4. searchView?.hideLoading() : 네트워크 통신이 끝났으니 View에 프로그레스바를 숨기도록 요청한다.</blockquote><ul><li>dropView : View가 제거된 것을 Presenter에 알려준다.</li></ul><h3>사용자 인터페이스를 처리하는 View를 구현한다.</h3><h4>SearchActivity</h4><pre>class SearchActivity : BaseActivity(), SearchContract.View {<br><br>    private lateinit var searchPresenter: SearchPresenter<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.<em>activity_search</em>)<br><br>        searchPresenter.takeView(this)<br><br>        setButton()<br><br>    }<br><br>    private fun setButton() {<br>        getDogListButton.setOnClickListener <strong>{<br>            </strong>searchPresenter.getDogList()<br>        <strong>}<br>    </strong>}<br><br>    @SuppressLint(&quot;SetTextI18n&quot;)<br>    override fun showDogList(dogList : List&lt;Dog&gt;) {<br>        firstDogText.<em>text </em>= &quot;Name : ${dogList[0].name}, Age : ${dogList[0].age}&quot;<br>        secondDogText.<em>text </em>= &quot;Name : ${dogList[1].name}, Age : ${dogList[1].age}&quot;<br>        thirdDogText.<em>text </em>= &quot;Name : ${dogList[2].name}, Age : ${dogList[2].age}&quot;<br>    }<br><br>    override fun onDestroy() {<br>        super.onDestroy()<br>        searchPresenter.dropView()<br>    }<br><br><br>    override fun initPresenter() {<br>        searchPresenter = SearchPresenter()<br>    }<br><br>    override fun showError(error: String) {<br>        Toast.makeText(this@SearchActivity, error, Toast.<em>LENGTH_SHORT</em>).show()<br>    }<br><br>    override fun showLoading() {<br>        searchRefresh.<em>visibility </em>= View.<em>VISIBLE<br>    </em>}<br><br>    override fun hideLoading() {<br>        searchRefresh.<em>visibility </em>= View.<em>GONE<br>    </em>}<br><br>}</pre><ul><li>lateinit var searchPresenter: SearchPresenter : SearchActivity와 1:1 대응하는 SerachPresenter를 연결시켜주기 위한 초기화 지연 변수</li><li>override fun initPresenter() : BaseActivity에서 Activity가 생성이되면 해당 Activity에 Presenter를 초기화 시켜준다.</li><li>searchPresenter.takeView(this) : SearchContract.View를 상속받는 Activity가 생성이 되었다는 것을 Presenter에 알려준다.</li><li>setButton() : 버튼 이벤트가 발생하면 Presenter에 이벤트가 발생하였다고 알려줌과 동시에 Model로 부터 데이터를 가져오라는 것을 알려준다.</li><li>override fun showDogList(dogList : List&lt;Dog&gt;) : Model로 부터 받은 데이터를 Presenter에서 View로 전달해 주며 TextView를 통해서 사용자에게 보여준다.</li></ul><h4>MVP패턴을 사용하면 Presenter와 View를 연결시켜주는 부분을 의존성 주입을 활용할 수 있습니다.</h4><h4>- 의존성 주입에 관한 예제는 이곳에서 확인할 수 있습니다.</h4><p><a href="https://medium.com/@dlgksah/dagger2-kotlin-example-4c90d3d56edc">Dagger2 + Kotlin Example</a></p><h4>- 이 글의 MVP 패턴에 예제는 이곳에서 확인하실 수 있습니다.</h4><p><a href="https://github.com/hanmolee/MVP_Example">hanmolee/MVP_Example</a></p><p>감사합니다.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2de93add4c82" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dagger2 + Kotlin Example]]></title>
            <link>https://medium.com/@Hanmolee/dagger2-kotlin-example-4c90d3d56edc?source=rss-17e4893dc857------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c90d3d56edc</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[dagger-2]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Hanmolee]]></dc:creator>
            <pubDate>Thu, 22 Nov 2018 09:28:31 GMT</pubDate>
            <atom:updated>2018-11-23T10:17:18.300Z</atom:updated>
            <content:encoded><![CDATA[<p>Dagger2로 의존성 주입하는 예제입니다.</p><p>원래 목적은 Dagger2 -&gt; AndroidDagger -&gt; Koin 까지 직접 구현 및 실제 프로젝트에서 개발을 해 본 이후에 차이점들을 글로 작성하려고 했었다.</p><p>이번 회사 프로젝트 스프린트가 조금 빠듯할 듯 하여 아쉽게도 Koin까지의 스터디가 부족한 상태에서 글을 쓰게 되었다.</p><p>현재는 Dagger2 -&gt; AndroidDagger 까지 스터디를 완료 하고 실제 회사 프로젝트에 도입을 마친 상태이다.</p><p>먼저 Dagger2를 사용해 의존성 주입을 하는 예제를 만들어 다른 사람들에게 도움이 되고자 한다.</p><h3><strong>Dagger2란?</strong></h3><p>Dagger2는 DI(Dependenct Injection) Framework Library입니다.</p><p>(좀더 구제적인 것을 원하신다면 구글링을 해주세요!)</p><p>DI란 외부에서 객체를 생성해서 넘겨주는 것이라고 생각하면 됩니다.</p><p>예를 들면 A객체를 외부에서 독립적으로 생성하여 A객체를 사용하고자 하는 곳에서 외부에서 생성된 A객체를 참조하는 것입니다.</p><p>즉 객체간의 결합도를 느슨하게 만들게 됩니다.</p><p>의존성 주입을 사용하여 프로그램을 구현하게 되면</p><p>재사용성과 테스트, 유지보수성에 좀 더 유연한 대처가 가능합니다.</p><p>실제로 사용하면서 재사용성, 유지보수성에 좀 더 효과적이라는 것을 직접 경험하였습니다.</p><p>테스트코드는 현재 진행중이며 Mock 객체와 실제 객체를 바꿔가며 테스트할 예정이며</p><p>유닛테스트 이외에도 Appium을 활용하여 테스트 자동화와 함께 스터디를 하고 있습니다.</p><p><strong><em>제가 Dagger2를 도입한 가장 큰 목적으로는</em></strong></p><p><strong><em>MVP 패턴을 사용하기 위해 Presenter를 Activity에 주입시키려는 목적으로 사용하게 되었습니다.</em></strong></p><h3>Dagger 기본개념</h3><p>Dagger2의 API가 존재합니다.</p><ol><li>@Inject : 의존성 주입을 요청</li><li>@Component : Moule을 이용하여 의존성 객체를 생성하며 Inject로 요청받은 인스턴스에 생성된 객체를 주입하는 Module과 Inject 사이의 다리역할</li><li>@SubComponent : Component의 하위 계층이라고 생각하면 됩니다. 처음 Inject로 주입을 요청받으면 SubComponet -&gt; Component 순서로 의존성을 검색합니다.</li><li>@Module : Componet에 연결되어 의존성을 제공하는 메서드들을 가진 객체를 생성</li><li>@Provide : 모듈 내에서 언급된 의존성을 어떻게 구성 및 제공하는지 알려준다.</li><li>@Scope : 의존성 관련 객체의 생명주기 범위, Module에서 Scope를 보고 객체를 관리 Ex&gt; @ActivityScope, @FragmentScope</li></ol><h3>Dagger2 Tutorial</h3><p>의존성 주입을 하여 버튼 이벤트로 주입된 객체의 함수를 사용하는 예제</p><h4>1. Gradle 추가 [dagger2_version = 2.18]</h4><pre>apply plugin: &#39;kotlin-kapt&#39;</pre><pre>dependencies {<br>    implementation &quot;com.google.dagger:dagger:$dagger2_version&quot;<br>    kapt &quot;com.google.dagger:dagger-compiler:$dagger2_version&quot;<br>}</pre><h4>2. 의존성 객체를 생성한다.</h4><ul><li>Cat (고양이 이름이 있는 객체)</li></ul><pre>class Cat {<br>    <br>    private val catName = &quot;RegDoll&quot;<br><br>    fun getCatName(): String {<br>        return catName<br>    }<br>}</pre><ul><li>Dog (개 이름이 있는 객체)</li></ul><pre>class Dog {<br><br>    private val dogName = &quot;puddle&quot;<br><br>    fun getDogName(): String {<br>        return dogName<br>    }<br>}</pre><h4>3. Component에 연결되어 의존성 객체를 제공할 모듈을 만든다.</h4><ul><li>Cat 객체를 생성하여 제공할 모듈</li></ul><pre>@Module<br>object CatModule {<br><br>    @Provides<br>    fun provideCat() : Cat {<br>        return Cat()<br>    }<br>    <br>}</pre><ol><li>singleTon으로 CatModule라는 모듈을 만들고 @Module 어노테이션을 붙여준다.</li><li>Cat 객체 생성하여 return하는 함수를 만들고 @Provides 어노테이션을 붙여준다.</li></ol><ul><li>Dog 객체를 생성하여 제공할 모듈</li></ul><pre>@Module<br>object DogModule {<br><br>    @Provides<br>    fun provideDog() : Dog {<br>        return Dog()<br>    }<br><br>}</pre><ol><li>singleTon으로 DogModule라는 모듈을 만들고 @Module 어노테이션을 붙여준다.</li><li>Dog 객체 생성하여 return하는 함수를 만들고 @Provides 어노테이션을 붙여준다.</li></ol><h4>4. 모듈을 연결하여 의존성 객체를 생성하고 @Inject 로 요청받은 인스턴스에 의존성 객체를 주입하는 Component를 만든다.</h4><ul><li>Cat과 Dog 객체를 생성하여 제공시키는 모듈을 주입시키는 Component를 만든다.</li></ul><pre>@Singleton<br>@Component(modules = [DogModule::class, CatModule::class])<br>interface PetComponent {<br><br>    fun inject(mainActivity: MainActivity)<br><br>    @Component.Builder<br>    interface Builder {<br><br>        fun build() : PetComponent<br><br>        fun dogModule(dogModule : DogModule) : Builder<br>        fun catModule(catModule: CatModule) : Builder<br><br><br>    }<br>}</pre><ol><li>DogModule, CatModule을 Component에 연결시킨다.</li><li>연결된 모듈을 사용할 인스턴스(MainActivity)에 주입하는 Inject 함수를 만든다.</li><li>MainActivity와의 연결을 도울 interface(Builder)를 만든다.</li></ol><h4>5. MainActivity에 의존성을 주입시켜 의존성 객체를 사용한다.</h4><pre>class MainActivity : AppCompatActivity() {<br><br>    @Inject<br>    lateinit var cat : Cat<br><br>    @Inject<br>    lateinit var dog: Dog<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.<em>activity_main</em>)<br><br>        injectComponent()<br><br>        setGetCatNameButton()<br>        setGetDogNameButton()<br>    }<br><br>    private fun injectComponent() {<br>        DaggerPetComponent.builder()<br>                .catModule(CatModule)<br>                .dogModule(DogModule)<br>                .build()<br>                .inject(this)<br>    }<br><br>    private fun setGetCatNameButton() {<br>        catNameButton.setOnClickListener <strong>{<br>            </strong>catNameText.<em>text </em>= cat.getCatName()<br>        <strong>}<br>    </strong>}<br>    private fun setGetDogNameButton() {<br>        dogNameButton.setOnClickListener <strong>{<br>            </strong>dogNameText.<em>text </em>= dog.getDogName()<br>        <strong>}<br>    </strong>}<br><br><br>}</pre><ol><li>@Inject 어노테이션을 사용해 의존성 객체를 주입한다.</li><li>MainActivity가 생성될 때 Component를 연결합니다. (Dagger[Component Name]) 이 생성이 안되어 있을텐데 빌드를 한번 해야만 생성이 됩니다.)</li><li>Component를 연결할 때 사용할 Module을 지정해 줍니다.</li><li>inject(this) 하여 의존성 주입을 실행합니다.</li><li>4번의 과정을 거치게 되면 @Inject 어노테이션이 정의되어 있는 객체가 주입됩니다.</li><li>button 이벤트가 발생하면 의존성 객체의 메서드를 사용하여 이름을 불러옵니다.</li><li>MainActivity에서 Dog와 Cat을 생성하지 않고 메서드를 사용하는 것을 확인 할 수 있습니다.</li></ol><h4>- 의존성 주입과 함께 사용할 MVP 패턴 관련된 예제는 이곳에서 확인할 수 있습니다.</h4><p><a href="https://medium.com/@dlgksah/mvp-kotlin-example-2de93add4c82">MVP + Kotlin Example</a></p><h4>- 이 글의 Dagger2 관련 예제는 이곳에서 확인하실 수 있습니다.</h4><p><a href="https://github.com/hanmolee/DI-Example">hanmolee/DI-Example</a></p><p>감사합니다.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c90d3d56edc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WaterPin — Technical stack #6–6 UI & UX — Custom Circular ProgressBar Indeterminate]]></title>
            <link>https://medium.com/@Hanmolee/waterpin-technical-stack-6-6-ui-ux-custom-circular-progressbar-indeterminate-1aa44c89a22e?source=rss-17e4893dc857------2</link>
            <guid isPermaLink="false">https://medium.com/p/1aa44c89a22e</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[ux]]></category>
            <dc:creator><![CDATA[Hanmolee]]></dc:creator>
            <pubDate>Mon, 08 Oct 2018 11:56:50 GMT</pubDate>
            <atom:updated>2018-10-08T11:56:50.266Z</atom:updated>
            <content:encoded><![CDATA[<ul><li>WaterPin에 적용한 Custom Circular ProgressBar Indeterminate 효과</li></ul><h4>WaterPin의 UX &amp;UI 디자인을 효과적으로 구현하기 위해 사용한 Animation 중에 Circular <a href="https://developer.android.com/reference/android/widget/ProgressBar">ProgressBar Indeterminate</a> 을 정리해보겠다.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*50Fb5pKWvY_rNXDiWsol4w.gif" /><figcaption>Circular ProgressBar Indeterminate</figcaption></figure><blockquote><strong>유저 시나리오</strong></blockquote><ol><li>사용자가 목표량 이상의 물을 마셨을 경우 잠금 화면을 키며 원안에 원이 돌고 있는 효과가 발생한다.</li><li>사용자가 버튼을 눌러 목표량 이상의 물을 마시면 잠금 화면의 원안에 원이 돌고 있는 효과가 발생한다.</li></ol><ul><li><strong><em>인앱에서 목표량의 물을 마셨을 경우 주었던 gradient 효과와는 다르게 잠금화면에서는 다른 효과를 주도록 기획하였다. 목표량을 채웠다는 보상을 받는 느낌을 주고 싶었다.</em></strong></li></ul><ol><li>xml에 Progress에 적용할 indeterminateDrawable을 정의한다.</li><li>정의한 indeterminateDrawable을 ProgressBar에 설정해준다. (초기화에는 indeterminate = false)</li><li>오늘 마신 물이 목표량 이상일 경우 indeterminate를 true로 바꿔준다.</li></ol><h4>1. xml에 Progress에 적용할 indeterminateDrawable을 정의한다.</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff9774ea4d0bb7853add942527de1a39/href">https://medium.com/media/ff9774ea4d0bb7853add942527de1a39/href</a></iframe><ul><li>rotate 속성으로 gradient를 주었지만 색상의 변화는 적용하지 않음 (색상 한개)</li><li>Shape 속성에 userLevel을 true로 주어 Shape가 보이지 않도록 함</li></ul><h4>2. 정의한 indeterminateDrawable을 ProgressBar에 설정해준다. (초기화에는 indeterminate = false)</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3bfb04e3a609e8befe3e90485338fff7/href">https://medium.com/media/3bfb04e3a609e8befe3e90485338fff7/href</a></iframe><ul><li>Circular로 Custom한 Progress Bar의 indeterminate 속성을 false로 준다.</li><li>indeterminateDrawable 속성에 만들어 놓은 indeterminate_progress를 지정해준다.</li></ul><h4>3. 오늘 마신 물이 목표량 이상일 경우 indeterminate를 true로 바꿔준다.</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2d98106f2f95e9c6532acc88d2375fc/href">https://medium.com/media/b2d98106f2f95e9c6532acc88d2375fc/href</a></iframe><pre>waterProgressbar?.<em>run </em><strong>{<br>    </strong>if (<strong>it</strong>.todayWater!! &gt;= <strong>it</strong>.goalWater!!) {<br>        if (!<em>isIndeterminate</em>) {<br>            <em>isIndeterminate </em>= true<br>        }<br>    }</pre><ul><li>오늘 마신 물의 양이 목표량 이상일 경우(100% 이상) Custom한 Progressbar의 <em>isIndeterminate를 true로 변경해 준다. (</em>isIndeterminate가 false일 경우<em>)</em></li></ul><p><strong><em>버튼을 클릭하여 목표량 이상이 될 경우</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*gHs_OvD445s1RYdLWLG8jA.gif" /><figcaption>목표량을 채울 경우</figcaption></figure><p>WaterPin의 모든 코드는 제 <a href="https://github.com/hanmolee/Drinking-Water-Assistant">Github</a> 에서 확인 가능합니다.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1aa44c89a22e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WaterPin — Technical stack #6–5 UI & UX — Animation Drawable]]></title>
            <link>https://medium.com/@Hanmolee/waterpin-technical-stack-6-5-ui-ux-animation-drawable-6f436efadbbb?source=rss-17e4893dc857------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f436efadbbb</guid>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[animation]]></category>
            <dc:creator><![CDATA[Hanmolee]]></dc:creator>
            <pubDate>Sun, 07 Oct 2018 14:33:29 GMT</pubDate>
            <atom:updated>2018-10-08T09:09:13.656Z</atom:updated>
            <content:encoded><![CDATA[<h3>WaterPin — Technical stack #6–5 UI &amp; UX — Animation Drawable</h3><ul><li>WaterPin에 적용한 Animation Drawable 효과</li></ul><h4>WaterPin의 UX &amp;UI 디자인을 효과적으로 구현하기 위해 사용한 Animation 중에 <a href="https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable">Animation Drawable</a> 을 정리해보겠다.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*9IRNCLbQhwYE-LxdklY38w.gif" /><figcaption>gradient animation drawable</figcaption></figure><blockquote><strong>유저 시나리오</strong></blockquote><ol><li>사용자가 목표량 이상의 물을 마셨을 경우 Main화면의 배경에 그라데이션 효과가 발생한다.</li><li>리스트에서 삭제할 경우 목표량을 채우지 못했을 경우 Main화면의 배경이 원상태로 복구한다.</li></ol><ul><li><strong><em>사용자가 목표량의 물을 모두 마셨다는 Mission을 완수하였을 경우 어떤식으로 보상받는 느낌을 줄지 생각하다가 gradient 효과(물속에 있는 듯한 느낌)를 주는 느낌을 기획하였다. 잠금화면에서는 다른 효과로 보상을 받는 느낌을 주었다. — 다음 포스트에 작성 예정</em></strong></li></ul><blockquote><strong>구현 과정</strong></blockquote><ol><li>animation Drawable에 작성한 그라데이션 애니메이션(drawable)을 원하는 순서대로 작성</li><li>적용할 View의 background resource를 1에서 작성한 xml로 설정</li><li>사용자가 목표량을 채울 경우 animation Drawable에 Fade in과 Fade out 값을 설정해 준 후 start 한다.</li></ol><h4>1. animation Drawable에 작성한 그라데이션 애니메이션(drawable)을 원하는 순서대로 작성</h4><ul><li>xml에 gradient animation 1~4 작성</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54f8cc233f15c4829a4c29b575c9ef35/href">https://medium.com/media/54f8cc233f15c4829a4c29b575c9ef35/href</a></iframe><ul><li>xml에 animation-list 원하는 순서대로 작성</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3933b083b0af8fed9a9e8d876b2b4a84/href">https://medium.com/media/3933b083b0af8fed9a9e8d876b2b4a84/href</a></iframe><ul><li>원하는 순서대로 gradient효과를 지정</li><li>각각 duration 설정</li></ul><h4>2. 적용할 View의 background resource를 1에서 작성한 xml로 설정</h4><h4>3. 사용자가 목표량을 채울 경우 animation Drawable에 Fade in과 Fade out 값을 설정해 준 후 start 한다.</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a66ba0154e8cb2740dee9867388817a/href">https://medium.com/media/2a66ba0154e8cb2740dee9867388817a/href</a></iframe><pre>mainLayout.setBackgroundResource(R.drawable.<em>gradient_animation_list</em>)<br>val animationDrawable = mainLayout.<em>background </em>as AnimationDrawable<br><em>with</em>(animationDrawable) <strong>{<br>    </strong>setEnterFadeDuration(3000)<br>    setExitFadeDuration(3000)<br>    start()<br><strong>}</strong></pre><ul><li>100%(목표량)이상일 경우 원하는 View의 BackgroundResource를 작성한 animation drawable로 설정해준다.</li><li>animation drawable에 Fade In Duration을 설정해준다.</li><li>animation drawable에 Fade Out Duration을 설정해준다.</li><li>animation drawable을 시작한다.</li></ul><h4><strong><em>- 100%(목표량)이 아닐 경우animation drawable이 중지된다.</em></strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*mB4rEUyd7F6eDTMkp4eN7w.gif" /><figcaption>100% 미만일 경우</figcaption></figure><p><strong><em>Android Version에 제한받지 않고 원하는대로 커스텀이 가능한 장점이 있다.</em></strong></p><p>WaterPin의 모든 코드는 제 <a href="https://github.com/hanmolee/Drinking-Water-Assistant">Github</a> 에서 확인 가능합니다.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f436efadbbb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WaterPin — Technical stack #6–4 UI & UX — Material design transition]]></title>
            <link>https://medium.com/@Hanmolee/waterpin-technical-stack-6-4-ui-ux-material-design-transition-ff71d549d460?source=rss-17e4893dc857------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff71d549d460</guid>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[animation]]></category>
            <dc:creator><![CDATA[Hanmolee]]></dc:creator>
            <pubDate>Sat, 06 Oct 2018 09:01:53 GMT</pubDate>
            <atom:updated>2018-10-06T09:01:53.403Z</atom:updated>
            <content:encoded><![CDATA[<h3>WaterPin — Technical stack #6–4 UI &amp; UX — Material design transition</h3><ul><li>WaterPin에 적용한 Material design transition Animation 효과</li></ul><h4>WaterPin의 UX &amp;UI 디자인을 효과적으로 구현하기 위해 사용한 Animation 중에 <a href="https://developer.android.com/training/transitions/start-activity">Material design transition Animation</a> 을 정리해보겠다.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*-imk06a43s9-r9RqvB5qBA.gif" /><figcaption>Activity Transition Animation</figcaption></figure><blockquote><strong>유저 시나리오</strong></blockquote><ol><li>사용자가 고래 아이콘을 클릭하면 나의 Water Info를 설정할 수 있는 화면이 보여야 한다.</li><li>화면 간에 고래 이미지, 물컵 이미지, 물의 양 Text를 서로 공유해야 한다.</li></ol><h4><em>롤리팝 이상부터 사용 가능한 ActivityOptionsCompat을 사용한 TransitionAnimation로 구현하였다.</em></h4><blockquote><strong>구현 과정</strong></blockquote><ol><li>서로 공유할 View의 layout에 [ android:transitionName ]을 추가</li><li>Pair에 layout에 추가한 transitionName를 생성</li><li>생성한 Pair를 ActivityOptionsCompat.makeSceneTransitionAnimation() 에 추가한 ActivityOptionCompat을 생성</li><li>롤리팝 이상에서부터만 ActivityCompat.startActivity(context, intent, ActivityOptionCompat.toBundle()) 를 사용하여 TrainsitionAnimation 시작</li></ol><h4>1. 서로 공유할 View의 layout에 [ android:transitionName ]을 추가</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afd73a7ae3849f75592531ffe25ae500/href">https://medium.com/media/afd73a7ae3849f75592531ffe25ae500/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/762b64e2f9ebbe29d584bc17d22051e6/href">https://medium.com/media/762b64e2f9ebbe29d584bc17d22051e6/href</a></iframe><ul><li>물의 양 텍스트과 고래 아이콘에 각각</li></ul><pre>android:transitionName=&quot;logoImage&quot;<br>android:transitionName=&quot;waterText&quot;</pre><p>transitionName을 추가해준다.</p><p>물컵 아이콘은 동적으로 생성해줄 것이다.</p><h4>2. Pair에 layout에 추가한 transitionName를 생성 후 Lollipop 이상일 경우 ActivityCompat.startActivity 호출</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36710085b3079b62574d9ea4b0e9a9a4/href">https://medium.com/media/36710085b3079b62574d9ea4b0e9a9a4/href</a></iframe><ul><li>Pair에 layout에 추가한 transitionName를 생성</li><li>생성한 Pair를 ActivityOptionsCompat.makeSceneTransitionAnimation() 에 추가한 ActivityOptionCompat을 생성</li><li>롤리팝 이상에서부터만 ActivityCompat.startActivity(context, intent, ActivityOptionCompat.toBundle()) 를 사용하여 TrainsitionAnimation 시작</li></ul><h4>3. 시작되는 액티비티의 물컵 아이콘에 일치하는 ImageView에 동적으로 transitionName을 지정해준다. (Lollipop이상인 경우만)</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4371089b9495b67fc24c0e1541bbab39/href">https://medium.com/media/4371089b9495b67fc24c0e1541bbab39/href</a></iframe><pre>if (Build.VERSION.<em>SDK_INT </em>&gt;= Build.VERSION_CODES.<em>LOLLIPOP</em>) {<br>    waterType200.<em>transitionName </em>= &quot;typeImage&quot;<br>}</pre><ul><li>물컵의 타입에 따라 다르게 transitionName을 지정해준다.</li></ul><p><strong><em>간단하게 Material Design을 활용한 Animation을 사용해 보았다.</em></strong></p><p>WaterPin의 모든 코드는 제 <a href="https://github.com/hanmolee/Drinking-Water-Assistant">Github</a> 에서 확인 가능합니다.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff71d549d460" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WaterPin — Technical stack #6–3 UI & UX — Reveal Animation]]></title>
            <link>https://medium.com/@Hanmolee/waterpin-technical-stack-6-3-ui-ux-reveal-animation-eae23216090c?source=rss-17e4893dc857------2</link>
            <guid isPermaLink="false">https://medium.com/p/eae23216090c</guid>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[animation]]></category>
            <dc:creator><![CDATA[Hanmolee]]></dc:creator>
            <pubDate>Sat, 06 Oct 2018 07:36:21 GMT</pubDate>
            <atom:updated>2018-10-06T07:36:21.119Z</atom:updated>
            <content:encoded><![CDATA[<h3>WaterPin — Technical stack #6–3 UI &amp; UX — Reveal Animation</h3><ul><li>WaterPin에 적용한 Reveal Animation 효과</li></ul><h4>WaterPin의 UX &amp;UI 디자인을 효과적으로 구현하기 위해 사용한 Animation 중에 <a href="https://developer.android.com/reference/android/view/ViewAnimationUtils">Reveal Animation</a>을 정리해보겠다.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*5XbwK4ya9M-I7Qs-JGADug.gif" /><figcaption>WaterPin Reveal Animation</figcaption></figure><blockquote><strong>유저 시나리오</strong></blockquote><ol><li>사용자가 설정 아이콘을 클릭하면 설정아이콘 에서부터 파란색 물결이 원 방향으로 퍼져나가는 애니메이션 효과가 시작되어야 한다.</li><li>물결이 퍼져 나가는 동안 다른 버튼의 기능이 동작하면 안된다.</li><li>파란색 물결이 퍼져 나간 후에 뒤에 배경(Histoy 화면으로 이동할 때)이 보여야 한다.</li><li>사용자가 X(close)버튼을 누르면 파란색 물결이 설정아이콘으로 줄어드는 애니메이션 효과가 시작되어야 한다.</li><li>물결이 줄어드는 동안 다른 버튼의 기능이 동작하면 안된다.</li><li>물결이 줄어 든 후 다시 원상태로 돌아와야 한다.</li></ol><blockquote><strong>구현 하면서 겪은 이슈</strong></blockquote><ul><li>Activity위에 ViewPager로 이미 구현해 놓은 상태였으며 내 머릿속의 기획은 설정은 반드시 MainFragment(메인 화면) 한곳에서만 하게 하고싶었다.</li></ul><p>— 사실 여기서부터 꼬였다…. 왜냐하면 MainFragment의 background는 transparent 였다. 그이유는 아이콘과 History에 뷰페이저가 변할 때마다 동적으로 애니메이션 효과를 주고 있었기 때문이다.</p><p>그렇기 때문에 설정화면이 나타나도 MainActivity가 보여야 하는 문제가 있었다.</p><p>만약 설정 화면의 background를 transparent로 한다면 reveal 효과가 진행되면서 MainFragment가 사라지지 않고 보이는 문제가 있었다.</p><p>첫째로 Reveal Animation이 진행될동안은 설정화면의 Background를 white로 해주었다.</p><p>두번째로 RxEventBus를 사용해서 애니메이션이 끝날때와 설정 Fragment의 create, destroy를 캐치해서 MainFragment의 View 상태를 바꿔 주어 해결하였다.</p><pre>Rx를 사용한 이유는 View 상태 외에도 설정의 잠금화면 switch 및 리스트의 delete button 등의 문제가 있었다.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*fh0dgBD8hgvy6VRqhwx0vA.gif" /><figcaption>이슈를 해결하고 구현한 화면</figcaption></figure><h4>- 먼저 Reveal Animation을 구현한 방법이다.</h4><ul><li>유저시나리오 1, 4에 해당</li><li>참조한 글 :</li></ul><p><a href="https://medium.com/@gabornovak/circular-reveal-animation-between-fragments-d8ed9011aec">Circular reveal animation between Fragments</a></p><h4>1. Reveal Animation을 관리하는 Util</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83a68da069d198919c095d0ca8acae00/href">https://medium.com/media/83a68da069d198919c095d0ca8acae00/href</a></iframe><ul><li>Reveal Animation이 퍼질 될 때와 줄어들 때 각각 애니메이션의 시작, 끝 색상을 지정하고 listener로 Animation이 끝날때를 캐치할 수 있도록 하였다.</li><li>Animation의 시작될때와 끝날때의 색상을 주어 물결이 퍼지는 효과를 주었다.</li><li>x, y좌표를 조정하여 설정 아이콘을 기준으로 Reveal Animation이 시작되도록 하였다.</li><li>롤리팝 이상부터 가능하도록 어노테이션을 걸어놨다.</li></ul><h4>2. Reveal Animation이 시작되는 부분 (물결이 퍼지는 효과)</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5fb5f10b15eeedf79f2c0e1d790c37f/href">https://medium.com/media/a5fb5f10b15eeedf79f2c0e1d790c37f/href</a></iframe><ul><li>Setting Fragment가 Create되는 동시에 RevealAnimationUtil.registerStartRevealAnimation() 를 호출</li><li>animation Finish Listener도 함께 전달</li></ul><h4>3. Reveal Animation이 되돌아 되는 부분 (물결이 줄어드는 효과)</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fdb1d231b5ec0420e247e266b9f3ab93/href">https://medium.com/media/fdb1d231b5ec0420e247e266b9f3ab93/href</a></iframe><ul><li>CloseButton(Lottie Animation)을 클릭 하였을 경우 RevealAnimationUtil.registerExitRevealAnimation()를 호출</li><li>animation Finish Listener도 함께 전달</li></ul><h4>— Reveal Animation 구현 영상</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*5ypVaMC-PToBvSs3bP512w.gif" /><figcaption>Reveal Animation</figcaption></figure><h4>- Reveal Animation 진행에 따라 View의 상태를 관리한 방법이다.</h4><ul><li>유저시나리오 2, 3, 5, 6에 해당</li></ul><p><strong><em>SettingFragment의 상태를 캐치할 수 있는 EventBus를 구현하여 사용하였다.</em></strong></p><p>— WaterPin에 EventBus를 자주 사용할 일이 생기면 DataModel로 구분하는 EventBus를 다시 구현할 예정</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1698d2af1fb3ed18952cee6dff754993/href">https://medium.com/media/1698d2af1fb3ed18952cee6dff754993/href</a></iframe><h4>1. 유저시나리오 2번 물결이 퍼져 나가는 동안 다른 버튼의 기능이 동작하면 안된다.</h4><ul><li>다른 MainActivity와 MainFragment의 버튼 클릭이 안되도록하며 List의 delete button click listener가 안되도록</li></ul><p><strong><em>- 물결이 퍼지기 시작 부터 물결이 완전히 퍼질 때 까지</em></strong></p><p><strong><em>[SettingFragment가 Created되며 SettingFragment의 Reveal Animation이 진행중 일 때]</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c80f0d579eb14a3b7dde8865c59a0b76/href">https://medium.com/media/c80f0d579eb14a3b7dde8865c59a0b76/href</a></iframe><pre>SettingsFragmentEventsBus.postFragmentAction(SettingsFragmentEventsBus.ACTION_FRAGMENT_CREATED)</pre><ul><li>MainFragment의 setting Button을 클릭하게 되면 eventBus로 CreatedEvent를 받아 setting Button을 비활성화 하며 List의 Delete button Listener를 제거한다.</li><li>물결이 퍼지고 있는 중이기 때문에 이때 SettingFragment를 제외한 모든 뷰는 Visible이어야 한다.</li></ul><h4>2. 유저시나리오 3번 파란색 물결이 퍼져 나간 후에 뒤에 배경(Histoy 화면으로 이동할 때)이 보여야 한다.</h4><ul><li>물결이 완전히 퍼진 후 MainActivity의 View가 보이며 MainFragment의 View는 보이면 안된다.</li></ul><p><strong><em>- 물결이 완전히 퍼진 후 (Reveal Animation이 Finished 될 때)</em></strong></p><p><strong><em>[SettingFragment가 Destroyed 되지 않았으며 SettingFragment의 Reveal Animation이 Finished 될 때]</em></strong></p><p>— 애니메이션이 종료가 되지 않았으나 SettingFragment가 종료 될 수도 있기 때문에 이런 조건이 발생</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e852282ccf31a7a8c0efcec9445008f/href">https://medium.com/media/6e852282ccf31a7a8c0efcec9445008f/href</a></iframe><pre>SettingsFragmentEventsBus.postFragmentAction(SettingsFragmentEventsBus.ACTION_FRAGMENT_START_ANIMATION_FINISHED)</pre><ul><li>SettingsFragment의 startRevealAnimation이 종료 되면 SettingFragment가 Destroyed 되지 않았을 경우 EventBus로 물결 퍼짐 애니메이션이 끝났다는 것을 보낸다.</li><li>물결이 완전히 퍼졌으므로 MainActivity의 View와 SettingsFragment의 View만 보여주어야 하기 때문에 MainFragment의 View 상태를 GONE으로 바꿔준다.</li></ul><h4>3. 유저시나리오 5번 물결이 줄어드는 동안 다른 버튼의 기능이 동작하면 안된다, 6번 물결이 줄어 든 후 다시 원상태로 돌아와야 한다.</h4><ul><li>물결이 줄어드는 동안 Setting Fragment의 기능이 정지되며 물결이 줄어 든 후 원상태로 복구한다.</li></ul><p><strong><em>- 물결이 줄어들기 시작 부터 물결이 완전히 줄어들 때 까지</em></strong></p><p><strong><em>[SettingFragment의 Reveal Animation이 Finished 되며 SettingFragment가 Destroyed 될 때]</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b6d16f16e7a2d679d0e95b237dff9c55/href">https://medium.com/media/b6d16f16e7a2d679d0e95b237dff9c55/href</a></iframe><pre>SettingsFragmentEventsBus.postFragmentAction(SettingsFragmentEventsBus.ACTION_FRAGMENT_DESTROYED)</pre><ul><li>SettingsFragment가 Destroyed 되면 EventBus로 Destroyed 되었다는 것을 보낸다.</li><li>SettingsFragment가 사라졌으므로 MainActivity, MainFragment의 뷰의 상태를 Visible로 만들며 버튼 클릭이 가능해야 한다.</li></ul><pre>SettingsFragmentEventsBus.postFragmentAction(SettingsFragmentEventsBus.ACTION_FRAGMENT_END_ANIMATION_FINISHED)</pre><ul><li>SettingsFragment의 줄어드는 Reveal Animation이 Finished되면 EventBus로 animation이 종료 되었다는 것을 보낸다.</li><li>SettingsFragment가 생성되기 전으로 원상복구를 시킨다.</li></ul><p><strong><em>destroyed와 animation Finished를 나눠논 이유</em></strong></p><p>애니메이션이 Finish되기 전에 다시 SettingFragment를 생성시기게 되면 View 상태가 겹치기 때문에 정확하게 하기 위해 나눠서 처리</p><h4>—Reveal Animation 진행에 따라 View의 상태를 관리한 구현 영상</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*W7Ry1a8SBIYnD6R5eXN6AA.gif" /><figcaption>View의 상태를 관리한 화면</figcaption></figure><p>기획과 디자인하는데 사실상 공수의 반 이상을 차지한다…. UI, UX는 역시나 중요하다.</p><p>이렇게 만들어야지 하는게 아닌 개발할때부터 몸에 기본으로 장착되어 있어야 한다고 생각한다.</p><p>WaterPin의 모든 코드는 제 <a href="https://github.com/hanmolee/Drinking-Water-Assistant">Github</a> 에서 확인 가능합니다.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eae23216090c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WaterPin — Technical stack #6–2 UI & UX — Drop Down Animation]]></title>
            <link>https://medium.com/@Hanmolee/waterpin-technical-stack-6-2-ui-ux-drop-down-animation-1b7b9c57cd43?source=rss-17e4893dc857------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b7b9c57cd43</guid>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Hanmolee]]></dc:creator>
            <pubDate>Sat, 06 Oct 2018 05:48:23 GMT</pubDate>
            <atom:updated>2018-10-06T05:48:23.963Z</atom:updated>
            <content:encoded><![CDATA[<ul><li>WaterPin에 적용한 List Drop Down Animation 효과 및 List Slide up, Down Animation 효과</li></ul><h4>WaterPin의 UX &amp;UI 디자인을 효과적으로 구현하기 위해 사용한 Animation 중에 List Drop Down Animation과 List Slide up, Down을 정리해보겠다.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*iVFL3WTGjowS09auZogAAQ.gif" /><figcaption>drop down and slide down, up Animation</figcaption></figure><blockquote><strong>유저 시나리오</strong></blockquote><ol><li>사용자가 Water History 화면을 보면 매일 마신 물의 기록 정보 리스트가 아래로 내려오는 효과와 함께 점점 진해지면서 나타나야 한다.</li></ol><p>2. 사용자가 매일 마신 물의 기록 정보 리스트를 클릭하면 펼쳐지는 효과가 나타나야 한다.</p><p>3. 사용자가 펼쳐진 리스트를 클릭하면 닫히는 효과가 나타나야 한다.</p><h4>List Drop Down Animation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*z-SJ3Jat46xCvWStBbfZeA.gif" /><figcaption>List Drop Down</figcaption></figure><ul><li>사용자가 Water History 화면을 보면 매일 마신 물의 기록 정보 리스트가 아래로 내려오는 효과와 함께 점점 진해지면서 나타나야 한다.</li></ul><ol><li>xml로 layoutAnimation을 정의한다.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a6ecb997b7493b7eb642c314d03263a/href">https://medium.com/media/3a6ecb997b7493b7eb642c314d03263a/href</a></iframe><p>2. xml로 Animation을 정의한다.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b562d90e92f8f57723e5ffa5a4f9a639/href">https://medium.com/media/b562d90e92f8f57723e5ffa5a4f9a639/href</a></iframe><p>3. onResume에 RecyclerView를 초기화하게 하였다.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3e5fa0540631b9aa88be1a5a9d8fd77/href">https://medium.com/media/e3e5fa0540631b9aa88be1a5a9d8fd77/href</a></iframe><ul><li>LayoutAnimation 속성을 정의한 xml(R.anim.<em>layout_list_animation_drop_down</em>)을 LayoutAnimationController 클래스를 이용해서 로드해서 RecyclerView를 초기화 할때 애니메이션을 적용하였다.</li></ul><h4>List Slide Down, Up Animation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*t8DMUEYk1EhWmx5mNBEfog.gif" /><figcaption>List Slide Down, Up</figcaption></figure><ul><li>사용자가 매일 마신 물의 기록 정보 리스트를 클릭하면 펼쳐지는 효과가 나타나야 한다.</li><li>사용자가 펼쳐진 리스트를 클릭하면 닫히는 효과가 나타나야 한다.</li></ul><ol><li>xml로 Slide Down Animation을 정의한다.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd680d296164eb347782442ee9fdcd7a/href">https://medium.com/media/fd680d296164eb347782442ee9fdcd7a/href</a></iframe><p>2. xml로 Slide Up Animation을 정의한다.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2e9dc94c233972f7a57a6a7a1f9adc6/href">https://medium.com/media/b2e9dc94c233972f7a57a6a7a1f9adc6/href</a></iframe><ul><li>Scalse Animation을 정의한다.</li></ul><p>3. Recycler View Adapter의 ViewHolder에 애니메이션을 로드하여 사용하였다.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32102baf12d2b61bd93f3d68670989f2/href">https://medium.com/media/32102baf12d2b61bd93f3d68670989f2/href</a></iframe><ul><li>클릭 이벤트가 발생하였을 때 각각의 상황에 맞춰서 slide up, slide down animation을 로드하여서 적용하였다.</li><li>AnimationListener를 달아서 다른 애니매이션 효과(<a href="https://medium.com/@dlgksah/waterpin-technical-stack-6-1-ui-ux-alpha-animation-515e09c9df2">Alpha Animation</a>)도 적용시켰다.</li></ul><p><a href="https://medium.com/@dlgksah/waterpin-technical-stack-6-1-ui-ux-alpha-animation-515e09c9df2">WaterPin — Technical stack #6–1 UI &amp; UX — Alpha Animation</a></p><p>이런식으로 애니메이션을 연계해서 사용하도록 할 수 있다.</p><p>WaterPin의 모든 코드는 제 <a href="https://github.com/hanmolee/Drinking-Water-Assistant">Github</a> 에서 확인 가능합니다.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b7b9c57cd43" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WaterPin — Technical stack #6–1 UI & UX — Alpha Animation]]></title>
            <link>https://medium.com/@Hanmolee/waterpin-technical-stack-6-1-ui-ux-alpha-animation-515e09c9df2?source=rss-17e4893dc857------2</link>
            <guid isPermaLink="false">https://medium.com/p/515e09c9df2</guid>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[animation]]></category>
            <dc:creator><![CDATA[Hanmolee]]></dc:creator>
            <pubDate>Thu, 04 Oct 2018 15:10:58 GMT</pubDate>
            <atom:updated>2018-10-04T15:10:58.118Z</atom:updated>
            <content:encoded><![CDATA[<h3>WaterPin — Technical stack #6–1 UI &amp; UX — Alpha Animation</h3><ul><li>WaterPin에 적용한 Alpha Animation 효과</li></ul><h4>WaterPin의 UX &amp;UI 디자인을 효과적으로 구현하기 위해 사용한 Animation 중에 Alpha Animation을 정리해보겠다.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*yT9HLG0CDAnRdgaJYZTV2A.gif" /><figcaption>TextView 에 적용한 Alpha Animation</figcaption></figure><blockquote><strong>유저 시나리오</strong></blockquote><p>1. 리스트가 안보일 경우 사용자가 리스트 아이템을 클릭하면 오늘 마실 물의 목표를 나타내는 Text가</p><ul><li>파란색 글씨 옆에서 점점 진해지면서 나타나야 한다.</li><li>파란색 글씨 아래에서 점점 흐려지면서 사라져야 한다.</li></ul><p>2. 리스트가 보일 경우 사용자가 리스트 아이템을 클릭하면 오늘 마실 물의 목표를 나타내는 Text가 파란색 글씨 아래에서 점점 진해지면서 나타나야 한다</p><ul><li>파란색 글씨 옆에서 점점 흐려지면서 사라져야 한다.</li><li>파란색 글씨 아래에서 점점 진해지면서 나타나야 한다.</li></ul><h4>Alpha Animation Util</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2199e456fabe29cbfdf845c3b233e1d/href">https://medium.com/media/f2199e456fabe29cbfdf845c3b233e1d/href</a></iframe><ul><li>apply fade animation function</li></ul><p>— 500 milliseconds 동안</p><p>— alpha 값을 1.0 에서 0.0 으로</p><p>—애니메이션이 종료된 상태를 유지한다.</p><ul><li>apply appear animation function</li></ul><p>— 500 milliseconds 동안</p><p>— alpha 값을 0.0 에서 1.0 으로</p><p>— 애니메이션이 종료된 상태를 유지한다.</p><p>유저시나리오 1 :</p><pre>AlphaAnim.startAppearAlphaAnim(itemView.waterGoal)<br>AlphaAnim.startFadeAlphaAnim(itemView.itemWaterGoal)</pre><p>유저 시나리오 2.:</p><pre>AlphaAnim.startAppearAlphaAnim(itemView.itemWaterGoal)<br>AlphaAnim.startFadeAlphaAnim(itemView.waterGoal)</pre><p>이런식으로 사용 가능하다.</p><p>WaterPin의 모든 코드는 제 <a href="https://github.com/hanmolee/Drinking-Water-Assistant">Github</a> 에서 확인 가능합니다.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=515e09c9df2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WaterPin — Technical stack #5 Tracking]]></title>
            <link>https://medium.com/@Hanmolee/waterpin-technical-stack-5-tracking-18f9153868e?source=rss-17e4893dc857------2</link>
            <guid isPermaLink="false">https://medium.com/p/18f9153868e</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[google-analytics]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[fabric]]></category>
            <category><![CDATA[tracking]]></category>
            <dc:creator><![CDATA[Hanmolee]]></dc:creator>
            <pubDate>Thu, 04 Oct 2018 11:36:00 GMT</pubDate>
            <atom:updated>2018-10-04T11:36:00.052Z</atom:updated>
            <content:encoded><![CDATA[<ul><li>tracking code : GA, Fabric, Firebase / WaterPin에 심어둔 Tracking Code를 정리하는 글이다.</li></ul><h4>WaterPin에는 GoogleAnalytics, FirebaseAnalytics, Fabric 3가지의 Event Tracking Code가 심어져 있다.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iYrYSEEQExxEbtIrSTUXVg.png" /><figcaption>GA View</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*38HQAUrrWgxoFbF_bOZjkg.png" /><figcaption>GA(Firebase) Event</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*peXnMWO3qSsm3SCWGCpDKQ.png" /><figcaption>Fabric Event</figcaption></figure><p>뷰 단위로 Tracking Code를 관리 하였다.</p><p>음… 사용자가 없어서 추적된 데이터를 분석할 필요가 없다…</p><p>그나마 내가 필요로한 데이터라고 생각했던 것이 있다. 그것을 기준으로 추적한 방법을 정리하겠다.</p><h4><strong>WaterPin 1.0.0 버전을 배포하면서 1.1.0에 업데이트 할 생각으로 만들어 놓은 아이콘이 2개 있다.</strong></h4><ol><li>Alarm page : 물마시는 시간을 주기적으로 혹은 특정 시간에 알람으로 알려주도록 할 페이지</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/234/1*Blrg36kTxYAA1Oke34V7sA.gif" /><figcaption>1. Alarm page</figcaption></figure><p>2. Custom Water Type : 현재는 200, 300, 500 ml 물의 단위가 있다. 그러므로 사용자가 필요한 물의 단위를 설정하도록 할 수 있도록 하기 위함</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/234/1*O-JCDfVzvhZ9ob35nO8wKA.gif" /><figcaption>2. Custom Water Type</figcaption></figure><p>이런식으로 사용자들에게 준비중이라는 것을 알려주었으며</p><p>얼마나 사용자들이 원하는지 알기 위해 버튼 클릭의 수를 추적하였다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*e1zBmSXFP4FGa9vxZHwH6Q.png" /><figcaption>button click event tracking</figcaption></figure><p>먼저 Tracking Code를 따로 하나의 패키지에서 관리하도록 하였다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*LzAVJf222Wbrfh9W2jb4gg.png" /><figcaption>이런식으로 View 단위로 Tracking Code를 관리하였다.</figcaption></figure><h4>먼저 Google Analytics Tracking을 보면</h4><ol><li>Gradle에 analytics 추가</li></ol><pre>//GA<br>implementation &quot;com.google.android.gms:play-services-analytics:16.0.4&quot;</pre><p>2. GA Tracking <a href="https://developers.google.com/analytics/devguides/collection/android/v4/">공식문서</a> 를 참조하여 Application이 onCreate될 때 Tracker 를 가져오도록 하였다.</p><pre>@Synchronized<br>fun getDefaultTracker(): Tracker? {<br>    // To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG<br>    sTracker?.<em>run </em><strong>{<br>        </strong>return this<br>    <strong>} </strong>?: kotlin.<em>run </em><strong>{<br>        </strong>val sAnalytics = GoogleAnalytics.getInstance(this@DWApplication)<br>        return sAnalytics.newTracker(R.xml.<em>global_tracker</em>)<br>    <strong>}<br></strong>}</pre><p>3. GA View와 GA Event를 관리하는 Util Class 를 만들었다.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4def6a58b7d3e66d176b880e599ed8be/href">https://medium.com/media/4def6a58b7d3e66d176b880e599ed8be/href</a></iframe><h4>두번째로 Firebase Analytics Tracking을 보면</h4><ol><li>gradle에 firebse core 추가</li></ol><pre>implementation &quot;com.google.firebase:firebase-core:16.0.4&quot;</pre><p>2. Firebase Analytics Tracking <a href="https://firebase.google.com/docs/analytics/android/start/?hl=ko">공식문서</a> 를 참조하여 Application이 onCreate될 때 firebaseAnalytics 를 가져오도록 하였다.</p><pre>firebaseAnalytics = FirebaseAnalytics.getInstance(this@DWApplication)</pre><h4>두번째로 Fabric Custom Event Tracking을 보면</h4><ol><li>gradle에 Fabric 추가</li></ol><pre>implementation(&#39;com.crashlytics.sdk.android:crashlytics:2.9.5@aar&#39;) { transitive = true }</pre><p>2. Fabric Tracking <a href="https://docs.fabric.io/android/answers/answers-events.html">공식문서</a> 를 참조하여 Application이 onCreate될 때 Fabric을 초기화하였다.</p><pre>Fabric.with(this, Crashlytics())</pre><h4>Application단을 보면</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8cf5d1e35553a4dcf2280305adcae53e/href">https://medium.com/media/8cf5d1e35553a4dcf2280305adcae53e/href</a></iframe><ul><li>이런식으로 Tracking 관련 초기화를 진행하였다.</li></ul><h4>1. Alarm 아이콘을 클릭하는 곳이 MainActivity 이므로 MainActivityTrackingUtil에 알람 버튼 클릭을 추적하는 부분을 작성하였다.</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e6419078c7678ddc534bca7a5a8400d3/href">https://medium.com/media/e6419078c7678ddc534bca7a5a8400d3/href</a></iframe><ul><li>Fabric Custom Event 추적</li><li>Firebase Event 추적</li><li>GA View, Event 추적</li></ul><h4>2. Custom Water Type 아이콘을 클릭하는 곳이 MyTargetWaterActivity이므로 MyTargetActivityTrackingUtil에 커스텀 버튼 클릭을 추적하는 부분을 작성하였다.</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6085b0609cb3e685e61d15c4dc5cee3c/href">https://medium.com/media/6085b0609cb3e685e61d15c4dc5cee3c/href</a></iframe><ul><li>Fabric Custom Event 추적</li><li>Firebase Event 추적</li><li>GA View, Event 추적</li><li><strong><em>이런식으로 data를 보낼 수도 있다. (잠금화면 Switch state)</em></strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/462c198f83999200fa8be5968f2cfc24/href">https://medium.com/media/462c198f83999200fa8be5968f2cfc24/href</a></iframe><p>내가 구현한 것은 가장 간단하게 Event를 추적하는 방법이라고 생각하면 된다.</p><p><em>사용자가 적어 넣지는 않았지만 유저 프로퍼티를 지정하거나 다양한 파라미터를 보낼 수도 있다. 또한 Fabric같은 경우엔 커스텀 이벤트가 아닌 Login, Share 등의 이벤트도 제공해 준다.</em></p><p>WaterPin의 모든 코드는 제 <a href="https://github.com/hanmolee/Drinking-Water-Assistant">Github</a> 에서 확인 가능합니다.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18f9153868e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>