-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ditclear
committed
May 13, 2018
1 parent
5f696a7
commit bfbbc45
Showing
10 changed files
with
613 additions
and
179 deletions.
There are no files selected for viewing
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
13 changes: 13 additions & 0 deletions
13
app/src/main/java/io/ditclear/app/di/component/AppComponent.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.ditclear.app.di.component | ||
|
||
import dagger.Component | ||
import io.ditclear.app.di.module.AppModule | ||
import io.ditclear.app.view.PaoActivity | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
@Component(modules = arrayOf(AppModule::class)) | ||
interface AppComponent{ | ||
|
||
fun inject(activity: PaoActivity) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.ditclear.app.di.module | ||
|
||
import android.content.Context | ||
import dagger.Module | ||
import dagger.Provides | ||
import io.ditclear.app.helper.Constants | ||
import io.ditclear.app.model.local.AppDatabase | ||
import io.ditclear.app.model.remote.PaoService | ||
import retrofit2.Retrofit | ||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
class AppModule(val applicationContext: Context){ | ||
|
||
//提供 Retrofit 实例 | ||
@Provides @Singleton | ||
fun provideRemoteClient(): Retrofit = Retrofit.Builder() | ||
.baseUrl(Constants.HOST_API) | ||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
|
||
//提供 PaoService 实例 | ||
@Provides @Singleton | ||
fun providePaoService(client:Retrofit) =client.create(PaoService::class.java) | ||
|
||
//提供 数据库 实例 | ||
@Provides @Singleton | ||
fun provideAppDataBase():AppDatabase = AppDatabase.getInstance(applicationContext) | ||
|
||
//提供PaoDao 实例 | ||
@Provides @Singleton | ||
fun providePaoDao(dataBase:AppDatabase)=dataBase.paoDao() | ||
} |
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
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.ditclear.app | ||
|
||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
/** | ||
* Example local unit test, which will execute on the development machine (host). | ||
* | ||
* @see [Testing documentation](http://d.android.com/tools/testing) | ||
*/ | ||
class ExampleUnitTest { | ||
@Test | ||
@Throws(Exception::class) | ||
fun addition_isCorrect() { | ||
assertEquals(4, (2 + 2).toLong()) | ||
} | ||
} |
Oops, something went wrong.