Skip to content
Snippets Groups Projects
Commit 879d1fd0 authored by Kamal Bramwell's avatar Kamal Bramwell
Browse files

Organized functionality into modules

parent c6e1ad40
Branches
No related tags found
No related merge requests found
Showing
with 267 additions and 57 deletions
......@@ -7,7 +7,7 @@
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="Embedded JDK" />
<option name="gradleJvm" value="11" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
......
package io.elixxir.dapp
import io.elixxir.dapp.android.model.AndroidConfig
import io.elixxir.dapp.api.model.*
import io.elixxir.dapp.logger.data.Logger
import io.elixxir.dapp.model.CommonProperties
import io.elixxir.dapp.model.DappConfig
/**
* Singleton entry point to modules provided by the dApp SDK.
*/
class DappModule private constructor(
config: DappConfig,
logger: Logger = Logger.newInstance(config.loggerConfig)
) : DappApi,
AndroidConfig by config.androidConfig,
Logger by logger,
CommonProperties
{
override val accountApi: AccountApi
get() = TODO("Not yet implemented")
override val directoryApi: DirectoryApi
get() = TODO("Not yet implemented")
override val messagesApi: MessagesApi
get() = TODO("Not yet implemented")
override val networkApi: NetworkApi
get() = TODO("Not yet implemented")
override val requestsApi: RequestsApi
get() = TODO("Not yet implemented")
override val groupsApi: GroupsApi
get() = TODO("Not yet implemented")
companion object {
@Volatile
private var instance: DappModule? = null
fun getInstance(config: DappConfig): DappModule {
return instance ?: DappModule(config).apply {
instance = this
}
}
}
}
\ No newline at end of file
package io.elixxir.dapp
import android.content.Context
import io.elixxir.dapp.android.model.AndroidConfig
import io.elixxir.dapp.logger.data.Logger
import io.elixxir.dapp.logger.model.LoggerConfig
import io.elixxir.dapp.model.DappConfig
import kotlinx.coroutines.CoroutineDispatcher
interface GlobalConfig : AndroidConfig, LoggerConfig
/**
* Singleton entry point to modules provided by the dApp SDK.
*/
class DappSdk private constructor(
config: DappConfig
) : GlobalConfig,
AndroidConfig by config.androidConfig,
LoggerConfig by config.loggerConfig
{
companion object {
internal val logger: Logger by lazy {
Logger.newInstance(instance!!)
}
internal val defaultDispatcher: CoroutineDispatcher by lazy {
instance!!.dispatcher
}
internal val context: () -> Context get() = instance!!.context
@Volatile
private var instance: DappSdk? = null
fun getInstance(config: DappConfig): DappSdk {
return instance ?: DappSdk(config).apply {
instance = this
}
}
}
}
\ No newline at end of file
package io.elixxir.dapp.api.data
import io.elixxir.dapp.api.model.AccountApi
import io.elixxir.dapp.session.repository.SessionDataSource
import kotlinx.coroutines.*
internal class AccountModule(
private val sessionManager: SessionDataSource
) : AccountApi {
private val scope: CoroutineScope = CoroutineScope(
CoroutineName("AccountModule")
+ Job()
+ Dispatchers.Default
)
override fun getCurrentUser() {
TODO("Not yet implemented")
}
override fun createAccount(username: String) {
scope.launch {
sessionManager.createSession()
}
}
override fun restoreAccount() {
scope.launch {
sessionManager.restoreSession()
}
}
override fun updateAccount() {
TODO("Not yet implemented")
}
override fun deleteAccount() {
scope.launch {
sessionManager.deleteSession()
}
}
}
\ No newline at end of file
package io.elixxir.dapp.api.data
import io.elixxir.dapp.api.model.NetworkApi
import io.elixxir.dapp.network.model.ConnectionStatus
import io.elixxir.dapp.network.data.NetworkManager
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.Flow
internal class NetworkModule(
private val networkManager: NetworkManager
) : NetworkApi {
private val scope: CoroutineScope = CoroutineScope(
CoroutineName("AccountModule")
+ Job()
+ Dispatchers.Default
)
override val connectionStatus: Flow<ConnectionStatus> by networkManager::connectionStatus
override fun connect() {
TODO("Not yet implemented")
}
override fun disconnect() {
TODO("Not yet implemented")
}
}
\ No newline at end of file
package io.elixxir.dapp.api.model
interface AccountApi {
fun getCurrentUser()
fun createAccount(username: String)
fun restoreAccount()
fun updateAccount()
fun deleteAccount()
}
\ No newline at end of file
package io.elixxir.dapp.api.model
interface DappApi {
val accountApi: AccountApi
val directoryApi: DirectoryApi
val messagesApi: MessagesApi
val networkApi: NetworkApi
val requestsApi: RequestsApi
val groupsApi: GroupsApi
}
\ No newline at end of file
package io.elixxir.dapp.api.model
interface DirectoryApi {
fun getContacts()
fun findUser()
fun blockUser()
}
\ No newline at end of file
package io.elixxir.dapp.api.model
import io.elixxir.dapp.messaging.model.Message
import kotlinx.coroutines.flow.Flow
interface GroupsApi {
val groupMessages: Flow<Message>
fun sendInvitation()
fun retryInvitation()
fun acceptInvitation()
fun sendMessage()
fun retryMessage()
}
\ No newline at end of file
package io.elixxir.dapp.api.model
import io.elixxir.dapp.messaging.model.Message
import kotlinx.coroutines.flow.Flow
interface MessagesApi {
val messages: Flow<Message>
fun sendMessage()
fun retryMessage()
}
\ No newline at end of file
package io.elixxir.dapp.api.model
import io.elixxir.dapp.network.model.ConnectionStatus
import kotlinx.coroutines.flow.Flow
interface NetworkApi {
val connectionStatus: Flow<ConnectionStatus>
fun connect()
fun disconnect()
}
\ No newline at end of file
package io.elixxir.dapp.api.model
import io.elixxir.dapp.request.model.Request
import kotlinx.coroutines.flow.Flow
interface RequestsApi {
val requests: Flow<Request>
fun sendRequest()
fun acceptRequest()
fun retryRequest()
}
\ No newline at end of file
package io.elixxir.dapp.messaging.model
interface Message {
}
\ No newline at end of file
......@@ -4,18 +4,28 @@ import bindings.Bindings
import bindings.Cmix
import io.elixxir.dapp.model.CommonProperties
import io.elixxir.dapp.network.model.*
import io.elixxir.dapp.network.repository.NdfDataSource
import io.elixxir.dapp.session.model.*
import io.elixxir.dapp.session.repository.SessionKeyStore
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.withContext
internal interface NetworkManager {
val connectionStatus: Flow<ConnectionStatus>
}
internal class DappNetworkManager private constructor(
properties: CommonProperties
properties: CommonProperties,
keyStore: SessionKeyStore,
ndfSource: NdfDataSource
): NetworkManager, CommonProperties by properties {
private fun login(
override val connectionStatus: Flow<ConnectionStatus> by ::_connectionStatus
private val _connectionStatus: MutableStateFlow<ConnectionStatus> =
MutableStateFlow(ConnectionStatus.DISCONNECTED)
fun login(
cmixId: Long,
authCallbacks: AuthCallbacksMediator,
identity: ReceptionIdentity,
......@@ -26,7 +36,7 @@ internal class DappNetworkManager private constructor(
)
}
private fun newCmix(
fun newCmix(
ndfJson: String,
sessionFolderPath: String,
sessionPassword: SessionPassword,
......@@ -40,7 +50,7 @@ internal class DappNetworkManager private constructor(
)
}
private suspend fun loadCmix(
suspend fun loadCmix(
sessionFolderPath: String,
sessionPassword: SessionPassword,
cmixParamsJson: E2eParams
......@@ -50,25 +60,29 @@ internal class DappNetworkManager private constructor(
)
}
private fun createIdentity(): ReceptionIdentity {
fun createIdentity(): ReceptionIdentity {
return ReceptionIdentity(
Cmix().makeReceptionIdentity()
)
}
private fun initNetworkFollower() {
fun initNetworkFollower() {
}
private fun stopNetworkFollower() {
fun stopNetworkFollower() {
}
private fun initUserDiscovery() {
fun initUserDiscovery() {
}
companion object {
internal fun newInstance(properties: CommonProperties) = DappNetworkManager(properties)
internal fun newInstance(
properties: CommonProperties,
keyStore: SessionKeyStore,
ndfSource: NdfDataSource
) = DappNetworkManager(properties, keyStore, ndfSource)
}
}
\ No newline at end of file
package io.elixxir.dapp.network.model
enum class ConnectionStatus {
DISCONNECTED, CONNECTING, CONNECTED
}
\ No newline at end of file
package io.elixxir.dapp.network.model
internal enum class NetworkFollowerStatus(val code: Long) {
STOPPED(0),
STARTING(1000),
RUNNING(2000),
STOPPING(3000);
companion object {
fun from(code: Long) = values().first { it.code == code }
}
}
\ No newline at end of file
package io.elixxir.dapp.session.data
package io.elixxir.dapp.network.repository
import androidx.annotation.RawRes
import bindings.Bindings
......
package io.elixxir.dapp.request.model
interface Request {
}
\ No newline at end of file
......@@ -6,17 +6,33 @@ import kotlinx.coroutines.*
/**
* Responsible for creation, deletion & storage of folder used to persist
* Cmix session. Only needs to be created once per app installation.
* Cmix session.
*/
internal interface SessionManager {
internal interface SessionDataSource {
val sessionFolder: File
fun doesSessionExist(): Boolean
/**
* Only needs to be created once per app installation.
* Return the [sessionFolder] if successful.
*/
suspend fun createSession(): Result<File>
/**
* Should be called during account deletion.
*/
suspend fun deleteSession(): Result<Unit>
/**
* Restore session
*/
suspend fun restoreSession(): Result<Unit>
}
internal class DappSessionManager private constructor(
internal class LocalSessionDataSource private constructor(
properties: CommonProperties
) : SessionManager, CommonProperties by properties {
) : SessionDataSource, CommonProperties by properties {
override val sessionFolder: File get() {
return try {
......@@ -27,6 +43,8 @@ internal class DappSessionManager private constructor(
}
}
override fun doesSessionExist(): Boolean = sessionFolder.exists()
override suspend fun createSession(): Result<File> = withContext(dispatcher) {
try {
Result.success(createSessionFolder())
......@@ -60,7 +78,11 @@ internal class DappSessionManager private constructor(
}
}
override suspend fun restoreSession(): Result<Unit> {
TODO("Not yet implemented")
}
companion object {
internal fun newInstance(properties: CommonProperties) = DappSessionManager(properties)
internal fun newInstance(properties: CommonProperties) = LocalSessionDataSource(properties)
}
}
\ No newline at end of file
package io.elixxir.dapp.ud.repository
interface UserDataSource {
fun createUser(username: String)
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment