-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5f89ff
commit 8c0d38c
Showing
7 changed files
with
207 additions
and
13 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
54 changes: 54 additions & 0 deletions
54
...c/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/AccountManager.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,54 @@ | ||
/* | ||
* Infomaniak SwissTransfer - Multiplatform | ||
* Copyright (C) 2024 Infomaniak Network SA | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.infomaniak.multiplatform_swisstransfer.managers | ||
|
||
import com.infomaniak.multiplatform_swisstransfer.database.RealmProvider | ||
import com.infomaniak.multiplatform_swisstransfer.database.cache.setting.AppSettingsController | ||
import com.infomaniak.multiplatform_swisstransfer.database.cache.setting.TransfersController | ||
import com.infomaniak.multiplatform_swisstransfer.database.cache.setting.UploadController | ||
import com.infomaniak.multiplatform_swisstransfer.utils.Constants | ||
|
||
class AccountManager internal constructor( | ||
private val appSettingsController: AppSettingsController, | ||
private val uploadController: UploadController, | ||
private val transfersController: TransfersController, | ||
private val realmProvider: RealmProvider, | ||
) { | ||
|
||
/** | ||
* Loads the default User account and initializes Realm Transfers for the default UserId defined in Constants. | ||
*/ | ||
@Throws(IllegalArgumentException::class, IllegalStateException::class) | ||
suspend fun loadUser(userId: Int) { | ||
appSettingsController.initAppSettings() | ||
realmProvider.loadRealmTransfers(Constants.DEFAULT_USER_ID) | ||
} | ||
|
||
/** | ||
* Delete specified User data | ||
*/ | ||
@Throws(IllegalArgumentException::class, IllegalStateException::class) | ||
suspend fun removeUser(userId: Int) { | ||
|
||
// TODO: If we are removing the last User, we also need to delete AppSettings data. | ||
// if (users.count() == 1) appSettingsController.removeData() | ||
|
||
uploadController.removeData() | ||
transfersController.removeData() | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
.../com/infomaniak/multiplatform_swisstransfer/database/cache/setting/TransfersController.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,42 @@ | ||
/* | ||
* Infomaniak SwissTransfer - Multiplatform | ||
* Copyright (C) 2024 Infomaniak Network SA | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.infomaniak.multiplatform_swisstransfer.database.cache.setting | ||
|
||
import com.infomaniak.multiplatform_swisstransfer.database.RealmProvider | ||
import com.infomaniak.multiplatform_swisstransfer.database.models.transfers.TransferDB | ||
import io.realm.kotlin.ext.query | ||
import io.realm.kotlin.query.RealmResults | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlin.coroutines.cancellation.CancellationException | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
class TransfersController(private val realmProvider: RealmProvider) { | ||
|
||
private val realm by lazy { realmProvider.realmTransfers } | ||
|
||
//region Get data | ||
fun getTransfers(): RealmResults<TransferDB>? = realm?.query<TransferDB>()?.find() | ||
//endregion | ||
|
||
//region Update data | ||
@Throws(IllegalArgumentException::class, CancellationException::class) | ||
suspend fun removeData() { | ||
realm?.write { deleteAll() } | ||
} | ||
//endregion | ||
} |
42 changes: 42 additions & 0 deletions
42
...lin/com/infomaniak/multiplatform_swisstransfer/database/cache/setting/UploadController.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,42 @@ | ||
/* | ||
* Infomaniak SwissTransfer - Multiplatform | ||
* Copyright (C) 2024 Infomaniak Network SA | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.infomaniak.multiplatform_swisstransfer.database.cache.setting | ||
|
||
import com.infomaniak.multiplatform_swisstransfer.database.RealmProvider | ||
import com.infomaniak.multiplatform_swisstransfer.database.models.upload.Upload | ||
import io.realm.kotlin.ext.query | ||
import io.realm.kotlin.query.RealmResults | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlin.coroutines.cancellation.CancellationException | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
class UploadController(private val realmProvider: RealmProvider) { | ||
|
||
private val realm by lazy { realmProvider.realmUploads } | ||
|
||
//region Get data | ||
fun getUploads(): RealmResults<Upload> = realm.query<Upload>().find() | ||
//endregion | ||
|
||
//region Update data | ||
@Throws(IllegalArgumentException::class, CancellationException::class) | ||
suspend fun removeData() { | ||
realm.write { deleteAll() } | ||
} | ||
//endregion | ||
} |
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
42 changes: 42 additions & 0 deletions
42
...in/com/infomaniak/multiplatform_swisstransfer/database/models/upload/UploadContainerDB.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,42 @@ | ||
/* | ||
* Infomaniak SwissTransfer - Multiplatform | ||
* Copyright (C) 2024 Infomaniak Network SA | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.infomaniak.multiplatform_swisstransfer.database.models.upload | ||
|
||
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.UploadContainer | ||
import io.realm.kotlin.types.EmbeddedRealmObject | ||
|
||
class UploadContainerDB : UploadContainer, EmbeddedRealmObject { | ||
|
||
override var uuid: String = "" | ||
|
||
override var duration: String = "" | ||
override var downloadLimit: Long = 0 | ||
override var lang: String = "" | ||
override var source: String = "" | ||
|
||
override var wsUser: String? = null | ||
|
||
override var authorIP: String = "" | ||
override var swiftVersion: String = "" | ||
|
||
// var createdDate: String // TODO: Why a complex date instead of a simple date ? May be Custom serial this | ||
override var expiredDateTimestamp: Long = 0 | ||
override var needPassword: Boolean = false | ||
override var message: String = "" | ||
override var numberOfFiles: Long = 0 | ||
} |