-
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.
Add implementation for data layer on non gms module
- Loading branch information
1 parent
9b9482d
commit 246f5ca
Showing
8 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...ive-nongms/src/main/java/com/omh/android/storage/api/drive/nongms/OmhStorageClientImpl.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 | ||
|
||
import android.content.Context | ||
import com.omh.android.storage.api.OmhStorageClient | ||
|
||
internal class OmhStorageClientImpl( | ||
context: Context | ||
) : OmhStorageClient { | ||
|
||
private val applicationContext: Context | ||
|
||
init { | ||
applicationContext = context.applicationContext | ||
} | ||
|
||
internal class Builder : OmhStorageClient.Builder { | ||
override fun build(context: Context): OmhStorageClient { | ||
return OmhStorageClientImpl(context) | ||
} | ||
} | ||
|
||
override fun setupAccessToken(token: String) { | ||
// Implement THIS | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ve-nongms/src/main/java/com/omh/android/storage/api/drive/nongms/OmhStorageFactoryImpl.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,11 @@ | ||
package com.omh.android.storage.api.drive.nongms | ||
|
||
import android.content.Context | ||
import com.omh.android.storage.api.OmhStorageFactory | ||
|
||
class OmhStorageFactoryImpl : OmhStorageFactory { | ||
|
||
override fun getStorageClient( | ||
context: Context | ||
) = OmhStorageClientImpl.Builder().build(context) | ||
} |
26 changes: 26 additions & 0 deletions
26
...-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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.omh.android.storage.api.drive.nongms.data | ||
|
||
import com.omh.android.storage.api.drive.nongms.BuildConfig | ||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.jackson.JacksonConverterFactory | ||
|
||
internal object GoogleRetrofitImpl { | ||
|
||
private val okHttpClient = OkHttpClient.Builder() | ||
.addInterceptor( | ||
HttpLoggingInterceptor().apply { | ||
if (BuildConfig.DEBUG) setLevel(HttpLoggingInterceptor.Level.BODY) | ||
} | ||
) | ||
.build() | ||
|
||
private val retrofitClient = Retrofit.Builder() | ||
.client(okHttpClient) | ||
.baseUrl(BuildConfig.G_STORAGE_URL) | ||
.addConverterFactory(JacksonConverterFactory.create()) | ||
.build() | ||
|
||
val googleStorageREST: GoogleStorageREST = retrofitClient.create(GoogleStorageREST::class.java) | ||
} |
15 changes: 15 additions & 0 deletions
15
...e-nongms/src/main/java/com/omh/android/storage/api/drive/nongms/data/GoogleStorageREST.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,15 @@ | ||
package com.omh.android.storage.api.drive.nongms.data | ||
|
||
import com.omh.android.storage.api.drive.nongms.data.model.FilesFoldersListResponse | ||
import retrofit2.Call | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
internal interface GoogleStorageREST { | ||
|
||
@GET("files") | ||
fun getFilesFoldersList( | ||
@Query("q") query: String = "'root' in parents and trashed = false", | ||
@Query("fields") fields: String = "files(id, name, mimeType, modifiedTime)" | ||
): Call<FilesFoldersListResponse> | ||
} |
14 changes: 14 additions & 0 deletions
14
...va/com/omh/android/storage/api/drive/nongms/data/datasource/FilesFoldersRestDataSource.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,14 @@ | ||
package com.omh.android.storage.api.drive.nongms.data.datasource | ||
|
||
import com.omh.android.storage.api.data.datasource.network.FilesFoldersNetworkDataSource | ||
import com.omh.android.storage.api.drive.nongms.data.GoogleStorageREST | ||
import com.omh.android.storage.api.drive.nongms.data.mapper.fromFilesFoldersResponseListToData | ||
|
||
internal class FilesFoldersRestDataSource( | ||
private val storageService: GoogleStorageREST, | ||
) : FilesFoldersNetworkDataSource { | ||
|
||
override fun getAll() = fromFilesFoldersResponseListToData( | ||
storageService.getFilesFoldersList().execute() | ||
) | ||
} |
38 changes: 38 additions & 0 deletions
38
...-nongms/src/main/java/com/omh/android/storage/api/drive/nongms/data/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,38 @@ | ||
package com.omh.android.storage.api.drive.nongms.data.mapper | ||
|
||
import com.omh.android.storage.api.data.model.RemoteFile | ||
import com.omh.android.storage.api.data.model.RemoteFileOrFolder | ||
import com.omh.android.storage.api.data.model.RemoteFolder | ||
import com.omh.android.storage.api.drive.nongms.data.model.FilesFoldersListResponse | ||
import retrofit2.Response | ||
import java.text.SimpleDateFormat | ||
|
||
private const val RESPONSE_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" | ||
|
||
internal fun fromFilesFoldersResponseListToData( | ||
response: Response<FilesFoldersListResponse> | ||
): List<RemoteFileOrFolder> { | ||
val outputList = mutableListOf<RemoteFileOrFolder>() | ||
val filesInBody = response.body()?.files | ||
if (!response.isSuccessful || filesInBody == null) return outputList | ||
filesInBody.map { fileFolderResponse -> | ||
val modifiedTimeAsLong = SimpleDateFormat(RESPONSE_DATE_FORMAT) | ||
.parse(fileFolderResponse.modifiedTime) | ||
.time | ||
outputList.add( | ||
if (fileFolderResponse.mimeType.contains("folder")) { | ||
RemoteFolder( | ||
fileFolderResponse.name, | ||
modifiedTimeAsLong | ||
) | ||
} else { | ||
RemoteFile( | ||
fileFolderResponse.name, | ||
fileFolderResponse.mimeType, | ||
modifiedTimeAsLong | ||
) | ||
} | ||
) | ||
} | ||
return outputList | ||
} |
16 changes: 16 additions & 0 deletions
16
...src/main/java/com/omh/android/storage/api/drive/nongms/data/model/FileOrFolderResponse.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,16 @@ | ||
package com.omh.android.storage.api.drive.nongms.data.model | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties | ||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
internal class FileOrFolderResponse( | ||
@JsonProperty("id") | ||
val id: String, | ||
@JsonProperty("name") | ||
val name: String, | ||
@JsonProperty("mimeType") | ||
val mimeType: String, | ||
@JsonProperty("modifiedTime") | ||
val modifiedTime: String | ||
) |
10 changes: 10 additions & 0 deletions
10
...main/java/com/omh/android/storage/api/drive/nongms/data/model/FilesFoldersListResponse.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,10 @@ | ||
package com.omh.android.storage.api.drive.nongms.data.model | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties | ||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
internal class FilesFoldersListResponse( | ||
@JsonProperty("files") | ||
val files: List<FileOrFolderResponse> | ||
) |