Skip to content

Commit 1000c82

Browse files
committed
fix: git conflict
Signed-off-by: alperozturk <alper_ozturk@proton.me>
1 parent f03f517 commit 1000c82

5 files changed

Lines changed: 78 additions & 27 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Nextcloud - Android Client
3+
*
4+
* SPDX-FileCopyrightText: 2025 Alper Ozturk <alper.ozturk@nextcloud.com>
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
package com.nextcloud.client.database.dao
9+
10+
import androidx.room.Dao
11+
import androidx.room.Query
12+
import com.nextcloud.client.database.entity.SyncedFolderEntity
13+
import com.owncloud.android.db.ProviderMeta
14+
15+
@Dao
16+
interface SyncedFolderDao {
17+
@Query(
18+
"""
19+
SELECT * FROM ${ProviderMeta.ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME}
20+
WHERE ${ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH} = :localPath
21+
AND ${ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ACCOUNT} = :account
22+
LIMIT 1
23+
"""
24+
)
25+
fun findByLocalPathAndAccount(localPath: String, account: String): SyncedFolderEntity?
26+
}

app/src/main/java/com/nextcloud/client/database/entity/SyncedFolderEntity.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ package com.nextcloud.client.database.entity
1010
import androidx.room.ColumnInfo
1111
import androidx.room.Entity
1212
import androidx.room.PrimaryKey
13+
import com.nextcloud.client.preferences.SubFolderRule
14+
import com.owncloud.android.datamodel.MediaFolderType
15+
import com.owncloud.android.datamodel.SyncedFolder
1316
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta
1417

1518
@Entity(tableName = ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME)
@@ -50,3 +53,40 @@ data class SyncedFolderEntity(
5053
@ColumnInfo(name = ProviderTableMeta.SYNCED_FOLDER_LAST_SCAN_TIMESTAMP_MS)
5154
val lastScanTimestampMs: Long?
5255
)
56+
57+
fun SyncedFolderEntity.toSyncedFolder(): SyncedFolder = SyncedFolder(
58+
// id
59+
(this.id ?: SyncedFolder.UNPERSISTED_ID).toLong(),
60+
// localPath
61+
this.localPath ?: "",
62+
// remotePath
63+
this.remotePath ?: "",
64+
// wifiOnly
65+
this.wifiOnly == 1,
66+
// chargingOnly
67+
this.chargingOnly == 1,
68+
// existing
69+
this.existing == 1,
70+
// subfolderByDate
71+
this.subfolderByDate == 1,
72+
// account
73+
this.account ?: "",
74+
// uploadAction
75+
this.uploadAction ?: 0,
76+
// nameCollisionPolicy
77+
this.nameCollisionPolicy ?: 0,
78+
// enabled
79+
this.enabled == 1,
80+
// timestampMs
81+
(this.enabledTimestampMs ?: SyncedFolder.EMPTY_ENABLED_TIMESTAMP_MS).toLong(),
82+
// type
83+
MediaFolderType.getById(this.type ?: MediaFolderType.CUSTOM.id),
84+
// hidden
85+
this.hidden == 1,
86+
// subFolderRule
87+
this.subFolderRule?.let { SubFolderRule.entries[it] },
88+
// excludeHidden
89+
this.excludeHidden == 1,
90+
// lastScanTimestampMs
91+
this.lastScanTimestampMs ?: SyncedFolder.NOT_SCANNED_YET
92+
)

app/src/main/java/com/nextcloud/client/jobs/autoUpload/FileSystemRepository.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class FileSystemRepository(private val dao: FileSystemDao) {
2020
const val BATCH_SIZE = 50
2121
}
2222

23+
@Suppress("NestedBlockDepth")
2324
suspend fun getFilePathsWithIds(syncedFolder: SyncedFolder, lastId: Int): List<Pair<String, Int>> {
2425
val syncedFolderId = syncedFolder.id.toString()
2526
Log_OC.d(TAG, "Fetching candidate files for syncedFolderId = $syncedFolderId")

app/src/main/java/com/owncloud/android/datamodel/SyncedFolder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public SyncedFolder(String localPath,
108108
*
109109
* @param id id
110110
*/
111-
protected SyncedFolder(long id,
111+
public SyncedFolder(long id,
112112
String localPath,
113113
String remotePath,
114114
boolean wifiOnly,

app/src/main/java/com/owncloud/android/datamodel/SyncedFolderProvider.java

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@
1515

1616
import com.nextcloud.client.account.User;
1717
import com.nextcloud.client.core.Clock;
18+
import com.nextcloud.client.database.NextcloudDatabase;
19+
import com.nextcloud.client.database.dao.SyncedFolderDao;
20+
import com.nextcloud.client.database.entity.SyncedFolderEntity;
21+
import com.nextcloud.client.database.entity.SyncedFolderEntityKt;
1822
import com.nextcloud.client.preferences.AppPreferences;
1923
import com.nextcloud.client.preferences.AppPreferencesImpl;
2024
import com.nextcloud.client.preferences.SubFolderRule;
25+
import com.owncloud.android.MainApp;
2126
import com.owncloud.android.db.ProviderMeta;
2227
import com.owncloud.android.lib.common.utils.Log_OC;
2328
import com.owncloud.android.lib.resources.files.model.ServerFileInterface;
@@ -42,6 +47,7 @@ public class SyncedFolderProvider extends Observable {
4247
private final ContentResolver mContentResolver;
4348
private final AppPreferences preferences;
4449
private final Clock clock;
50+
public final SyncedFolderDao dao = NextcloudDatabase.getInstance(MainApp.getAppContext()).syncedFolderDao();
4551

4652
/**
4753
* constructor.
@@ -183,33 +189,11 @@ public int updateSyncedFolderEnabled(long id, Boolean enabled) {
183189
}
184190

185191
public SyncedFolder findByLocalPathAndAccount(String localPath, User user) {
186-
SyncedFolder result = null;
187-
Cursor cursor = mContentResolver.query(
188-
ProviderMeta.ProviderTableMeta.CONTENT_URI_SYNCED_FOLDERS,
189-
null,
190-
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH + " LIKE ? AND " +
191-
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ACCOUNT + " =? ",
192-
new String[]{localPath + "%", user.getAccountName()},
193-
null
194-
);
195-
196-
if (cursor != null && cursor.getCount() == 1) {
197-
result = createSyncedFolderFromCursor(cursor);
198-
} else {
199-
if (cursor == null) {
200-
Log_OC.e(TAG, "Sync folder db cursor for local path=" + localPath + " in NULL.");
201-
} else {
202-
Log_OC.e(TAG, cursor.getCount() + " items for local path=" + localPath
203-
+ " available in sync folder db. Expected 1. Failed to update sync folder db.");
204-
}
205-
}
206-
207-
if (cursor != null) {
208-
cursor.close();
192+
final SyncedFolderEntity entity = dao.findByLocalPathAndAccount(localPath, user.getAccountName());
193+
if (entity == null) {
194+
return null;
209195
}
210-
211-
return result;
212-
196+
return SyncedFolderEntityKt.toSyncedFolder(entity);
213197
}
214198

215199
@Nullable

0 commit comments

Comments
 (0)