Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Mohammed Audhil Audhil

🎯
Focusing
Block or report user

Report or block Audhil

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View somefile.kt
class MainActivity : AppCompatActivity() {
@Inject lateinit var info: Info
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
DaggerMagicBox.create().poke(this)
text_view.text = info.text
}
View AppRepositoryInjectTest.kt
class AppRepositoryInjectTest {
@Inject
lateinit var appAPIs: AppAPIs
@Before
fun setUp() {
val component = DaggerTestAppComponent.builder()
.applicationModule(TestApplicationModule(GDelegate()))
.build()
View TestAppComponent.kt
@Singleton
@Component(
modules = [
(ApplicationModule::class)
]
)
interface TestAppComponent : ApplicationComponent {
fun into(appRepositoryTest: AppRepositoryInjectNamedTest)
fun into(appRepositoryTest: AppRepositoryInjectTest)
fun into(baseTest: BaseTest)
View TestApplicationModule.kt
class TestApplicationModule(delegate: GDelegate) : ApplicationModule(delegate) {
override fun giveAppAPIs(): AppAPIs = mockk()
override fun giveRetrofitService(okHttpClient: OkHttpClient): AppAPIs = mockk()
override fun giveOkHttpClient(loggingInterceptor: HttpLoggingInterceptor): OkHttpClient = mockk()
override fun giveLoggingInterceptor(): HttpLoggingInterceptor = mockk()
}
View build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion rootProject.compileSdkVersion
View ApplicationComponent.kt
@Singleton
@Component(
modules = [
(ApplicationModule::class)
]
)
interface ApplicationComponent {
fun inject(into: GDelegate)
fun inject(into: BaseRepository)
fun inject(into: BaseViewModel)
View ApplicationModule.kt
@Module
open class ApplicationModule(private val application: GDelegate) {
@Provides
@Singleton
fun giveContext(): Context = this.application
@Provides
@Singleton
fun givePackageManager(): PackageManager = application.packageManager
View someotherfile.kt
APIKindaStuff
.service
.greetUser("Audhil")
.enqueue(object : Callback<ResponseBody> {
override fun onFailure(call: Call<ResponseBody>, t: Throwable) {
println("---TTTT :: GET Throwable EXCEPTION:: " + t.message)
}
override fun onResponse(call: Call<ResponseBody>, response: Response<ResponseBody>) {
if (response.isSuccessful) {
View somefile.kt
val jsonObj = JsonObject()
jsonObj.addProperty("title", "rhythm")
jsonObj.addProperty("singer", "meee")
jsonObj.addProperty("text", "Jack and jill went up the hill to fetch a pail of water!")
// POST demo
APIKindaStuff
.service
.getVectors(jsonObj)
.enqueue(object : Callback<ResponseBody> {
View APIs.kt
class APIKindaStuff {
interface APIService {
@GET("/users/{user}")
fun greetUser(@Path("user") user: String): Call<ResponseBody>
@Headers("Content-type: application/json")
@POST("/api/post_some_data")
fun getVectors(@Body body: JsonObject): Call<ResponseBody>
}
You can’t perform that action at this time.