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 FetchMoviesUseCase( | |
private val dataSource: MovieRemoteDataSource | |
) { | |
suspend operator fun invoke(): Result<MoviesResponse> = | |
withContext(Dispatchers.IO) { | |
try { | |
Result.success(dataSource.fetchMovies()) | |
} catch (exception: IOException) { | |
Result.failure(exception) |
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
sealed class Failure : IOException() | |
object JsonError : Failure() | |
object UnknownHostError : Failure() | |
object NoConnectivityError : Failure() | |
data class TimeOutError( | |
override val message: String? | |
) : Failure() | |
data class UnknownError( |
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 ErrorHandlingInterceptor( | |
private val networkHandler: NetworkHandler | |
) : Interceptor { | |
override fun intercept(chain: Interceptor.Chain): Response { | |
if (!networkHandler.isConnected) { | |
throw NoConnectivityError | |
} | |
return try { |
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
enum class MockRequestType(val filePath: String) { | |
MOVIES(MovieService.MOVIES) | |
} |
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 MockRequestInterceptor : Interceptor { | |
override fun intercept(chain: Interceptor.Chain): Response { | |
return with(chain.request()) { | |
when (val mockRequestType = findMockTag()) { | |
is MockRequestType -> createLocalResponse( | |
request = this, | |
filePath = mockRequestType.filePath | |
) | |
else -> chain.proceed(this) |
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 int shortestSubstring(String s) { // "dabbcabcd", "bcaacbc", "bab" | |
// for 'dabbcabcd' there is 4 unique letters, so shortest substring can be minimum 4 letter length. if not, | |
// we need to increase that length and keep searching. | |
List<String> letters = new ArrayList<>(); | |
for (char each : s.toCharArray()){ | |
String letter = String.valueOf(each); | |
if (!letters.contains(letter)) { | |
letters.add(letter); | |
} | |
} |
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
https://askubuntu.com/questions/182587/build-32-bit-on-64-bit-ubuntu-installing-ia32-libs-does-not-include-libstdc/182677#182677 | |
https://stackoverflow.com/questions/35911302/cannot-launch-emulator-on-linux-ubuntu-15-10/43091301#43091301 |