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 outputFile = File(filesDir, "test.jpeg") | |
val imageUri = FileProvider.getUriForFile( | |
this@MainActivity, | |
context.packageName.plus("provider"), | |
outputFile) | |
val takePhotoIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE).apply { | |
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) | |
putExtra(MediaStore.EXTRA_OUTPUT, imageUri) | |
} |
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 bitmap = MediaStore.Images.Media.getBitmap(contentResolver, imageUri) | |
val matrix = Matrix().apply { postRotate(90f) } | |
val rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true) |
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
private const val EXHAUSTED_SOURCE = -1L | |
/** | |
* A [ResponseBody] that informs a [ProgressListener] about the download progress. | |
*/ | |
class DownloadProgressBody( | |
private val responseBody: ResponseBody, | |
private val progressListener: ProgressListener | |
) : ResponseBody() { |
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
private val client = HttpClient(clientEngine) { | |
install(JsonFeature) { | |
serializer = KotlinxSerializer() | |
} | |
} | |
suspend fun getPopularMovies(): PopularMoviesEntity { | |
val response = client.get<HttpResponse> { | |
url { | |
protocol = URLProtocol.HTTPS |
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
actual val httpClientEngine: HttpClientEngine by lazy { | |
OkHttp.create { | |
val networkInterceptor = HttpLoggingInterceptor().apply { | |
level = HttpLoggingInterceptor.Level.BODY | |
} | |
addNetworkInterceptor(networkInterceptor) | |
} | |
} |
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 GetPopularMovies(private val moviesApi: MoviesApi) | |
: UseCase<PopularMovies, UseCase.None>() { | |
override suspend fun run(params: None): Either<Exception, PopularMovies> { | |
return try { | |
val movies = moviesApi.getPopularMovies().toModel() | |
Success(movies) | |
} catch (e: Exception) { | |
Failure(e) | |
} |
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
abstract class BasePresenter<T>(private val coroutineContext: CoroutineContext) { | |
protected var view: T? = null | |
protected lateinit var scope: PresenterCoroutineScope | |
fun attachView(view: T) { | |
this.view = view | |
scope = PresenterCoroutineScope(coroutineContext) | |
onViewAttached(view) | |
} |
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 PopularMoviesPresenter( | |
private val getPopularMovies: GetPopularMovies, | |
coroutineContext: CoroutineContext = defaultDispatcher | |
) : BasePresenter<PopularMoviesView>(coroutineContext) { | |
override fun onViewAttached(view: PopularMoviesView) { | |
view.setLoadingVisible(true) | |
getPopularMovies() | |
} |
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
abstract class UseCase<out Type, in Params> where Type : Any { | |
abstract suspend fun run(params: Params): Either<Exception, Type> | |
suspend operator fun invoke(params: Params, onSuccess: (Type) -> Unit, onFailure: (Exception) -> Unit) { | |
val result = run(params) | |
coroutineScope { | |
launch(uiDispatcher) { | |
result.fold( | |
failed = { onFailure(it) }, |
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
version: "3.9" | |
services: | |
api_service: | |
build: . | |
restart: always | |
ports: | |
- 8080:8080 | |
depends_on: | |
- db |