Keep a service running on background mode in iOS.
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
artistAdapter = ArtistAdapter(this@fragment, R.layout.item_artist_type_1, artistRes) { holder, item, _ -> | |
// !! The problem will happen here. | |
// The ViewModel will be created again and again. | |
holder.binding.avm = RecyclerViewSearchArtistChartViewModel(item) | |
} |
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
artistAdapter = ArtistAdapter(this@ChartIndexFragment, R.layout.item_artist_type_1, artistRes) { holder, item, _ -> | |
// If a ViewModel doesn't exist, I will create a ViewModel. | |
if (null == holder.binding.avm) | |
holder.binding.avm = RecyclerViewSearchArtistChartViewModel(item) | |
// Otherwise, I just reset the data to the ViewModel. | |
else | |
holder.binding.avm?.setArtistItem(item) | |
} |
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 ActivityModule { | |
@Provides | |
@PerActivity | |
fun provideNavigator(): Navigator = Navigator() | |
@Provides | |
@PerActivity | |
fun provideMainPresenter(): MainContract.Presenter = MainPresenter() | |
} |
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
@Singleton | |
@Component(modules = arrayOf(AppModule::class)) | |
interface AppComponent { | |
object Initializer { | |
fun init(app: App): AppComponent = DaggerAppComponent.builder() | |
.appModule(AppModule(app)) | |
.netModule(NetModule(app)) | |
.build() | |
} |
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 App: Application() { | |
companion object { | |
lateinit private var context: Context | |
@JvmStatic fun appComponent(): AppComponent = (context as App).appComponent | |
// Provide the global application context. | |
@JvmStatic fun getAppContext(): Context = context | |
} | |
// Before dagger 2.11 |
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 | |
class AppModule { | |
@Provides | |
@Singleton | |
fun provideApplication(app: App): Application = app | |
@Provides | |
@Singleton | |
fun provideAppContext(app: App): Context = app.applicationContext | |
} |
NewerOlder