Skip to content

Instantly share code, notes, and snippets.

🤖

Sato Shun satoshun

🤖
View GitHub Profile
View DiffCallbackItem.kt
import androidx.recyclerview.widget.DiffUtil
import com.xwray.groupie.GroupieViewHolder
import com.xwray.groupie.Item
abstract class DiffCallbackItem<T, VH : GroupieViewHolder>(
private val data: T,
private val callback: DiffUtil.ItemCallback<T>
) : Item<VH>() {
override fun isSameAs(other: Item<*>): Boolean {
if (viewType != other.viewType) {
View compose_flow.kt
@Composable
fun <T> observe(
data: Flow<T>,
transform: (T) -> T = { it }
): T? {
var result: T? by state { null }
val action: suspend (T) -> Unit = remember { { result = transform(it) } }
onCommit(data) {
val job = GlobalScope.launch(Dispatchers.Main) {
View HideHelper.kt
import android.content.Context
import android.util.AttributeSet
import androidx.constraintlayout.widget.ConstraintHelper
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.isGone
import androidx.core.view.marginLeft
import androidx.core.view.marginRight
import androidx.core.view.updateLayoutParams
class GoneOverflow @JvmOverloads constructor(
View FragmentViewBinding2.kt
class MainFragment : Fragment(R.layout.main_frag2) {
private val binding: MainFrag2Binding by viewBinding()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// ...
}
}
View FragmentViewBinding.kt
class MainFragment : Fragment(R.layout.main_frag) {
// private lateinit var binding: MainFragBinding <-- memory leak?
private val binding: MainFragBinding get() = MainFragBinding.bind(view!!)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// ...
}
}
View viewpager2-cache-size.kt
class ChildFragment : Fragment() {
private lateinit var binding: ChildFragBinding
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = ChildFragBinding.inflate(inflater, container, false)
return binding.root
View dagger2.25-object-generated-code.java
public final class AppModule_ProvideFugaFactory implements Factory<Fuga> {
@Override
public Fuga get() {
return provideFuga();
}
public static AppModule_ProvideFugaFactory create() {
return InstanceHolder.INSTANCE;
}
View HogeFragment.kt
package com.github.satoshun.example
// sample code
@RuntimePermissions
internal class HogeFragment : Fragment() {
@NeedsPermission(Manifest.permission.CAMERA)
fun camera() {
TODO()
}
}
View CompanionTest.kt
class CompanionTest {
companion object {
fun show(i: Int) {
println("started show method")
println("processing show method action $i")
println("finished show method")
}
}
}
View contract.kt
@UseExperimental(ExperimentalContracts::class)
fun <T : Activity> ActivityScenario<T>.onActivity2(block: (T) -> Unit) {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
onActivity {
block(it)
}
}
You can’t perform that action at this time.