Archiving Sync

This commit is contained in:
soraefir
2026-09-02 23:12:08 +02:00
parent e2d9088dea
commit 4c2edc77ca
7 changed files with 83 additions and 106 deletions
@@ -415,16 +415,8 @@ class EditBillActivity : AppCompatActivity() {
val proj = db.getProject(bill.projectId)
if (proj != null) db.syncIfRemote(proj)
db.updateProject(
bill.projectId,
null,
null,
null,
viewModel.payerId,
null,
null,
null,
null,
null
projId = bill.projectId,
newLastPayerId = viewModel.payerId
)
return@withContext firstSavedId
@@ -468,16 +460,8 @@ class EditBillActivity : AppCompatActivity() {
newOwersIds.forEach { newBill.billOwers += DBBillOwer(0, 0, it) }
val newBillId = db.addBill(newBill)
db.updateProject(
bill.projectId,
null,
null,
null,
viewModel.payerId,
null,
null,
null,
null,
null
projId = bill.projectId,
newLastPayerId = viewModel.payerId
)
val proj = db.getProject(bill.projectId)
if (proj != null) db.syncIfRemote(proj)
@@ -84,9 +84,8 @@ class ManageCurrenciesActivity : AppCompatActivity() {
lifecycleScope.launch {
withContext(Dispatchers.IO) {
db!!.updateProject(
selectedProjectID, null, null, null,
null, null, newMainCurrencyName,
null, null, null
projId = selectedProjectID,
newCurrencyName = newMainCurrencyName
)
val project = db!!.getProject(selectedProjectID)
if (project != null) {
@@ -94,7 +93,12 @@ class ManageCurrenciesActivity : AppCompatActivity() {
if (project.type == ProjectType.COSPEND) {
withContext(Dispatchers.Main) {
if (!db!!.cowspentServerSyncHelper
.editRemoteProject(selectedProjectID, project.name, null, null, newMainCurrencyName, editMainCurrencyCallBack)
.editRemoteProject(
projId = selectedProjectID,
newName = project.name,
newMainCurrencyName = newMainCurrencyName,
callback = editMainCurrencyCallBack
)
) {
showToast(this@ManageCurrenciesActivity, getString(R.string.remote_project_operation_no_network), Toast.LENGTH_LONG)
}
@@ -427,19 +427,26 @@ class BillsListViewActivity :
withContext(Dispatchers.IO) {
db.updateProject(
projId = projectId,
newName = null,
newEmail = null,
newPassword = null,
newLastPayerId = null,
newLastSyncedTimestamp = null,
newCurrencyName = null,
newDeletionDisabled = null,
newMyAccessLevel = null,
newBearerToken = null,
newArchivedTs = newArchivedTs
)
}
if (!proj.isLocal) {
db.cowspentServerSyncHelper.editRemoteProject(
projId = projectId,
newArchivedTs = newArchivedTs,
callback = object : ICallback {
override fun onFinish() {}
override fun onFinish(result: String, message: String) {
if (message.isNotEmpty()) {
showToast(this@BillsListViewActivity, getString(R.string.error_sync, message))
}
}
override fun onScheduled() {}
}
)
}
setupDrawerProjects()
refreshLists()
@@ -85,10 +85,11 @@ class EditProjectActivity : AppCompatActivity() {
lifecycleScope.launch {
withContext(Dispatchers.IO) {
db.updateProject(
project.id, newName, newEmail, targetPwd,
null, project.type, null,
null, null,
null, null
projId = project.id,
newName = newName,
newEmail = newEmail,
newPassword = targetPwd,
projectType = project.type
)
}
closeOnEdit(project.id)
@@ -103,18 +104,21 @@ class EditProjectActivity : AppCompatActivity() {
project.password = currentPwd
lifecycleScope.launch {
withContext(Dispatchers.IO) {
db.updateProject(project.id, null, null, currentPwd, null, project.type, null, null, null, null, null)
db.updateProject(
projId = project.id,
newPassword = currentPwd,
projectType = project.type
)
}
}
}
if (!db.cowspentServerSyncHelper.editRemoteProject(
project.id,
newName,
newEmail,
if (pwdChanged) newPwd else null,
null,
editCallBack
projId = project.id,
newName = newName,
newEmail = newEmail,
newPassword = if (pwdChanged) newPwd else null,
callback = editCallBack
)
) {
showToast(this, getString(R.string.remote_project_operation_no_network), Toast.LENGTH_LONG)
@@ -124,10 +128,9 @@ class EditProjectActivity : AppCompatActivity() {
lifecycleScope.launch {
withContext(Dispatchers.IO) {
db.updateProject(
project.id, null, null, currentPwd,
null, project.type, null,
null, null,
null, null
projId = project.id,
newPassword = currentPwd,
projectType = project.type
)
}
closeOnEdit(project.id)
@@ -271,12 +271,18 @@ class CowspentSQLiteOpenHelper private constructor(val context: Context) :
}
fun updateProject(
projId: Long, newName: String?, newEmail: String?,
newPassword: String?, newLastPayerId: Long?,
newLastSyncedTimestamp: Long?,
newCurrencyName: String?, newDeletionDisabled: Boolean?,
newMyAccessLevel: Int?, newBearerToken: String?,
newArchivedTs: Long? = null
projId: Long,
newName: String? = null,
newEmail: String? = null,
newPassword: String? = null,
newLastPayerId: Long? = null,
newLastSyncedTimestamp: Long? = null,
newCurrencyName: String? = null,
newDeletionDisabled: Boolean? = null,
newMyAccessLevel: Int? = null,
newBearerToken: String? = null,
newArchivedTs: Long? = null,
projectType: ProjectType? = null
) {
val db = writableDatabase
val values = ContentValues()
@@ -290,47 +296,7 @@ class CowspentSQLiteOpenHelper private constructor(val context: Context) :
if (newDeletionDisabled != null) values.put(key_deletionDisabled, if (newDeletionDisabled) 1 else 0)
if (newMyAccessLevel != null) values.put(key_myAccessLevel, newMyAccessLevel)
if (newArchivedTs != null) values.put(key_archived, newArchivedTs)
if (values.size() > 0) {
db.update(table_projects, values, "$key_id = ?", arrayOf(projId.toString()))
}
}
fun updateProject(
projId: Long, newName: String?, newEmail: String?,
newPassword: String?, newLastPayerId: Long?,
projectType: ProjectType, newLastSyncedTimestamp: Long?,
newCurrencyName: String?, newDeletionDisabled: Boolean?,
newMyAccessLevel: Int?, newBearerToken: String?,
newArchivedTs: Long? = null
) {
val db = writableDatabase
updateProject(
projId, newName, newEmail, newPassword, newLastPayerId, projectType,
newLastSyncedTimestamp, newCurrencyName, newDeletionDisabled, newMyAccessLevel,
newBearerToken, newArchivedTs, db
)
}
private fun updateProject(
projId: Long, newName: String?, newEmail: String?,
newPassword: String?, newLastPayerId: Long?,
projectType: ProjectType, newLastSyncedTimestamp: Long?,
newCurrencyName: String?, newDeletionDisabled: Boolean?,
newMyAccessLevel: Int?, newBearerToken: String?,
newArchivedTs: Long?, db: SQLiteDatabase
) {
val values = ContentValues()
if (newName != null) values.put(key_name, newName)
if (newEmail != null) values.put(key_email, newEmail)
if (newPassword != null) SecureStorage.savePasswordSync(context, "ProjectPassword_$projId", newPassword)
if (newBearerToken != null) values.put(key_bearer_token, newBearerToken)
if (newLastPayerId != null) values.put(key_lastPayerId, newLastPayerId)
if (newLastSyncedTimestamp != null) values.put(key_lastSyncTimestamp, newLastSyncedTimestamp)
if (newCurrencyName != null) values.put(key_currencyName, newCurrencyName)
if (newDeletionDisabled != null) values.put(key_deletionDisabled, if (newDeletionDisabled) 1 else 0)
if (newMyAccessLevel != null) values.put(key_myAccessLevel, newMyAccessLevel)
if (newArchivedTs != null) values.put(key_archived, newArchivedTs)
values.put(key_type, projectType.id)
if (projectType != null) values.put(key_type, projectType.id)
if (values.size() > 0) {
db.update(table_projects, values, "$key_id = ?", arrayOf(projId.toString()))
}
@@ -817,10 +817,8 @@ class CowspentServerSyncHelper private constructor(private val dbHelper: Cowspen
}
dbHelper.updateProject(
project.id, null, null,
null, null, serverSyncTimestamp,
null, null, null,
null
projId = project.id,
newLastSyncedTimestamp = serverSyncTimestamp
)
LoginStatus.OK
} catch (_: ServerResponse.NotModifiedException) {
@@ -935,11 +933,18 @@ class CowspentServerSyncHelper private constructor(private val dbHelper: Cowspen
return isCospend && projUrl == accountUrl
}
fun editRemoteProject(projId: Long, newName: String?, newEmail: String?,
newPassword: String?, newMainCurrencyName: String?, callback: ICallback): Boolean {
fun editRemoteProject(
projId: Long,
newName: String? = null,
newEmail: String? = null,
newPassword: String? = null,
newMainCurrencyName: String? = null,
newArchivedTs: Long? = null,
callback: ICallback
): Boolean {
updateNetworkStatus()
if (isSyncPossible) {
EditRemoteProjectTask(projId, newName, newEmail, newPassword, newMainCurrencyName, callback).execute()
EditRemoteProjectTask(projId, newName, newEmail, newPassword, newMainCurrencyName, newArchivedTs, callback).execute()
return true
}
return false
@@ -951,6 +956,7 @@ class CowspentServerSyncHelper private constructor(private val dbHelper: Cowspen
private val newEmail: String?,
private val newPassword: String?,
private val newMainCurrencyName: String?,
private val newArchivedTs: Long?,
private val callback: ICallback
) {
private val project: DBProject? = dbHelper.getProject(projId)
@@ -985,7 +991,7 @@ class CowspentServerSyncHelper private constructor(private val dbHelper: Cowspen
var status = LoginStatus.OK
try {
val response = client!!.editRemoteProject(
project!!, newName, newEmail, newPassword, newMainCurrencyName
project!!, newName, newEmail, newPassword, newMainCurrencyName, newArchivedTs
)
if (BillsListViewActivity.DEBUG) {
Log.i(TAG, "RESPONSE edit remote project : ${response.stringContent}")
@@ -1025,8 +1031,11 @@ class CowspentServerSyncHelper private constructor(private val dbHelper: Cowspen
}
} else {
dbHelper.updateProject(
project!!.id, newName, newEmail, newPassword,
null, null, null, null, null, null
projId = project!!.id,
newName = newName,
newEmail = newEmail,
newPassword = newPassword,
newArchivedTs = newArchivedTs
)
}
callback.onFinish(newName ?: "", errorString)
@@ -114,7 +114,7 @@ class VersatileProjectSyncClient(
@Throws(IOException::class, TokenMismatchException::class, NextcloudHttpRequestFailedException::class)
fun editRemoteProject(
project: DBProject, newName: String?, newEmail: String?, newPassword: String?,
newMainCurrencyName: String?
newMainCurrencyName: String?, newArchivedTs: Long? = null
): ServerResponse.EditRemoteProjectResponse {
val paramKeys: MutableList<String> = ArrayList()
val paramValues: MutableList<String> = ArrayList()
@@ -130,6 +130,10 @@ class VersatileProjectSyncClient(
paramKeys.add("password")
paramValues.add(newPassword)
}
if (newArchivedTs != null) {
paramKeys.add("archived_ts")
paramValues.add(newArchivedTs.toString())
}
var target: String
var username: String? = null