Skip to content

Commit bd05c80

Browse files
Merge pull request #15 from ImaginativeShohag/dev
Fix and refactor code
2 parents 92814d2 + 37fd175 commit bd05c80

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ A simple Android MVVM pattern example and template.
2929
- Awesome module naming example (see `AwesomeModuleConstants`)
3030
- Dynamic accent color from image (see `calculatePaletteInImage()`)
3131
- Simple Encryption Utils (see `EncryptionUtils`)
32-
- Data pass example between activities and fragments
32+
- Data pass and receive example between Activities
33+
- Data pass and receive example between Fragments
3334

3435
## Extension Functions (see `utils/extensions`)
3536

app/src/main/java/org/imaginativeworld/simplemvvm/ui/fragments/demo_fragment_nav/DemoFragmentNavDetails.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import android.os.Bundle
44
import android.view.View
55
import androidx.core.os.bundleOf
66
import androidx.fragment.app.Fragment
7-
import androidx.fragment.app.activityViewModels
87
import androidx.fragment.app.setFragmentResult
8+
import androidx.fragment.app.viewModels
99
import org.imaginativeworld.simplemvvm.R
1010
import org.imaginativeworld.simplemvvm.databinding.FragmentDemoFragmentNavDetailsBinding
1111
import org.imaginativeworld.simplemvvm.interfaces.CommonFunctions
@@ -15,7 +15,9 @@ class DemoFragmentNavDetails :
1515
Fragment(R.layout.fragment_demo_fragment_nav_details),
1616
CommonFunctions {
1717

18-
private val parentViewModel: DemoFragmentNavViewModel by activityViewModels()
18+
private val parentViewModel: DemoFragmentNavViewModel by viewModels(ownerProducer = {
19+
requireParentFragment()
20+
})
1921

2022
private lateinit var binding: FragmentDemoFragmentNavDetailsBinding
2123

app/src/main/java/org/imaginativeworld/simplemvvm/ui/fragments/demo_fragment_nav/DemoFragmentNavList.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import android.view.View
55
import android.widget.AdapterView.OnItemClickListener
66
import android.widget.ArrayAdapter
77
import androidx.fragment.app.Fragment
8-
import androidx.fragment.app.activityViewModels
98
import androidx.fragment.app.setFragmentResultListener
9+
import androidx.fragment.app.viewModels
1010
import org.imaginativeworld.simplemvvm.R
1111
import org.imaginativeworld.simplemvvm.databinding.FragmentDemoFragmentNavListBinding
1212
import org.imaginativeworld.simplemvvm.interfaces.CommonFunctions
@@ -15,7 +15,9 @@ import timber.log.Timber
1515

1616
class DemoFragmentNavList : Fragment(R.layout.fragment_demo_fragment_nav_list), CommonFunctions {
1717

18-
private val parentViewModel: DemoFragmentNavViewModel by activityViewModels()
18+
private val parentViewModel: DemoFragmentNavViewModel by viewModels(ownerProducer = {
19+
requireParentFragment()
20+
})
1921

2022
private lateinit var binding: FragmentDemoFragmentNavListBinding
2123

0 commit comments

Comments
 (0)