This file contains 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 com.jakewharton.disklrucache.DiskLruCache; | |
import com.nytimes.android.external.fs3.filesystem.FileSystem; | |
import com.nytimes.android.external.store3.base.RecordState; | |
import java.io.FileNotFoundException; | |
import java.io.IOException; | |
import java.io.OutputStream; | |
import java.util.Collection; | |
import java.util.concurrent.TimeUnit; | |
import javax.annotation.Nonnull; |
This file contains 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 com.diousk.serializationsample | |
import androidx.appcompat.app.AppCompatActivity | |
import android.os.Bundle | |
import android.util.Log | |
import androidx.lifecycle.lifecycleScope | |
import com.diousk.serializationsample.model.MockData | |
import com.diousk.serializationsample.model.mockDataList | |
import com.diousk.serializationsample.model.mockJsonString | |
import com.diousk.serializationsample.parser.GsonParser |
This file contains 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 MainActivity: FragmentInjectActivity() { | |
@Inject lateinit var fragmentFactory: FragmentFactory | |
override fun onCreate(savedInstanceState: Bundle?) { | |
supportFragmentManager.fragmentFactory = fragmentFactory | |
super.onCreate(savedInstanceState) | |
// launch fragment and add to fragmen container view | |
supportFragmentManager.beginTransaction() | |
.add<DummyFragment>(R.id.fragmentContainer) | |
.commit() |
This file contains 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 DummyFragment @Inject constructor( | |
private val repo: AppRepo | |
) : DaggerFragment() { | |
@Inject | |
lateinit var vmFactory: ViewModelProvider.Factory | |
private val viewModel by viewModels<DummyViewModel> { vmFactory } | |
// ... | |
} |
This file contains 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 DaggerFragmentFactory @Inject constructor( | |
private val providers: @JvmSuppressWildcards Map<Class<out Fragment>, Provider<Fragment>> | |
) : FragmentFactory() { | |
override fun instantiate(classLoader: ClassLoader, className: String): Fragment { | |
val fragmentClass = loadFragmentClass(classLoader, className) | |
val provider = providers[fragmentClass] | |
return provider?.get() ?: super.instantiate(classLoader, className) | |
} | |
} |
This file contains 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
@Target( | |
AnnotationTarget.FUNCTION, | |
AnnotationTarget.PROPERTY_GETTER, | |
AnnotationTarget.PROPERTY_SETTER | |
) | |
@Retention(AnnotationRetention.RUNTIME) | |
@MapKey | |
annotation class FragmentKey(val value: KClass<out Fragment>) |
This file contains 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
@Module | |
abstract class FragmentBuilder { | |
@Binds | |
abstract fun bindFragmentFactory( | |
factory: DaggerFragmentFactory | |
): FragmentFactory | |
} |
This file contains 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
@Module | |
abstract class MainBuilder { | |
@ContributesAndroidInjector(modules = [ | |
ViewModelBuilder::class, | |
FragmentBuilder::class, // <- for injection of fragment factory | |
MainModule::class, | |
DummyBuilder::class // <- our fragment | |
]) | |
abstract fun bindMainActivity(): MainActivity | |
} |
This file contains 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
@Module | |
abstract class DummyBuilder { | |
@ContributesAndroidInjector(modules = [DummyModule::class]) | |
abstract fun bindDummygFragment(): DummyFragment | |
// put binding of fragment at this layer(not DummyModule) for parent to inject | |
@Binds | |
@IntoMap | |
@FragmentKey(DummyFragment::class) | |
abstract fun bindDummyFragment(fragment: DummyFragment): Fragment |
This file contains 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 MainActivity : DaggerAppCompatActivity() { | |
@Inject lateinit var fragmentFactory: FragmentFactory | |
override fun onCreate(savedInstanceState: Bundle?) { | |
supportFragmentManager.fragmentFactory = fragmentFactory | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
} | |
} |
OlderNewer