Skip to content
Batu Tasvaluan edited this page May 14, 2020 · 6 revisions

This chapter would show you how to setup BubbleMock. If you DO NOT want to support changing mock response through Bubble in run time, you just have to do these first three steps.

1. Import library

implementation 'com.github.Dcard:BubbleMock:0.0.7'

2. Init MockBubbleManager with MockResource

  • You can init MockBubbleManager in your Application class.
  • MyMockSource, inherited from MockSource, would setup all the mock model.
class DcardApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        
        MockBubbleManager.init(MyMockSource())
    
    }
}

3. Add BubbleMockInterceptor into OkHttpClient.Builder

val mockInterceptor = BubbleMockInterceptor(
    isEnable = true
)
      

Retrofit.Builder()
    .addConverterFactory(GsonConverterFactory.create(Gson()))
    .baseUrl(BASE_URL)
    .client(
        OkHttpClient.Builder()
            .addInterceptor(mockInterceptor)
            .build()
    )
    .build()

If you don't want to support changing mock response through Bubble in run time, you just have to do these first three steps.

4. Declare BubbleActivity in AndroidManifest

  • You have to implement your AppTheme.NoActionBar style, or just use AppTheme is fine as well.
<activity
	android:name="tw.dcard.bubblemock.sample.screen.BubbleActivity"
	android:allowEmbedded="true"
	android:documentLaunchMode="always"
	android:resizeableActivity="true"
	android:theme="@style/AppTheme.NoActionBar"
	tools:ignore="UnusedAttribute" />

5. Call bubble launcher

class YourActivity: AppCompatActivity(){
    override fun onCreate(savedInstanceState: Bundle?) {
    
        MockBubbleManager.getInstance().launchBubble(
            activity = this, 
            isEnable = true
        )
    }
}