Revisions
-
adam-hurwitz revised this gist
Apr 8, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ class SomeViewModel(private val state: SavedStateHandle, private val someString: class Fragment: Fragment() { // Create VM in activity/fragment with VM factory. // Don't forget to add "kotlinOptions { jvmTarget = '1.8' }" to "android" build.gradle (:app) val someViewModel: SomeViewModel by viewModels { SomeViewModelFactory( savedStateRegistryOwner = this, defaultArgs = Bundle().apply { -
adam-hurwitz revised this gist
Apr 8, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ class SomeViewModel(private val state: SavedStateHandle, private val someString: class Fragment: Fragment() { // Create VM in activity/fragment with VM factory. // Don't forget to add "kotlinOptions { jvmTarget = '1.8' }" to build.gradle (:app) val someViewModel: SomeViewModel by viewModels { SomeViewModelFactory( savedStateRegistryOwner = this, defaultArgs = Bundle().apply { -
adam-hurwitz revised this gist
Apr 8, 2020 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -21,6 +21,7 @@ class SomeViewModel(private val state: SavedStateHandle, private val someString: class Fragment: Fragment() { // Create VM in activity/fragment with VM factory. // Don't forget to add 'kotlinOptions { jvmTarget = '1.8' } to build.gradle (:app)' val someViewModel: SomeViewModel by viewModels { SomeViewModelFactory( savedStateRegistryOwner = this, defaultArgs = Bundle().apply { -
adam-hurwitz revised this gist
Feb 27, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ class Fragment: Fragment() { val someViewModel: SomeViewModel by viewModels { SomeViewModelFactory( savedStateRegistryOwner = this, defaultArgs = Bundle().apply { putInt(SOME_INT_KEY, 18) }, someString = "someString") } private var someInt: Int = 0 -
adam-hurwitz revised this gist
Feb 27, 2020 . 1 changed file with 5 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,13 +3,12 @@ class SomeViewModelFactory( private val defaultArgs: Bundle, private val someString: String) : AbstractSavedStateViewModelFactory(owner, defaultArgs) { override fun <T : ViewModel?> create(key: String, modelClass: Class<T>, state: SavedStateHandle) = SomeViewModel(state, someString) as T } class SomeViewModel(private val state: SavedStateHandle, private val someString: String) : ViewModel() { // The default value is used from 'defaultArgs' since 'defaultArgs' are saved in the ViewModelFactory. val someInt = state.get<Int>(SOME_INT_KEY) init { //TODO: Use 'defaultString' and 'someString' to init process when VM is created. i.e. Get data request. @@ -25,7 +24,7 @@ class Fragment: Fragment() { val someViewModel: SomeViewModel by viewModels { SomeViewModelFactory( savedStateRegistryOwner = this, defaultArgs = Bundle().apply { putInt("SOME_INT_KEY", 18) }, someString = "someString") } private var someInt: Int = 0 -
adam-hurwitz revised this gist
Feb 27, 2020 . 1 changed file with 11 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,18 @@ class SomeViewModelFactory( private val owner: SavedStateRegistryOwner, private val defaultArgs: Bundle, private val someString: String) : AbstractSavedStateViewModelFactory(owner, defaultArgs) { override fun <T : ViewModel?> create(key: String, modelClass: Class<T>, state: SavedStateHandle) = SomeViewModel(state, defaultArgs.getString("DEFAULT_STRING"), someString) as T } class SomeViewModel(private val state: SavedStateHandle, private val defaultString: String, private val someString: String) : ViewModel() { val someInt = state.get<Int>(SOME_INT_KEY).let { someInt -> if (someInt == null) 0 else someInt } init { //TODO: Use 'defaultString' and 'someString' to init process when VM is created. i.e. Get data request. } fun saveSomeInt(someInt: Int) { @@ -21,7 +22,12 @@ class SomeViewModel(private val state: SavedStateHandle, private val someString: class Fragment: Fragment() { // Create VM in activity/fragment with VM factory. val someViewModel: SomeViewModel by viewModels { SomeViewModelFactory( savedStateRegistryOwner = this, defaultArgs = Bundle().apply { putString("DEFAULT_STRING", "defaultValue") }, someString = "someString") } private var someInt: Int = 0 override fun onSaveInstanceState(outState: Bundle) { -
adam-hurwitz revised this gist
Feb 26, 2020 . 1 changed file with 7 additions and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,32 +6,31 @@ class SomeViewModelFactory( } class SomeViewModel(private val state: SavedStateHandle, private val someString: String) : ViewModel() { val someInt = state.get<Int>(SOME_INT_KEY).let { someInt -> if (someInt == null) 0 else someInt } init { //TODO: Use 'someString' to init process when VM is created. i.e. Get data request. } fun saveSomeInt(someInt: Int) { state.set(SOME_INT_KEY, position) } } class Fragment: Fragment() { // Create VM in activity/fragment with VM factory. val someViewModel: SomeViewModel by viewModels { SomeViewModelFactory(this, "someString") } private var someInt: Int = 0 override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) someViewModel.saveSomeInt(...) } override fun onViewStateRestored(savedInstanceState: Bundle?) { super.onViewStateRestored(savedInstanceState) someInt = someViewModel.someInt } } -
adam-hurwitz revised this gist
Feb 8, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -32,6 +32,6 @@ class Fragment: Fragment() { override fun onViewStateRestored(savedInstanceState: Bundle?) { super.onViewStateRestored(savedInstanceState) feedPosition = someViewModel.feedPosition } } -
adam-hurwitz revised this gist
Feb 8, 2020 . No changes.There are no files selected for viewing
-
adam-hurwitz revised this gist
Feb 8, 2020 . 1 changed file with 14 additions and 14 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,20 @@ class SomeViewModelFactory( SomeViewModel(state, someString) as T } class SomeViewModel(private val state: SavedStateHandle, private val someString: String) : ViewModel() { val feedPosition = state.get<Int>(FEED_POSITION_KEY).let { position -> if (position == null) 0 else position } init { //TODO: Use 'someString' to init process when VM is created. i.e. Get data request. } fun saveFeedPosition(position: Int) { state.set(FEED_POSITION_KEY, position) } } class Fragment: Fragment() { // Create VM in activity/fragment with VM factory. val someViewModel: SomeViewModel by viewModels { SomeViewModelFactory(this, "someString") } @@ -20,18 +34,4 @@ class Fragment: Fragment() { super.onViewStateRestored(savedInstanceState) savedRecyclerPosition = someViewModel.feedPosition } } -
adam-hurwitz revised this gist
Feb 8, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ class Fragment: Fragment() { override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) someViewModel.saveFeedPosition((contentRecyclerView.layoutManager as LinearLayoutManager) .findFirstVisibleItemPosition()) } -
adam-hurwitz revised this gist
Feb 8, 2020 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,13 +12,13 @@ class Fragment: Fragment() { override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) someViewModel.saveSomeInt((contentRecyclerView.layoutManager as LinearLayoutManager) .findFirstVisibleItemPosition()) } override fun onViewStateRestored(savedInstanceState: Bundle?) { super.onViewStateRestored(savedInstanceState) savedRecyclerPosition = someViewModel.feedPosition } } -
adam-hurwitz revised this gist
Feb 8, 2020 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,7 @@ class SomeViewModelFactory( class Fragment: Fragment() { // Create VM in activity/fragment with VM factory. val someViewModel: SomeViewModel by viewModels { SomeViewModelFactory(this, "someString") } private var feedPosition: Int = 0 override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) -
adam-hurwitz revised this gist
Feb 8, 2020 . No changes.There are no files selected for viewing
-
adam-hurwitz revised this gist
Feb 8, 2020 . 1 changed file with 15 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,18 +8,29 @@ class SomeViewModelFactory( class Fragment: Fragment() { // Create VM in activity/fragment with VM factory. val someViewModel: SomeViewModel by viewModels { SomeViewModelFactory(this, "someString") } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) feedViewModel.saveSomeInt((contentRecyclerView.layoutManager as LinearLayoutManager) .findFirstVisibleItemPosition()) } override fun onViewStateRestored(savedInstanceState: Bundle?) { super.onViewStateRestored(savedInstanceState) savedRecyclerPosition = feedViewModel.feedPosition } } class SomeViewModel(private val state: SavedStateHandle, private val someString: String) : ViewModel() { val feedPosition = state.get<Int>(FEED_POSITION_KEY).let { position -> if (position == null) 0 else position } init { //TODO: Use 'someString' to init process when VM is created. i.e. Get data request. } fun saveFeedPosition(position: Int) { state.set(FEED_POSITION_KEY, position) } } -
adam-hurwitz revised this gist
Feb 8, 2020 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,15 @@ class Fragment: Fragment() { } class SomeViewModel(private val state: SavedStateHandle, private val someString: String) : ViewModel() { val someInt = state.get<Int>(SOME_KEY).let { someInt -> if (someInt == null) 0 else someInt } init { //TODO: Use 'someString' to init process when VM is created. i.e. Get data request. } fun saveSomething(someInt: Int) { state.set(SOME_KEY, someInt) } } -
adam-hurwitz created this gist
Feb 8, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ class SomeViewModelFactory( private val owner: SavedStateRegistryOwner, private val someString: String) : AbstractSavedStateViewModelFactory(owner, null) { override fun <T : ViewModel?> create(key: String, modelClass: Class<T>, state: SavedStateHandle) = SomeViewModel(state, someString) as T } class Fragment: Fragment() { // Create VM in activity/fragment with VM factory. val someViewModel: SomeViewModel by viewModels { SomeViewModelFactory(this, "someString") } } class SomeViewModel(private val state: SavedStateHandle, private val someString: String) : ViewModel() { init { //TODO: Use 'someString' to init process when VM is created. i.e. Get data request. } }