Skip to content

Commit

Permalink
add exclude hidden file or folder option when create custom media fol…
Browse files Browse the repository at this point in the history
…der type

Signed-off-by: JinWeiyang <[email protected]>
  • Loading branch information
BBBOND committed Dec 21, 2023
1 parent 14a6d65 commit 642287b
Show file tree
Hide file tree
Showing 18 changed files with 1,372 additions and 33 deletions.
1,185 changes: 1,185 additions & 0 deletions app/schemas/com.nextcloud.client.database.NextcloudDatabase/77.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public void testSyncedFolderDialog() {
"Name",
MediaFolderType.IMAGE,
false,
SubFolderRule.YEAR_MONTH);
SubFolderRule.YEAR_MONTH,
false);
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 @@ -187,7 +187,8 @@ class SyncedFolderUtilsTest : AbstractIT() {
0L,
MediaFolderType.IMAGE,
false,
SubFolderRule.YEAR_MONTH
SubFolderRule.YEAR_MONTH,
false
)
Assert.assertFalse(SyncedFolderUtils.isQualifyingMediaFolder(folder))
}
Expand All @@ -210,7 +211,8 @@ class SyncedFolderUtilsTest : AbstractIT() {
0L,
MediaFolderType.IMAGE,
false,
SubFolderRule.YEAR_MONTH
SubFolderRule.YEAR_MONTH,
false
)
Assert.assertFalse(SyncedFolderUtils.isQualifyingMediaFolder(folder))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ import com.owncloud.android.db.ProviderMeta
AutoMigration(from = 72, to = 73),
AutoMigration(from = 73, to = 74, spec = DatabaseMigrationUtil.ResetCapabilitiesPostMigration::class),
AutoMigration(from = 74, to = 75),
AutoMigration(from = 75, to = 76)
AutoMigration(from = 75, to = 76),
AutoMigration(from = 76, to = 77)
],
exportSchema = true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@ data class SyncedFolderEntity(
@ColumnInfo(name = ProviderTableMeta.SYNCED_FOLDER_HIDDEN)
val hidden: Int?,
@ColumnInfo(name = ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_RULE)
val subFolderRule: Int?
val subFolderRule: Int?,
@ColumnInfo(name = ProviderTableMeta.SYNCED_EXCLUDE_HIDDEN)
val excludeHidden: Int?
)
21 changes: 18 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 @@ -51,6 +51,7 @@ public class SyncedFolder implements Serializable, Cloneable {
private MediaFolderType type;
private boolean hidden;
private SubFolderRule subfolderRule;
private boolean excludeHidden;

/**
* constructor for new, to be persisted entity.
Expand All @@ -68,6 +69,8 @@ public class SyncedFolder implements Serializable, Cloneable {
* @param timestampMs the current timestamp in milliseconds
* @param type the type of the folder
* @param hidden hide item flag
* @param subFolderRule whether to filter subFolder by year/month/day
* @param excludeHidden exclude hidden file or folder, for {@link MediaFolderType#CUSTOM} only
*/
public SyncedFolder(String localPath,
String remotePath,
Expand All @@ -82,7 +85,8 @@ public SyncedFolder(String localPath,
long timestampMs,
MediaFolderType type,
boolean hidden,
SubFolderRule subFolderRule) {
SubFolderRule subFolderRule,
boolean excludeHidden) {
this(UNPERSISTED_ID,
localPath,
remotePath,
Expand All @@ -97,7 +101,8 @@ public SyncedFolder(String localPath,
timestampMs,
type,
hidden,
subFolderRule);
subFolderRule,
excludeHidden);
}

/**
Expand All @@ -119,7 +124,8 @@ protected SyncedFolder(long id,
long timestampMs,
MediaFolderType type,
boolean hidden,
SubFolderRule subFolderRule) {
SubFolderRule subFolderRule,
boolean excludeHidden) {
this.id = id;
this.localPath = localPath;
this.remotePath = remotePath;
Expand All @@ -134,6 +140,7 @@ protected SyncedFolder(long id,
this.type = type;
this.hidden = hidden;
this.subfolderRule = subFolderRule;
this.excludeHidden = excludeHidden;
}

/**
Expand Down Expand Up @@ -263,4 +270,12 @@ public void setHidden(boolean hidden) {
}

public void setSubFolderRule(SubFolderRule subFolderRule) { this.subfolderRule = subFolderRule; }

public boolean isExcludeHidden() {
return excludeHidden;
}

public void setExcludeHidden(boolean excludeHidden) {
this.excludeHidden = excludeHidden;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class SyncedFolderDisplayItem extends SyncedFolder {
* @param type the type of the folder
* @param hidden hide item flag
* @param subFolderRule whether to filter subFolder by year/month/day
* @param excludeHidden exclude hidden file or folder, for {@link MediaFolderType#CUSTOM} only
*/
public SyncedFolderDisplayItem(long id,
String localPath,
Expand All @@ -72,7 +73,8 @@ public SyncedFolderDisplayItem(long id,
long numberOfFiles,
MediaFolderType type,
boolean hidden,
SubFolderRule subFolderRule) {
SubFolderRule subFolderRule,
boolean excludeHidden) {
super(id,
localPath,
remotePath,
Expand All @@ -87,7 +89,8 @@ public SyncedFolderDisplayItem(long id,
timestampMs,
type,
hidden,
subFolderRule);
subFolderRule,
excludeHidden);
this.filePaths = filePaths;
this.folderName = folderName;
this.numberOfFiles = numberOfFiles;
Expand All @@ -108,7 +111,8 @@ public SyncedFolderDisplayItem(long id,
String folderName,
MediaFolderType type,
boolean hidden,
SubFolderRule subFolderRule) {
SubFolderRule subFolderRule,
boolean excludeHidden) {
super(id,
localPath,
remotePath,
Expand All @@ -123,7 +127,8 @@ public SyncedFolderDisplayItem(long id,
timestampMs,
type,
hidden,
subFolderRule);
subFolderRule,
excludeHidden);
this.folderName = folderName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ private SyncedFolder createSyncedFolderFromCursor(Cursor cursor) {
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_HIDDEN)) == 1;
SubFolderRule subFolderRule = SubFolderRule.values()[cursor.getInt(
cursor.getColumnIndexOrThrow(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_RULE))];
boolean excludeHidden = cursor.getInt(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.SYNCED_EXCLUDE_HIDDEN)) == 1;


syncedFolder = new SyncedFolder(id,
Expand All @@ -388,7 +390,8 @@ private SyncedFolder createSyncedFolderFromCursor(Cursor cursor) {
enabledTimestampMs,
type,
hidden,
subFolderRule);
subFolderRule,
excludeHidden);
}
return syncedFolder;
}
Expand Down Expand Up @@ -417,6 +420,7 @@ private ContentValues createContentValuesFromSyncedFolder(SyncedFolder syncedFol
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_TYPE, syncedFolder.getType().id);
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_HIDDEN, syncedFolder.isHidden());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_RULE, syncedFolder.getSubfolderRule().ordinal());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_EXCLUDE_HIDDEN, syncedFolder.isExcludeHidden());

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 = 76;
public static final int DB_VERSION = 77;

private ProviderMeta() {
// No instance
Expand Down Expand Up @@ -299,6 +299,7 @@ static public class ProviderTableMeta implements BaseColumns {
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";
public static final String SYNCED_EXCLUDE_HIDDEN = "exclude_hidden";

// Columns of external links table
public static final String EXTERNAL_LINKS_ICON_URL = "icon_url";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ class SyncedFoldersActivity :
files.size.toLong(),
syncedFolder.type,
syncedFolder.isHidden,
syncedFolder.subfolderRule
syncedFolder.subfolderRule,
syncedFolder.isExcludeHidden
)
}

Expand Down Expand Up @@ -433,7 +434,8 @@ class SyncedFoldersActivity :
mediaFolder.numberOfFiles,
mediaFolder.type,
syncedFolder.isHidden,
syncedFolder.subfolderRule
syncedFolder.subfolderRule,
syncedFolder.isExcludeHidden
)
}

Expand Down Expand Up @@ -462,7 +464,8 @@ class SyncedFoldersActivity :
mediaFolder.numberOfFiles,
mediaFolder.type,
false,
SubFolderRule.YEAR_MONTH
SubFolderRule.YEAR_MONTH,
false
)
}

Expand Down Expand Up @@ -554,7 +557,8 @@ class SyncedFoldersActivity :
null,
MediaFolderType.CUSTOM,
false,
SubFolderRule.YEAR_MONTH
SubFolderRule.YEAR_MONTH,
false
)
onSyncFolderSettingsClick(0, emptyCustomFolder)
} else {
Expand Down Expand Up @@ -670,7 +674,8 @@ class SyncedFoldersActivity :
File(syncedFolder.localPath).name,
syncedFolder.type,
syncedFolder.isHidden,
syncedFolder.subFolderRule
syncedFolder.subFolderRule,
syncedFolder.isExcludeHidden
)
saveOrUpdateSyncedFolder(newCustomFolder)
adapter.addSyncFolderItem(newCustomFolder)
Expand All @@ -688,7 +693,8 @@ class SyncedFoldersActivity :
syncedFolder.uploadAction,
syncedFolder.nameCollisionPolicy.serialize(),
syncedFolder.isEnabled,
syncedFolder.subFolderRule
syncedFolder.subFolderRule,
syncedFolder.isExcludeHidden
)
saveOrUpdateSyncedFolder(item)

Expand Down Expand Up @@ -759,6 +765,7 @@ class SyncedFoldersActivity :
* @param uploadAction upload action
* @param nameCollisionPolicy what to do on name collision
* @param enabled is sync enabled
* @param excludeHidden exclude hidden file or folder, for {@link MediaFolderType#CUSTOM} only
*/
@Suppress("LongParameterList")
private fun updateSyncedFolderItem(
Expand All @@ -773,7 +780,8 @@ class SyncedFoldersActivity :
uploadAction: Int,
nameCollisionPolicy: Int,
enabled: Boolean,
subFolderRule: SubFolderRule
subFolderRule: SubFolderRule,
excludeHidden: Boolean
) {
item.id = id
item.localPath = localPath
Expand All @@ -786,6 +794,7 @@ class SyncedFoldersActivity :
item.setNameCollisionPolicy(nameCollisionPolicy)
item.setEnabled(enabled, clock.currentTime)
item.setSubFolderRule(subFolderRule)
item.setExcludeHidden(excludeHidden)
}

override fun onRequestPermissionsResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,16 @@ class SyncedFolderPreferencesDialogFragment : DialogFragment(), Injectable {
// hide local folder chooser and delete for non-custom folders
binding.localFolderContainer.visibility = View.GONE
isNeutralButtonActive = false
binding.settingInstantUploadExcludeHiddenContainer.visibility = View.GONE
} else if (syncedFolder!!.id <= SyncedFolder.UNPERSISTED_ID) {
isNeutralButtonActive = false

// Hide delete/enabled for unpersisted custom folders
binding.syncEnabled.visibility = View.GONE

// Show exclude hidden checkbox when {@link MediaFolderType#CUSTOM}
binding.settingInstantUploadExcludeHiddenContainer.visibility = View.VISIBLE

// auto set custom folder to enabled
syncedFolder?.isEnabled = true

Expand All @@ -146,6 +150,10 @@ class SyncedFolderPreferencesDialogFragment : DialogFragment(), Injectable {
binding.btnPositive.isEnabled = false
} else {
binding.localFolderContainer.visibility = View.GONE
if (MediaFolderType.CUSTOM.id == syncedFolder!!.type.id) {
// Show exclude hidden checkbox when {@link MediaFolderType#CUSTOM}
binding.settingInstantUploadExcludeHiddenContainer.visibility = View.VISIBLE
}
}
}

Expand All @@ -156,7 +164,8 @@ class SyncedFolderPreferencesDialogFragment : DialogFragment(), Injectable {
binding.settingInstantUploadOnWifiCheckbox,
binding.settingInstantUploadOnChargingCheckbox,
binding.settingInstantUploadExistingCheckbox,
binding.settingInstantUploadPathUseSubfoldersCheckbox
binding.settingInstantUploadPathUseSubfoldersCheckbox,
binding.settingInstantUploadExcludeHiddenCheckbox
)

viewThemeUtils?.material?.colorMaterialButtonPrimaryTonal(binding.btnPositive)
Expand Down Expand Up @@ -209,6 +218,7 @@ class SyncedFolderPreferencesDialogFragment : DialogFragment(), Injectable {
binding.settingInstantUploadOnChargingCheckbox.isChecked = it.isChargingOnly
binding.settingInstantUploadExistingCheckbox.isChecked = it.isExisting
binding.settingInstantUploadPathUseSubfoldersCheckbox.isChecked = it.isSubfolderByDate
binding.settingInstantUploadExcludeHiddenCheckbox.isChecked = it.isExcludeHidden

binding.settingInstantUploadSubfolderRuleSpinner.setSelection(it.subFolderRule.ordinal)

Expand Down Expand Up @@ -311,6 +321,8 @@ class SyncedFolderPreferencesDialogFragment : DialogFragment(), Injectable {
binding.settingInstantUploadExistingContainer.alpha = alpha
binding.settingInstantUploadPathUseSubfoldersContainer.isEnabled = enable
binding.settingInstantUploadPathUseSubfoldersContainer.alpha = alpha
binding.settingInstantUploadExcludeHiddenContainer.isEnabled = enable
binding.settingInstantUploadExcludeHiddenContainer.alpha = alpha
binding.remoteFolderContainer.isEnabled = enable
binding.remoteFolderContainer.alpha = alpha
binding.localFolderContainer.isEnabled = enable
Expand All @@ -321,6 +333,7 @@ class SyncedFolderPreferencesDialogFragment : DialogFragment(), Injectable {
binding.settingInstantUploadOnChargingCheckbox.isEnabled = enable
binding.settingInstantUploadExistingCheckbox.isEnabled = enable
binding.settingInstantUploadPathUseSubfoldersCheckbox.isEnabled = enable
binding.settingInstantUploadExcludeHiddenCheckbox.isEnabled = enable
}

checkWritableFolder()
Expand Down Expand Up @@ -364,6 +377,10 @@ class SyncedFolderPreferencesDialogFragment : DialogFragment(), Injectable {
binding.settingInstantUploadSubfolderRuleContainer.visibility = View.GONE
}
}
binding.settingInstantUploadExcludeHiddenContainer.setOnClickListener {
syncedFolder.isExcludeHidden = !syncedFolder.isExcludeHidden
binding.settingInstantUploadExcludeHiddenCheckbox.toggle()
}
binding.settingInstantUploadSubfolderRuleSpinner.onItemSelectedListener =
object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(adapterView: AdapterView<*>?, view: View, i: Int, l: Long) {
Expand Down
Loading

0 comments on commit 642287b

Please sign in to comment.