koin

Koin sharing instances between modules

ε祈祈猫儿з 提交于 2020-01-23 18:18:09
问题 I'm using the Koin library for an Android project. I want to share some instances between modules since they are used a lot throughout the application. For instance: val moduleA = module { scope(named<FragmentA>()) { scoped { FirebaseFirestore.getInstance() } scoped { LocalDatabase.getInstance(App.sContext) } scoped { NetworkDataSourceA(get()) } } } val moduleB = module { scope(named<FragmentB>()) { scoped { FirebaseFirestore.getInstance() } scoped { LocalDatabase.getInstance(App.sContext) }

Koin sharing instances between modules

泪湿孤枕 提交于 2020-01-23 18:17:48
问题 I'm using the Koin library for an Android project. I want to share some instances between modules since they are used a lot throughout the application. For instance: val moduleA = module { scope(named<FragmentA>()) { scoped { FirebaseFirestore.getInstance() } scoped { LocalDatabase.getInstance(App.sContext) } scoped { NetworkDataSourceA(get()) } } } val moduleB = module { scope(named<FragmentB>()) { scoped { FirebaseFirestore.getInstance() } scoped { LocalDatabase.getInstance(App.sContext) }

Optimizing Parent Fragment for ViewModel and DataBinding in order to avoid boilerplate code

天大地大妈咪最大 提交于 2019-12-25 01:47:17
问题 I have a ParentFragment and a ChildFragment . They are working pretty fine. My problem is that in the future I might create many child fragments and this makes me write this boilerplate code for every single child fragment. Thus, I would like to optimize my ParentFragment so that I do not have to write boilerplate code for every single new child framment I create in the future. ParentFragment abstract class ParentFragment<T: ViewDataBinding>: Fragment() { @LayoutRes abstract fun

DataBinding is not working if setVariable() method is used to set ViewModel

删除回忆录丶 提交于 2019-12-23 05:27:57
问题 I have ParentFragment and ChildFragment . I am using Koin for DI. In one case, data binding is not working and in another it is working. NOT WORKING CASE: ParentFragment abstract class ParentFragment<T: ViewDataBinding, V: ParentViewModel>: Fragment() { @LayoutRes abstract fun getLayoutResId(): Int abstract fun init() protected lateinit var binding: T protected abstract val mViewModel: V override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?):

Koin how to inject outside of Android activity / appcompatactivity

本秂侑毒 提交于 2019-12-22 03:25:24
问题 Koin is a new, lightweight library for DI and can be used in Android as well as in standalone kotlin apps. Usually you inject dependencies like this: class SplashScreenActivity : Activity() { val sampleClass : SampleClass by inject() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } } with the inject() method. But what about injecting stuff in places where Activity context is not available i.e. outside of an Activity ? 回答1: There is the KoinComponent

Koin how to inject outside of Android activity / appcompatactivity

喜夏-厌秋 提交于 2019-12-22 03:25:07
问题 Koin is a new, lightweight library for DI and can be used in Android as well as in standalone kotlin apps. Usually you inject dependencies like this: class SplashScreenActivity : Activity() { val sampleClass : SampleClass by inject() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } } with the inject() method. But what about injecting stuff in places where Activity context is not available i.e. outside of an Activity ? 回答1: There is the KoinComponent

recyclerview not showing data?

怎甘沉沦 提交于 2019-12-13 11:25:36
问题 I am developing news app I am new to MVVM and I have implemented Kotlin coroutines and Koin with ViewModel hosted RecyclerView in fragment class but data not showing only progress bar loading below my screenshot I have posted my code to gist my code on gist below my code where I have implemented recyclerview and viewmodel logic class TopHeadlinesFragment : Fragment() { private val viewModel: MainViewModel by viewModel() private lateinit var topHeadlinesAdapter: TopHeadlinesAdapter //3

Pass data back to previous fragment using Android Navigation

元气小坏坏 提交于 2019-12-10 13:35:17
问题 I've started using Android Architecture Components (Navigation and Safe Args, View Models) along with Koin library. Currently, I've got a problem with passing arguments between two fragments - I need to pass a string value from fragment A to fragment B, modify this value in fragment B and pass it back to fragment A. I've found one possible solution to my problem - shared view models. Unfortunately, this approach has one problem because I can pass and modify values between screens, but when