-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Setup retrofit and refactor on data layer due to architecture changes * Sample app module is broken. Removed temporally * Solve comments * Solve comments --------- Co-authored-by: Hector Narvaez <hector.narvaez@CSABOGMB042.local>
- Loading branch information
1 parent
48eabf3
commit ed4c933
Showing
26 changed files
with
236 additions
and
177 deletions.
There are no files selected for viewing
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
71 changes: 60 additions & 11 deletions
71
...-nongms/src/main/java/com/omh/android/storage/api/drive/nongms/data/GoogleRetrofitImpl.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,75 @@ | ||
package com.omh.android.storage.api.drive.nongms.data | ||
|
||
import com.omh.android.storage.api.drive.nongms.BuildConfig | ||
import okhttp3.Interceptor | ||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.jackson.JacksonConverterFactory | ||
|
||
internal object GoogleRetrofitImpl { | ||
internal class GoogleRetrofitImpl(private val bearerToken: String) { | ||
|
||
private val okHttpClient = OkHttpClient.Builder() | ||
.addInterceptor( | ||
HttpLoggingInterceptor().apply { | ||
if (BuildConfig.DEBUG) setLevel(HttpLoggingInterceptor.Level.BODY) | ||
companion object { | ||
private const val HEADER_AUTHORIZATION_NAME = "Authorization" | ||
|
||
private var instance: GoogleRetrofitImpl? = null | ||
|
||
internal fun getInstance(bearerToken: String): GoogleRetrofitImpl { | ||
if (instance == null) { | ||
instance = GoogleRetrofitImpl(bearerToken) | ||
} | ||
|
||
return instance!! | ||
} | ||
} | ||
|
||
private var apiService: GoogleStorageApiService? = null | ||
|
||
fun getGoogleStorageApiService(): GoogleStorageApiService { | ||
if (apiService != null) { | ||
return apiService!! | ||
} | ||
|
||
val retrofit = Retrofit.Builder() | ||
.client(createOkHttpClient()) | ||
.addConverterFactory(createConverterFactory()) | ||
.baseUrl(BuildConfig.G_STORAGE_URL) | ||
.build() | ||
|
||
apiService = retrofit.create(GoogleStorageApiService::class.java) | ||
return apiService!! | ||
} | ||
|
||
private fun createOkHttpClient(): OkHttpClient { | ||
val loggingInterceptor = setupLoggingInterceptor() | ||
|
||
return OkHttpClient.Builder() | ||
.addInterceptor(loggingInterceptor) | ||
.addInterceptor { chain -> | ||
val request = setupRequestInterceptor(chain) | ||
chain.proceed(request) | ||
} | ||
.build() | ||
} | ||
|
||
private fun setupLoggingInterceptor() = HttpLoggingInterceptor().apply { | ||
setLevel( | ||
if (BuildConfig.DEBUG) { | ||
HttpLoggingInterceptor.Level.BODY | ||
} else { | ||
HttpLoggingInterceptor.Level.NONE | ||
} | ||
) | ||
.build() | ||
} | ||
|
||
private val retrofitClient = Retrofit.Builder() | ||
.client(okHttpClient) | ||
.baseUrl(BuildConfig.G_STORAGE_URL) | ||
.addConverterFactory(JacksonConverterFactory.create()) | ||
private fun setupRequestInterceptor(chain: Interceptor.Chain) = chain | ||
.request() | ||
.newBuilder() | ||
.addHeader( | ||
HEADER_AUTHORIZATION_NAME, | ||
bearerToken | ||
) | ||
.build() | ||
|
||
val googleStorageREST: GoogleStorageREST = retrofitClient.create(GoogleStorageREST::class.java) | ||
private fun createConverterFactory() = JacksonConverterFactory.create() | ||
} |
25 changes: 25 additions & 0 deletions
25
...ms/src/main/java/com/omh/android/storage/api/drive/nongms/data/GoogleStorageApiService.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.omh.android.storage.api.drive.nongms.data | ||
|
||
import com.omh.android.storage.api.drive.nongms.data.source.response.FileListRemoteResponse | ||
import retrofit2.Call | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
internal interface GoogleStorageApiService { | ||
|
||
companion object { | ||
private const val GET_ALL_FILES_AND_FOLDERS_LIST_PARTICLE = "files" | ||
|
||
private const val QUERY_Q = "q" | ||
private const val QUERY_FIELDS = "fields" | ||
|
||
private const val Q_VALUE = "'root' in parents and trashed = false" | ||
private const val FIELDS_VALUE = "files(id, name, mimeType, modifiedTime)" | ||
} | ||
|
||
@GET(GET_ALL_FILES_AND_FOLDERS_LIST_PARTICLE) | ||
fun getRootFilesList( | ||
@Query(QUERY_Q) query: String = Q_VALUE, | ||
@Query(QUERY_FIELDS) fields: String = FIELDS_VALUE | ||
): Call<FileListRemoteResponse> | ||
} |
15 changes: 0 additions & 15 deletions
15
...e-nongms/src/main/java/com/omh/android/storage/api/drive/nongms/data/GoogleStorageREST.kt
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
...va/com/omh/android/storage/api/drive/nongms/data/datasource/FilesFoldersRestDataSource.kt
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
...-nongms/src/main/java/com/omh/android/storage/api/drive/nongms/data/mapper/DataMappers.kt
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
...src/main/java/com/omh/android/storage/api/drive/nongms/data/model/FileOrFolderResponse.kt
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
...main/java/com/omh/android/storage/api/drive/nongms/data/model/FilesFoldersListResponse.kt
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
...rc/main/java/com/omh/android/storage/api/drive/nongms/data/source/FileRemoteDataSource.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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.toFileList | ||
|
||
internal class FileRemoteDataSource : FileRemoteDataSource { | ||
|
||
override fun getRootFilesList(): List<File> { | ||
val response = GoogleRetrofitImpl | ||
.getInstance("") | ||
.getGoogleStorageApiService() | ||
.getRootFilesList() | ||
.execute() | ||
|
||
return if (response.isSuccessful) { | ||
response.body()?.toFileList().orEmpty() | ||
} else { | ||
emptyList() | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
.../src/main/java/com/omh/android/storage/api/drive/nongms/data/source/mapper/DataMappers.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.omh.android.storage.api.drive.nongms.data.source.mapper | ||
|
||
import com.omh.android.storage.api.domain.model.File | ||
import com.omh.android.storage.api.drive.nongms.data.source.response.FileListRemoteResponse | ||
import com.omh.android.storage.api.drive.nongms.data.source.response.FileRemoteResponse | ||
|
||
@SuppressWarnings("ComplexCondition") | ||
internal fun FileRemoteResponse.toFile(): File? { | ||
if (mimeType == null || id == null || name == null || modifiedTime == null) { | ||
return null | ||
} | ||
|
||
return File( | ||
mimeType, | ||
id, | ||
name, | ||
modifiedTime | ||
) | ||
} | ||
|
||
internal fun FileListRemoteResponse.toFileList(): List<File> = | ||
files?.mapNotNull { remoteFileModel -> remoteFileModel?.toFile() }.orEmpty() |
9 changes: 9 additions & 0 deletions
9
...a/com/omh/android/storage/api/drive/nongms/data/source/response/FileListRemoteResponse.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.omh.android.storage.api.drive.nongms.data.source.response | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties | ||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
internal data class FileListRemoteResponse( | ||
@JsonProperty("files") val files: List<FileRemoteResponse?>? | ||
) |
12 changes: 12 additions & 0 deletions
12
.../java/com/omh/android/storage/api/drive/nongms/data/source/response/FileRemoteResponse.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.omh.android.storage.api.drive.nongms.data.source.response | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties | ||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
internal data class FileRemoteResponse( | ||
@JsonProperty("mimeType")val mimeType: String?, | ||
@JsonProperty("id")val id: String?, | ||
@JsonProperty("name")val name: String?, | ||
@JsonProperty("modifiedTime")val modifiedTime: String? | ||
) |
7 changes: 0 additions & 7 deletions
7
...java/com/omh/android/storage/api/data/datasource/network/FilesFoldersNetworkDataSource.kt
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
storage-api/src/main/java/com/omh/android/storage/api/data/mapper/DataMappers.kt
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
storage-api/src/main/java/com/omh/android/storage/api/data/mapper/FileTypeMapper.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.omh.android.storage.api.data.mapper | ||
|
||
import com.omh.android.storage.api.domain.model.FileType | ||
|
||
internal object FileTypeMapper { | ||
|
||
private val MAP_FILE_TYPES: Map<String, FileType> = | ||
FileType.values().associateBy { fileType -> fileType.mimeType } | ||
|
||
fun getFileTypeWithMime(mimeType: String): FileType { | ||
return if (MAP_FILE_TYPES.containsKey(mimeType)) { | ||
MAP_FILE_TYPES[mimeType] ?: FileType.OTHER | ||
} else { | ||
FileType.OTHER | ||
} | ||
} | ||
} |
14 changes: 0 additions & 14 deletions
14
storage-api/src/main/java/com/omh/android/storage/api/data/model/DataModel.kt
This file was deleted.
Oops, something went wrong.
10 changes: 4 additions & 6 deletions
10
...i/src/main/java/com/omh/android/storage/api/data/repository/FilesFoldersDataRepository.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
package com.omh.android.storage.api.data.repository | ||
|
||
import com.omh.android.storage.api.data.datasource.network.FilesFoldersNetworkDataSource | ||
import com.omh.android.storage.api.data.mapper.fromFilesFoldersRemoteListToDomain | ||
import com.omh.android.storage.api.data.source.remote.FileRemoteDataSource | ||
import com.omh.android.storage.api.domain.abstraction.FilesFoldersRepository | ||
|
||
class FilesFoldersDataRepository( | ||
private val networkDataSource: FilesFoldersNetworkDataSource | ||
private val networkDataSource: FileRemoteDataSource | ||
) : FilesFoldersRepository { | ||
override fun getAll() = fromFilesFoldersRemoteListToDomain( | ||
networkDataSource.getAll() | ||
) | ||
|
||
override fun getRootFilesList() = networkDataSource.getRootFilesList() | ||
} |
2 changes: 1 addition & 1 deletion
2
...tasource/network/FileNetworkDataSource.kt → ...ta/source/remote/FileNetworkDataSource.kt
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
8 changes: 8 additions & 0 deletions
8
...-api/src/main/java/com/omh/android/storage/api/data/source/remote/FileRemoteDataSource.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.omh.android.storage.api.data.source.remote | ||
|
||
import com.omh.android.storage.api.domain.model.File | ||
|
||
interface FileRemoteDataSource { | ||
|
||
fun getRootFilesList(): List<File> | ||
} |
Oops, something went wrong.