-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define abstractions #10
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.omh.android.storage.api | ||
|
||
import android.content.Context | ||
|
||
interface OmhStorageClient { | ||
|
||
interface Builder { | ||
fun build(context: Context): OmhStorageClient | ||
} | ||
|
||
fun setupAccessToken(token: String) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should depend on the OMH Auth library to handle the access token and it's refreshing |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.omh.android.storage.api | ||
|
||
import android.content.Context | ||
|
||
interface OmhStorageFactory { | ||
fun getStorageClient(context: Context): OmhStorageClient | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.omh.android.storage.api | ||
|
||
import android.content.Context | ||
import kotlin.reflect.KClass | ||
|
||
object OmhStorageProvider { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a TODO comment to indicate that this needs to be refactored in the future once there's more code done for GMS and non GMS |
||
|
||
private const val NGMS_ADDRESS = "com.omh.android.storage.api.drive.nongms.OmhStorageFactoryImpl" | ||
|
||
@SuppressWarnings("SwallowedException") | ||
fun provideStorageClient(context: Context): OmhStorageClient { | ||
val clazz: KClass<out Any> = Class.forName(NGMS_ADDRESS).kotlin | ||
val omhStorageFactory = clazz.objectInstance as OmhStorageFactory | ||
return omhStorageFactory.getStorageClient(context) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package com.omh.android.storage.api.data.datasource.network | ||
|
||
import com.omh.android.storage.api.data.model.RemoteFileOrFolder | ||
|
||
interface FilesFoldersNetworkDataSource { | ||
fun getAll() | ||
fun getAll(): List<RemoteFileOrFolder> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,32 @@ | ||
package com.omh.android.storage.api.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.domain.model.File | ||
import com.omh.android.storage.api.domain.model.FileOrFolder | ||
import com.omh.android.storage.api.domain.model.Folder | ||
|
||
fun fromFilesFoldersRemoteListToDomain(inputList: List<RemoteFileOrFolder>): List<FileOrFolder> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be feasible using a |
||
val outputList = mutableListOf<FileOrFolder>() | ||
if (inputList.isEmpty()) { | ||
return outputList | ||
} | ||
for (gDriveFileOrFolder in inputList) { | ||
outputList.add( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you extract the content of the for loop into a separate function to reduce indentation? |
||
if (gDriveFileOrFolder is RemoteFile) { | ||
File( | ||
gDriveFileOrFolder.name, | ||
gDriveFileOrFolder.ext, | ||
gDriveFileOrFolder.lastModDate | ||
) | ||
} else { | ||
Folder( | ||
(gDriveFileOrFolder as RemoteFolder).name, | ||
gDriveFileOrFolder.lastModDate | ||
) | ||
} | ||
) | ||
} | ||
return outputList | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
package com.omh.android.storage.api.data.model | ||
|
||
interface RemoteFileOrFolder | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would we benefit of using a sealed class here instead? |
||
|
||
data class RemoteFile( | ||
val name: String = "", | ||
val ext: String = "", | ||
val lastModDate: Long = 0L | ||
) : RemoteFileOrFolder | ||
|
||
data class RemoteFolder( | ||
val name: String = "", | ||
val lastModDate: Long = 0L | ||
) : RemoteFileOrFolder |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
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.domain.abstraction.FilesFoldersRepository | ||
|
||
class FilesFoldersDataRepository( | ||
private val networkDataSource: FilesFoldersNetworkDataSource | ||
) : FilesFoldersRepository { | ||
override fun getAll() = fromFilesFoldersRemoteListToDomain( | ||
networkDataSource.getAll() | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package com.omh.android.storage.api.domain.abstraction | ||
|
||
import com.omh.android.storage.api.domain.model.FileOrFolder | ||
|
||
interface FilesFoldersRepository { | ||
fun getAll() | ||
fun getAll(): List<FileOrFolder> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,17 @@ | ||
package com.omh.android.storage.api.domain.model | ||
|
||
interface FileOrFolder { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here with the sealed class |
||
val name: String | ||
val modificationDate: Long | ||
} | ||
|
||
data class File( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you using the additional functions of the data class implementation? If not, I'd suggest removing the anotation |
||
override val name: String, | ||
val extension: String, | ||
override val modificationDate: Long | ||
) : FileOrFolder | ||
|
||
data class Folder( | ||
override val name: String, | ||
override val modificationDate: Long | ||
) : FileOrFolder |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package com.omh.android.storage.api.domain.usecase | ||
|
||
import com.omh.android.storage.api.domain.model.FileOrFolder | ||
|
||
interface GetAllFilesAndFolders { | ||
fun execute() | ||
fun execute(): List<FileOrFolder> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should return an OmhTask object. You can copy the implementation from the auth lib. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.omh.android.storage.api.domain.usecase | ||
|
||
import com.omh.android.storage.api.domain.abstraction.FilesFoldersRepository | ||
|
||
class GetAllFilesAndFoldersUseCase( | ||
private val repository: FilesFoldersRepository | ||
) : GetAllFilesAndFolders { | ||
override fun execute() = repository.getAll() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also request the OmhAuthClient. Let me know when you're available to help you setup that dependency.