Skip to content

Instantly share code, notes, and snippets.

View Tougee's full-sized avatar
🏠
Working from home

touge Tougee

🏠
Working from home
View GitHub Profile
@Tougee
Tougee / Demo.kt
Last active June 19, 2019 09:56
Handle network response provide by Retrofit suspend style function
fun fetchFoo() = GlobalScope.launch {
handleNetworkResponse<Foo, Unit>(
invokeNetwork = {
fooService.fetchFoo()
},
successBlock = { r ->
// success logic
},
errorBlock = {
// error logic
@Tougee
Tougee / DraggableRecyclerView.kt
Last active March 20, 2019 10:25
DraggableRecyclerView
package one.mixin.android.widget
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.VelocityTracker
import android.view.ViewConfiguration
import androidx.recyclerview.widget.RecyclerView
import one.mixin.android.R
@Tougee
Tougee / DecodeQRCode.kt
Created June 12, 2018 10:09
Zxing Android decode QR code
fun Bitmap.decodeQR(): String? {
val width = width
val height = height
val pixels = IntArray(width * height)
getPixels(pixels, 0, width, 0, 0, width, height)
val source = RGBLuminanceSource(width, height, pixels)
val binaryBitmap = BinaryBitmap(GlobalHistogramBinarizer(source))
val reader = MultiFormatReader()
val hints = EnumMap<DecodeHintType, Any>(DecodeHintType::class.java)