This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 // |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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只涉及到了只读的操作 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |