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 testNetworkModule(baseUrl: String) = module { | |
single { provideTestRetrofit(baseUrl) } | |
single { provideTestApiService(get(), ApiService::class.java) } | |
} | |
fun provideTestRetrofit(baseUrl: String): Retrofit = | |
Retrofit.Builder().baseUrl(baseUrl) | |
.addConverterFactory(GsonConverterFactory.create()).build() | |
fun provideTestApiService(retrofit: Retrofit, apiService: Class<ApiService>) = |
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 NasaRoverPhotosApp : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
Timber.plant(DebugTree()) | |
startKoin { | |
androidContext(this@NasaRoverPhotosApp) | |
modules(appModules) | |
} | |
} |
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 viewModelModule = module { | |
viewModel { PhotosViewModel(get()) } | |
} |
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 repositoryModule = module { | |
factory { | |
PhotosRepository(get()) | |
} | |
} |
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 networkModule = module { | |
single { provideOkHttpClient() } | |
single { provideRetrofit(get()) } | |
single { provideApiService(get(), ApiService::class.java) } | |
} | |
fun provideOkHttpClient(): OkHttpClient = OkHttpClient.Builder().build() | |
fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit = | |
Retrofit.Builder().baseUrl(BuildConfig.BASE_URL) |
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
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(binding.root) | |
binding.cameraIcon.setOnClickListener { | |
openSettings() | |
} | |
} | |
private fun openSettings() { |
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
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(binding.root) | |
binding.cameraIcon.setOnClickListener { | |
cameraPermission.launch(Manifest.permission.CAMERA) | |
} | |
} |
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
private val cameraPermission = | |
registerForActivityResult(ActivityResultContracts.RequestPermission()) { granted -> | |
with(binding.root) { | |
when { | |
granted -> snackBar("Permission granted!") | |
shouldShowRequestPermissionRationale(Manifest.permission.CAMERA) -> { | |
//this option is available starting in API 23 | |
snackBar("Permission denied, show more info!") | |
} | |
else -> snackBar("Permission denied") |
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
def activityKtxVersion = "1.2.0-alpha07" | |
implementation "androidx.activity:activity-ktx:$activityKtxVersion" | |
def fragmentKtxVersion = "1.3.0-alpha07" | |
implementation "androidx.fragment:fragment-ktx:$fragmentKtxVersion" |
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
@RunWith(JUnit4::class) | |
class PhotosRepositoryTest : MockWebServerBaseTest() { | |
@get:Rule | |
val testInstantTaskExecutorRule: TestRule = InstantTaskExecutorRule() | |
private lateinit var photosRepository: PhotosRepository | |
private lateinit var apiService: ApiService | |
private val sol = anyInt() | |
private val page = anyInt() |