This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal fun <VM : ViewModel> viewModelFactory( | |
create: () -> VM | |
): ViewModelProvider.Factory { | |
return object : ViewModelProvider.Factory { | |
@Suppress("UNCHECKED_CAST") | |
override fun <VM : ViewModel> create(modelClass: Class<VM>): VM = create() as VM | |
} | |
} | |
internal fun <VM : ViewModel> Fragment.savedStateViewModelFactory( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <reified VM : ViewModel> ComponentActivity.viewModels( | |
noinline customCreator: (() -> VM)? = null | |
): Lazy<VM> = | |
viewModels(factoryProducer = customCreator?.let { { ViewModelFactory(it) } }) | |
inline fun <reified VM : ViewModel> Fragment.activityViewModels( | |
noinline customCreator: (() -> VM)? = null | |
): Lazy<VM> = | |
activityViewModels(factoryProducer = customCreator?.let { { ViewModelFactory(it) } }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Suppress("UNCHECKED_CAST") | |
class ViewModelFactory<VM : ViewModel>( | |
private val creator: () -> VM | |
) : ViewModelProvider.NewInstanceFactory() { | |
override fun <T : ViewModel> create(modelClass: Class<T>): T = creator() as T | |
} | |
inline fun <reified VM : ViewModel> Fragment.viewModels( | |
noinline ownerProducer: () -> ViewModelStoreOwner = { this }, | |
noinline customCreator: (() -> VM)? = null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Graph { | |
private lateinit var appContext: Application | |
// lazily initialized singleton scope | |
val fancyManager by lazy { FancyManager(appContext) } | |
fun init(appContext: Application) { | |
this.appContext = appContext | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FancyViewModel( | |
private val fancyDataRepository: FancyDataRepository = FancyDataRepository(), | |
private val dispatchers: DispatcherProvider = DefaultDispatcherProvider(), | |
private val notificationManager: NotificationManager = | |
Graph.appContext | |
.getSystemService(Context.NOTIFICATION_SERVICE) | |
as NotificationManager, | |
) : ViewModel() { | |
class FancyFragment : Fragment() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FancyViewModel { | |
val viewState: MutableStateFlow<ViewState> = MutableStateFlow(ViewState()) | |
val viewEffect: MutableSharedFlow<ViewState> = MutableSharedFlow() | |
fun executeAction(action: Action) { | |
//handle action | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.util.Base64 | |
import io.mockk.every | |
import io.mockk.mockkStatic | |
import io.mockk.unmockkStatic | |
import org.junit.jupiter.api.extension.AfterEachCallback | |
import org.junit.jupiter.api.extension.BeforeEachCallback | |
import org.junit.jupiter.api.extension.ExtensionContext | |
class Base64TestExtension : BeforeEachCallback, AfterEachCallback { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable.just(1,2,3,4) | |
.map { /*someMapping*/ } | |
.filter { /*someFilter*/ } | |
.subscribe( | |
{ /*onNext*/ }, | |
{ /*onError*/ } | |
) |