Skip to content

Instantly share code, notes, and snippets.

View kirich1409's full-sized avatar

Kirill Rozov kirich1409

View GitHub Profile
@kirich1409
kirich1409 / refactoring.kt
Created August 8, 2022 16:10
Порефакторил код
override fun observe(permissions: List<MintPermission>): Flow<List<MintPermissionStatus>> {
return statusesController.observe()
.combine(permissions.asFlow()) { statuses, permission ->
statuses.getStatus(permission)
}
.runningList()
.distinctUntilChanged()
}
fun <T> Flow<T>.runningList(): Flow<List<T>> {
class FragmentViewBindingProperty<T : ViewBinding>(
private val viewBinder: ViewBinder<T>
) : ReadOnlyProperty<Fragment, T> {
private var viewBinding: T? = null
private val lifecycleObserver = BindingLifecycleObserver()
@MainThread
override fun getValue(thisRef: Fragment, property: KProperty<*>): T {
checkIsMainThread()
class ProfileFragment() : Fragment(R.layout.profile) {
private val viewBinding: ProfileBinding by viewBinding()
override fun onDestroyView() {
super.onDestroyView()
// Clear data in views from viewBinding
// ViewBinding inside viewBinding is null
}
}
class ProfileFragment : Fragment(R.layout.profile) {
private val viewBinding: ProfileBinding by viewBinding()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// Use viewBinding
}
}
class ProfileFragment : Fragment(R.layout.profile) {
private var viewBinding: ProfileBinding? = null
override fun onViewCreated(view: View, savedState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewBinding = ProfileBinding.bind(view)
// Use viewBinding
}
class FragmentViewBindingProperty<T : ViewBinding>(
private val viewBinder: ViewBinder<T>
) : ReadOnlyProperty<Fragment, T> {
private var viewBinding: T? = null
private val lifecycleObserver = BindingLifecycleObserver()
@MainThread
override fun getValue(thisRef: Fragment, property: KProperty<*>): T {
checkIsMainThread()
class SetFragmentFactoryActivityCallback(
private val newFragmentFactory: FragmentFactory
) : EmptyActivityLifecycleCallbacks {
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
if (activity is FragmentActivity) {
activity.supportFragmentManager.fragmentFactory = newFragmentFactory
}
}
}
@MapKey
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER)
@Retention(AnnotationRetention.RUNTIME)
annotation class ActivityKey(val value: KClass<out Activity>)
@MapKey
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER)
@Retention(AnnotationRetention.RUNTIME)
annotation class FragmentKey(val value: KClass<out Fragment>)
@Module
interface FragmentBindsModule {
@Binds
@IntoMap
@FragmentKey(MessageFragment::class)
fun bindMessageFragmentToFragmentForMultiBinding(fragment: MessageFragment): Fragment
}