Skip to content

Instantly share code, notes, and snippets.

View trunghq3101's full-sized avatar

Miller Go Dev trunghq3101

View GitHub Profile
meta:
title: The Lost Adventure
description: A magical bedtime story about a curious boy who learns the value of courage and wisdom.
author: Lily
version: 1.1.0
items:
- id: flashlight
name: Shimmering Lantern
description: A tiny lantern that glows with a soft golden light. Helpful in the dark.
@trunghq3101
trunghq3101 / list_item.dart
Last active March 28, 2022 01:14
Make item content wrapped vertically inside a horizontal ListView
// ListView applies a tight constraint (minHeight = maxHeight in this case) to its children.
// So all children are forced to have the same height. To let an item to have its own size,
// first, remove constraints by using UnconstrainedBox.
// then, apply new loosen constraints with ConstrainedBox.
// Using only UnconstrainedBox would be sufficient in this specific case,
// but it can cause errors in case the child want to be as big as possible.
// So ConstrainedBox is needed to provide a specific constraints.
ListView(
scrollDirection: Axis.horizontal,
@trunghq3101
trunghq3101 / zlibDecompress.kt
Created May 30, 2020 14:41 — forked from eren/zlibDecompress.kt
Zlib Inflate/Decompress in Kotlin
/**
* Zlib decompress a file and return its contents
*
* @param filePath absolute path to file
* @return unzipped file contents
*/
fun decompress(filePath: String) : String {
val content = File(filePath).readBytes()
val inflater = Inflater()
val outputStream = ByteArrayOutputStream()
@trunghq3101
trunghq3101 / AuthenticatorInterceptor.kt
Created May 28, 2020 08:56
Refresh token interceptor
class AuthenticateInterceptor(
private val dataStorage: DataStorage,
private val authService: AuthService
) : Interceptor {
override fun intercept(chain: Chain): Response {
val newRequest = buildAuthorizedRequest(chain)
val response = chain.proceed(newRequest)
return if (response.code == CODE_TOKEN_EXPIRED) {
@trunghq3101
trunghq3101 / CoroutineUnderstanding.kt
Created April 25, 2020 06:52
Kotlin Coroutine Understanding
/**
* You can edit, run, and share this code.
* play.kotlinlang.org
*/
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import kotlin.system.*
fun test1() {
var time = 0L
@trunghq3101
trunghq3101 / BaseRecyclerAdapter.kt
Created November 28, 2019 15:18
example RecyclerView Adapter using view type
abstract class BaseRecyclerAdapter<Item, ViewBinding : ViewDataBinding>(
callBack: DiffUtil.ItemCallback<Item>
) : ListAdapter<Item, BaseViewHolder<ViewBinding>>(
AsyncDifferConfig.Builder<Item>(callBack)
.setBackgroundThreadExecutor(Executors.newSingleThreadExecutor())
.build()
) {
override fun submitList(list: List<Item>?) {
super.submitList(ArrayList<Item>(list ?: listOf()))
@trunghq3101
trunghq3101 / MessagingFragment.kt
Created October 21, 2019 04:34
Detech when soft keyboard shows over a RecyclerView
recyclerMessages.addOnLayoutChangeListener { v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom ->
if (bottom < oldBottom) {
recyclerMessages.smoothScrollToPosition(0)
}
}
@trunghq3101
trunghq3101 / nav_graph.xml
Created October 21, 2019 03:43
Pop this fragment from backstack when go to new destination
<fragment
android:id="@+id/blankFragment"
android:name="com.miller.futurechat.presentation.blank.BlankFragment"
android:label="Home"
tools:layout="@layout/fragment_blank">
<action
android:id="@+id/action_blank_to_conversations"
app:destination="@id/conversationsFragment"
app:popUpTo="@id/blankFragment"
app:popUpToInclusive="true" />
@trunghq3101
trunghq3101 / styles.xml
Created October 16, 2019 02:07
Custom drawer arrow style (Up arrow)
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="drawerArrowStyle">@style/AppTheme.DrawerArrowStyle</item>
<item name="android:textSize">14sp</item>
</style>
<style name="AppTheme.DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
package com.miller.futurechat
import android.content.Context
import android.util.Log
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.signature.ObjectKey
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable