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 is part of a stateful widget, that uses Isolates.compute to do a heavy task, in this case download and | |
/// display an image from internet in parallel. | |
/// this will help to improve performance for our scenario when a chat messages screen should display all messages | |
class _MessagesImageState extends State<MessagesImage> { | |
@override | |
Widget build(BuildContext context) { | |
return InkWell( | |
onTap: () { | |
// onTap logic |
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
// Complete the maxInversions function below. | |
fun maxInversions(prices: Array<Int>): Long { | |
var inversionsCounter = 0L | |
val arraySize = prices.size | |
for (i in 0 until arraySize - 1) { | |
var smaller = 0 //smaller elements on right | |
for (j in i + 1 until arraySize) { | |
if (prices[i] > prices[j]) { | |
smaller++ |
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
/* | |
* Copyright 2017 Google Inc. | |
* | |
* 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 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
sealed class Result<out T : Any> { | |
data class Success<out T : Any>(val data: T) : Result<T>() | |
data class Error(val exception: Exception) : Result<Nothing>() | |
object InProgress : Result<Nothing>() | |
val extractData: T? | |
get() = when (this) { | |
is Success -> data | |
is Error -> null | |
is InProgress -> null |
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
public static Matcher<View> textInputLayoutwithItemHint(final String matcherText) { | |
return new BoundedMatcher<View, TextInputLayout>(TextInputLayout.class) { | |
@Override | |
public void describeTo(Description description) { | |
description.appendText("with item hint: " + matcherText); | |
} | |
@Override | |
protected boolean matchesSafely(TextInputLayout editTextField) { |
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
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 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 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 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 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) |