DependencyProperty is a library that resolves dependent objects with Delegated Properties.
DependencyProperty is a library of Service Locator patterns for use with manual DI. Dependencies can be easily defined and resolved with a simple concept and implementation. Classes that can access Application instances, such as Activity and Fragment, can take advantage of Delegated Properties to resolve dependent objects.
It also supports app design requirements such as ViewModel, UI Test, Dynamic Feature Module. ViewModel allows constructor injection without any special settings. UI Test can be set with less code than Dagger Hilt. …
A library that makes it easy to use DataBinding and ViewBinding.
You can do the following
- Unify the way you declare properties in Activity and Fragment
- Set the property to null after onDestroyView in Fragment
- Automatically set the LifecycleOwner (DataBinding only)
There were the following issue
- DataBinding is enabled by DataBinding-ktx
- DataBinding wraps the ViewStub with ViewStubProxy
- If you only use ViewBinding, ViewStub will be wrapped by ViewStubProxy
We’ve released ViewBinding-ktx because it’s redundant for users who only use ViewBinding, and because we’re using jitpack to distribute it, we’ve split the repository.
There are several ways to make a property’s lifetime match that of the View in the Fragment. However, you need to be familiar with the Fragment to choose the right method for the requirements you want to meet.
This article organizes the requirements such properties should meet and how to define them and introduces ViewLifecycleProperty that meets all the requirements.
The comparison table of each method is as follows.
A library that makes it easy to handle AndroidX SavedState with Delegated Properties. It is easy to describe in Activity and Fragment.
It is one of the AndroidX libraries and is a library that can be hooked to the savedInstanceState’s state saving / restoring process.
The state variables of an Activity or Fragment that previously had to be saved with onSavedInstanceState() and restored with onCreate can be written in Kotlin’s Delegated Properties as:
class SampleActivity : AppCompatActivity(R.layout.sample_activity) { private val state by savedState() private var count by state.property( { getInt(it) }, { key, value -> putInt(key, value) } ) private…
ViewModel-SavedState-ktx is a library that allows you to easily use SavedStateHandle of ViewModel-SavedState by Delegated Property.
Up to now, UI states is usually stored in onSavedInstanceState
and restored in onCreate
. From now on, you can store and restore UI states by SavedStateHandle using ViewModel-SavedState.
ViewModel has been kept alive when configuration changes occurred, but ViewModel has been destroyed when Activity killed by OS. By using ViewModel-SavedState, ViewModel save its property when Activity killed by OS.
by viewModels()
in Activity or Fragment, SavedStateHandle
is automatically passed. The intent.extra
…
It is a library for solving problems related to DataBinding and ViewBinding, and for safe and easy use.
Activity can use by lazy, but Fragment cannot use by lazy because there is View regeneration (*).
*: Because no binding instance is generated for the View after regeneration
When using the navigation component, back stack, and detach, Fragment’s view is released after onDestroyView, but the Fragment is still alive. The binding wastes memory if it is not released since it holds the View Tree.
Only DataBinding is a problem, but if you are using LiveData, LiveData will not be binding unless…
A library that disposes automatically RxJava2 streams using the Android Architecture Components Lifecycle.
In short, LifecycleDispose is the reinvention of uber/AutoDispose. Because it uses AAC Lifecycle, it only works in Android, but its implementation and usage are simple. See the repository for details.
A library that solves problems related to DataBinding and ViewBinding, and is safe and easy to use.
By lazy can be used in Activity , but when using BackStack or Attach / Detach in Fragment’s view is regenerated, so by lazy cannot be used (*).
*: Because binding instance is not generated for the view after regeneration
This is only a problem with DataBinding. When using LiveData, LiveData will not be binding unless setLifecycleOwner is called.
Kotlin’s Delegated Properties allows you to declare properties in the same way in Activity and Fragment .
The setLifecycleOwner is automatically called when you…
A library that hides the SavedStateHandle of ViewModel-SavedState so that it can be easily handled by Delegated Property.
- `androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-beta01`
An enum can be passed to an Activity Intent or Fragment Bundle and referenced in the ViewModel. You can pass enum to Intent or Bundle with extension function as follows.
// Intent
intent.putExtraEnum("key", YourEnum.ENUM_VALUE)// Bundle
bundle.putEnum("key", YourEnum.ENUM_VALUE)
In ViewModel, you can access to enum as follows.
class YourViewModel(
savedStateHandle: SavedStateHandle
) : SavedStateViewModel(savedStateHandle) {
// Property
var yourEnum: YourEnum by savedStateProperty("key")
// LiveData
val yourEnumLiveData: MutableLiveData<YourEnum> by savedStateLiveData("key")
}
You can set serialization / deserialization and save / restore…
A library that hides the SavedStateHandle of ViewModel-SavedState so that it can be easily handled by Delegated Property.
Since the ViewModel is destroyed when the process is killed, there is no state left when the Activity is regenerated. Therefore, if you want to keep the state, you need to save the state with onSavedInstanceState. This is a situation where you need to use onSavedInstanceState to handle process kills even though you have separated the state from the activity.
ViewModel-SavedState is a Jetpack library that makes it easy to manage state with ViewModel without using onSavedInstanceState by using SavedStateHandle.
Android Application Architect