Skip to content

Instantly share code, notes, and snippets.

name: Build
on:
push:
branches:
- master
jobs:
build:
name: Build
@hkusu
hkusu / LiveDataExt.kt
Last active October 8, 2020 07:14
旧版の実装は https://gist.github.com/hkusu/b258c4e4ef488ccd8b213586417ffbec を参照。このコードは Ktolin 1.4.0、Coroutines 1.3.9 で動作確認しています。
package io.github.hkusu.sample.ext
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.Observer
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext
inline fun <T, U> LiveData<T>.mapNotNull(
package io.github.hkusu.sample.ui
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import io.github.hkusu.sample.databinding.MainFragmentBinding
class MainFragment : Fragment(R.layout.main_fragment) {
private val binding: MainFragmentBinding by viewBinding()
package io.github.hkusu.sample.ext
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.Observer
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext
inline fun <T, U> LiveData<T>.mapNotNull(
@hkusu
hkusu / Dangerfile
Last active December 4, 2019 13:19
github.dismiss_out_of_range_messages
# ktlint
Dir.glob("**//build/reports/ktlint-results.xml").each { |report|
checkstyle_format.base_path = Dir.pwd
checkstyle_format.report report.to_s
}
# Android Lint
Dir.glob("**//build/reports/lint-results*.xml").each { |report|
@hkusu
hkusu / SomeViewModel.kt
Last active September 17, 2019 14:53
Androidの連続クリック対策
fun onButtonClicked(view: View?) { // unitテスト時はnullを渡す
view?.disableContinuousClicks()
// do something..
}
@hkusu
hkusu / LiveDataExt.kt
Created April 18, 2019 15:22
suspend function が利用できる map
inline fun <T, U> LiveData<T>.map(
scope: CoroutineScope,
crossinline block: suspend (T) -> U
): LiveData<U> {
val result = MediatorLiveData<U>()
result.addSource(this) {
scope.launch {
result.postValue(block.invoke(it))
}
}
package io.github.hkusu.sample.android.lib.rx;
import rx.Observable;
import rx.subjects.PublishSubject;
import rx.subjects.SerializedSubject;
import rx.subjects.Subject;
public class Event<T> {
private final Subject<T, T> subject = new SerializedSubject<>(PublishSubject.create());
package io.github.hkusu.example.lib.type;
import android.support.annotation.NonNull;
import java.util.LinkedHashSet;
import java.util.Set;
public class ImmutableSet<T> {
private final Set<T> set = new LinkedHashSet<>();
package jp.sample.android.lib.type;
import android.support.annotation.NonNull;
public final class SuccessFailure<Success, Failure> {
public interface SuccessResult<Success> {
void result(Success successResult);
}