mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 09:49:30 +01:00
Username UX refresh.
This commit is contained in:
committed by
Cody Henthorne
parent
3252871ed5
commit
28310a88f5
@@ -0,0 +1,23 @@
|
||||
package org.thoughtcrime.securesms.util
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import java.util.function.Consumer
|
||||
|
||||
/**
|
||||
* Generic Fragment result contract.
|
||||
*/
|
||||
abstract class FragmentResultContract<T> protected constructor(private val resultKey: String) {
|
||||
|
||||
protected abstract fun getResult(bundle: Bundle): T
|
||||
|
||||
fun registerForResult(fragmentManager: FragmentManager, lifecycleOwner: LifecycleOwner, consumer: Consumer<T>) {
|
||||
fragmentManager.setFragmentResultListener(resultKey, lifecycleOwner) { key, bundle ->
|
||||
if (key == resultKey) {
|
||||
val result = getResult(bundle)
|
||||
consumer.accept(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.thoughtcrime.securesms.util.adapter.mapping
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.viewbinding.ViewBinding
|
||||
|
||||
/**
|
||||
* Allows ViewHolders to be generated with a ViewBinding. Intended usage is as follows:
|
||||
*
|
||||
* BindingFactory(::MyBindingViewHolder, MyBinding::inflate)
|
||||
*/
|
||||
class BindingFactory<T : MappingModel<T>, B : ViewBinding>(
|
||||
private val creator: (B) -> BindingViewHolder<T, B>,
|
||||
private val inflater: (LayoutInflater, ViewGroup, Boolean) -> B
|
||||
) : Factory<T> {
|
||||
override fun createViewHolder(parent: ViewGroup): MappingViewHolder<T> {
|
||||
val binding = inflater(LayoutInflater.from(parent.context), parent, false)
|
||||
return creator(binding)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.thoughtcrime.securesms.util.adapter.mapping
|
||||
|
||||
import androidx.viewbinding.ViewBinding
|
||||
|
||||
/**
|
||||
* A ViewHolder which is populated with a ViewBinding, used in conjunction with BindingFactory
|
||||
*/
|
||||
abstract class BindingViewHolder<T, B : ViewBinding>(protected val binding: B) : MappingViewHolder<T>(binding.root)
|
||||
@@ -13,7 +13,7 @@ import io.reactivex.rxjava3.subjects.PublishSubject
|
||||
*/
|
||||
class RxStore<T : Any>(
|
||||
defaultValue: T,
|
||||
private val scheduler: Scheduler = Schedulers.computation()
|
||||
scheduler: Scheduler = Schedulers.computation()
|
||||
) {
|
||||
|
||||
private val behaviorProcessor = BehaviorProcessor.createDefault(defaultValue)
|
||||
|
||||
Reference in New Issue
Block a user