Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra options for uploading subfolders #11852

Merged
merged 10 commits into from
Aug 30, 2023
1,155 changes: 1,155 additions & 0 deletions app/schemas/com.nextcloud.client.database.NextcloudDatabase/73.json

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.app.Activity;
import android.content.Intent;

import com.nextcloud.client.preferences.SubFolderRule;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.datamodel.MediaFolderType;
import com.owncloud.android.datamodel.SyncedFolderDisplayItem;
Expand Down Expand Up @@ -72,7 +73,8 @@ public void testSyncedFolderDialog() {
1000,
"Name",
MediaFolderType.IMAGE,
false);
false,
SubFolderRule.YEAR_MONTH);
SyncedFolderPreferencesDialogFragment sut = SyncedFolderPreferencesDialogFragment.newInstance(item, 0);

Intent intent = new Intent(targetContext, SyncedFoldersActivity.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package com.owncloud.android.utils

import com.nextcloud.client.preferences.SubFolderRule
import com.owncloud.android.AbstractIT
import com.owncloud.android.datamodel.MediaFolder
import com.owncloud.android.datamodel.MediaFolderType
Expand Down Expand Up @@ -185,7 +186,8 @@ class SyncedFolderUtilsTest : AbstractIT() {
true,
0L,
MediaFolderType.IMAGE,
false
false,
SubFolderRule.YEAR_MONTH
)
Assert.assertFalse(SyncedFolderUtils.isQualifyingMediaFolder(folder))
}
Expand All @@ -207,7 +209,8 @@ class SyncedFolderUtilsTest : AbstractIT() {
true,
0L,
MediaFolderType.IMAGE,
false
false,
SubFolderRule.YEAR_MONTH
)
Assert.assertFalse(SyncedFolderUtils.isQualifyingMediaFolder(folder))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ import com.owncloud.android.db.ProviderMeta
AutoMigration(from = 66, to = 67),
AutoMigration(from = 68, to = 69),
AutoMigration(from = 69, to = 70),
AutoMigration(from = 71, to = 72)
AutoMigration(from = 71, to = 72),
AutoMigration(from = 72, to = 73)
],
exportSchema = true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@ data class SyncedFolderEntity(
@ColumnInfo(name = ProviderTableMeta.SYNCED_FOLDER_TYPE)
val type: Int?,
@ColumnInfo(name = ProviderTableMeta.SYNCED_FOLDER_HIDDEN)
val hidden: Int?
val hidden: Int?,
@ColumnInfo(name = ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_RULE)
val subFolderRule: Int?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one (new column, so no auto migration, right @tobiasKaminsky ?

)
7 changes: 6 additions & 1 deletion app/src/main/java/com/nextcloud/client/jobs/FilesSyncWork.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import androidx.work.WorkerParameters
import com.nextcloud.client.account.UserAccountManager
import com.nextcloud.client.device.PowerManagementService
import com.nextcloud.client.network.ConnectivityService
import com.nextcloud.client.preferences.SubFolderRule
import com.owncloud.android.R
import com.owncloud.android.datamodel.ArbitraryDataProvider
import com.owncloud.android.datamodel.ArbitraryDataProviderImpl
Expand Down Expand Up @@ -203,20 +204,24 @@ class FilesSyncWork(
val lastModificationTime = calculateLastModificationTime(file, syncedFolder, sFormatter)
val remoteFolder: String
val useSubfolders: Boolean
val subFolderRule: SubFolderRule
if (lightVersion) {
useSubfolders = resources.getBoolean(R.bool.syncedFolder_light_use_subfolders)
remoteFolder = resources.getString(R.string.syncedFolder_remote_folder)
subFolderRule = SubFolderRule.YEAR_MONTH
} else {
useSubfolders = syncedFolder.isSubfolderByDate
remoteFolder = syncedFolder.remotePath
subFolderRule = syncedFolder.subfolderRule
}
return FileStorageUtils.getInstantUploadFilePath(
file,
currentLocale,
remoteFolder,
syncedFolder.localPath,
lastModificationTime,
useSubfolders
useSubfolders,
subFolderRule
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Nextcloud Android client application
*
* @author Dean Birch
* Copyright (C) 2023 Dean Birch
* Copyright (C) 2023 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.nextcloud.client.preferences

enum class SubFolderRule {
YEAR_MONTH, YEAR, YEAR_MONTH_DAY
}
18 changes: 15 additions & 3 deletions app/src/main/java/com/owncloud/android/datamodel/SyncedFolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package com.owncloud.android.datamodel;

import com.nextcloud.client.preferences.SubFolderRule;
import com.owncloud.android.files.services.NameCollisionPolicy;

import java.io.Serializable;
Expand All @@ -33,6 +34,8 @@ public class SyncedFolder implements Serializable, Cloneable {
public static final long EMPTY_ENABLED_TIMESTAMP_MS = -1;
private static final long serialVersionUID = -793476118299906429L;



private long id;
private String localPath;
private String remotePath;
Expand All @@ -47,6 +50,7 @@ public class SyncedFolder implements Serializable, Cloneable {
private long enabledTimestampMs;
private MediaFolderType type;
private boolean hidden;
private SubFolderRule subfolderRule;

/**
* constructor for new, to be persisted entity.
Expand Down Expand Up @@ -77,7 +81,8 @@ public SyncedFolder(String localPath,
boolean enabled,
long timestampMs,
MediaFolderType type,
boolean hidden) {
boolean hidden,
SubFolderRule subFolderRule) {
this(UNPERSISTED_ID,
localPath,
remotePath,
Expand All @@ -91,7 +96,8 @@ public SyncedFolder(String localPath,
enabled,
timestampMs,
type,
hidden);
hidden,
subFolderRule);
}

/**
Expand All @@ -112,7 +118,8 @@ protected SyncedFolder(long id,
boolean enabled,
long timestampMs,
MediaFolderType type,
boolean hidden) {
boolean hidden,
SubFolderRule subFolderRule) {
this.id = id;
this.localPath = localPath;
this.remotePath = remotePath;
Expand All @@ -126,6 +133,7 @@ protected SyncedFolder(long id,
this.setEnabled(enabled, timestampMs);
this.type = type;
this.hidden = hidden;
this.subfolderRule = subFolderRule;
}

/**
Expand Down Expand Up @@ -204,6 +212,8 @@ public boolean isHidden() {
return this.hidden;
}

public SubFolderRule getSubfolderRule() { return this.subfolderRule; }

public void setId(long id) {
this.id = id;
}
Expand Down Expand Up @@ -251,4 +261,6 @@ public void setType(MediaFolderType type) {
public void setHidden(boolean hidden) {
this.hidden = hidden;
}

public void setSubFolderRule(SubFolderRule subFolderRule) { this.subfolderRule = subFolderRule; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

package com.owncloud.android.datamodel;

import com.nextcloud.client.preferences.SubFolderRule;

import java.util.List;

/**
Expand All @@ -32,6 +34,7 @@ public class SyncedFolderDisplayItem extends SyncedFolder {
private String folderName;
private long numberOfFiles;


/**
* constructor for the display item specialization for a synced folder object.
*
Expand All @@ -50,6 +53,7 @@ public class SyncedFolderDisplayItem extends SyncedFolder {
* @param numberOfFiles the UI info for number of files within the folder
* @param type the type of the folder
* @param hidden hide item flag
* @param subFolderRule whether to filter subFolder by year/month/day
*/
public SyncedFolderDisplayItem(long id,
String localPath,
Expand All @@ -67,7 +71,8 @@ public SyncedFolderDisplayItem(long id,
String folderName,
long numberOfFiles,
MediaFolderType type,
boolean hidden) {
boolean hidden,
SubFolderRule subFolderRule) {
super(id,
localPath,
remotePath,
Expand All @@ -81,7 +86,8 @@ public SyncedFolderDisplayItem(long id,
enabled,
timestampMs,
type,
hidden);
hidden,
subFolderRule);
this.filePaths = filePaths;
this.folderName = folderName;
this.numberOfFiles = numberOfFiles;
Expand All @@ -101,7 +107,8 @@ public SyncedFolderDisplayItem(long id,
long timestampMs,
String folderName,
MediaFolderType type,
boolean hidden) {
boolean hidden,
SubFolderRule subFolderRule) {
super(id,
localPath,
remotePath,
Expand All @@ -115,7 +122,8 @@ public SyncedFolderDisplayItem(long id,
enabled,
timestampMs,
type,
hidden);
hidden,
subFolderRule);
this.folderName = folderName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.nextcloud.client.core.Clock;
import com.nextcloud.client.preferences.AppPreferences;
import com.nextcloud.client.preferences.AppPreferencesImpl;
import com.nextcloud.client.preferences.SubFolderRule;
import com.owncloud.android.db.ProviderMeta;
import com.owncloud.android.lib.common.utils.Log_OC;

Expand Down Expand Up @@ -361,6 +362,9 @@ private SyncedFolder createSyncedFolderFromCursor(Cursor cursor) {
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_TYPE)));
boolean hidden = cursor.getInt(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_HIDDEN)) == 1;
SubFolderRule subFolderRule = SubFolderRule.values()[cursor.getInt(
cursor.getColumnIndexOrThrow(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_RULE))];


syncedFolder = new SyncedFolder(id,
localPath,
Expand All @@ -375,7 +379,8 @@ private SyncedFolder createSyncedFolderFromCursor(Cursor cursor) {
enabled,
enabledTimestampMs,
type,
hidden);
hidden,
subFolderRule);
}
return syncedFolder;
}
Expand Down Expand Up @@ -403,6 +408,7 @@ private ContentValues createContentValuesFromSyncedFolder(SyncedFolder syncedFol
syncedFolder.getNameCollisionPolicyInt());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_TYPE, syncedFolder.getType().getId());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_HIDDEN, syncedFolder.isHidden());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_RULE, syncedFolder.getSubfolderRule().ordinal());

return cv;
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/owncloud/android/db/ProviderMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
public class ProviderMeta {
public static final String DB_NAME = "filelist";
public static final int DB_VERSION = 72;
public static final int DB_VERSION = 73;

private ProviderMeta() {
// No instance
Expand Down Expand Up @@ -292,6 +292,7 @@ static public class ProviderTableMeta implements BaseColumns {
public static final String SYNCED_FOLDER_UPLOAD_ACTION = "upload_option";
public static final String SYNCED_FOLDER_NAME_COLLISION_POLICY = "name_collision_policy";
public static final String SYNCED_FOLDER_HIDDEN = "hidden";
public static final String SYNCED_FOLDER_SUBFOLDER_RULE = "sub_folder_rule";

// Columns of external links table
public static final String EXTERNAL_LINKS_ICON_URL = "icon_url";
Expand Down
Loading