Skip to content

Instantly share code, notes, and snippets.

View f3401pal's full-sized avatar

Andy Wang f3401pal

View GitHub Profile
@f3401pal
f3401pal / RelativeTimeUtils.kt
Last active January 31, 2023 16:14
Relative time utils
/**
* Parse a local date time string into a UTC date time object
* TODO: update to Java 8 time API https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html, return java.time.Instant
*/
fun String.toDate(
dateFormat: String = "yyyy-MM-dd'T'HH:mm:ss",
timeZone: TimeZone = TimeZone.getTimeZone("UTC")
): Date? {
val parser = SimpleDateFormat(dateFormat, Locale.getDefault())
parser.timeZone = timeZone
@f3401pal
f3401pal / app\build.gradle.kts
Last active January 5, 2024 13:53
Multi-module Android project with Kotlin DSL for Gradle
plugins {
`android-base-app`
`android-base`
id("io.fabric")
}
android {
defaultConfig {
versionCode = 20
versionName = "1.6.3"
@f3401pal
f3401pal / demo.webm
Last active April 14, 2023 18:21
Animated vector drawable (NFC icon)
@f3401pal
f3401pal / DowloadJob.kt
Created April 8, 2019 14:28
RxBroadcastReceiver + DownloadManager example
fun dowloadFile(url: String): Single<Long> {
val expectedId: Long = DownloadManager.Request(Uri.parse(builder.apkUrl)).run { downloadManager.enqueue(this) }
return downloadReceiver.map {
it.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)
}.takeWhile {
it == expectedId
}.firstOrError().timeout(3, TimeUnit.MINUTES)
}
@f3401pal
f3401pal / RxExtension.kt
Last active December 20, 2018 22:29
RxKotlin Flowable from staged completables (draft)
import io.reactivex.Completable
import io.reactivex.Flowable
object FlowableEx {
/**
* Create a Flowable by chaining multiple completables and execute them in order.
* Note that the completables will be run in sequense. If previous completable fails, the next one will NOT run.
* For example:
@f3401pal
f3401pal / BounceCircleLoadingView.java
Last active March 30, 2017 22:17
BounceCircleLoadingView
package com.f3401pal.shb.android.ui;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
@f3401pal
f3401pal / ListShimmerView.java
Last active August 5, 2021 16:37
ListShimmerView
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;