{
    "version": "https://jsonfeed.org/version/1",
    "title": "Hunga1ok's blog",
    "home_page_url": "https://hunga1ok.github.io/blog/",
    "feed_url": "https://hunga1ok.github.io/blog/feed.json",
    "description": "just a minimalist, personal blog",
    "icon": "https://hunga1ok.github.io/blog/apple-touch-icon.png",
    "favicon": "https://hunga1ok.github.io/blog/favicon.ico",
    "expired": false,
    
    "author":  {
        "name": "hunga1ok",
        "url": null,
        "avatar": null
    },
    
"items": [
    
        {
            "id": "https://hunga1ok.github.io/blog/2023/09/24/android-logging-with-timber",
            "title": "Android logging with Timber",
            "summary": "Android logging with timber and how to implement",
            "content_text": "Android logging with TimberTriển khai TimberLogging là một vấn đề không còn xa lạ với các lập trình viên. Hôm nay mình cũng sẽ trình bày về cách implement logging sử dụng thư viện Timber.Đầu tiên thì Timber là một API cho class Log của Android. Nó bổ trợ và nâng cấp cho chức năng log của Android. Ta làm việc đó bằng cách trồng (plant) một đối tượng Tree. Để sử dụng Timber, ta khai báo việc implement timber vào build.gradlerepositories {  mavenCentral()}implementation 'com.jakewharton.timber:timber:5.0.1'Việc cài đặt timber rất dễ dàng chúng ta chỉ cần tạo một Timber Tree. Tree ở đây là một dạng cây hỗ trợ việc triển khai cách ghi log vào hệ thống mà ta có thể tự tuỳ chỉnh hoặc dùng tree default là DebugTree. Ví dụ:class MyApplication: Application() {    override fun onCreate() {        super.onCreate()        Timber.plant(Timber.DebugTree())    }    override fun onTerminate() {        super.onTerminate()        Timber.uprootAll()    }}Trên đây là một cách cài đặt đợt giản, chúng ta nên cài đặt Timber sớm nhất có thể. Khi dùng chúng ta có thể dùng như log bình thường:Timber.v(\"content to log\")Timber.i(\"content to log\")Timber.d(\"content to log\")Tạo một cây tuỳ chỉnh với TimberSau đây mình cùng tiến hành tạo một Timber Tree cho mình, ta cần override lại function log :class LoggingCustom : Timber.Tree() {    override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {        TODO(\"Not yet implemented\")    }}Dưới đây mình có một ví dụ về lưu custom Tree dùng với logger để lưu log vào file:  tạo 1 file FileLoggingCustom.ktclass FileLoggingCustom private constructor(    context: Context,    fileDir: String,    fileName: String,    sizeLimit: Int,    fileLimitCount: Int,    isAppendable: Boolean,    tag: String,    levelLog: Level): Timber.Tree() {    private var myLogger: Logger    init {        val path: String = File(context.getExternalFilesDir(fileDir), fileName).absolutePath        val fileHandler: FileHandler        val logger: Logger = MyLogger(tag)        logger.level = levelLog        if (logger.handlers.isEmpty()) {            fileHandler = FileHandler(path, sizeLimit, fileLimitCount, isAppendable)            fileHandler.formatter = SimpleFormatter()            logger.addHandler(fileHandler)        } else {            fileHandler = logger.handlers[0] as FileHandler            logger.addHandler(fileHandler)        }        myLogger = logger    }    override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {        myLogger.log(fromPriorityToLevel(priority), message)    }    private fun fromPriorityToLevel(priority: Int): Level {        return when (priority) {            Log.VERBOSE -&gt; Level.FINER            Log.DEBUG -&gt; Level.FINE            Log.INFO -&gt; Level.INFO            Log.WARN -&gt; Level.WARNING            Log.ERROR -&gt; Level.SEVERE            Log.ASSERT -&gt; Level.SEVERE            else -&gt; Level.FINEST        }    }    data class Builder(        val context: Context,        private var fileDir: String = \"LogDir\",        private var fileName: String = \"File%g.log\",        private var sizeLimit: Int = 1000_000,        private var fileLimitCount: Int = 3,        private var isAppendable: Boolean = true,        private var tag: String = \"FileLoggerTree\",        private var levelLog: Level = Level.ALL    ) {        fun fileDir(dir: String) = apply { this.fileDir = dir }        fun fileName(name: String) = apply { this.fileName = name }        fun sizeLimit(limit: Int) = apply { this.sizeLimit = limit }        fun fileLimit(limit: Int) = apply { this.fileLimitCount = limit }        fun isAppendable(append: Boolean) = apply { this.isAppendable = append }        fun tag(tag: String) = apply { this.tag = tag }        fun levelLog(level: Level) = apply { this.levelLog = level }        fun build() = FileLoggingCustom(context, fileDir, fileName, sizeLimit, fileLimitCount, isAppendable, tag, levelLog)    }}Khi khởi tạo Tree:val t: Tree = FileLoggingCustom.Builder(this).build()Timber.plant(t)ta có thể custom lại các thông số của Logging:val t: Tree = FileLoggingCustom.Builder(this)                    .fileDir(\"DirFile\")                    .fileName(\"file%g.log\")                    .tag(\"CustomTag\")                    .sizeLimit(1000_000_000) // ~1MB                    .fileLimit(3) // create limit 3 file                    .levelLog(Level.ALL) // receive all log                    .isAppendable(true) // true: append log to file, false: create new file                    .build()                Timber.plant(t)File log sẽ được lưu vào pathsdcard/Android/data/your package name/DirFile/filei.logTrên đây là một cách triển khai Timber và timber log to file.Dưới đây là source code: Source Code",
            "content_html": "<h1 id=\"android-logging-with-timber\">Android logging with Timber</h1><h2 id=\"triển-khai-timber\">Triển khai Timber</h2><p>Logging là một vấn đề không còn xa lạ với các lập trình viên. Hôm nay mình cũng sẽ trình bày về cách implement logging sử dụng thư viện Timber.</p><p>Đầu tiên thì Timber là một API cho class Log của Android. Nó bổ trợ và nâng cấp cho chức năng log của Android. Ta làm việc đó bằng cách trồng (plant) một đối tượng Tree. Để sử dụng Timber, ta khai báo việc implement timber vào build.gradle</p><div class=\"language-gradle highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"k\">repositories</span> <span class=\"o\">{</span>  <span class=\"n\">mavenCentral</span><span class=\"o\">()</span><span class=\"o\">}</span><span class=\"n\">implementation</span> <span class=\"s1\">'com.jakewharton.timber:timber:5.0.1'</span></code></pre></div></div><p>Việc cài đặt timber rất dễ dàng chúng ta chỉ cần tạo một Timber Tree. Tree ở đây là một dạng cây hỗ trợ việc triển khai cách ghi log vào hệ thống mà ta có thể tự tuỳ chỉnh hoặc dùng tree default là DebugTree. Ví dụ:</p><pre><code class=\"language-Kotlin\">class MyApplication: Application() {    override fun onCreate() {        super.onCreate()        Timber.plant(Timber.DebugTree())    }    override fun onTerminate() {        super.onTerminate()        Timber.uprootAll()    }}</code></pre><p>Trên đây là một cách cài đặt đợt giản, chúng ta nên cài đặt Timber sớm nhất có thể. Khi dùng chúng ta có thể dùng như log bình thường:</p><div class=\"language-kotlin highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"nc\">Timber</span><span class=\"p\">.</span><span class=\"nf\">v</span><span class=\"p\">(</span><span class=\"s\">\"content to log\"</span><span class=\"p\">)</span><span class=\"nc\">Timber</span><span class=\"p\">.</span><span class=\"nf\">i</span><span class=\"p\">(</span><span class=\"s\">\"content to log\"</span><span class=\"p\">)</span><span class=\"nc\">Timber</span><span class=\"p\">.</span><span class=\"nf\">d</span><span class=\"p\">(</span><span class=\"s\">\"content to log\"</span><span class=\"p\">)</span></code></pre></div></div><h2 id=\"tạo-một-cây-tuỳ-chỉnh-với-timber\">Tạo một cây tuỳ chỉnh với Timber</h2><p>Sau đây mình cùng tiến hành tạo một Timber Tree cho mình, ta cần override lại function log :</p><div class=\"language-kotlin highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"kd\">class</span> <span class=\"nc\">LoggingCustom</span> <span class=\"p\">:</span> <span class=\"nc\">Timber</span><span class=\"p\">.</span><span class=\"nc\">Tree</span><span class=\"p\">()</span> <span class=\"p\">{</span>    <span class=\"k\">override</span> <span class=\"k\">fun</span> <span class=\"nf\">log</span><span class=\"p\">(</span><span class=\"n\">priority</span><span class=\"p\">:</span> <span class=\"nc\">Int</span><span class=\"p\">,</span> <span class=\"n\">tag</span><span class=\"p\">:</span> <span class=\"nc\">String</span><span class=\"p\">?,</span> <span class=\"n\">message</span><span class=\"p\">:</span> <span class=\"nc\">String</span><span class=\"p\">,</span> <span class=\"n\">t</span><span class=\"p\">:</span> <span class=\"nc\">Throwable</span><span class=\"p\">?)</span> <span class=\"p\">{</span>        <span class=\"nc\">TODO</span><span class=\"p\">(</span><span class=\"s\">\"Not yet implemented\"</span><span class=\"p\">)</span>    <span class=\"p\">}</span><span class=\"p\">}</span></code></pre></div></div><p>Dưới đây mình có một ví dụ về lưu custom Tree dùng với logger để lưu log vào file:</p><ul>  <li>tạo 1 file <code class=\"language-plaintext highlighter-rouge\">FileLoggingCustom.kt</code></li></ul><div class=\"language-kotlin highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"kd\">class</span> <span class=\"nc\">FileLoggingCustom</span> <span class=\"k\">private</span> <span class=\"k\">constructor</span><span class=\"p\">(</span>    <span class=\"n\">context</span><span class=\"p\">:</span> <span class=\"nc\">Context</span><span class=\"p\">,</span>    <span class=\"n\">fileDir</span><span class=\"p\">:</span> <span class=\"nc\">String</span><span class=\"p\">,</span>    <span class=\"n\">fileName</span><span class=\"p\">:</span> <span class=\"nc\">String</span><span class=\"p\">,</span>    <span class=\"n\">sizeLimit</span><span class=\"p\">:</span> <span class=\"nc\">Int</span><span class=\"p\">,</span>    <span class=\"n\">fileLimitCount</span><span class=\"p\">:</span> <span class=\"nc\">Int</span><span class=\"p\">,</span>    <span class=\"n\">isAppendable</span><span class=\"p\">:</span> <span class=\"nc\">Boolean</span><span class=\"p\">,</span>    <span class=\"n\">tag</span><span class=\"p\">:</span> <span class=\"nc\">String</span><span class=\"p\">,</span>    <span class=\"n\">levelLog</span><span class=\"p\">:</span> <span class=\"nc\">Level</span><span class=\"p\">):</span> <span class=\"nc\">Timber</span><span class=\"p\">.</span><span class=\"nc\">Tree</span><span class=\"p\">()</span> <span class=\"p\">{</span>    <span class=\"k\">private</span> <span class=\"kd\">var</span> <span class=\"py\">myLogger</span><span class=\"p\">:</span> <span class=\"nc\">Logger</span>    <span class=\"nf\">init</span> <span class=\"p\">{</span>        <span class=\"kd\">val</span> <span class=\"py\">path</span><span class=\"p\">:</span> <span class=\"nc\">String</span> <span class=\"p\">=</span> <span class=\"nc\">File</span><span class=\"p\">(</span><span class=\"n\">context</span><span class=\"p\">.</span><span class=\"nf\">getExternalFilesDir</span><span class=\"p\">(</span><span class=\"n\">fileDir</span><span class=\"p\">),</span> <span class=\"n\">fileName</span><span class=\"p\">).</span><span class=\"n\">absolutePath</span>        <span class=\"kd\">val</span> <span class=\"py\">fileHandler</span><span class=\"p\">:</span> <span class=\"nc\">FileHandler</span>        <span class=\"kd\">val</span> <span class=\"py\">logger</span><span class=\"p\">:</span> <span class=\"nc\">Logger</span> <span class=\"p\">=</span> <span class=\"nc\">MyLogger</span><span class=\"p\">(</span><span class=\"n\">tag</span><span class=\"p\">)</span>        <span class=\"n\">logger</span><span class=\"p\">.</span><span class=\"n\">level</span> <span class=\"p\">=</span> <span class=\"n\">levelLog</span>        <span class=\"k\">if</span> <span class=\"p\">(</span><span class=\"n\">logger</span><span class=\"p\">.</span><span class=\"n\">handlers</span><span class=\"p\">.</span><span class=\"nf\">isEmpty</span><span class=\"p\">())</span> <span class=\"p\">{</span>            <span class=\"n\">fileHandler</span> <span class=\"p\">=</span> <span class=\"nc\">FileHandler</span><span class=\"p\">(</span><span class=\"n\">path</span><span class=\"p\">,</span> <span class=\"n\">sizeLimit</span><span class=\"p\">,</span> <span class=\"n\">fileLimitCount</span><span class=\"p\">,</span> <span class=\"n\">isAppendable</span><span class=\"p\">)</span>            <span class=\"n\">fileHandler</span><span class=\"p\">.</span><span class=\"n\">formatter</span> <span class=\"p\">=</span> <span class=\"nc\">SimpleFormatter</span><span class=\"p\">()</span>            <span class=\"n\">logger</span><span class=\"p\">.</span><span class=\"nf\">addHandler</span><span class=\"p\">(</span><span class=\"n\">fileHandler</span><span class=\"p\">)</span>        <span class=\"p\">}</span> <span class=\"k\">else</span> <span class=\"p\">{</span>            <span class=\"n\">fileHandler</span> <span class=\"p\">=</span> <span class=\"n\">logger</span><span class=\"p\">.</span><span class=\"n\">handlers</span><span class=\"p\">[</span><span class=\"mi\">0</span><span class=\"p\">]</span> <span class=\"k\">as</span> <span class=\"nc\">FileHandler</span>            <span class=\"n\">logger</span><span class=\"p\">.</span><span class=\"nf\">addHandler</span><span class=\"p\">(</span><span class=\"n\">fileHandler</span><span class=\"p\">)</span>        <span class=\"p\">}</span>        <span class=\"n\">myLogger</span> <span class=\"p\">=</span> <span class=\"n\">logger</span>    <span class=\"p\">}</span>    <span class=\"k\">override</span> <span class=\"k\">fun</span> <span class=\"nf\">log</span><span class=\"p\">(</span><span class=\"n\">priority</span><span class=\"p\">:</span> <span class=\"nc\">Int</span><span class=\"p\">,</span> <span class=\"n\">tag</span><span class=\"p\">:</span> <span class=\"nc\">String</span><span class=\"p\">?,</span> <span class=\"n\">message</span><span class=\"p\">:</span> <span class=\"nc\">String</span><span class=\"p\">,</span> <span class=\"n\">t</span><span class=\"p\">:</span> <span class=\"nc\">Throwable</span><span class=\"p\">?)</span> <span class=\"p\">{</span>        <span class=\"n\">myLogger</span><span class=\"p\">.</span><span class=\"nf\">log</span><span class=\"p\">(</span><span class=\"nf\">fromPriorityToLevel</span><span class=\"p\">(</span><span class=\"n\">priority</span><span class=\"p\">),</span> <span class=\"n\">message</span><span class=\"p\">)</span>    <span class=\"p\">}</span>    <span class=\"k\">private</span> <span class=\"k\">fun</span> <span class=\"nf\">fromPriorityToLevel</span><span class=\"p\">(</span><span class=\"n\">priority</span><span class=\"p\">:</span> <span class=\"nc\">Int</span><span class=\"p\">):</span> <span class=\"nc\">Level</span> <span class=\"p\">{</span>        <span class=\"k\">return</span> <span class=\"k\">when</span> <span class=\"p\">(</span><span class=\"n\">priority</span><span class=\"p\">)</span> <span class=\"p\">{</span>            <span class=\"nc\">Log</span><span class=\"p\">.</span><span class=\"nc\">VERBOSE</span> <span class=\"p\">-&gt;</span> <span class=\"nc\">Level</span><span class=\"p\">.</span><span class=\"nc\">FINER</span>            <span class=\"nc\">Log</span><span class=\"p\">.</span><span class=\"nc\">DEBUG</span> <span class=\"p\">-&gt;</span> <span class=\"nc\">Level</span><span class=\"p\">.</span><span class=\"nc\">FINE</span>            <span class=\"nc\">Log</span><span class=\"p\">.</span><span class=\"nc\">INFO</span> <span class=\"p\">-&gt;</span> <span class=\"nc\">Level</span><span class=\"p\">.</span><span class=\"nc\">INFO</span>            <span class=\"nc\">Log</span><span class=\"p\">.</span><span class=\"nc\">WARN</span> <span class=\"p\">-&gt;</span> <span class=\"nc\">Level</span><span class=\"p\">.</span><span class=\"nc\">WARNING</span>            <span class=\"nc\">Log</span><span class=\"p\">.</span><span class=\"nc\">ERROR</span> <span class=\"p\">-&gt;</span> <span class=\"nc\">Level</span><span class=\"p\">.</span><span class=\"nc\">SEVERE</span>            <span class=\"nc\">Log</span><span class=\"p\">.</span><span class=\"nc\">ASSERT</span> <span class=\"p\">-&gt;</span> <span class=\"nc\">Level</span><span class=\"p\">.</span><span class=\"nc\">SEVERE</span>            <span class=\"k\">else</span> <span class=\"p\">-&gt;</span> <span class=\"nc\">Level</span><span class=\"p\">.</span><span class=\"nc\">FINEST</span>        <span class=\"p\">}</span>    <span class=\"p\">}</span>    <span class=\"kd\">data class</span> <span class=\"nc\">Builder</span><span class=\"p\">(</span>        <span class=\"kd\">val</span> <span class=\"py\">context</span><span class=\"p\">:</span> <span class=\"nc\">Context</span><span class=\"p\">,</span>        <span class=\"k\">private</span> <span class=\"kd\">var</span> <span class=\"py\">fileDir</span><span class=\"p\">:</span> <span class=\"nc\">String</span> <span class=\"p\">=</span> <span class=\"s\">\"LogDir\"</span><span class=\"p\">,</span>        <span class=\"k\">private</span> <span class=\"kd\">var</span> <span class=\"py\">fileName</span><span class=\"p\">:</span> <span class=\"nc\">String</span> <span class=\"p\">=</span> <span class=\"s\">\"File%g.log\"</span><span class=\"p\">,</span>        <span class=\"k\">private</span> <span class=\"kd\">var</span> <span class=\"py\">sizeLimit</span><span class=\"p\">:</span> <span class=\"nc\">Int</span> <span class=\"p\">=</span> <span class=\"mi\">1000_000</span><span class=\"p\">,</span>        <span class=\"k\">private</span> <span class=\"kd\">var</span> <span class=\"py\">fileLimitCount</span><span class=\"p\">:</span> <span class=\"nc\">Int</span> <span class=\"p\">=</span> <span class=\"mi\">3</span><span class=\"p\">,</span>        <span class=\"k\">private</span> <span class=\"kd\">var</span> <span class=\"py\">isAppendable</span><span class=\"p\">:</span> <span class=\"nc\">Boolean</span> <span class=\"p\">=</span> <span class=\"k\">true</span><span class=\"p\">,</span>        <span class=\"k\">private</span> <span class=\"kd\">var</span> <span class=\"py\">tag</span><span class=\"p\">:</span> <span class=\"nc\">String</span> <span class=\"p\">=</span> <span class=\"s\">\"FileLoggerTree\"</span><span class=\"p\">,</span>        <span class=\"k\">private</span> <span class=\"kd\">var</span> <span class=\"py\">levelLog</span><span class=\"p\">:</span> <span class=\"nc\">Level</span> <span class=\"p\">=</span> <span class=\"nc\">Level</span><span class=\"p\">.</span><span class=\"nc\">ALL</span>    <span class=\"p\">)</span> <span class=\"p\">{</span>        <span class=\"k\">fun</span> <span class=\"nf\">fileDir</span><span class=\"p\">(</span><span class=\"n\">dir</span><span class=\"p\">:</span> <span class=\"nc\">String</span><span class=\"p\">)</span> <span class=\"p\">=</span> <span class=\"nf\">apply</span> <span class=\"p\">{</span> <span class=\"k\">this</span><span class=\"p\">.</span><span class=\"n\">fileDir</span> <span class=\"p\">=</span> <span class=\"n\">dir</span> <span class=\"p\">}</span>        <span class=\"k\">fun</span> <span class=\"nf\">fileName</span><span class=\"p\">(</span><span class=\"n\">name</span><span class=\"p\">:</span> <span class=\"nc\">String</span><span class=\"p\">)</span> <span class=\"p\">=</span> <span class=\"nf\">apply</span> <span class=\"p\">{</span> <span class=\"k\">this</span><span class=\"p\">.</span><span class=\"n\">fileName</span> <span class=\"p\">=</span> <span class=\"n\">name</span> <span class=\"p\">}</span>        <span class=\"k\">fun</span> <span class=\"nf\">sizeLimit</span><span class=\"p\">(</span><span class=\"n\">limit</span><span class=\"p\">:</span> <span class=\"nc\">Int</span><span class=\"p\">)</span> <span class=\"p\">=</span> <span class=\"nf\">apply</span> <span class=\"p\">{</span> <span class=\"k\">this</span><span class=\"p\">.</span><span class=\"n\">sizeLimit</span> <span class=\"p\">=</span> <span class=\"n\">limit</span> <span class=\"p\">}</span>        <span class=\"k\">fun</span> <span class=\"nf\">fileLimit</span><span class=\"p\">(</span><span class=\"n\">limit</span><span class=\"p\">:</span> <span class=\"nc\">Int</span><span class=\"p\">)</span> <span class=\"p\">=</span> <span class=\"nf\">apply</span> <span class=\"p\">{</span> <span class=\"k\">this</span><span class=\"p\">.</span><span class=\"n\">fileLimitCount</span> <span class=\"p\">=</span> <span class=\"n\">limit</span> <span class=\"p\">}</span>        <span class=\"k\">fun</span> <span class=\"nf\">isAppendable</span><span class=\"p\">(</span><span class=\"n\">append</span><span class=\"p\">:</span> <span class=\"nc\">Boolean</span><span class=\"p\">)</span> <span class=\"p\">=</span> <span class=\"nf\">apply</span> <span class=\"p\">{</span> <span class=\"k\">this</span><span class=\"p\">.</span><span class=\"n\">isAppendable</span> <span class=\"p\">=</span> <span class=\"n\">append</span> <span class=\"p\">}</span>        <span class=\"k\">fun</span> <span class=\"nf\">tag</span><span class=\"p\">(</span><span class=\"n\">tag</span><span class=\"p\">:</span> <span class=\"nc\">String</span><span class=\"p\">)</span> <span class=\"p\">=</span> <span class=\"nf\">apply</span> <span class=\"p\">{</span> <span class=\"k\">this</span><span class=\"p\">.</span><span class=\"n\">tag</span> <span class=\"p\">=</span> <span class=\"n\">tag</span> <span class=\"p\">}</span>        <span class=\"k\">fun</span> <span class=\"nf\">levelLog</span><span class=\"p\">(</span><span class=\"n\">level</span><span class=\"p\">:</span> <span class=\"nc\">Level</span><span class=\"p\">)</span> <span class=\"p\">=</span> <span class=\"nf\">apply</span> <span class=\"p\">{</span> <span class=\"k\">this</span><span class=\"p\">.</span><span class=\"n\">levelLog</span> <span class=\"p\">=</span> <span class=\"n\">level</span> <span class=\"p\">}</span>        <span class=\"k\">fun</span> <span class=\"nf\">build</span><span class=\"p\">()</span> <span class=\"p\">=</span> <span class=\"nc\">FileLoggingCustom</span><span class=\"p\">(</span><span class=\"n\">context</span><span class=\"p\">,</span> <span class=\"n\">fileDir</span><span class=\"p\">,</span> <span class=\"n\">fileName</span><span class=\"p\">,</span> <span class=\"n\">sizeLimit</span><span class=\"p\">,</span> <span class=\"n\">fileLimitCount</span><span class=\"p\">,</span> <span class=\"n\">isAppendable</span><span class=\"p\">,</span> <span class=\"n\">tag</span><span class=\"p\">,</span> <span class=\"n\">levelLog</span><span class=\"p\">)</span>    <span class=\"p\">}</span><span class=\"p\">}</span></code></pre></div></div><p>Khi khởi tạo Tree:</p><div class=\"language-kotlin highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"kd\">val</span> <span class=\"py\">t</span><span class=\"p\">:</span> <span class=\"nc\">Tree</span> <span class=\"p\">=</span> <span class=\"nc\">FileLoggingCustom</span><span class=\"p\">.</span><span class=\"nc\">Builder</span><span class=\"p\">(</span><span class=\"k\">this</span><span class=\"p\">).</span><span class=\"nf\">build</span><span class=\"p\">()</span><span class=\"nc\">Timber</span><span class=\"p\">.</span><span class=\"nf\">plant</span><span class=\"p\">(</span><span class=\"n\">t</span><span class=\"p\">)</span></code></pre></div></div><p>ta có thể custom lại các thông số của Logging:</p><div class=\"language-kotlin highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"kd\">val</span> <span class=\"py\">t</span><span class=\"p\">:</span> <span class=\"nc\">Tree</span> <span class=\"p\">=</span> <span class=\"nc\">FileLoggingCustom</span><span class=\"p\">.</span><span class=\"nc\">Builder</span><span class=\"p\">(</span><span class=\"k\">this</span><span class=\"p\">)</span>                    <span class=\"p\">.</span><span class=\"nf\">fileDir</span><span class=\"p\">(</span><span class=\"s\">\"DirFile\"</span><span class=\"p\">)</span>                    <span class=\"p\">.</span><span class=\"nf\">fileName</span><span class=\"p\">(</span><span class=\"s\">\"file%g.log\"</span><span class=\"p\">)</span>                    <span class=\"p\">.</span><span class=\"nf\">tag</span><span class=\"p\">(</span><span class=\"s\">\"CustomTag\"</span><span class=\"p\">)</span>                    <span class=\"p\">.</span><span class=\"nf\">sizeLimit</span><span class=\"p\">(</span><span class=\"mi\">1000_000_000</span><span class=\"p\">)</span> <span class=\"c1\">// ~1MB</span>                    <span class=\"p\">.</span><span class=\"nf\">fileLimit</span><span class=\"p\">(</span><span class=\"mi\">3</span><span class=\"p\">)</span> <span class=\"c1\">// create limit 3 file</span>                    <span class=\"p\">.</span><span class=\"nf\">levelLog</span><span class=\"p\">(</span><span class=\"nc\">Level</span><span class=\"p\">.</span><span class=\"nc\">ALL</span><span class=\"p\">)</span> <span class=\"c1\">// receive all log</span>                    <span class=\"p\">.</span><span class=\"nf\">isAppendable</span><span class=\"p\">(</span><span class=\"k\">true</span><span class=\"p\">)</span> <span class=\"c1\">// true: append log to file, false: create new file</span>                    <span class=\"p\">.</span><span class=\"nf\">build</span><span class=\"p\">()</span>                <span class=\"nc\">Timber</span><span class=\"p\">.</span><span class=\"nf\">plant</span><span class=\"p\">(</span><span class=\"n\">t</span><span class=\"p\">)</span></code></pre></div></div><p>File log sẽ được lưu vào path</p><p>sdcard/Android/data/<code class=\"language-plaintext highlighter-rouge\">your package name</code>/DirFile/file<code class=\"language-plaintext highlighter-rouge\">i</code>.log</p><p>Trên đây là một cách triển khai Timber và timber log to file.</p><p>Dưới đây là source code: <a href=\"https://github.com/hunga1ok/POC-Logging\">Source Code</a></p>",
            "url": "https://hunga1ok.github.io/blog/2023/09/24/android-logging-with-timber",
            
            
            
            "tags": ["android","logging"],
            
            "date_published": "2023-09-24T00:00:00+02:00",
            "date_modified": "2023-09-24T00:00:00+02:00",
            
                "author":  {
                "name": "hunga1ok",
                "url": null,
                "avatar": null
                }
                
            
        },
    
        {
            "id": "https://hunga1ok.github.io/blog/2023/06/26/architecture-learning-journey",
            "title": "Architecture Learning Journey",
            "summary": "android app architecture",
            "content_text": "Architecture Learning JourneyIn this learning journey you will learn about the Now in Android app architecture: its layers, key classes and the interactions between them.Goals and requirementsThe goals for the app architecture are:  Follow the official architecture guidance as closely as possible.  Easy for developers to understand, nothing too experimental.  Support multiple developers working on the same codebase.  Facilitate local and instrumented tests, both on the developer’s machine and using Continuous Integration (CI).  Minimize build times.Architecture overviewThe app architecture has three layers: a data layer, a domain layer and a UI layer.The architecture follows a reactive programming model with unidirectional data flow. With the data layer at the bottom, the key concepts are:  Higher layers react to changes in lower layers.  Events flow down.  Data flows up.The data flow is achieved using streams, implemented using Kotlin Flows.Example: Displaying news on the For You screenWhen the app is first run it will attempt to load a list of news resources from a remote server (when the prod build flavor is selected, demo builds will use local data). Once loaded, these are shown to the user based on the interests they choose.The following diagram shows the events which occur and how data flows from the relevant objects to achieve this.Here’s what’s happening in each step. The easiest way to find the associated code is to load the project into Android Studio and search for the text in the Code column (handy shortcut: tap ⇧ SHIFT twice).     Step      Description      Code           1      On app startup, a WorkManager job to sync all repositories is enqueued.      Sync.initialize          2      The ForYouViewModel calls GetUserNewsResourcesUseCase to obtain a stream of news resources with their bookmarked/saved state. No items will be emitted into this stream until both the user and news repositories emit an item. While waiting, the feed state is set to Loading.      Search for usages of NewsFeedUiState.Loading          3      The user data repository obtains a stream of UserData objects from a local data source backed by Proto DataStore.      NiaPreferencesDataSource.userData          4      WorkManager executes the sync job which calls OfflineFirstNewsRepository to start synchronizing data with the remote data source.      SyncWorker.doWork          5      OfflineFirstNewsRepository calls RetrofitNiaNetwork to execute the actual API request using Retrofit.      OfflineFirstNewsRepository.syncWith          6      RetrofitNiaNetwork calls the REST API on the remote server.      RetrofitNiaNetwork.getNewsResources          7      RetrofitNiaNetwork receives the network response from the remote server.      RetrofitNiaNetwork.getNewsResources          8      OfflineFirstNewsRepository syncs the remote data with NewsResourceDao by inserting, updating or deleting data in a local Room database.      OfflineFirstNewsRepository.syncWith          9      When data changes in NewsResourceDao it is emitted into the news resources data stream (which is a Flow).      NewsResourceDao.getNewsResources          10      OfflineFirstNewsRepository acts as an intermediate operator on this stream, transforming the incoming PopulatedNewsResource (a database model, internal to the data layer) to the public NewsResource model which is consumed by other layers.      OfflineFirstNewsRepository.getNewsResources          11      GetUserNewsResourcesUseCase combines the list of news resources with the user data to emit a list of UserNewsResources.        GetUserNewsResourcesUseCase.invoke          12      When ForYouViewModel receives the saveable news resources it updates the feed state to Success.  ForYouScreen then uses the saveable news resources in the state to render the screen.      Search for instances of NewsFeedUiState.Success     Data layerThe data layer is implemented as an offline-first source of app data and business logic. It is the source of truth for all data in the app.Each repository has its own models. For example, the TopicsRepository has a Topic model and the NewsRepository has a NewsResource model.Repositories are the public API for other layers, they provide the only way to access the app data. The repositories typically offer one or more methods for reading and writing data.Reading dataData is exposed as data streams. This means each client of the repository must be prepared to react to data changes. Data is not exposed as a snapshot (e.g. getModel) because there’s no guarantee that it will still be valid by the time it is used.Reads are performed from local storage as the source of truth, therefore errors are not expected when reading from Repository instances. However, errors may occur when trying to reconcile data in local storage with remote sources. For more on error reconciliation, check the data synchronization section below.Example: Read a list of topicsA list of Topics can be obtained by subscribing to TopicsRepository::getTopics flow which emits List&lt;Topic&gt;.Whenever the list of topics changes (for example, when a new topic is added), the updated List&lt;Topic&gt; is emitted into the stream.Writing dataTo write data, the repository provides suspend functions. It is up to the caller to ensure that their execution is suitably scoped.Example: Follow a topicSimply call UserDataRepository.toggleFollowedTopicId with the ID of the topic the user wishes to follow and followed=true to indicate that the topic should be followed (use false to unfollow a topic).Data sourcesA repository may depend on one or more data sources. For example, the OfflineFirstTopicsRepository depends on the following data sources:     Name      Backed by      Purpose          TopicsDao      Room/SQLite      Persistent relational data associated with Topics          NiaPreferencesDataSource      Proto DataStore      Persistent unstructured data associated with user preferences, specifically which Topics the user is interested in. This is defined and modeled in a .proto file, using the protobuf syntax.          NiaNetworkDataSource      Remote API accessed using Retrofit      Data for topics, provided through REST API endpoints as JSON.     Data synchronizationRepositories are responsible for reconciling data in local storage with remote sources. Once data is obtained from a remote data source it is immediately written to local storage. The  updated data is emitted from local storage (Room) into the relevant data stream and received by any listening clients.This approach ensures that the read and write concerns of the app are separate and do not interfere with each other.In the case of errors during data synchronization, an exponential backoff strategy is employed. This is delegated to WorkManager via the SyncWorker, an implementation of the Synchronizer interface.See the OfflineFirstNewsRepository.syncWith for an example of data synchronization.Domain layerThe domain layer contains use cases. These are classes which have a single invocable method (operator fun invoke) containing business logic.These use cases are used to simplify and remove duplicate logic from ViewModels. They typically combine and transform data from repositories.For example, GetUserNewsResourcesUseCase combines a stream (implemented using Flow) of NewsResources from a NewsRepository with a stream of UserData objects from a UserDataRepository to create a stream of UserNewsResources. This stream is used by various ViewModels to display news resources on screen with their bookmarked state.Notably, the domain layer in Now in Android does not (for now) contain any use cases for event handling. Events are handled by the UI layer calling methods on repositories directly.UI LayerThe UI layer comprises:  UI elements built using Jetpack Compose  Android ViewModelsThe ViewModels receive streams of data from use cases and repositories, and transforms them into UI state. The UI elements reflect this state, and provide ways for the user to interact with the app. These interactions are passed as events to the ViewModel where they are processed.Modeling UI stateUI state is modeled as a sealed hierarchy using interfaces and immutable data classes. State objects are only ever emitted through the transform of data streams. This approach ensures that:  the UI state always represents the underlying app data - the app data is the source-of-truth.  the UI elements handle all possible states.Example: News feed on For You screenThe feed (a list) of news resources on the For You screen is modeled using NewsFeedUiState. This is a sealed interface which creates a hierarchy of two possible states:  Loading indicates that the data is loading  Success indicates that the data was loaded successfully. The Success state contains the list of news resources.The feedState is passed to the ForYouScreen composable, which handles both of these states.Transforming streams into UI stateViewModels receive streams of data as cold flows from one or more use cases or repositories. These are combined together, or simply mapped, to produce a single flow of UI state. This single flow is then converted to a hot flow using stateIn. The conversion to a state flow enables UI elements to read the last known state from the flow.Example: Displaying followed topicsThe InterestsViewModel exposes uiState as a StateFlow&lt;InterestsUiState&gt;. This hot flow is created by obtaining the cold flow of List&lt;FollowableTopic&gt; provided by GetFollowableTopicsUseCase. Each time a new list is emitted, it is converted into an InterestsUiState.Interests state which is exposed to the UI.Processing user interactionsUser actions are communicated from UI elements to ViewModels using regular method invocations. These methods are passed to the UI elements as lambda expressions.Example: Following a topicThe InterestsScreen takes a lambda expression named followTopic which is supplied from InterestsViewModel.followTopic. Each time the user taps on a topic to follow this method is called. The ViewModel then processes this action by informing the user data repository.Further readingGuide to app architectureJetpack Compose",
            "content_html": "<h1 id=\"architecture-learning-journey\">Architecture Learning Journey</h1><p>In this learning journey you will learn about the Now in Android app architecture: its layers, key classes and the interactions between them.</p><h2 id=\"goals-and-requirements\">Goals and requirements</h2><p>The goals for the app architecture are:</p><ul>  <li>Follow the <a href=\"https://developer.android.com/jetpack/guide\">official architecture guidance</a> as closely as possible.</li>  <li>Easy for developers to understand, nothing too experimental.</li>  <li>Support multiple developers working on the same codebase.</li>  <li>Facilitate local and instrumented tests, both on the developer’s machine and using Continuous Integration (CI).</li>  <li>Minimize build times.</li></ul><h2 id=\"architecture-overview\">Architecture overview</h2><p>The app architecture has three layers: a <a href=\"https://developer.android.com/jetpack/guide/data-layer\">data layer</a>, a <a href=\"https://developer.android.com/jetpack/guide/domain-layer\">domain layer</a> and a <a href=\"https://developer.android.com/jetpack/guide/ui-layer\">UI layer</a>.</p><center><img src=\"https://raw.githubusercontent.com/hunga1ok/blog/hung.lv2/images/architecture/architecture-1-overall.png\" width=\"600px\" alt=\"Diagram showing overall app architecture\" /></center><p>The architecture follows a reactive programming model with <a href=\"https://developer.android.com/jetpack/guide/ui-layer#udf\">unidirectional data flow</a>. With the data layer at the bottom, the key concepts are:</p><ul>  <li>Higher layers react to changes in lower layers.</li>  <li>Events flow down.</li>  <li>Data flows up.</li></ul><p>The data flow is achieved using streams, implemented using <a href=\"https://developer.android.com/kotlin/flow\">Kotlin Flows</a>.</p><h3 id=\"example-displaying-news-on-the-for-you-screen\">Example: Displaying news on the For You screen</h3><p>When the app is first run it will attempt to load a list of news resources from a remote server (when the <code class=\"language-plaintext highlighter-rouge\">prod</code> build flavor is selected, <code class=\"language-plaintext highlighter-rouge\">demo</code> builds will use local data). Once loaded, these are shown to the user based on the interests they choose.</p><p>The following diagram shows the events which occur and how data flows from the relevant objects to achieve this.</p><p><img src=\"https://raw.githubusercontent.com/hunga1ok/blog/hung.lv2/images/architecture/architecture-2-example.png\" alt=\"Diagram showing how news resources are displayed on the For You screen\" title=\"Diagram showing how news resources are displayed on the For You screen\" /></p><p>Here’s what’s happening in each step. The easiest way to find the associated code is to load the project into Android Studio and search for the text in the Code column (handy shortcut: tap <kbd>⇧ SHIFT</kbd> twice).</p><table>  <tr>   <td><strong>Step</strong>   </td>   <td><strong>Description</strong>   </td>   <td><strong>Code </strong>   </td>  </tr>  <tr>   <td>1   </td>   <td>On app startup, a <a href=\"https://developer.android.com/topic/libraries/architecture/workmanager\">WorkManager</a> job to sync all repositories is enqueued.   </td>   <td><code>Sync.initialize</code>   </td>  </tr>  <tr>   <td>2   </td>   <td>The <code>ForYouViewModel</code> calls <code>GetUserNewsResourcesUseCase</code> to obtain a stream of news resources with their bookmarked/saved state. No items will be emitted into this stream until both the user and news repositories emit an item. While waiting, the feed state is set to <code>Loading</code>.   </td>   <td>Search for usages of <code>NewsFeedUiState.Loading</code>   </td>  </tr>  <tr>   <td>3   </td>   <td>The user data repository obtains a stream of <code>UserData</code> objects from a local data source backed by Proto DataStore.   </td>   <td><code>NiaPreferencesDataSource.userData</code>   </td>  </tr>  <tr>   <td>4   </td>   <td>WorkManager executes the sync job which calls <code>OfflineFirstNewsRepository</code> to start synchronizing data with the remote data source.   </td>   <td><code>SyncWorker.doWork</code>   </td>  </tr>  <tr>   <td>5   </td>   <td><code>OfflineFirstNewsRepository</code> calls <code>RetrofitNiaNetwork</code> to execute the actual API request using <a href=\"https://square.github.io/retrofit/\">Retrofit</a>.   </td>   <td><code>OfflineFirstNewsRepository.syncWith</code>   </td>  </tr>  <tr>   <td>6   </td>   <td><code>RetrofitNiaNetwork</code> calls the REST API on the remote server.   </td>   <td><code>RetrofitNiaNetwork.getNewsResources</code>   </td>  </tr>  <tr>   <td>7   </td>   <td><code>RetrofitNiaNetwork</code> receives the network response from the remote server.   </td>   <td><code>RetrofitNiaNetwork.getNewsResources</code>   </td>  </tr>  <tr>   <td>8   </td>   <td><code>OfflineFirstNewsRepository</code> syncs the remote data with <code>NewsResourceDao</code> by inserting, updating or deleting data in a local <a href=\"https://developer.android.com/training/data-storage/room\">Room database</a>.   </td>   <td><code>OfflineFirstNewsRepository.syncWith</code>   </td>  </tr>  <tr>   <td>9   </td>   <td>When data changes in <code>NewsResourceDao</code> it is emitted into the news resources data stream (which is a <a href=\"https://developer.android.com/kotlin/flow\">Flow</a>).   </td>   <td><code>NewsResourceDao.getNewsResources</code>   </td>  </tr>  <tr>   <td>10   </td>   <td><code>OfflineFirstNewsRepository</code> acts as an <a href=\"https://developer.android.com/kotlin/flow#modify\">intermediate operator</a> on this stream, transforming the incoming <code>PopulatedNewsResource</code> (a database model, internal to the data layer) to the public <code>NewsResource</code> model which is consumed by other layers.   </td>   <td><code>OfflineFirstNewsRepository.getNewsResources</code>   </td>  </tr>  <tr>   <td>11   </td>   <td><code>GetUserNewsResourcesUseCase</code> combines the list of news resources with the user data to emit a list of <code>UserNewsResource</code>s.     </td>   <td><code>GetUserNewsResourcesUseCase.invoke</code>   </td>  </tr>  <tr>   <td>12   </td>   <td>When <code>ForYouViewModel</code> receives the saveable news resources it updates the feed state to <code>Success</code>.  <code>ForYouScreen</code> then uses the saveable news resources in the state to render the screen.   </td>   <td>Search for instances of <code>NewsFeedUiState.Success</code>   </td>  </tr></table><h2 id=\"data-layer\">Data layer</h2><p>The data layer is implemented as an offline-first source of app data and business logic. It is the source of truth for all data in the app.</p><p><img src=\"https://raw.githubusercontent.com/hunga1ok/blog/hung.lv2/images/architecture/architecture-3-data-layer.png\" alt=\"Diagram showing the data layer architecture\" title=\"Diagram showing the data layer architecture\" /></p><p>Each repository has its own models. For example, the <code class=\"language-plaintext highlighter-rouge\">TopicsRepository</code> has a <code class=\"language-plaintext highlighter-rouge\">Topic</code> model and the <code class=\"language-plaintext highlighter-rouge\">NewsRepository</code> has a <code class=\"language-plaintext highlighter-rouge\">NewsResource</code> model.</p><p>Repositories are the public API for other layers, they provide the <em>only</em> way to access the app data. The repositories typically offer one or more methods for reading and writing data.</p><h3 id=\"reading-data\">Reading data</h3><p>Data is exposed as data streams. This means each client of the repository must be prepared to react to data changes. Data is not exposed as a snapshot (e.g. <code class=\"language-plaintext highlighter-rouge\">getModel</code>) because there’s no guarantee that it will still be valid by the time it is used.</p><p>Reads are performed from local storage as the source of truth, therefore errors are not expected when reading from <code class=\"language-plaintext highlighter-rouge\">Repository</code> instances. However, errors may occur when trying to reconcile data in local storage with remote sources. For more on error reconciliation, check the data synchronization section below.</p><p><em>Example: Read a list of topics</em></p><p>A list of Topics can be obtained by subscribing to <code class=\"language-plaintext highlighter-rouge\">TopicsRepository::getTopics</code> flow which emits <code class=\"language-plaintext highlighter-rouge\">List&lt;Topic&gt;</code>.</p><p>Whenever the list of topics changes (for example, when a new topic is added), the updated <code class=\"language-plaintext highlighter-rouge\">List&lt;Topic&gt;</code> is emitted into the stream.</p><h3 id=\"writing-data\">Writing data</h3><p>To write data, the repository provides suspend functions. It is up to the caller to ensure that their execution is suitably scoped.</p><p><em>Example: Follow a topic</em></p><p>Simply call <code class=\"language-plaintext highlighter-rouge\">UserDataRepository.toggleFollowedTopicId</code> with the ID of the topic the user wishes to follow and <code class=\"language-plaintext highlighter-rouge\">followed=true</code> to indicate that the topic should be followed (use <code class=\"language-plaintext highlighter-rouge\">false</code> to unfollow a topic).</p><h3 id=\"data-sources\">Data sources</h3><p>A repository may depend on one or more data sources. For example, the <code class=\"language-plaintext highlighter-rouge\">OfflineFirstTopicsRepository</code> depends on the following data sources:</p><table>  <tr>   <td><strong>Name</strong>   </td>   <td><strong>Backed by</strong>   </td>   <td><strong>Purpose</strong>   </td>  </tr>  <tr>   <td>TopicsDao   </td>   <td><a href=\"https://developer.android.com/training/data-storage/room\">Room/SQLite</a>   </td>   <td>Persistent relational data associated with Topics   </td>  </tr>  <tr>   <td>NiaPreferencesDataSource   </td>   <td><a href=\"https://developer.android.com/topic/libraries/architecture/datastore\">Proto DataStore</a>   </td>   <td>Persistent unstructured data associated with user preferences, specifically which Topics the user is interested in. This is defined and modeled in a .proto file, using the protobuf syntax.   </td>  </tr>  <tr>   <td>NiaNetworkDataSource   </td>   <td>Remote API accessed using Retrofit   </td>   <td>Data for topics, provided through REST API endpoints as JSON.   </td>  </tr></table><h3 id=\"data-synchronization\">Data synchronization</h3><p>Repositories are responsible for reconciling data in local storage with remote sources. Once data is obtained from a remote data source it is immediately written to local storage. The  updated data is emitted from local storage (Room) into the relevant data stream and received by any listening clients.</p><p>This approach ensures that the read and write concerns of the app are separate and do not interfere with each other.</p><p>In the case of errors during data synchronization, an exponential backoff strategy is employed. This is delegated to <code class=\"language-plaintext highlighter-rouge\">WorkManager</code> via the <code class=\"language-plaintext highlighter-rouge\">SyncWorker</code>, an implementation of the <code class=\"language-plaintext highlighter-rouge\">Synchronizer</code> interface.</p><p>See the <code class=\"language-plaintext highlighter-rouge\">OfflineFirstNewsRepository.syncWith</code> for an example of data synchronization.</p><h2 id=\"domain-layer\">Domain layer</h2><p>The <a href=\"https://developer.android.com/topic/architecture/domain-layer\">domain layer</a> contains use cases. These are classes which have a single invocable method (<code class=\"language-plaintext highlighter-rouge\">operator fun invoke</code>) containing business logic.</p><p>These use cases are used to simplify and remove duplicate logic from ViewModels. They typically combine and transform data from repositories.</p><p>For example, <code class=\"language-plaintext highlighter-rouge\">GetUserNewsResourcesUseCase</code> combines a stream (implemented using <code class=\"language-plaintext highlighter-rouge\">Flow</code>) of <code class=\"language-plaintext highlighter-rouge\">NewsResource</code>s from a <code class=\"language-plaintext highlighter-rouge\">NewsRepository</code> with a stream of <code class=\"language-plaintext highlighter-rouge\">UserData</code> objects from a <code class=\"language-plaintext highlighter-rouge\">UserDataRepository</code> to create a stream of <code class=\"language-plaintext highlighter-rouge\">UserNewsResource</code>s. This stream is used by various ViewModels to display news resources on screen with their bookmarked state.</p><p>Notably, the domain layer in Now in Android <em>does not</em> (for now) contain any use cases for event handling. Events are handled by the UI layer calling methods on repositories directly.</p><h2 id=\"ui-layer\">UI Layer</h2><p>The <a href=\"https://developer.android.com/topic/architecture/ui-layer\">UI layer</a> comprises:</p><ul>  <li>UI elements built using <a href=\"https://developer.android.com/jetpack/compose\">Jetpack Compose</a></li>  <li><a href=\"https://developer.android.com/topic/libraries/architecture/viewmodel\">Android ViewModels</a></li></ul><p>The ViewModels receive streams of data from use cases and repositories, and transforms them into UI state. The UI elements reflect this state, and provide ways for the user to interact with the app. These interactions are passed as events to the ViewModel where they are processed.</p><p><img src=\"https://raw.githubusercontent.com/hunga1ok/blog/hung.lv2/images/architecture/architecture-4-ui-layer.png\" alt=\"Diagram showing the UI layer architecture\" title=\"Diagram showing the UI layer architecture\" /></p><h3 id=\"modeling-ui-state\">Modeling UI state</h3><p>UI state is modeled as a sealed hierarchy using interfaces and immutable data classes. State objects are only ever emitted through the transform of data streams. This approach ensures that:</p><ul>  <li>the UI state always represents the underlying app data - the app data is the source-of-truth.</li>  <li>the UI elements handle all possible states.</li></ul><p><strong>Example: News feed on For You screen</strong></p><p>The feed (a list) of news resources on the For You screen is modeled using <code class=\"language-plaintext highlighter-rouge\">NewsFeedUiState</code>. This is a sealed interface which creates a hierarchy of two possible states:</p><ul>  <li><code class=\"language-plaintext highlighter-rouge\">Loading</code> indicates that the data is loading</li>  <li><code class=\"language-plaintext highlighter-rouge\">Success</code> indicates that the data was loaded successfully. The Success state contains the list of news resources.</li></ul><p>The <code class=\"language-plaintext highlighter-rouge\">feedState</code> is passed to the <code class=\"language-plaintext highlighter-rouge\">ForYouScreen</code> composable, which handles both of these states.</p><h3 id=\"transforming-streams-into-ui-state\">Transforming streams into UI state</h3><p>ViewModels receive streams of data as cold <a href=\"https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html\">flows</a> from one or more use cases or repositories. These are <a href=\"https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/combine.html\">combined</a> together, or simply <a href=\"https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/map.html\">mapped</a>, to produce a single flow of UI state. This single flow is then converted to a hot flow using <a href=\"https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/state-in.html\">stateIn</a>. The conversion to a state flow enables UI elements to read the last known state from the flow.</p><p><strong>Example: Displaying followed topics</strong></p><p>The <code class=\"language-plaintext highlighter-rouge\">InterestsViewModel</code> exposes <code class=\"language-plaintext highlighter-rouge\">uiState</code> as a <code class=\"language-plaintext highlighter-rouge\">StateFlow&lt;InterestsUiState&gt;</code>. This hot flow is created by obtaining the cold flow of <code class=\"language-plaintext highlighter-rouge\">List&lt;FollowableTopic&gt;</code> provided by <code class=\"language-plaintext highlighter-rouge\">GetFollowableTopicsUseCase</code>. Each time a new list is emitted, it is converted into an <code class=\"language-plaintext highlighter-rouge\">InterestsUiState.Interests</code> state which is exposed to the UI.</p><h3 id=\"processing-user-interactions\">Processing user interactions</h3><p>User actions are communicated from UI elements to ViewModels using regular method invocations. These methods are passed to the UI elements as lambda expressions.</p><p><strong>Example: Following a topic</strong></p><p>The <code class=\"language-plaintext highlighter-rouge\">InterestsScreen</code> takes a lambda expression named <code class=\"language-plaintext highlighter-rouge\">followTopic</code> which is supplied from <code class=\"language-plaintext highlighter-rouge\">InterestsViewModel.followTopic</code>. Each time the user taps on a topic to follow this method is called. The ViewModel then processes this action by informing the user data repository.</p><h2 id=\"further-reading\">Further reading</h2><p><a href=\"https://developer.android.com/topic/architecture\">Guide to app architecture</a></p><p><a href=\"https://developer.android.com/jetpack/compose\">Jetpack Compose</a></p>",
            "url": "https://hunga1ok.github.io/blog/2023/06/26/architecture-learning-journey",
            
            
            
            "tags": ["android","architecture"],
            
            "date_published": "2023-06-26T00:00:00+02:00",
            "date_modified": "2023-06-26T00:00:00+02:00",
            
                "author":  {
                "name": "hunga1ok",
                "url": null,
                "avatar": null
                }
                
            
        },
    
        {
            "id": "https://hunga1ok.github.io/blog/2022/05/12/simple-date-format",
            "title": "How to create a SimpleDateFormat",
            "summary": "Create a SimpleDateFormat is so easy ^^",
            "content_text": "SimpleDateFormat  Table content for reference:            Letter      Date or Time Component      Presentation      Examples                  G      Era designator      Text      AD              y      Year      Year      1996; 96              Y      Week year      Year      2009; 09              M      Month in year      Month      July; Jul; 07              w      Week in year      Number      27              W      Week in month      Number      2              D      Day in year      Number      189              d      Day in month      Number      10              F      Day of week in month      Number      2              E      Day name in week      Text      Tuesday; Tue              u      Day number of week (1 = Monday, …, 7 = Sunday)      Number      1              a      Am/pm marker      Text      PM              H      Hour in day (0-23)      Number      0              k      Hour in day (1-24)      Number      24              K      Hour in am/pm (0-11)      Number      0              h      Hour in am/pm (1-12)      Number      12              m      Minute in hour      Number      30              s      Second in minute      Number      55              S      Millisecond      Number      978              z      Time zone      General time zone      Pacific Standard Time; PST; GMT-08:00              Z      Time zone      RFC 822 time zone      -0800              X      Time zone      ISO 8601 time zone      -08; -0800; -08:00      ##Some code extensions kotlin:  I use JodaTime library for support handle featuresfun String?.formatHour(toPattern: String) = formatHour(\"HH:mm:ss\", toPattern)fun String?.formatHour(fromPattern: String, toPattern: String): String {    if (this == null) return \"\"    return try {        DateTime.parse(this, DateTimeFormat.forPattern(fromPattern)).toString(toPattern)    } catch (e: Exception) {        \"Invalid Date\"    }}fun String?.formatDate(toPattern: String): String {    if (this == null) return \"\"    return try {        DateTime(this).toString(toPattern)    } catch (e: Exception) {        \"Invalid Date\"    }}fun String?.formatDate(fromPattern: String, toPattern: String): String {    if (this == null) return \"\"    return try {        DateTime.parse(this, DateTimeFormat.forPattern(fromPattern)).toString(toPattern)    } catch (e: Exception) {        \"Invalid Date\"    }}fun String?.parseDate(pattern: String? = null): DateTime? {    if (this == null) return null    return try {        pattern?.let { DateTime.parse(this, DateTimeFormat.forPattern(pattern)) } ?: DateTime(this)    } catch (e: Exception) {        null    }}",
            "content_html": "<h2 id=\"simpledateformat\"><a href=\"https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html\">SimpleDateFormat</a></h2><blockquote>  <p>Table content for reference:</p></blockquote><table>  <thead>    <tr>      <th>Letter</th>      <th>Date or Time Component</th>      <th>Presentation</th>      <th>Examples</th>    </tr>  </thead>  <tbody>    <tr>      <td>G</td>      <td>Era designator</td>      <td>Text</td>      <td>AD</td>    </tr>    <tr>      <td>y</td>      <td>Year</td>      <td>Year</td>      <td>1996; 96</td>    </tr>    <tr>      <td>Y</td>      <td>Week year</td>      <td>Year</td>      <td>2009; 09</td>    </tr>    <tr>      <td>M</td>      <td>Month in year</td>      <td>Month</td>      <td>July; Jul; 07</td>    </tr>    <tr>      <td>w</td>      <td>Week in year</td>      <td>Number</td>      <td>27</td>    </tr>    <tr>      <td>W</td>      <td>Week in month</td>      <td>Number</td>      <td>2</td>    </tr>    <tr>      <td>D</td>      <td>Day in year</td>      <td>Number</td>      <td>189</td>    </tr>    <tr>      <td>d</td>      <td>Day in month</td>      <td>Number</td>      <td>10</td>    </tr>    <tr>      <td>F</td>      <td>Day of week in month</td>      <td>Number</td>      <td>2</td>    </tr>    <tr>      <td>E</td>      <td>Day name in week</td>      <td>Text</td>      <td>Tuesday; Tue</td>    </tr>    <tr>      <td>u</td>      <td>Day number of week (1 = Monday, …, 7 = Sunday)</td>      <td>Number</td>      <td>1</td>    </tr>    <tr>      <td>a</td>      <td>Am/pm marker</td>      <td>Text</td>      <td>PM</td>    </tr>    <tr>      <td>H</td>      <td>Hour in day (0-23)</td>      <td>Number</td>      <td>0</td>    </tr>    <tr>      <td>k</td>      <td>Hour in day (1-24)</td>      <td>Number</td>      <td>24</td>    </tr>    <tr>      <td>K</td>      <td>Hour in am/pm (0-11)</td>      <td>Number</td>      <td>0</td>    </tr>    <tr>      <td>h</td>      <td>Hour in am/pm (1-12)</td>      <td>Number</td>      <td>12</td>    </tr>    <tr>      <td>m</td>      <td>Minute in hour</td>      <td>Number</td>      <td>30</td>    </tr>    <tr>      <td>s</td>      <td>Second in minute</td>      <td>Number</td>      <td>55</td>    </tr>    <tr>      <td>S</td>      <td>Millisecond</td>      <td>Number</td>      <td>978</td>    </tr>    <tr>      <td>z</td>      <td>Time zone</td>      <td>General time zone</td>      <td>Pacific Standard Time; PST; GMT-08:00</td>    </tr>    <tr>      <td>Z</td>      <td>Time zone</td>      <td>RFC 822 time zone</td>      <td>-0800</td>    </tr>    <tr>      <td>X</td>      <td>Time zone</td>      <td>ISO 8601 time zone</td>      <td>-08; -0800; -08:00</td>    </tr>  </tbody></table><p>##Some code extensions kotlin:</p><blockquote>  <p>I use <a href=\"https://github.com/JodaOrg/joda-time\">JodaTime</a> library for support handle features</p></blockquote><div class=\"language-kotlin highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"k\">fun</span> <span class=\"nf\">String</span><span class=\"o\">?.</span><span class=\"nf\">formatHour</span><span class=\"p\">(</span><span class=\"n\">toPattern</span><span class=\"p\">:</span> <span class=\"nc\">String</span><span class=\"p\">)</span> <span class=\"p\">=</span> <span class=\"nf\">formatHour</span><span class=\"p\">(</span><span class=\"s\">\"HH:mm:ss\"</span><span class=\"p\">,</span> <span class=\"n\">toPattern</span><span class=\"p\">)</span><span class=\"k\">fun</span> <span class=\"nf\">String</span><span class=\"o\">?.</span><span class=\"nf\">formatHour</span><span class=\"p\">(</span><span class=\"n\">fromPattern</span><span class=\"p\">:</span> <span class=\"nc\">String</span><span class=\"p\">,</span> <span class=\"n\">toPattern</span><span class=\"p\">:</span> <span class=\"nc\">String</span><span class=\"p\">):</span> <span class=\"nc\">String</span> <span class=\"p\">{</span>    <span class=\"k\">if</span> <span class=\"p\">(</span><span class=\"k\">this</span> <span class=\"p\">==</span> <span class=\"k\">null</span><span class=\"p\">)</span> <span class=\"k\">return</span> <span class=\"s\">\"\"</span>    <span class=\"k\">return</span> <span class=\"k\">try</span> <span class=\"p\">{</span>        <span class=\"nc\">DateTime</span><span class=\"p\">.</span><span class=\"nf\">parse</span><span class=\"p\">(</span><span class=\"k\">this</span><span class=\"p\">,</span> <span class=\"nc\">DateTimeFormat</span><span class=\"p\">.</span><span class=\"nf\">forPattern</span><span class=\"p\">(</span><span class=\"n\">fromPattern</span><span class=\"p\">)).</span><span class=\"nf\">toString</span><span class=\"p\">(</span><span class=\"n\">toPattern</span><span class=\"p\">)</span>    <span class=\"p\">}</span> <span class=\"k\">catch</span> <span class=\"p\">(</span><span class=\"n\">e</span><span class=\"p\">:</span> <span class=\"nc\">Exception</span><span class=\"p\">)</span> <span class=\"p\">{</span>        <span class=\"s\">\"Invalid Date\"</span>    <span class=\"p\">}</span><span class=\"p\">}</span><span class=\"k\">fun</span> <span class=\"nf\">String</span><span class=\"o\">?.</span><span class=\"nf\">formatDate</span><span class=\"p\">(</span><span class=\"n\">toPattern</span><span class=\"p\">:</span> <span class=\"nc\">String</span><span class=\"p\">):</span> <span class=\"nc\">String</span> <span class=\"p\">{</span>    <span class=\"k\">if</span> <span class=\"p\">(</span><span class=\"k\">this</span> <span class=\"p\">==</span> <span class=\"k\">null</span><span class=\"p\">)</span> <span class=\"k\">return</span> <span class=\"s\">\"\"</span>    <span class=\"k\">return</span> <span class=\"k\">try</span> <span class=\"p\">{</span>        <span class=\"nc\">DateTime</span><span class=\"p\">(</span><span class=\"k\">this</span><span class=\"p\">).</span><span class=\"nf\">toString</span><span class=\"p\">(</span><span class=\"n\">toPattern</span><span class=\"p\">)</span>    <span class=\"p\">}</span> <span class=\"k\">catch</span> <span class=\"p\">(</span><span class=\"n\">e</span><span class=\"p\">:</span> <span class=\"nc\">Exception</span><span class=\"p\">)</span> <span class=\"p\">{</span>        <span class=\"s\">\"Invalid Date\"</span>    <span class=\"p\">}</span><span class=\"p\">}</span><span class=\"k\">fun</span> <span class=\"nf\">String</span><span class=\"o\">?.</span><span class=\"nf\">formatDate</span><span class=\"p\">(</span><span class=\"n\">fromPattern</span><span class=\"p\">:</span> <span class=\"nc\">String</span><span class=\"p\">,</span> <span class=\"n\">toPattern</span><span class=\"p\">:</span> <span class=\"nc\">String</span><span class=\"p\">):</span> <span class=\"nc\">String</span> <span class=\"p\">{</span>    <span class=\"k\">if</span> <span class=\"p\">(</span><span class=\"k\">this</span> <span class=\"p\">==</span> <span class=\"k\">null</span><span class=\"p\">)</span> <span class=\"k\">return</span> <span class=\"s\">\"\"</span>    <span class=\"k\">return</span> <span class=\"k\">try</span> <span class=\"p\">{</span>        <span class=\"nc\">DateTime</span><span class=\"p\">.</span><span class=\"nf\">parse</span><span class=\"p\">(</span><span class=\"k\">this</span><span class=\"p\">,</span> <span class=\"nc\">DateTimeFormat</span><span class=\"p\">.</span><span class=\"nf\">forPattern</span><span class=\"p\">(</span><span class=\"n\">fromPattern</span><span class=\"p\">)).</span><span class=\"nf\">toString</span><span class=\"p\">(</span><span class=\"n\">toPattern</span><span class=\"p\">)</span>    <span class=\"p\">}</span> <span class=\"k\">catch</span> <span class=\"p\">(</span><span class=\"n\">e</span><span class=\"p\">:</span> <span class=\"nc\">Exception</span><span class=\"p\">)</span> <span class=\"p\">{</span>        <span class=\"s\">\"Invalid Date\"</span>    <span class=\"p\">}</span><span class=\"p\">}</span><span class=\"k\">fun</span> <span class=\"nf\">String</span><span class=\"o\">?.</span><span class=\"nf\">parseDate</span><span class=\"p\">(</span><span class=\"n\">pattern</span><span class=\"p\">:</span> <span class=\"nc\">String</span><span class=\"p\">?</span> <span class=\"p\">=</span> <span class=\"k\">null</span><span class=\"p\">):</span> <span class=\"nc\">DateTime</span><span class=\"p\">?</span> <span class=\"p\">{</span>    <span class=\"k\">if</span> <span class=\"p\">(</span><span class=\"k\">this</span> <span class=\"p\">==</span> <span class=\"k\">null</span><span class=\"p\">)</span> <span class=\"k\">return</span> <span class=\"k\">null</span>    <span class=\"k\">return</span> <span class=\"k\">try</span> <span class=\"p\">{</span>        <span class=\"n\">pattern</span><span class=\"o\">?.</span><span class=\"nf\">let</span> <span class=\"p\">{</span> <span class=\"nc\">DateTime</span><span class=\"p\">.</span><span class=\"nf\">parse</span><span class=\"p\">(</span><span class=\"k\">this</span><span class=\"p\">,</span> <span class=\"nc\">DateTimeFormat</span><span class=\"p\">.</span><span class=\"nf\">forPattern</span><span class=\"p\">(</span><span class=\"n\">pattern</span><span class=\"p\">))</span> <span class=\"p\">}</span> <span class=\"o\">?:</span> <span class=\"nc\">DateTime</span><span class=\"p\">(</span><span class=\"k\">this</span><span class=\"p\">)</span>    <span class=\"p\">}</span> <span class=\"k\">catch</span> <span class=\"p\">(</span><span class=\"n\">e</span><span class=\"p\">:</span> <span class=\"nc\">Exception</span><span class=\"p\">)</span> <span class=\"p\">{</span>        <span class=\"k\">null</span>    <span class=\"p\">}</span><span class=\"p\">}</span></code></pre></div></div>",
            "url": "https://hunga1ok.github.io/blog/2022/05/12/simple-date-format",
            
            
            
            "tags": ["android","coding"],
            
            "date_published": "2022-05-12T00:00:00+02:00",
            "date_modified": "2022-05-12T00:00:00+02:00",
            
                "author":  {
                "name": "hunga1ok",
                "url": null,
                "avatar": null
                }
                
            
        },
    
        {
            "id": "https://hunga1ok.github.io/blog/2022/05/05/android-roadmap",
            "title": "Android Developer Roadmap",
            "summary": "This is a roadmap for android developer for beginners",
            "content_text": "  A complete roadmap to learn Android App Development. This roadmap will help you in becoming a complete Android Developer.Roadmap to learn Android App Development  Programming          Java      Kotlin        Android Studio          Android Studio IDE Overview      Project Structure \t   * Java/Kotlin \t   * XML \t   * .gradle files        Android Component          Activity                  Activity Lifecycle          Tasks &amp; Back Stack                    Service      Broadcast Receiver      Content Provider        Intents          Types of Intent                  Implicit          Explicit                    Intent Filter        Static User Interface          View                  Button, ImageView, TextView, EditText etc                    ViewGroup     * LinearLayout, RelativeLayout, FrameLayout, ConstraintLayout        Dynamic User Interface          RecyclerView      ViewPager      Spinner        CustomView          Canvas      Bitmap      Paint        UI Resources          Drawables      String      Styles        Fragments          Fragment Lifecycle      Fragment Manager        Support User Interface          ProgressBar      Dialogs      Toast &amp; Snackbar        Storage          Shared Preferences      File Systems      Database                  RoomDB                      Build          Gradle      Debug / Release Configuration        Threading          Threads      Handler / Looper        Debugging          Memory profiling      Logging      Systrace      Exceptions      Error Handling        Memory Leak          Detecting and Fixing Memory Leaks      Context        3rd Party Library          Image Loading                  Glide          Picasso                    Dependency Injection                  Dagger                    Networking                  Fast Android Networking Library          Retrofit                    MultiThreading                  RxJava          Coroutines                      Data Format          JSON                  GSON                    Flat Buffer      Protocol Buffer        Android Jetpack          Foundation Components                  AppCompat          Android KTX          Multidex                    Architecture Components                  LiveData          ViewModel          DataBinding          Paging          Work Manager          Navigation                    Behaviour Components                  Download Manager          Media Playback          Notification          Permissions          Preference          Sharing          Slice                    UI Component                  Animation &amp; Transition          Android Auto          Emoji          Palette          Android TV          Android Wear                      Architecture          MVVM      MVI      MVP        Unit Testing\t * Local Unit Testing\t * Instrumentation Testing  Firebase          FCM      Crashlytics      Analytics      Remote Config      App Indexing      Dynamic Link        Security          Encrypt / Decrypt      Proguard      R8        App Release          .keystore file      App Bundle      Playstore        Keep Learning and Improving",
            "content_html": "<blockquote>  <p>A complete roadmap to learn Android App Development. This roadmap will help you in becoming a complete Android Developer.</p></blockquote><p align=\"center\"><img alt=\"Android Developer Roadmap\" src=\"https://raw.githubusercontent.com/hunga1ok/blog/hung.lv2/images/android_developer_roadmap.png\" /></p><h2 id=\"roadmap-to-learn-android-app-development\">Roadmap to learn Android App Development</h2><ul>  <li>Programming    <ul>      <li>Java</li>      <li>Kotlin</li>    </ul>  </li>  <li>Android Studio    <ul>      <li>Android Studio IDE Overview</li>      <li>Project Structure \t   * Java/Kotlin \t   * XML \t   * .gradle files</li>    </ul>  </li>  <li>Android Component    <ul>      <li>Activity        <ul>          <li>Activity Lifecycle</li>          <li>Tasks &amp; Back Stack</li>        </ul>      </li>      <li>Service</li>      <li>Broadcast Receiver</li>      <li>Content Provider</li>    </ul>  </li>  <li>Intents    <ul>      <li>Types of Intent        <ul>          <li>Implicit</li>          <li>Explicit</li>        </ul>      </li>      <li>Intent Filter</li>    </ul>  </li>  <li>Static User Interface    <ul>      <li>View        <ul>          <li>Button, ImageView, TextView, EditText etc</li>        </ul>      </li>      <li>ViewGroup     * LinearLayout, RelativeLayout, FrameLayout, ConstraintLayout</li>    </ul>  </li>  <li>Dynamic User Interface    <ul>      <li>RecyclerView</li>      <li>ViewPager</li>      <li>Spinner</li>    </ul>  </li>  <li>CustomView    <ul>      <li>Canvas</li>      <li>Bitmap</li>      <li>Paint</li>    </ul>  </li>  <li>UI Resources    <ul>      <li>Drawables</li>      <li>String</li>      <li>Styles</li>    </ul>  </li>  <li>Fragments    <ul>      <li>Fragment Lifecycle</li>      <li>Fragment Manager</li>    </ul>  </li>  <li>Support User Interface    <ul>      <li>ProgressBar</li>      <li>Dialogs</li>      <li>Toast &amp; Snackbar</li>    </ul>  </li>  <li>Storage    <ul>      <li>Shared Preferences</li>      <li>File Systems</li>      <li>Database        <ul>          <li>RoomDB</li>        </ul>      </li>    </ul>  </li>  <li>Build    <ul>      <li>Gradle</li>      <li>Debug / Release Configuration</li>    </ul>  </li>  <li>Threading    <ul>      <li>Threads</li>      <li>Handler / Looper</li>    </ul>  </li>  <li>Debugging    <ul>      <li>Memory profiling</li>      <li>Logging</li>      <li>Systrace</li>      <li>Exceptions</li>      <li>Error Handling</li>    </ul>  </li>  <li>Memory Leak    <ul>      <li>Detecting and Fixing Memory Leaks</li>      <li>Context</li>    </ul>  </li>  <li>3rd Party Library    <ul>      <li>Image Loading        <ul>          <li>Glide</li>          <li>Picasso</li>        </ul>      </li>      <li>Dependency Injection        <ul>          <li>Dagger</li>        </ul>      </li>      <li>Networking        <ul>          <li>Fast Android Networking Library</li>          <li>Retrofit</li>        </ul>      </li>      <li>MultiThreading        <ul>          <li>RxJava</li>          <li>Coroutines</li>        </ul>      </li>    </ul>  </li>  <li>Data Format    <ul>      <li>JSON        <ul>          <li>GSON</li>        </ul>      </li>      <li>Flat Buffer</li>      <li>Protocol Buffer</li>    </ul>  </li>  <li>Android Jetpack    <ul>      <li>Foundation Components        <ul>          <li>AppCompat</li>          <li>Android KTX</li>          <li>Multidex</li>        </ul>      </li>      <li>Architecture Components        <ul>          <li>LiveData</li>          <li>ViewModel</li>          <li>DataBinding</li>          <li>Paging</li>          <li>Work Manager</li>          <li>Navigation</li>        </ul>      </li>      <li>Behaviour Components        <ul>          <li>Download Manager</li>          <li>Media Playback</li>          <li>Notification</li>          <li>Permissions</li>          <li>Preference</li>          <li>Sharing</li>          <li>Slice</li>        </ul>      </li>      <li>UI Component        <ul>          <li>Animation &amp; Transition</li>          <li>Android Auto</li>          <li>Emoji</li>          <li>Palette</li>          <li>Android TV</li>          <li>Android Wear</li>        </ul>      </li>    </ul>  </li>  <li>Architecture    <ul>      <li>MVVM</li>      <li>MVI</li>      <li>MVP</li>    </ul>  </li>  <li>Unit Testing\t * Local Unit Testing\t * Instrumentation Testing</li>  <li>Firebase    <ul>      <li>FCM</li>      <li>Crashlytics</li>      <li>Analytics</li>      <li>Remote Config</li>      <li>App Indexing</li>      <li>Dynamic Link</li>    </ul>  </li>  <li>Security    <ul>      <li>Encrypt / Decrypt</li>      <li>Proguard</li>      <li>R8</li>    </ul>  </li>  <li>App Release    <ul>      <li>.keystore file</li>      <li>App Bundle</li>      <li>Playstore</li>    </ul>  </li>  <li>Keep Learning and Improving</li></ul>",
            "url": "https://hunga1ok.github.io/blog/2022/05/05/android-roadmap",
            
            
            
            "tags": ["android","coding"],
            
            "date_published": "2022-05-05T00:00:00+02:00",
            "date_modified": "2022-05-05T00:00:00+02:00",
            
                "author":  {
                "name": "hunga1ok",
                "url": null,
                "avatar": null
                }
                
            
        }
    
    ]
}