Skip to content

Commit

Permalink
Merge pull request #10 from openmobilehub/state/defineAbstractions
Browse files Browse the repository at this point in the history
Define abstractions
  • Loading branch information
HectorNarvaez committed May 15, 2023
2 parents 0f4ecf4 + 29627a2 commit 45b9631
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 3 deletions.
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)
}
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 {

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> {
val outputList = mutableListOf<FileOrFolder>()
if (inputList.isEmpty()) {
return outputList
}
for (gDriveFileOrFolder in inputList) {
outputList.add(
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

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 {
val name: String
val modificationDate: Long
}

data class File(
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>
}
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()
}

0 comments on commit 45b9631

Please sign in to comment.