Skip to content

Instantly share code, notes, and snippets.

View xiaofeidev's full-sized avatar
:octocat:
Working from home

xiaofei xiaofeidev

:octocat:
Working from home
View GitHub Profile
@xiaofeidev
xiaofeidev / IpUtil
Created January 15, 2019 03:10
Kotlin 实现的工具类,获取本机内网 IP 和公网 IP
import org.json.JSONException
import org.json.JSONObject
import java.io.BufferedInputStream
import java.io.ByteArrayOutputStream
import java.io.IOException
import java.lang.Exception
import java.net.*
/**
* Created by xiaofei on 2019/1/15.
@xiaofeidev
xiaofeidev / BooleanExt
Created November 30, 2018 07:09
Boolean Extension, Say Goodbye to if-else expression
/**
* Created by xiaofei on 2018/11/30.
* desc:Boolean Extension, Say Goodbye to if-else expression
*/
sealed class BooleanExt<out T>//定义成协变
object Otherwise : BooleanExt<Nothing>()//Nothing是所有类型的子类型,协变的类继承关系和泛型参数类型继承关系一致
class TransferData<T>(val data: T) : BooleanExt<T>()//data只涉及到了只读的操作
val timer:TextView = findViewById(R.id.textView) //这里的 timer 就是你要控制显示倒计时效果的 TextView
val mSubscription: Subscription? = null // Subscription 对象,用于取消订阅关系,防止内存泄露
//开始倒计时,用 RxJava2 实现
private fun timer() {
val count = 59L
Flowable.interval(0, 1, TimeUnit.SECONDS)//设置0延迟,每隔一秒发送一条数据
.onBackpressureBuffer()//加上背压策略
.take(count) //设置循环次数
.map{ aLong ->
count - aLong //