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 characters
@Singleton | |
@Component( | |
modules = arrayOf(AndroidInjectionModule::class, BuildersModule::class, AppModule::class) | |
) | |
interface AppComponent { | |
fun inject(app: Application) | |
} |
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 characters
@Module | |
class AppModule(val app: Application){ | |
@Provides | |
@Singleton | |
fun provideApplication(): Application = app | |
} |
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 characters
@Module | |
abstract class BuildersModule { | |
@ContributesAndroidInjector | |
abstract fun contributeCryptocurrenciesActivity(): CryptocurrenciesActivity | |
} |
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 characters
class CryptocurrenciesActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
AndroidInjection.inject(this) | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
//... | |
} | |
} |
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 characters
dependencies { | |
//android libs | |
implementation fileTree(dir: 'libs', include: ['*.jar']) | |
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" | |
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}" | |
implementation "com.android.support.constraint:constraint-layout:${rootProject.ext.constraintLayoutVersion}" | |
//moshi | |
implementation "com.squareup.moshi:moshi-kotlin:${rootProject.ext.moshiKotlinVersion}" | |
//dagger2 | |
implementation "com.google.dagger:dagger-android:${rootProject.ext.dagger2Version}" |
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 characters
class CryptocurrencyApplication: Application(), HasActivityInjector { | |
@Inject lateinit var activityInjector: DispatchingAndroidInjector<Activity> | |
override fun onCreate() { | |
super.onCreate() | |
DaggerAppComponent.builder().appModule(AppModule(this)).build().inject(this) | |
} |
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 characters
dependencies { | |
//android libs | |
implementation fileTree(dir: 'libs', include: ['*.jar']) | |
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" | |
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}" | |
implementation "com.android.support.constraint:constraint-layout:${rootProject.ext.constraintLayoutVersion}" | |
//moshi | |
implementation "com.squareup.moshi:moshi-kotlin:${rootProject.ext.moshiKotlinVersion}" | |
//dagger2 | |
implementation "com.google.dagger:dagger-android:${rootProject.ext.dagger2Version}" |
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 characters
@Entity( | |
tableName = "cryptocurrency" | |
) | |
data class Cryptocurrency( | |
@Json(name = "id") | |
@PrimaryKey | |
val id: Int, | |
@Json(name = "name") |
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 characters
@Database(entities = arrayOf(Cryptocurrency::class), version = 1) | |
abstract class Database : RoomDatabase() { | |
abstract fun cryptocurrenciesDao(): CryptocurrenciesDao | |
} |
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 characters
@Dao | |
interface CryptocurrenciesDao { | |
@Query("SELECT * FROM cryptocurrency") | |
fun queryCryptocurrencies(): LiveData<List<Cryptocurrency>> | |
@Insert( | |
onConflict = OnConflictStrategy.REPLACE | |
) | |
fun insertCryptocurrency(cryptocurrency: Cryptocurrency) |
OlderNewer