<?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 Su on Medium]]></title>
        <description><![CDATA[Stories by Su on Medium]]></description>
        <link>https://medium.com/@devsumyat?source=rss-1fb72ca1e471------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zVCPxuFn4Re_haADipUj7A.jpeg</url>
            <title>Stories by Su on Medium</title>
            <link>https://medium.com/@devsumyat?source=rss-1fb72ca1e471------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 11:35:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@devsumyat/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[How can we inflate a layout with a one-liner?]]></title>
            <link>https://medium.com/@devsumyat/how-can-we-inflate-a-layout-with-a-one-liner-1c63508f978a?source=rss-1fb72ca1e471------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c63508f978a</guid>
            <category><![CDATA[fragments]]></category>
            <category><![CDATA[layout]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Su]]></dc:creator>
            <pubDate>Mon, 13 Jul 2020 08:26:09 GMT</pubDate>
            <atom:updated>2020-07-13T08:26:09.161Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*10udiIv8UuxR8wyZbTJmZg.jpeg" /></figure><p>Usually we create a View using onCreateView() in a Fragment like this:</p><pre>override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {        <br>return inflater.inflate(R.layout.fragment_todo, container, false)<br>}</pre><p>Suppose we have 50 Fragments where every one of them have a different layout. There will be 150 lines of code just for inflating a view. We can reduce this 150 to about 50 with some setup:</p><pre>@Target(AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.CLASS)<br>@kotlin.annotation.Retention<br>annotation class Screen(val resourceLayout: Int)</pre><p>Create a BaseFragment and call onCreateView function and use layout from annotation class like below</p><pre>override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceStateceState: Bundle?): View? <br>{<br>val layout: Int = javaClass.getAnnotation(Screen::class.java)?.resourceLayout ?: R.layout.default_layout<br>return inflater.inflate(layout, container,false)<br>}</pre><p>You can now create your Views with a one-liner<br>@Screen(resourceLayout = R.layout.fragment_a)<br>class AFragment : BaseFragment() { … }@Screen(resourceLayout = R.layout.fragment_b)<br>class BFragment: BaseFragment() { … }@Screen(resourceLayout = R.layout.fragment_c)<br>class CFragment: BaseFragment() { … }and so on…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c63508f978a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hilt Dependency Injection in Action]]></title>
            <link>https://medium.com/@devsumyat/hilt-dependency-injection-in-action-fb3cfb49e21a?source=rss-1fb72ca1e471------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb3cfb49e21a</guid>
            <dc:creator><![CDATA[Su]]></dc:creator>
            <pubDate>Mon, 15 Jun 2020 14:58:36 GMT</pubDate>
            <atom:updated>2020-06-15T14:58:36.747Z</atom:updated>
            <content:encoded><![CDATA[<p>Hiltရဲ့ ရည်ရွယ်ချက်ကတော့ DIရေးရတာ ပိုမိုလွယ်ကူရိုးရှင်းစေဖို့အတွက်ပါ။ Google ကနေ Hilt Dependency Injectionကို DI ရေးသားသူတွေအတွက် အသုံးပြုဖို့ recommend ပေးထားတယ်။ DI ကတော့ လက်ရှိရေးပန်းစားနေတဲ့ programming တစ်ခုပါ။ DIက classအတွက် လိုအပ်တဲ့ dependenciesတွေကို classကသူဘာသာသူဆောက်လုပ်မဲ့အစား DIကထောက်ပံ့ပေးပါတယ်။ အဲဒါကြောင့် code အရေးအတွက်တွေ လျှော့ချပေးနိုင်တယ်။ သူကို အဓိက အသုံးပြုရတဲ့ ရည်ရွယ်ချက်ကတော့ code reusabilityဖြစ်ဖို့နဲ့ refactoringလုပ်တာလွယ်ကူဖို့အပြင် testing ရေးသားရလွယ်ကူစေဖို့အတွက် DIကိုရေးသားကြခြင်းဖြစ်ပါတယ်။ လက်ရှိ Top 10K appတွေရဲ့74%ဟာ daggerကိုအသုံးပြုထားကြတယ်။ ဒီBlogမှာ ရေးသားထားတာကတော့ ရှိပြီးသား Dagger Projectတစ်ခုကနေ Hiltဘယ်လိုImplement လုပ်သလဲဆိုတာကို step by step ဖော်ပြရေးသားပေးထားပါတယ်။</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06530b2b56dad3c15e871e5fb193a3c9/href">https://medium.com/media/06530b2b56dad3c15e871e5fb193a3c9/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0777a5fdf546e99e85e2ff0c0c68c01/href">https://medium.com/media/b0777a5fdf546e99e85e2ff0c0c68c01/href</a></iframe><p>Hilt library အသုံးပြုလို့ရဖို့အတွက် လိုအပ်တဲ့ library dependencies တွေကို အရင် implementလုပ်မယ်။</p><p>DIအသုံးပြုဖို့အတွက် Base Application classကို <a href="http://twitter.com/HiltAndroidApp">@HiltAndroidApp</a> annotationကိုအသုံးပြုဖို့လိုအပ်ပါတယ်။ <a href="http://twitter.com/HiltAndroidApp">@HiltAndroidApp</a> annotationကြောင့် Appရဲ့ base Class ထဲမှာ Hilt’s code generationရှိသွားတာဖြစ်တဲ့အတွက် Dependency Injectionကို အသုံးပြုနိုင်တယ်။ Base classဆိုတာ application containerပါ။ Application containerက appတစ်ခုလုံးရဲ့ parent containerဖြစ်တာကြောင့် တစ်ခြားcontainerအတွက် လိုအပ်တဲ့dependenciesကိုထောက်ပံ့ပေးနိုင်တယ်။</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7da6296b971e680361af19a5da7426c8/href">https://medium.com/media/7da6296b971e680361af19a5da7426c8/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*bIFTvgy1T2w2F-gardLBpQ.png" /></figure><p>ပုံမှာပြထားတဲ့အတိုင်း di folderထဲမှာ AppModuleတစ်ခုပဲချန်ထားခဲ့ပြီး ကျန်ရှိတဲ့ classတွေအကုန်းလုံးဖြတ်လိုက်ပါ မလိုအပ်တော့ပါဘူး။</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88cae63a9e9caf83262e13a7cf9e7b22/href">https://medium.com/media/88cae63a9e9caf83262e13a7cf9e7b22/href</a></iframe><p>ပြီးတော့ AppModuleထဲကအရာတွေမှာ <a href="http://twitter.com/InstallIn">@InstallIn</a> annotation အသုံးပြုပြီး Hilt’s ApplicationComponent ထဲမှာ installလုပ်လိုက်ပါတယ်။</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15166f92cc5ac6157ede2a78781d93e6/href">https://medium.com/media/15166f92cc5ac6157ede2a78781d93e6/href</a></iframe><p>ViewModelအတွက် <a href="http://twitter.com/Inject">@Inject</a> အစား <a href="http://twitter.com/ViewModelInject">@ViewModelInject</a>ပြောင်းလဲအသုံးပြုပေးဖို့လိုအပ်ပါတယ်။</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de0ca12467cb41ecf2592333c1fe3744/href">https://medium.com/media/de0ca12467cb41ecf2592333c1fe3744/href</a></iframe><p><a href="http://twitter.com/AndroidEntryPoint">@AndroidEntryPoint</a> annotationကို DI အသုံးပြုချင်တဲ့ classတွေအပေါ်မှာရေးသားလိုက်ရုံပါပဲ။ daggerနဲ့တုန်းက ViewModelအသုံးပြုနိုင်ဖို့အတွက် ViewModelProvider.Factory ရေးသားဖို့လိုအပ်ပေမယ့် Hiltမှာ မလိုအပ်တော့ပါဘူး။ Hilt refactoring ခြင်းပြီးဆုံးပါပြီ။ အားလုံး Hilt Dependency Injection ကိုလွယ်လွယ်ကူကူလေ့လာ ရေးသားနိုင်ကြပါစေ။ အောက်မှာပေးထားတဲ့ Official Guidelinesများကိုလည်း ဝင်ရောက်လေ့လာကြပါ။</p><ul><li><a href="https://medium.com/androiddevelopers/dependency-injection-on-android-with-hilt-67b6031e62d">Dependency injection on Android with Hilt</a></li><li><a href="https://codelabs.developers.google.com/codelabs/android-hilt/#0">Using Hilt in your Android app</a></li><li><a href="https://codelabs.developers.google.com/codelabs/android-hilt/#0">Using Hilt in your Android app</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb3cfb49e21a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[@BindingAdapterသုံးပြီး Data Binding ရေးကြမယ်]]></title>
            <link>https://medium.com/@devsumyat/bindingadapter%E1%80%9E%E1%80%AF%E1%80%B6%E1%80%B8%E1%80%95%E1%80%BC%E1%80%AE%E1%80%B8-data-binding-%E1%80%9B%E1%80%B1%E1%80%B8%E1%80%80%E1%80%BC%E1%80%99%E1%80%9A%E1%80%BA-28bfeb84887?source=rss-1fb72ca1e471------2</link>
            <guid isPermaLink="false">https://medium.com/p/28bfeb84887</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-data-binding]]></category>
            <dc:creator><![CDATA[Su]]></dc:creator>
            <pubDate>Tue, 12 May 2020 15:18:07 GMT</pubDate>
            <atom:updated>2020-05-12T15:18:07.512Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9CZVkLir_-h2iRTy-23ceg.png" /></figure><p>လက်လမ်းမှီသလောက် Data Bind နည်းများကို မျှဝေပေးလိုက်ပါတယ်။ အဓိက ၃မျိုးသုံးပြထားပါတယ်။ Data Bindingက များသောအာဖြင့် Projectကြီးတွေမှာသုံးဖြစ်တယ်။ အလုပ်Interview တော်တော်များများမှာလဲ မေးလေ့မေးထရှိတယ်။ လေ့လာရ အဆင်ပြေအောင် Sample project link ပေးထားတယ်။ Sample Project ထဲကမှ SimilarFragment class နဲ့ fragment_movie_detail xml နှစ်ခုကို သေချာလေ့လာရင် data bindingရေးနည်းကို နားလည်သွားမှာပါ။ feature/coil branch ကို checkout လုပ်ပြီးမှ ကြည့်ရင် ပိုအဆင်ပြေတယ်။ Image Libarary အပိုင်းလေး နည်းနည်း update လုပ်ထားလို့ပါ။</p><p><a href="https://github.com/suhtun/Movie-Sample">suhtun/Movie-Sample</a></p><h3>Setup</h3><p>Data Binding ရေးဖို့အတွက်ဆို ကနဦးအနေနဲ့ build.module(app) file ထဲမှာ အောက်ပါအတိုင်း configureလုပ်ပေးဖို့ လိုအပ်ပါတယ်။</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cfe4f1a115b29e4517cdb97bfd898e1c/href">https://medium.com/media/cfe4f1a115b29e4517cdb97bfd898e1c/href</a></iframe><blockquote>TextView ထဲမှာ data bind နည်းရေးမယ်ဆိုရင်</blockquote><p>ပထမဆုံး XML ထဲမှာ Data Bind ချင်ရင် အောက်ပါအတိုင်း layout ထဲက data အတွင်းမှာ variableရေးမယ်။ ဒီနေရာမှာ လက်ရှိ variable type က Movie Object type ဖြစ်နေတယ် typeက ကိုယ်လိုချင်တဲ့ type ကြေငြာလို့ရတယ်။ ဥပမာ String, Int, Double, Float… အစရှိသဖြင့်ပေါ့။</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52633c20aabf2334891a00b15150ba09/href">https://medium.com/media/52633c20aabf2334891a00b15150ba09/href</a></iframe><p>အဲဒီလို XML ထဲမှာ ရေးပြီးတာနဲ့ auto generate file ထွက်လာလိမ့်မယ်။ ဥပမာ xml file name ကို fragment_movie_detail ပေးခဲ့ရင် FragmentMovieDetailBindingView ဆိုတဲ့ auto generate file ထွက်လာလိမ့်မယ်။ ထွက်လာတဲ့ auto generate file ကို Viewမှာ ခေါ်သုံးမယ်။ အောက်က နမူနာရေးပြထားပါတယ်။</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/207308138697d7b904844074ab35d385/href">https://medium.com/media/207308138697d7b904844074ab35d385/href</a></iframe><p>onCreateView ထဲမှာ data binding အသုံးပြုနိုင်ရန်အတွက် DataBindingUtil သုံးပြီး return ပြန်ထားတယ်။ onViewCreated ထဲမှာ Viewရဲ့ lifecycle အခြေအနေကို နားလည်းစေချင်လို့ binding.lifecycleOwner = viewLifecycleOwnerလို့ ထည့်လိုက်တယ်။ ပြီးတော့ ခုဏက ကြေငြာခဲ့တဲ့ movie variable အတွက် data set လိုက်တယ်။ဒါဆို data setပြီးသွားပြီး ဘယ်လိုပြန်သုံးမလဲ ကြည့်ရအောင်။</p><pre>android:text=&quot;@{movie.title}&quot;</pre><p>movie.title ဆိုပြီး XML ထဲမှာ ယူသုံးလိုက်ပါ။ ဒါဆို Object varible ဆောက်ပြီး TextView ထဲမှာ data bind တက်သွားပြီ။</p><blockquote>ImageView ထဲမှာ data bind နည်းရေးမယ်ဆိုရင်</blockquote><pre>&lt;ImageView<br>app:imageUrl=&quot;@{`https://image.tmdb.org/t/p/w500`+repo.poster_path}&quot;/&gt;</pre><p>ImageView မှာ အခုလို codeline တစ်ကြောင်းထဲနဲ့ ရေးနိုင်ဖို့အတွက် Adapter class အရင်းဆောက်ရမယ်။ ဆောက်ထားတဲ့ class ကို DataBindingComponent class အသစ်တစ်ခုဆောက်ပြီး bindingAdapter override method ထဲမှာ ခုဏက ဆောက်ထားတဲ Adapter class ကိုပြန်ထည့်ပေးရမယ် ပြီးရင်တော့ View class ထဲမှာ ပြန်ခေါ်သုံးရမယ်။ အောက်မှာ ရေးပြထားတဲ့ နာမူနာကို ကြည့်ပါ။</p><pre>step 1)<br>class FragmentBindingAdapters @Inject constructor(val fragment: Fragment) {<br>    @BindingAdapter(value = [&quot;imageUrl&quot;], requireAll = false)<br>    fun bindImage(imageView: ImageView, url: String?) {<br>        imageView.<em>load</em>(url)<br>    }<br>}<br>step 2)<br>class FragmentDataBindingComponent(fragment: Fragment) : DataBindingComponent {<br><br>    private val adapter = FragmentBindingAdapters(fragment)<br><br>    override fun getFragmentBindingAdapters(): FragmentBindingAdapters  = adapter<br>}<br>step 3)<br>var dataBindingComponent: DataBindingComponent = FragmentDataBindingComponent(this)</pre><p>imageUrl ထဲကို value ရောက်လာတာနဲ့ bindImage ဆိုတဲ့ Method စအလုပ်လုပ်မှာပါ။ အဲဒီအတွက် <a href="http://twitter.com/BindingAdapter">@BindingAdapter</a> အကို အသုံးပြုထားတယ်။ ဒီနေရာမှာ တစ်ခုသိစေချင်တာက bindImage function ထဲမှာ parameter နှစ်ခုရှိတယ် တစ်ခုက သူကိုလှမ်းခေါ်သုံးလိုက်တဲ့ XML ထဲက View type ဖြစ်ပြီး နှောက်တစ်ခု ထည့်ပေးလိုက်တဲ့ value ပါ။ မြင်သာအောင် အောက်ကsample ကိုကြည့်ပါ။</p><pre>@BindingAdapter(&quot;visibleGone&quot;)<br>fun showHide(view: View, show: Boolean) {<br>    view.<em>visibility </em>= if (show) View.<em>VISIBLE </em>else View.<em>GONE<br></em>}</pre><p>visibleGone function ကိုတော့ Progressbar အတွက် နမူနာအနေနဲ့ ရေးပြထားပါအပြင် View Type အနေနဲ့ Generic Type ကို သုံးပြထားတယ်။ (ကိုယ်သုံးချင်တဲ့အပေါ်မူတည်ပြီး customize function တွေရေးလို့ရတယ်။) အောက်မှာ နမူနာ ပြထားပါတယ်။</p><pre>&lt;ProgressBar app:visibleGone=&quot;@{true}&quot; /&gt; (OR)</pre><pre>&lt;variable<br>    name=&quot;loadmore&quot;<br>    type=&quot;mm.com.sumyat.archiecture_sample.ui.common.RetryCallback&quot; /&gt;</pre><pre>&lt;ProgressBar app:visibleGone=&quot;@{loadingMore}&quot; /&gt;</pre><blockquote>Listener data bindနည်းရေးမယ်ဆိုရင်</blockquote><p>နှောက်ဆုံးအနေနဲ့ Listener data bind နည်းရေးမယ်။ အရင်းဆုံး RetryCallback ဆိုတဲ့ class ဆောက်မယ် ပြီးတော့ XML ထဲမှာ variable အနေနဲ့ထည့်၊ နှောက်ဆုံး action တစ်ခုမှာ Listener အနေနဲ့သုံးမယ်။ နမူနာမှာတော့ Button ရဲ့ onclick action ထဲမှာ listener method ခေါ်ထားတယ်။ ပြီးတော့ View class ကနေ ပြန်ဖမ်းထားတယ်။ View ကနေ အဲဒီ action ကို စောင့်ဖမ်းပြီး အလုပ်လုပ်ဖို့ပေါ့။ ဒီနည်းက သုံးတက်ရင်အများကြီး အသုံးဝင်ပါတယ်။</p><pre>1)<br>interface RetryCallback {<br>    fun retry()<br>}<br>2)<br>&lt;variable<br>   name=&quot;callback&quot;<br>   type=&quot;mm.com.sumyat.archiecture_sample.ui.common.RetryCallback&quot;/&gt;<br>3)<br>android:onClick=&quot;@{() -&gt; callback.retry()}&quot;</pre><p>စာအရမ်းရှည်ရင် မဖတ်ဖြစ်မှာ စိုရိမ်လို့ အတက်နိုင်ဆုံး အကျဉ်းချုပ် မလိုအပ်တာတွေ မရေးပဲ လိုရင်း data binding ရေးနည်းကိုပဲ အဓိကထားရေးတယ်။ ၃မျိုးပဲ ရေးပြထားတယ်ဆိုပေမဲ့ project တစ်ခုလုံးအတွက် cover ဖြစ်ပါတယ်။ Article ကို ကြိုက်နစ်သက်ရင် 👏ပေးခဲ့ပါ။ အားလုံးအတွက်အထောက်အကူပြုနိုင်တဲ့ Article တစ်ခုဖြစ်ဖို့ မျှော်လင့်မိပါတယ်။</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28bfeb84887" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Codelineတစ်ကြောင်းထဲနဲ့ Blur/Circle/Gray/Rounded Image တွေရေးလို့ရလား]]></title>
            <link>https://medium.com/@devsumyat/codeline%E1%80%90%E1%80%85%E1%80%BA%E1%80%80%E1%80%BC%E1%80%B1%E1%80%AC%E1%80%84%E1%80%BA%E1%80%B8%E1%80%91%E1%80%B2%E1%80%94%E1%80%B2%E1%80%B7-blur-circle-gray-rounded-image-%E1%80%90%E1%80%BD%E1%80%B1%E1%80%9B%E1%80%B1%E1%80%B8%E1%80%9C%E1%80%AD%E1%80%AF%E1%80%B7%E1%80%9B%E1%80%9C%E1%80%AC%E1%80%B8-fac3a0f87668?source=rss-1fb72ca1e471------2</link>
            <guid isPermaLink="false">https://medium.com/p/fac3a0f87668</guid>
            <category><![CDATA[coil-image-library]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-circle-image]]></category>
            <category><![CDATA[android-image-blur]]></category>
            <category><![CDATA[android-gray-image]]></category>
            <dc:creator><![CDATA[Su]]></dc:creator>
            <pubDate>Mon, 11 May 2020 12:59:57 GMT</pubDate>
            <atom:updated>2020-05-11T12:59:57.294Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EtqOZJz0koc0PZXBtL54Fw.png" /></figure><p>Coil နဲ့ ရေးလို့ရပါတယ်။ ဒီ Articleမှာ Coilအကြောင်း အသေးစိတ်မပြောဘူ။း Coilကိုအသုံးပြုပြီး Blur Image နဲ့ Circle Image ကို codeline တစ်ကြောင်းထဲနဲ့ ဘယ်လိုရေးလို့ရတယ်ဆိုတာကိုပဲ အဓိက ဖော်ပြထားပါတယ်။ Circle Image View အတွက်ကတော့ သူ့ရဲ့ Offical Pageရှိပြီးသားဆိုတော့ ယူသုံးလိုက်ရုံပဲ။ ဒါပေမဲ့ Blur အတွက်ကတော့ မတွေ့ဘူး ဒါနဲ့ ဒီ article လေးရေးဖြစ်သွားတယ်။</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*yaYb1jjg5rcwAloLHwBxiw.png" /><figcaption>Blur Image Preview</figcaption></figure><pre>transformations(BlurTransformation(this))</pre><p>ပထမဦးဆုံးအနေနဲ့ Blur Image View လိုချင်တဲ့အခါ transformationsထဲမှာ BlurTransformation() ကိုထည့်ရေးပေးလိုက်ရင်ရပြီ။ အာက်မှာ နမူနာရေးပြထားတယ်။</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f966e134a90c9a54005f78138a0f8c3/href">https://medium.com/media/4f966e134a90c9a54005f78138a0f8c3/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*cI-iUx8CrV1OsEnqj7Nt8Q.png" /><figcaption>Circle Image Preview</figcaption></figure><p>Circle Image View အတွက်လဲ transformationsထဲမှ CircleCropTransformation() ဆိုပြီး ရေးပေးယုံပဲ။</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b2e4e3bfa0ea732d7c45e28ccb7e1eb/href">https://medium.com/media/1b2e4e3bfa0ea732d7c45e28ccb7e1eb/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*_36lQ1cFZNu5yRsE7ymjOQ.png" /><figcaption>Gary Image Preview</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/584ccf18a8eaed43738839643595a68e/href">https://medium.com/media/584ccf18a8eaed43738839643595a68e/href</a></iframe><p>Rounded Corner Image View အတွက်က ကိုယ်ချိုးချင်တဲ့ ပုံစံအလိုက် Px value ကိုထည့်ပေးလိုက်ပါ။ နမူနာအနေနဲ့ ဒီပုံမှာ ထောင့်ချိုးအားလုံးအတွက် 8px(8f) သုံးထားတယ်။</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*qlApCyTCbLou6ecEVqdHng.png" /><figcaption>Rounded Corner Image Preview</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4c0d9f774a3db831a548b78a84e3982/href">https://medium.com/media/b4c0d9f774a3db831a548b78a84e3982/href</a></iframe><p>အခုရေးသားခဲ့တာတွေက Coil Image Library ကို အသုံးပြုပြီး transform လုပ်လိုရတဲ့ Image ပုံစံတွေပါ။ ရေးသားရလွယ်ကူပြီး လက်တွေ့လဲ အများကြီး အထောက်အကူပြု အသုံးဝင်တဲ့ အသုံးပြုသူအားလုံး အချိန်တိုတိုနဲ့ အသုံးဝင်စေဖို့ ရည်ရွယ်၍ ဒီArticle လေးတင်ပေးလိုက်ပါတယ်။ Article လေးကို ကြိုက်နှစ်သက်ရင် 👏 ပေးခဲ့ပါ 😀😉။</p><p><a href="https://coil-kt.github.io/coil/transformations/">Transformations - Coil</a></p><p>Coil ရဲ့ Official Pageမှာလဲ အသေးစိတ် သွားရောက်လေ့လာနိုင်ပါတယ်။</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fac3a0f87668" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Android Vitals to build high quality Apps]]></title>
            <link>https://medium.com/@devsumyat/using-android-vitals-to-build-high-quality-apps-f4b544e74949?source=rss-1fb72ca1e471------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4b544e74949</guid>
            <category><![CDATA[android-platform]]></category>
            <category><![CDATA[google-play-store]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-vital]]></category>
            <category><![CDATA[high-quality-app]]></category>
            <dc:creator><![CDATA[Su]]></dc:creator>
            <pubDate>Sun, 05 Apr 2020 06:33:04 GMT</pubDate>
            <atom:updated>2020-04-05T06:33:04.627Z</atom:updated>
            <content:encoded><![CDATA[<p>As developers, we always strive to build useful and quality apps but some of use may not be aware of the tools that can aid us in this endeavor. Hence this post aims to shed some light on how Android Vitals can help us build high quality apps. But before I begin, why do we want quality apps?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oULBnpBb0zWPmKRL" /></figure><p>Nobody enjoys using an app that crashes and freezes frequently.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QFxZ77q8AAZ-ky1d2srjOA.png" /><figcaption>tiny.cc/vitalreference</figcaption></figure><p>During Google I/O 2018, Google provided an analysis of all reviews on the Google Play Store over the past year and found that over 40% of users left one-star reviews; citing negative performance indicators like poor stability and numerous bugs. On the other end of the spectrum, more than 70% of users left five-stars review; citing positives like speed, design and usability. As reviews are direct indicators of customer satisfaction, this can have significant impact on downstream business KPI like user engagement, retention, and monetization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*9Gnt3xtdeYNba79FhXo_pA.png" /><figcaption>tiny.cc/vitalreference</figcaption></figure><p>Google also found that apps with the lowest crash rates saw more than double the number of plays per day, compared to apps with high crash rates. Users also spend almost three minutes more per day on stable apps. To put this into perspective, this translates to 18 additional hours of gameplay per day year that the more stable apps are getting per user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0eNlMJ86ckqelQUTx86O8Q.png" /><figcaption>tiny.cc/vitalreference</figcaption></figure><p>From business perspective, more stable apps have better opportunities to succeed due to app curation by Google Play. So apps that are regularly updated and experience little crashes are more likely to be featured as Editor’s Choice and be nominated for Google Play Awards, hence improving visibility to Google Play users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*lL5himPjocsiV1_Vdi-XQQ.png" /><figcaption>tiny.cc/vitalreference</figcaption></figure><p>With that in mind, what is Android Vitals then?</p><p>Android Vitals is an initiative which provides developers an accessible way to the most important metrics of app performance, namely: battery, stability and graphics rendering.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q0tTRk9kRJmVNGgmZ75paQ.png" /><figcaption>tiny.cc/vitalreference</figcaption></figure><p>Starbucks is an enormously popular app with over 15 million downloads on the Google Play Store. Android Vitals was added to the app in December 2017 and the Starbucks mobile team successfully reduced ANR rate by 70% and crash rate by 85% within a week. This is one notable example of developers who have been able to leverage Android Vitals to see significant gains in app quality and thus business growth.</p><p>In conclusion, Android Vitals is a platform-level tool which is able to detect crashes and identify the underlying cause of these crashes. In the next blog, I will write how does Android Vitals do this + technical stuff.</p><p>Thanks for reading and follow me for more articles. :) ;)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4b544e74949" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[View Binding in Android 3.6 (how to use it) ]]></title>
            <link>https://medium.com/@devsumyat/view-binding-in-android-3-6-how-to-use-it-4e99921883d2?source=rss-1fb72ca1e471------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e99921883d2</guid>
            <category><![CDATA[view-binding]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[data-binding]]></category>
            <dc:creator><![CDATA[Su]]></dc:creator>
            <pubDate>Sat, 05 Oct 2019 05:10:13 GMT</pubDate>
            <atom:updated>2019-10-05T09:20:01.024Z</atom:updated>
            <content:encoded><![CDATA[<h3>View Binding for Android (New Api) 😀</h3><p>I talked about this topic at Devfest Mobile Day in Thailand in 2019.</p><p>Why I choose this talk?</p><p>In Google IO 2019, introduced ViewBinding at “What’s new in Android” talk.</p><p>Now it’s available.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cWrEGnyfQzy46ZaL4NTZuA.png" /></figure><h3>What’s ViewBinding?</h3><p>Before we go to ViewBinding, let’s recap what’s DataBinding.</p><p>So DataBinding is our declarative UIs inside XML. It tries binding the gap between the code and XML. Now we knew a little about it.</p><p>So let’s start move on ViewBinding which is a new API and is available in Android Studio 3.6 canary 11+. You can use it now. It similar concept as DataBinding.</p><p>Pro tip: ViewBinding/DataBinding can provide the binding class which is a nice way of directly calling views by id with just initializing one variable.</p><h3>How do we access View on Android?</h3><p>Let’s look up the options we have.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lZsHEB7MOcgSd5dE64Nu8Q.png" /></figure><p>So first, we have good old <strong>findViewById</strong>, it’s not elegance and it very verbose. It doesn’t provide compile type safety and it doesn’t know what type you’re using. But it doesn’t have any build time speed impact, that’s good.</p><p>You could use <strong>DataBinding</strong> which provides a really nice API with compile type safety. But it draws an annotation processor, so it does slow your build.</p><p>You could use <strong>Butterknife</strong> similarly. It’s also another annotation processor, so it does slow your build.</p><p>If you’re using Kotlin, you could use <strong>Kotlin Synthethic</strong>, it provides partial compile type safety. It doesn’t have any build time speed impact.</p><p>But we are looking for something that has a green mark for all these things which is <strong>ViewBinding</strong>.</p><h3>Let’s make a practice.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*WKQCmuv1SnfTnTo71MZbwA.png" /><figcaption>sample application</figcaption></figure><p>Here, we will be using a small sample application which will show as count depends on how many times you have been clicked.</p><p>Start first with <strong>findViewById</strong>, we declare a view using <strong>findViewByID</strong>. Please check it out below example.</p><pre>lateinit var loveCountTxt: TextView<br>lateinit var likeBtn: Button<br>override fun onCreate(savedInstanceState: Bundle?) {<br>    super.onCreate(savedInstanceState)<br>    setContentView(R.layout.<em>activity_main</em>)<br>    loveCountTxt = findViewById(R.id.<em>txt_love_count</em>)<br>    likeBtn = findViewById(R.id.<em>btn_like</em>)<br><br>    viewModel.likes.observe(this, <em>Observer </em><strong>{<br>        </strong>loveCountTxt.<em>text </em>= &quot;${<strong>it</strong>}&quot;<br>    <strong>}</strong>)<br><br>    likeBtn.setOnClickListener <strong>{<br>        </strong>viewModel.onLike()<br>    <strong>}<br></strong>}</pre><p>For <strong>DataBinding</strong>, we declare a variable in XML then write a binding class in an activity.</p><pre>&lt;?xml&gt;<br>&lt;layout&gt;<br>    &lt;data&gt;<br>        &lt;variable<br>            name=&quot;viewmodel&quot;<br>            type=&quot;.SampleViewModel&quot; /&gt;<br>    &lt;/data&gt;<br>&lt;LinearLayout&gt;<br>    &lt;TextViewandroid:text=&quot;@{Integer.toString(viewmodel.likes)}&quot;/&gt; <br>    &lt;Button android:onClick=&quot;@{() -&gt; viewmodel.onLike()}&quot;/&gt;        <br>&lt;/layout&gt;</pre><pre>override fun onCreate(savedInstanceState: Bundle?) {<br>    super.onCreate(savedInstanceState)<br>    val binding : ActivityMainBinding = DataBindingUtil.<br>        setContentView(this, R.layout.activity_main)<br>    binding.lifecycleOwner = this<br>    binding.viewmodel = viewModel<br>}</pre><p>In ViewBinding, we write both views and a binding class in an activity.</p><pre>override fun onCreate(savedInstanceState: Bundle?) {<br>    super.onCreate(savedInstanceState)<br><br>    var binding = ActivityMainBinding.inflate(<em>layoutInflater</em>)<br>    setContentView(binding.<em>root</em>)<br><br>    viewModel.likes.observe(this, <em>Observer </em><strong>{<br>        </strong>binding.count.<em>text </em>= &quot;${<strong>it</strong>}&quot;<br>    <strong>}</strong>)<br><br>    binding.like.setOnClickListener <strong>{ </strong>viewModel.onLike() <strong>}<br></strong>}</pre><p>Thank you 😀.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e99921883d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dependency Injection Koin Vs. Dagger]]></title>
            <link>https://medium.com/@devsumyat/dependency-injection-koin-vs-dagger-5f7baaad758c?source=rss-1fb72ca1e471------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f7baaad758c</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[koin]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[dagger-2]]></category>
            <dc:creator><![CDATA[Su]]></dc:creator>
            <pubDate>Thu, 03 Oct 2019 12:22:26 GMT</pubDate>
            <atom:updated>2019-10-03T12:22:26.131Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FpBFEqdG6s6aiPdulaYABg.png" /><figcaption><a href="https://blog.ippon.fr/2019/09/03/android-di-de-dagger-vers-koin/">https://blog.ippon.fr/2019/09/03/android-di-de-dagger-vers-koin/</a></figcaption></figure><p>ဒီ article ထဲမှာ Dependency Inject အကြောင်း အကျဉ်းချုပ်ပြောထားတယ် ပြီးတော့ Koin နဲ့ Dagger တို့ရဲ့ setup လုပ်ပုံပါတယ်။</p><p>ပထမဆုံး ဒီအကြောင်းအရာပြောဖြစ်တာက Koin ကလက်ရှိအချိန်မှာ DI စိတ်ဝင်စား သူတွေအတွက် လေ့လာရ အဆင်ပြေတဲ့ DI framework တစ်ခုဖြစ်လာပါတယ်။</p><p>ဆိုတော့ Dependency Injection ဆိုတာဘာလဲ?</p><p>DI က လက်ရှိအချိန်အထိ blog post တွေ article တွေမှာ အသစ်အသစ်အနေနဲ့ Internet ပေါ်မှာ အမြဲ မြင်တွေ့နေရတယ်။</p><p>DI ကို အဓိက large and complex project တွေမှာ အသုံးပြုကြတယ်။ သူရဲ့ အကျိုးကျေးဇူးတွေက reusable, readable, extendable, testable အပြင် တစ်ခြားရှိပါသေးတယ်။</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eKlEBa28KdHrR2p_MmICCw.png" /><figcaption>A has a dependency on class B.</figcaption></figure><p>ပုံမှာ ပြထားတဲ့ အတိုင်ဆို class A က class Bထဲက method ကိုသုံးပြုချင်းတယ်။ ဒါက class A မှ class Bရဲ့ dependency ရှိတယ်ဆိုတာ နမူနာ ပြထားတာပါ။</p><p>Java မှာ ကိုယ်က တစ်ခြား class တစ်ခုရဲ့ method တွေကို ယူမသုံးခင် ကိုယ်အသုံးပြုချင်တဲ့ class ရဲ့ object ကို creat လုပ်ထားဖို့ လိုအပ်ပါတယ်။</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M_Xz1FZQ-nOrpKsRrGcKrg.png" /></figure><p>ဒီ ကာတွန်းပုံမှာဆို DI ဘာလုပ်ပေးသလဲ ရှင်းရှင်းလင်းလင်း မြင်ရပါတယ်။</p><p>ကောင်းလေက class A နဲ့ B ရဲ့ object လိုချင်းပါတယ်လို့ DI request လုပ်တယ်။ DI က လိုအပ်တာတွေကို သူထဲမှာ လုပ်တယ် ပြီးတော့ request လုပ်တဲ့သူဆီကို ပြန်ပို့ပေးတယ်။</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dqXJ5Y6HtbSRlpuiDHzVTA.png" /><figcaption>Injection လုပ်နေတဲ့ပုံပါ။</figcaption></figure><pre>class ClassA {<br>    var classB = ClassB()<br>    <br>    fun doSomething(){<br>        classB.Info()<br>    }<br>}</pre><p>injection မလုပ်ရသေးတဲ့ အခြေအနေပါ။</p><pre>class ClassA(val classB : ClassB) {<br><br>    fun doSomething(){<br>        classB.Info()<br>    }<br>}</pre><p>Injection လုပ်ထားပြီးပါပြီ။ Injection typeက constructor injectionပါ။</p><p>Injection Type သုံးမျိုးရှိတယ်။ Constructor injection, Setter injection နဲ့ Field injectionရယ်ပါ။</p><pre>class ClassA(val classB : ClassB) {<br><br>    fun doSomething(){<br>        classB.Info()<br>    }<br>}</pre><p>class ရဲ့ constructor ကနေမှ တစ်ဆင့် inject လုပ်တာကို Constructor Injection လို့ခေါ်ပါတယ်။</p><pre>class ClassA {<br><br>    fun doSomething(classB : ClassB){<br>        classB.Info()<br>    }<br>}</pre><p>Injector က client expose လုပ်ထားတဲ့ method ကို အသုံးပြုပြီး inject လုပ်တာကို setter inject လို့ခေါ်တယ်။</p><pre>class ClassA {<br><br>    @Inject<br>    val classB : ClassB<br>    fun doSomething(){<br>        classB.Info()<br>    }<br>}</pre><p>Field injection လဲ အတူတူပါပဲ client expose လုပ်ထားတဲ့ field ကို injector က inject လုပ်ဖို့အတွက်အသုံးပြုတယ်။</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zr_pSkpQWNr7zp6fltftRg.png" /></figure><p>လက်ရှိအချိန်မှာ DI အတွက် ရွေးချယ်စရာ framework တွေများလာပါပြီ။</p><p>Koin, Dagger, Kodien-DI, toothpick, DYI စသျဖင့္ ႐ွိလာတယ္။ ဒိထဲမွာမွ လူသံုးမ်ားတာက Dagger နဲ႔ Koin ပါ။</p><p>ဒီတော့ လက်တွေ့ step by step ရေးကြည့်ရအောင်။ မရေးခင် နဲ့ အကြောင်းလေ့လာကြည့်ရအောင်။</p><blockquote><strong>Dagger2</strong><br>Simple annotation structure<br>Readable generated code<br>No reflection<br>No runtime error<br>Proguard Friendly<br>Pure Java</blockquote><p>Dagger က Pure Java ဒိအပြင် stable ဖြစ်နေတာကြားပြီး google ကလဲ support ပေးထားတယ်။ သူက DI fully acknowledge ဖြစ်ပါတယ်။</p><blockquote><strong>Koin</strong><br> 100% Kotlin<br> DSL very intuitive<br> No code generation<br> No reflection<br> No compile time overhead</blockquote><p>Koinက pure kotlin နှောက်ပြီး သူက service locatorပါ။</p><p>Kotlin project မှာ dagger ရော koin ရော အသုံးပြုရ အဆင်ပြေပေးမဲ့ java project ထဲမှာ koin အသုံးပြုလို့ အဆင်ပြေမှာ မဟုတ်ပါဘူး။</p><p>ပထမဆုံး small project တစ်ခုရေးမယ်။ အထဲမှာ single activity သူနဲ့တွဲ အလုပ်လုပ်မဲ့ viewmodel ပါမယ်။ viewmodel အတွက် Dependency တစ်ခု လိုအပ်တယ်။ အဲဒါကို framework အသုံးပြုပြီး ဘယ်လို inject လုပ်သွားလဲ ဆိုတာကို dagger နဲ့ အရင် setup လုပ်ကြည့်ကြမယ်။ ဘာလို့လဲဆိုတော့ dagger setup က များတယ်။ koin ကတော့ setup လုပ်ရတာ ပိုရိုးရှင်းတယ်။ အဲဒါကြောင့် dagger ကနေပဲ စလိုက်ကြမယ်။</p><pre>implementation &#39;com.google.dagger:dagger:2.16&#39;<br>implementation &#39;com.google.dagger:dagger-android:2.16&#39;<br>kapt &#39;com.google.dagger:dagger-compiler:2.16&#39;<br>kapt &#39;com.google.dagger:dagger-android-processor:2.16&#39;</pre><pre>class NewsViewModel @Inject constructor(private val news: News) : ViewModel() {<br><br>    fun getNews(): String {<br>        return news.fetchNews()<br>    }<br><br>}</pre><p>ပထမဆုံး Dagger အတွက်လိုအပ်တဲ့ dependencies တွေကို implement လုပ်မယ်။<br>ပြီးတော့ UI အတွက်ViewModel class ရေးမယ်။</p><pre>@Singleton<br>class ViewModelFactory @Inject constructor(<br>    private val creators: Map&lt;Class&lt;out ViewModel&gt;, @JvmSuppressWildcards Provider&lt;ViewModel&gt;&gt;<br>) : ViewModelProvider.Factory {<br>    override fun &lt;T : ViewModel&gt; create(modelClass: Class&lt;T&gt;): T {<br>        val creator = creators[modelClass] ?: creators.entries.<em>firstOrNull </em><strong>{<br>            </strong>modelClass.isAssignableFrom(<strong>it</strong>.key)<br>        <strong>}</strong>?.value ?: throw IllegalArgumentException(&quot;unknown model class $modelClass&quot;)<br>        try {<br>            @Suppress(&quot;UNCHECKED_CAST&quot;)<br>            return creator.get() as T<br>        } catch (e: Exception) {<br>            throw RuntimeException(e)<br>        }<br>    }<br>}</pre><pre>@Target(<br>    AnnotationTarget.FUNCTION,<br>    AnnotationTarget.PROPERTY_GETTER,<br>    AnnotationTarget.PROPERTY_SETTER<br>)<br>@Retention(AnnotationRetention.RUNTIME)<br>@MapKey<br>annotation class ViewModelKey(val value: KClass&lt;out ViewModel&gt;)</pre><p>ViewModelFactory class နဲ့ ViewModelKey annotation class ဆောက်ပေးပါ။ ViewModel ကို support ပေးဖို့ပါ။</p><pre>@Module<br>abstract class ViewModelModule {<br>    @Binds<br>    @IntoMap<br>    @ViewModelKey(NewsViewModel::class)<br>    abstract fun bindMainViewModel(mainViewModel: NewsViewModel): ViewModel<br><br>    @Binds<br>    abstract fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory<br>}</pre><p>ViewModelModule က view model Binding လုပ်ဖို့အတွက်ပါ။</p><pre>@Module<br>open class ApplicationModule {<br><br>    @Provides<br>    fun provideNes() = News()<br>}</pre><p>Application Module က view model လိုအပ်တဲ့ parameter ကို provide လုပ်ဖို့ပါ။</p><pre>@Module<br>abstract class ActivityModule {<br>    @ContributesAndroidInjector<br>    abstract fun mainActivityInjector(): MainActivity<br>}</pre><p>Activity Module ဆောက်ပါ။</p><pre>@Singleton<br>@Component(<br>    modules = [<br>        AndroidInjectionModule::class,<br>        AndroidSupportInjectionModule::class,<br>        ApplicationModule::class,<br>        ActivityModule::class,<br>        ViewModelModule::class<br>    ]<br>)<br>internal interface ApplicationComponent : AndroidInjector&lt;SampleApplication&gt; {<br>    @Component.Builder<br>    abstract class Builder : AndroidInjector.Builder&lt;SampleApplication&gt;()<br>}</pre><p>မပြီးသေးပါဘူးနော်။<br>ခုနက ဆောက်ခဲ့တဲ Module တွေအတွက် component ထပ်ဆောက်ပေးရပါမယ်။</p><pre>class SampleApplication : DaggerApplication() {<br>    override fun applicationInjector(): AndroidInjector&lt;out DaggerApplication&gt; =<br>        DaggerApplicationComponent.builder().create(this)<br><br>}</pre><p>ပြီးတော့ dagger ကို launch လုပ်ဖို့အတွက် SampleApplication မှာ အထက်ပါအတိုင် ရေးသားပေးပါ။</p><pre>class MainActivity : DaggerAppCompatActivity() {<br><br>    @Inject<br>    lateinit var viewModelFactory: ViewModelProvider.Factory<br><br>    private val viewmodel by <em>lazy </em><strong>{<br>        </strong>ViewModelProviders.of(<br>            this,<br>            viewModelFactory<br>        )[NewsViewModel::class.<em>java</em>]<br>    <strong>}<br><br><br>    </strong>override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.<em>activity_main</em>)<br><br>        txt_new.<em>text </em>= viewmodel.getNews()<br>    }<br>}</pre><p>စိတ်မပျက်ပါနဲ့ စရေးလို့ရပါပြီးနော်။<br>MainActivity က viewmodel နဲ့ တွဲအလုပ်လက်မှာဖြစ်တယ်တဲ့ viewmodel အတွက် သက်ဆိုင်ရာ factory ကို inject လုပ်တယ်။ နှောက် viewmodel ထဲက method ကို အသုံးပြုလို့ရသွားပါပြီ။</p><p>ကဲ koin အကြောင်းလေသွားလိုက်ရအောင်။</p><pre>implementation &#39;org.koin:koin-android:2.0.1&#39;<br>implementation &#39;org.koin:koin-androidx-scope:2.0.1&#39;<br>implementation &#39;org.koin:koin-androidx-viewmodel:2.0.1&#39;</pre><pre>class NewsViewModel(private val news: News) : ViewModel() {<br><br>    fun sendMessage() :String{<br>        return news.fetchNews()<br>    }<br><br>}</pre><p>Koin အတွက်လိုအပ်တဲ့ dependencies ကြေငြာမယ်။ အတူတူပဲ NewViewModel ဆောက်မယ်။ ဒီမှာ သတိပြုရမှာက <a href="http://twitter.com/Inject">@Inject</a> constructor မလိုအပ်တော့ပါဘူး။</p><pre>class SampleApplication : Application() {<br>    override fun onCreate() {<br>        super.onCreate()<br><br>        <em>startKoin </em><strong>{<br>            </strong><em>androidContext</em>(this@SampleApplication)<br>            modules(modules = module)<br>        <strong>}<br>    </strong>}<br><br>    companion object{<br>        val module = <em>module</em><strong>{<br>            </strong>factory <strong>{ </strong>News() <strong>}<br>            </strong><em>viewModel </em><strong>{ </strong>NewsViewModel(get()) <strong>}<br>        }<br>    </strong>}<br>}</pre><p>ၿပီးေတာ့ SampleApplication ထဲမွာ companion object အသုံးျပဳၿပီး module နဲ့ viewmodel<br>ကို ေဆာက္တယ္။ ၿပီးေတာ့ launchလုပ္တယ္။</p><pre>class MainActivity : AppCompatActivity() {<br>    <br>    private val viewmodel: NewsViewModel by <em>viewModel</em>()<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.<em>activity_main</em>)<br><br>        txt_new.<em>text </em>= viewmodel.sendMessage()<br><br>    }<br>}</pre><p>Activity ထဲမွာ လိုခ်င္တဲ့ viewmodel ကို တစ္ခါတည္းေခၚၿပီး အသုံးျပဳလိုက္တယ္။</p><p>ၿပီးပါၿပီ။ 😀</p><p>ဒါဆိုရင် koin အသုံးပြုပုံလေးကို တော်တော်များများ သဘောကျလိမ့်မယ်လို့ ယူဆမိပါတယ်။ ဒိနေရာမှာ ဘာကပိုကောင်းတယ် သာတယ် ပြောပြနေခြင်း မဟုတ်ပါဘူး။ နည်းပညာ အသစ်ကို စမ်းအသုံးပြုလို သူတွေအတွက် အနည်းအကျဉ်း နိူှင်းယှဉ်ပြထားတာပါ။</p><p>SOLID principles အကြောင်းအရာအပြင် Inversion of control — the concept behind DI စသဖြင့် အကြောင်းအရာများကိုလဲ ဆက်လက်လေ့လာစေလိုပါတယ်။</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f7baaad758c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What SOLID principles help us?]]></title>
            <link>https://medium.com/@devsumyat/what-solid-principles-help-us-d655e74e10da?source=rss-1fb72ca1e471------2</link>
            <guid isPermaLink="false">https://medium.com/p/d655e74e10da</guid>
            <category><![CDATA[software-design]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Su]]></dc:creator>
            <pubDate>Tue, 01 Oct 2019 15:32:17 GMT</pubDate>
            <atom:updated>2019-10-01T15:32:17.873Z</atom:updated>
            <content:encoded><![CDATA[<p>What <strong>SOLID</strong> principles help us?</p><p>It makes our software design more understandable, flexible and maintainable.</p><p>S<strong>ingle Responsibility</strong>: each component should have only one reason to change.</p><p>-&gt;not follow principle</p><pre><strong>@Override</strong> <br><strong>public</strong> <strong>void</strong> <strong>onBindViewHolder(</strong>ViewHolder holder<strong>,</strong> <strong>int</strong> position<strong>)</strong> <strong>{</strong><br>    <strong>long</strong> total <strong>=</strong> 0<strong>;</strong><br>    <strong>for</strong> <strong>(</strong>LineItem item <strong>:</strong> order<strong>.</strong>getItems<strong>())</strong> <strong>{</strong><br>        total <strong>+=</strong> item<strong>.</strong>getPrice<strong>();</strong><br>    <strong>}</strong><br>    NumberFormat formatter <strong>=</strong> NumberFormat<strong>.</strong>getCurrencyInstance<strong>(</strong>Locale<strong>.</strong>US<strong>);</strong><br>    String totalValue <strong>=</strong> formatter<strong>.</strong>format<strong>(</strong>cents <strong>/</strong> 100.0<strong>);</strong> <br>    <strong><em>holder.orderTotal.setText(totalValue)</em></strong><br><strong>}</strong></pre><p>-&gt;follow now</p><pre><strong>@Override</strong> <br><strong>public</strong> <strong>void</strong> <strong>onBindViewHolder(</strong>ViewHolder holder<strong>,</strong> <strong>int</strong> position<strong>)</strong> <strong>{</strong><br>    holder<strong>.</strong>orderTotal<strong>.</strong>setText<strong>(</strong>order<strong>.</strong>getOrderTotal<strong>());</strong> <br><strong>}</strong></pre><p>O<strong>pen-closed</strong>: able to extend a component, without breaking its usage, or modifying its extensions. Below is an example.</p><pre><strong>public</strong> <strong>interface</strong> <strong>Shape</strong> <strong>{</strong><br>    <strong>double</strong> <strong>getArea();</strong> <br><strong>}public</strong> <strong>class</strong> <strong>Rectangle</strong> <strong>implements</strong> Shape <strong>{</strong><br>    <strong>private</strong> <strong>double</strong> length<strong>;</strong><br>    <strong>private</strong> <strong>double</strong> height<strong>;</strong> </pre><pre>    <strong>@Override</strong><br>    <strong>public</strong> <strong>double</strong> <strong>getArea()</strong> <strong>{</strong><br>        <strong>return</strong> <strong>(</strong>length <strong>*</strong> height<strong>);</strong><br>    <strong>}</strong><br><strong>}public</strong> <strong>class</strong> <strong>Circle</strong> <strong>implements</strong> Shape <strong>{</strong><br>    <strong>private</strong> <strong>double</strong> radius<strong>;</strong> </pre><pre>    <strong>@Override</strong><br>    <strong>public</strong> <strong>double</strong> <strong>getArea()</strong> <strong>{</strong><br>        <strong>return</strong> <strong>(</strong>radius <strong>*</strong> radius <strong>*</strong> Math<strong>.</strong>PI<strong>);</strong><br>    <strong>}</strong><br><strong>}public</strong> <strong>class</strong> <strong>AreaManager</strong> <strong>{</strong><br>    <strong>public</strong> <strong>double</strong> <strong>calculateArea(</strong>ArrayList<strong>&lt;</strong>Shape<strong>&gt;</strong> shapes<strong>)</strong> <strong>{</strong><br>        <strong>double</strong> area <strong>=</strong> 0<strong>;</strong><br>        <strong>for</strong> <strong>(</strong>Shape shape <strong>:</strong> shapes<strong>)</strong> <strong>{</strong><br>            area <strong>+=</strong> shape<strong>.</strong>getArea<strong>();</strong><br>        <strong>}</strong><br>        <strong>return</strong> area<strong>;</strong><br>    <strong>}</strong><br><strong>}</strong></pre><p>L<strong>iskov Substitution</strong>: let’s say you have T class, and any subclasses of T, should be able to represent the base class usage with the subclasses.</p><pre>List&lt;Integer&gt; arr = new ArrayList&lt;Integer&gt;();</pre><p>I<strong>nterface Segregation</strong>: It’s better to have many smaller interfaces than a large one, to prevent the class from implementing the methods that it doesn’t need.</p><pre><strong>public</strong> <strong>interface</strong> <strong>OnClickListener</strong> <strong>{</strong> <br>    <strong>void</strong> <strong>onClick(</strong>View v<strong>);</strong><br>    <strong>void</strong> <strong>onLongClick(</strong>View v<strong>);</strong> <br>    <strong>void</strong> <strong>onTouch(</strong>View v<strong>,</strong> MotionEvent event<strong>);</strong><br><strong>}</strong></pre><p>D<strong>ependency Inversion</strong>: Components should depend on abstractions rather than concrete implementations. Also, higher-level modules shouldn’t depend on lower-level modules. Both depend on abstractions.</p><p><strong>Thank you so much. </strong>😀😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d655e74e10da" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tips & Tricks Migration Java to Kotlin]]></title>
            <link>https://medium.com/@devsumyat/tips-tricks-migration-java-to-kotlin-7ec40148c307?source=rss-1fb72ca1e471------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ec40148c307</guid>
            <category><![CDATA[kotlin-beginners]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[nullability]]></category>
            <dc:creator><![CDATA[Su]]></dc:creator>
            <pubDate>Thu, 29 Aug 2019 18:32:17 GMT</pubDate>
            <atom:updated>2019-08-29T18:40:50.194Z</atom:updated>
            <content:encoded><![CDATA[<p>Kotlin စလေ့လာနေသူတွေရော Java ကနေ Kotlin ပြောင်းချင်တယ် ဒါပေးမဲ့ ဘာတွေသိဖို့လိုလဲ စသဖြင့် အခက်အခဲရှိနေသူတွေရော ဗဟုသုတအနေနှင့် ဖြစ်စေ ဖတ်ချင်သူတွေအတွက် ရည်ညွန်းပါတယ်။ မလေ့လာရသေးတဲ့ သူများအတွက်လဲ Kotlin လေ့လာပြီးသာ ဖြစ်သွားမယ်။</p><p>Java ကနေ Kotlin သို့ IDE အသုံးပြု၍ ပြောင်းလဲချိန်မှာ convert code၊ more idomatic နဲ့ ဖြစ်လေ့ဖြစ်ထရှိတဲ့ pitfalls တွေ ဘယ်လိုရှောင်းမလဲ စတဲ့ အကြောင်းအရာများကို ဦးစားပေး ရေးသားထားပါတယ်။</p><p><strong>ဘာတွေရှိထားဖို့ လိုအပ်သလဲ</strong></p><p><a href="https://developer.android.com/studio/">Android Studio 3.3</a> နှင့် အထက်</p><p><strong>Set Up စလုပ်မယ်</strong><br><strong>Project အသစ်တစ်ခုဆောက်ပါ။</strong><br>Android Studio ကို အသုံးပြုသူဆိုရင် new project ဆောက်တဲ့အခါ no activity ရွေးပါ ပြီးတော့ language နေရာမှာ kotlin လို့ ရွေးပေးခဲ့ပါ။<br>Default language ကို kotlin လို့ရွေးပေးခဲ့တဲ့အတွက် project ထဲမှာ kotlin ရေးနိုင်ရန် auto configured လုပ်ပေးပါတယ်။</p><h3>The code</h3><p>အောက်ပါအတိုင်း User.java file အသစ်တစ်ခုဆောက်ပါ။</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11fb30a708c06f49b5002212cda6659b/href">https://medium.com/media/11fb30a708c06f49b5002212cda6659b/href</a></iframe><p>အောက်ပါအတိုင်း Repository.java အသစ်တစ်ခုဆောက်ပါ။ ဒီ singleton class မစှာ User list နဲ့ formatted user names အသုံးပြုနိုင်ရင် ရေးသားထားပါတယ်။</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4428b5326d281da1cd5c2ea48783edfc/href">https://medium.com/media/4428b5326d281da1cd5c2ea48783edfc/href</a></iframe><h3>Declaring nullability, val, var and data classes</h3><p><strong>IDE </strong>က Java ကနေ Kotlin ကို automatically refactoring လုပ်ပေးနိုင်တယ်။ Refactor ဘယ်လိုလုပ်ရလဲဆိုတော့ User.java ဖွင့်ပြီး <strong>Code -&gt; Convert Java File to Kotlin File</strong></p><p><strong>IDE</strong> က <strong>covert java to kotlin</strong> ပြောင်းမှာလဲ မေးပါတယ် <strong>Yes</strong> ကိုနှိပ်ပါ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*Hvhj6zM7sl-swWmear7p5g.png" /></figure><p>အောက်ပါအတိုင်း မြင်တွေ့ရပါလိမ့်မယ် code တော်တော်လေ နည်းသွားတယ် ဟုတ် 😀</p><pre>class User(var firstName: String?, var lastName: String?)</pre><p><strong>Pro Tip :</strong> User.javaအစား User.ktချိန်သွားပါတယ်။ ဒီအပြင် ဒီ class ထဲကို java code လာထည့်ရင် auto convert လုပ်ပေးပါတယ်။<br>အရင် Java class မှာ properties နှစ်ခုရှိတယ်။ value mutable အတွက် Property ကိုယ်စီ ကိုယ်ပိုင် getter/setter ရှိတယ်။ Kotlin မှာဆိုရင် var က mutable variable keywordဖြစ်တာကြောင့် properties var အဖြစ် convert လုပ်သွားတယ်။ တကယ်လို့ getter တစ်မျိုးသာ အသုံးပြုခဲ့မယ်ဆိုရင် val အနေနဲ့ကြေငြာသွားမှာပါ။ val keyword ဆိုတာ java ရဲ့ final keyword ပါ။<br>Kotlin နဲ့ java ရဲ့ အဓိက ကွားခြားချက်က null value တိတိ ကျကျ သတ်မှတ်ပေးလို့ရတာပါ။ ဒါကြောင့် property က null value လုပ်ခံနိုင်ချင်ရင် ‘?’ type declaration လုပ်ပေးရင် ရပါပြီ။ Converter က အဲဒိ field ကို non-null လို့ သတ်မှတ်ပေးပါလိမ့်မယ်။<br><strong>Pro Tip :</strong> တက်နိုသမျှ immutable(val) ကိုအသုံးပြုပါ။ nullable type ကို avoid လုပ်နိုင်ပါတယ်။Nullability နဲ့ပတ်သက်ပြီး သေသေချာချာ specifically လုပ်သင့်ပါတယ်။</p><p><strong>ဆက်ရန်…….</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ec40148c307" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[COIL First Tast]]></title>
            <link>https://medium.com/@devsumyat/coil-first-tast-47646b120451?source=rss-1fb72ca1e471------2</link>
            <guid isPermaLink="false">https://medium.com/p/47646b120451</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[coroutine]]></category>
            <category><![CDATA[coils]]></category>
            <dc:creator><![CDATA[Su]]></dc:creator>
            <pubDate>Mon, 19 Aug 2019 17:31:53 GMT</pubDate>
            <atom:updated>2019-08-19T18:07:16.070Z</atom:updated>
            <content:encoded><![CDATA[<h3>COIL First Taste</h3><p><strong>COIL</strong> <strong>က Glide, Picasso, Fresco Library ေတြထက္ ဘာေတြ ထူးျခားလာလဲ</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R3L3Pa49cJPr6fMVS_YJDA.jpeg" /></figure><p>Coil ဆိုတာ Image Loading library တစ္ခုျဖစ္ၿပီး Kotlin Coroutines အေပၚ မွာ အေျခခံထားပါတယ္။ Coroutine ျဖစ္တဲ့အတြက္ Thread re-use နဲ႔ non-blocking asynchronous အတြက္ strong support ပါ။ Coil က -</p><p><strong>ျမန္တယ္</strong><br>Memory နဲ႔ Disk cashing ပိုေကာင္းေအာင္ လုပ္ေဆာင္တယ္ image size ကိုေလ်ွာ့ခ်တာတို႔ bitmaps re-use request ေတြကို အလိုအေလ်ာက္ pausing/canceling လုပ္ေပးပါတယ္။</p><p><strong>ေပါ့ပါးတယ္ </strong><br>APK ထဲကို Coil က 1500 method ပဲထည့္တယ္။Picasso နဲ႔ ယွဥ္ရင္ 8ဆသက္သာတယ္။ Glide နဲ႔ Fresco တို႔လဲ Picasso နဲ႔သိပ္မကြာဘူး။</p><p><strong>Modern </strong><br>Coil က kotlin-first ၿပီးေတာ့ modern libraries ေတြကို အသံုးၿပီးထားတယ္။ Modern Libraries ထဲမွာ Coroutines, OkHttp, Okio နဲ႔ AndroidX lifecycles ပါဝင္ပါတယ္။</p><p><strong>Extensions လုပ္လို႔ရတယ္</strong><br>Mappers, Fetchers ႏွင့္ Decoder ေတြကို argument သို႔ override အေနနဲ႔အသံုးျပဳလို႔ရပါတယ္။</p><p><strong>Testing လုပ္လို႔ရတယ္</strong><br>Coil ရဲ႕ main class က Image Loader. အဲဒါကို implementation လုပ္ၿပီး fake စမ္းလို႔ရတယ္။ ေႏွာက္ Dependency Injection လဲရတယ္။</p><p><strong>Annotation Processing ေ႐ွာင္တယ္</strong><br>တစ္ခါတစ္ေလ Annotation ေၾကာင့္ build speed က်တက္တယ္။ Coil က Kotlin extension ဆိုေတာ့ အဆင္ေျပတယ္။</p><p><strong>COIL</strong> ရဲ႕ အ႐ွည္က <strong>Co</strong>routine <strong>I</strong>mage <strong>L</strong>oader ျဖစ္ပါတယ္။</p><p>ေအာက္မွာ နမူနာ ေရးျပထားပါတယ္</p><p><a href="https://github.com/devsumyat/coil-firstlook">devsumyat/coil-firstlook</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*69oviYPucApmEOvAKRzsbA.gif" /></figure><p>Glide/ Picasso တို႔ကေန ေျပာင္းမယ္ဆို….</p><pre>* basic usage <br>// in Glide<br>Glide.with(context)<br>    .load(url)<br>    .into(imageView)<br><br>// in Picasso<br>Picasso.get()<br>    .load(url)<br>    .into(imageView)<br><br>// in Coil<br>-&gt; imageView.load(url)</pre><pre>* custom request<br><br>// in Glide<br>Glide.with(context)<br>    .load(url)<br>    .placeholder(placeholder)<br>    .fitCenter()<br>    .into(imageView)<br><br>// in Picasso<br>Picasso.get()<br>    .load(url)<br>    .placeholder(placeholder)<br>    .fit()<br>    .into(imageView)<br><br>// in Coil (autodetects the scale type)<br>-&gt; imageView.load(url) {<br>    placeholder(placeholder)<br>}</pre><p>နမူနာ repo ပါ</p><p><a href="https://github.com/devsumyat/coil-firstlook">devsumyat/coil-firstlook</a></p><p>ဆက္လက္ဖတ္႐ႈရန္</p><p><a href="https://coil-kt.github.io/coil/">Coil</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47646b120451" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>