Archiving Sync

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