Skip to content

Commit

Permalink
Solve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
HectorNarvaez committed May 16, 2023
1 parent 8887893 commit eebbefd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ internal object GoogleRetrofitImpl {
private fun createOkHttpClient(): OkHttpClient {
val loggingInterceptor = setupLoggingInterceptor()

return OkHttpClient.Builder().apply {
addInterceptor(loggingInterceptor)
addInterceptor { chain ->
return OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
.addInterceptor { chain ->
val request = setupRequestInterceptor(chain)
chain.proceed(request)
}
connectTimeout(TIMEOUT, TimeUnit.SECONDS)
}.build()
.connectTimeout(TIMEOUT, TimeUnit.SECONDS)
.build()
}

private fun setupLoggingInterceptor() = HttpLoggingInterceptor().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.omh.android.storage.api.drive.nongms.data.source
import com.omh.android.storage.api.data.source.remote.FileRemoteDataSource
import com.omh.android.storage.api.domain.model.File
import com.omh.android.storage.api.drive.nongms.data.GoogleRetrofitImpl
import com.omh.android.storage.api.drive.nongms.data.source.mapper.toFileResponseList
import com.omh.android.storage.api.drive.nongms.data.source.mapper.toFileList

internal class FileRemoteDataSource : FileRemoteDataSource {

Expand All @@ -14,7 +14,7 @@ internal class FileRemoteDataSource : FileRemoteDataSource {
.execute()

return if (response.isSuccessful) {
response.body()?.toFileResponseList().orEmpty()
response.body()?.toFileList().orEmpty()
} else {
emptyList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import com.omh.android.storage.api.drive.nongms.data.source.response.FileListRem
import com.omh.android.storage.api.drive.nongms.data.source.response.FileRemoteResponse

@SuppressWarnings("ComplexCondition")
internal fun FileRemoteResponse.toFileResponse() =
if (mimeType == null || id == null || name == null || modifiedTime == null) {
internal fun FileRemoteResponse.toFile(): File? {
return if (mimeType == null || id == null || name == null || modifiedTime == null) {
null
} else {
File(
Expand All @@ -16,6 +16,7 @@ internal fun FileRemoteResponse.toFileResponse() =
modifiedTime
)
}
}

internal fun FileListRemoteResponse.toFileResponseList() =
files?.mapNotNull { it?.toFileResponse() }.orEmpty()
internal fun FileListRemoteResponse.toFileList(): List<File> =
files?.mapNotNull { remoteFileModel -> remoteFileModel?.toFile() }.orEmpty()
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import com.omh.android.storage.api.domain.model.FileType

internal object FileTypeMapper {

private val MAP_FILE_TYPES = FileType.values().associateBy { it.mimeType }
private val MAP_FILE_TYPES: Map<String, FileType> =
FileType.values().associateBy { fileType -> fileType.mimeType }

fun getFileTypeWithMime(mimeType: String) = if (MAP_FILE_TYPES.containsKey(mimeType)) {
MAP_FILE_TYPES[mimeType] ?: FileType.OTHER
} else {
FileType.OTHER
fun getFileTypeWithMime(mimeType: String): FileType {
return if (MAP_FILE_TYPES.containsKey(mimeType)) {
MAP_FILE_TYPES[mimeType] ?: FileType.OTHER
} else {
FileType.OTHER
}
}
}

0 comments on commit eebbefd

Please sign in to comment.