This file contains hidden or 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 androidx.fragment.app.DialogFragment | |
import androidx.fragment.app.Fragment | |
import androidx.fragment.app.FragmentFactory | |
import androidx.fragment.app.FragmentManager | |
/** | |
* Create a new instance of a [Fragment] with the given class name. This uses | |
* [FragmentFactory.loadFragmentClass] and the empty constructor of the resulting | |
* [Class] by default. | |
* |
This file contains hidden or 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.content.Intent | |
import android.os.Bundle | |
import androidx.annotation.CallSuper | |
import androidx.appcompat.app.AppCompatActivity | |
import androidx.fragment.app.Fragment | |
import androidx.fragment.app.FragmentContainerView | |
import androidx.fragment.app.commitNow | |
import com.deliveryhero.commons.mvvm.R | |
import kotlin.reflect.KClass |
This file contains hidden or 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
allprojects { | |
afterEvaluate { | |
// Global KAPT flags applied to all projects. | |
extensions.findByType<KaptExtension>()?.apply { | |
// Do not replace unknown types (including types for the generated classes) by NonExistentClass. | |
correctErrorTypes = true | |
// Provide links to locations in the original Kotlin code rather than generated Java stubs | |
// as it reports errors encountered during annotation processing. |
This file contains hidden or 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
package dev.marcellogalhardo.viewmodel | |
import android.os.Bundle | |
import androidx.activity.ComponentActivity | |
import androidx.activity.viewModels | |
import androidx.core.os.bundleOf | |
import androidx.fragment.app.Fragment | |
import androidx.fragment.app.activityViewModels | |
import androidx.fragment.app.viewModels | |
import androidx.lifecycle.AbstractSavedStateViewModelFactory |
This file contains hidden or 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 MainApplication : Application() { | |
private val component = MainComponent.Factory.create(application = this) | |
private val locator = SystemServiceLocator { | |
register { component.getFragmentFactory() } | |
} | |
override fun getSystemService(name: String): Any? { | |
return locator.getSystemService(name) ?: super.getSystemService(name) |
This file contains hidden or 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> View.getViewModel(): VM { | |
check(isAttachedToWindow) { "ViewModel can be accessed only when View is attached." } | |
val lifecycleOwner = lifecycleOwner | |
check(lifecycleOwner is ViewModelStoreOwner) | |
check(lifecycleOwner is HasDefaultViewModelProviderFactory) | |
return ViewModelProvider(lifecycleOwner, lifecycleOwner.defaultViewModelProviderFactory) | |
.get(id.toString(), VM::class.java) | |
} | |
@PublishedApi | |
internal val View.lifecycleOwner: LifecycleOwner |
This file contains hidden or 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 kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.test.TestCoroutineDispatcher | |
import kotlinx.coroutines.test.TestCoroutineScope | |
import kotlinx.coroutines.test.resetMain | |
import kotlinx.coroutines.test.setMain | |
import org.junit.rules.TestWatcher | |
import org.junit.runner.Description | |
@Suppress("MemberVisibilityCanBePrivate") | |
class CoroutineRule( |
This file contains hidden or 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
/** | |
* Launches a [View] in an [ViewHostFragment] root view container (onCreateView). | |
* [ViewHostFragment] is hosted by an empty [FragmentActivity] which will [instantiate] | |
* the [Fragment] and waits for it to reach a resumed state. | |
* | |
* If your testing [View] has a dependency to specific theme such as [R.style.Theme_AppCompat], | |
* use the theme ID parameter in [launchViewInFragment] method. | |
* | |
* Usage example: | |
* |
This file contains hidden or 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
/** | |
* Returns a [StateFlow] that access data associated with the given key. | |
* | |
* @param scope The scope used to synchronize the [StateFlow] and [SavedStateHandle] | |
* @param key The identifier for the value | |
* @param initialValue If no value exists with the given [key], a new one is created | |
* with the given [initialValue]. | |
* | |
* @see SavedStateHandle.getLiveData | |
*/ |
This file contains hidden or 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 java.io.Serializable | |
import kotlin.contracts.ExperimentalContracts | |
import kotlin.contracts.InvocationKind | |
import kotlin.contracts.contract | |
/** | |
* A type that represents either a wrapped value or null, the absence of a value. | |
*/ | |
public sealed class Option<out T> : Serializable { |