Skip to content

Instantly share code, notes, and snippets.

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.subjects.BehaviorSubject
import java.util.concurrent.TimeUnit
class ClickUtil(lifecycle: Lifecycle, private val delay: Long = 1000L) : LifecycleObserver {
private lateinit var compositeDisposable: CompositeDisposable
private lateinit var clickSubject: BehaviorSubject<(() -> Unit)>
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.subjects.BehaviorSubject
import java.util.concurrent.TimeUnit
class ClickUtil(lifecycle: Lifecycle, private val delay: Long = 1000L) : LifecycleObserver {
private lateinit var compositeDisposable: CompositeDisposable
private lateinit var clickSubject: BehaviorSubject<(() -> Unit)>
@seoft
seoft / usage.kt
Last active February 27, 2020 14:17
// in activity
class SettingInFingerActivity : AppCompatActivity() {
private val click by lazy { ClickUtil(this.lifecycle) }
// (생략)
private fun initListener() {
testButton.SetOnClickListener {
// in koin module
val viewModelModule = module {
viewModel { MainViewModel() }
}
// in activity
val mainViewModel by viewModel<MainViewModel>()
@seoft
seoft / 1.kt
Last active May 27, 2020 13:10
// 확장함수 정의
fun Date.convert(): String {
val diff = (Date().time - this.time) / 1000
return when (diff) {
in 0 until 10 -> "지금 막"
in 10 until 60 -> "${diff}초 전"
in 60 until 60 * 60 -> "${diff / 60}분 전"
in 60 * 60 until 60 * 60 * 24 -> "${diff / (60 * 60)}시간 전"
in 60 * 60 * 24 until 60 * 60 * 48 -> "어제"
in 60 * 60 * 48 until 60 * 60 * 24 * 7 -> "${diff / (60 * 60 * 24)}일 전"
package kr.co.seoft.ah
import org.junit.Test
import org.junit.Assert.*
import java.text.SimpleDateFormat
import java.util.*
/**
* Example local unit test, which will execute on the development machine (host).
val items = listOf("AA", "BB", "CC", "DD", "EE", "FF")
val findItems = setOf("CCa", "DD")
val whetherOneOrMoreFindItemInItems = items.any { it in findItems }
assertEquals(true, whetherOneOrMoreFindItemInItems)
@GET("api/emptyResponse")
fun getEmptyResponse(): Single<Response<Unit>>
abstract class Animal(val type: String)
data class Cat constructor(val age: Int) : Animal("cat")
data class Dog constructor(val weight: Int) : Animal("dog")
fun combineVoteItems(): List<VoteItem> {
return LiveDataUtil.convertToTypeList(title, contens, optionEdit, optionMultiple, optionOverlap) ?: return emptyList()
}