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
| /* | |
| * Copyright 2018 Google LLC | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software |
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
| val cacheSize = (5 x 1024 x 1024).toLong() | |
| val myCache = Cache(context.cacheDir, cacheSize) | |
| val okHttpClient = OkHttpClient.Builder() | |
| .cache(myCache) | |
| .addInterceptor { chain -> | |
| var request = chain.request() | |
| request = if (hasNetwork(context)!!) | |
| request.newBuilder().header("Cache-Control", "public, max-age=" + 5).build() | |
| else |
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
| val retrofit = Retrofit.Builder() | |
| .baseUrl(BASE_URL) | |
| .addConverterFactory(GsonConverterFactory.create()) | |
| // Adding our OkHttpClient | |
| .client(okHttpClient) | |
| .build() |
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
| val okHttpClient = OkHttpClient.Builder() | |
| // Specify the cache we created earlier. | |
| .cache(myCache) | |
| // Add an Interceptor to the OkHttpClient. | |
| .addInterceptor { chain -> | |
| // Get the request from the chain. | |
| var request = chain.request() | |
| /* |
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
| fun hasNetwork(context: Context): Boolean? { | |
| var isConnected: Boolean? = false // Initial Value | |
| val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | |
| val activeNetwork: NetworkInfo? = connectivityManager.activeNetworkInfo | |
| if (activeNetwork != null && activeNetwork.isConnected) | |
| isConnected = true | |
| return isConnected | |
| } |
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
| val cacheSize = (5 x 1024 x 1024).toLong() | |
| val myCache = Cache(context.cacheDir, cacheSize) | |
| val okHttpClient = OkHttpClient.Builder() | |
| .cache(myCache) | |
| .addInterceptor { chain -> | |
| var request = chain.request() | |
| request = if (hasNetwork(context)!!) | |
| request.newBuilder().header("Cache-Control", "public, max-age=" + 5).build() | |
| else |
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
| val retrofit = Retrofit.Builder() | |
| .baseUrl(BASE_URL) | |
| .addConverterFactory(GsonConverterFactory.create()) | |
| .build() |
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
| // Global instance of SplitInstallManager, needed to send the request to download the required module(s) | |
| private SplitInstallManager splitInstallManager = null; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| // Instantiate an instance of SplitInstallManager for the dynamic feature module | |
| splitInstallManager = |
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
| apply plugin: 'com.android.dynamic-feature' | |
| android { | |
| ... | |
| } | |
| dependencies { | |
| ... | |
| // Add the app module as a dependency in the dynamic feature modules. | |
| implementation project(':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
| apply plugin: 'com.android.application' | |
| android { | |
| ... | |
| // This specifies the dynamic features. | |
| dynamicFeatures = [":feature1", ":feature2"] | |
| } |