Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ default void onDarkThemeModeChanged(DarkMode mode) {

boolean isShowHiddenFilesEnabled();
void setShowHiddenFilesEnabled(boolean enabled);


boolean isShowRecommendationsEnabled();
void setShowRecommendationsEnabled(boolean enabled);

boolean isSortFoldersBeforeFiles();
void setSortFoldersBeforeFiles(boolean enabled);

boolean isSortFavoritesFirst();
void setSortFavoritesFirst(boolean enabled);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public final class AppPreferencesImpl implements AppPreferences {
private static final String PREF__INSTANT_UPLOADING = "instant_uploading";
private static final String PREF__INSTANT_VIDEO_UPLOADING = "instant_video_uploading";
private static final String PREF__SHOW_HIDDEN_FILES = "show_hidden_files_pref";
private static final String PREF__SHOW_RECOMMENDATIONS = "show_recommendations_pref";
private static final String PREF__SORT_FOLDERS_BEFORE_FILES = "sort_folders_before_files";
private static final String PREF__SORT_FAVORITES_FIRST = "sort_favorites_first";
private static final String PREF__SHOW_ECOSYSTEM_APPS = "show_ecosystem_apps";
Expand Down Expand Up @@ -247,6 +248,16 @@ public void setShowHiddenFilesEnabled(boolean enabled) {
preferences.edit().putBoolean(PREF__SHOW_HIDDEN_FILES, enabled).apply();
}

@Override
public boolean isShowRecommendationsEnabled() {
return preferences.getBoolean(PREF__SHOW_RECOMMENDATIONS, true);
}

@Override
public void setShowRecommendationsEnabled(boolean enabled) {
preferences.edit().putBoolean(PREF__SHOW_RECOMMENDATIONS, enabled).apply();
}

@Override
public boolean isSortFoldersBeforeFiles() {
return preferences.getBoolean(PREF__SORT_FOLDERS_BEFORE_FILES, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ class FileDisplayActivity :

if (SettingsActivity.isBackPressed) {
Log_OC.d(TAG, "User returned from settings activity, skipping reset content logic")
updateRecommendationsVisibilityAfterSettings()
return
}

Expand Down Expand Up @@ -1712,7 +1713,12 @@ class FileDisplayActivity :

private fun fetchRecommendedFilesIfNeeded(ignoreETag: Boolean, folder: OCFile?) {
val capability = capabilities.orElse(null) ?: return
if (folder?.isRootDirectory == false || capability.recommendations.isFalse) return
if (!preferences.isShowRecommendationsEnabled ||
folder?.isRootDirectory == false ||
capability.recommendations.isFalse
) {
return
}

val accountName = user.orElse(null)?.accountName ?: return
val fileList = listOfFilesFragment
Expand All @@ -1724,6 +1730,16 @@ class FileDisplayActivity :
}
}

private fun updateRecommendationsVisibilityAfterSettings() {
val fileList = listOfFilesFragment ?: return
val folder = fileList.currentFile ?: return
if (preferences.isShowRecommendationsEnabled) {
fetchRecommendedFilesIfNeeded(ignoreETag = false, folder = folder)
} else {
fileList.adapter?.updateRecommendedFiles(emptyList())
}
}

private fun startMetadataSyncForRoot() {
backgroundJobManager.startMetadataSyncJob(OCFile.ROOT_PATH, folderAlreadySynced = true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -786,10 +786,20 @@ private void setupFilesCategory() {
boolean fShowHiddenFilesEnabled = getResources().getBoolean(R.bool.show_hidden_files_enabled);

setupHiddenFilesPreference(preferenceCategoryDetails, fShowHiddenFilesEnabled);
setupShowRecommendationsPreference();
setupFoldersBeforeFilesPreference();
setupSortFavoritesFirstPreference();
}

private void setupShowRecommendationsPreference() {
ThemeableSwitchPreference showRecommendations =
(ThemeableSwitchPreference) findPreference("show_recommendations_pref");
showRecommendations.setOnPreferenceClickListener(preference -> {
preferences.setShowRecommendationsEnabled(showRecommendations.isChecked());
return true;
});
}

private void setupShowMediaScanNotifications(PreferenceCategory preferenceCategoryDetails,
boolean fShowMediaScanNotifications) {
ThemeableSwitchPreference mShowMediaScanNotifications =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,11 @@ class OCFileListAdapter(
}
}

private fun shouldShowRecommendedFiles(): Boolean =
recommendedFiles.isNotEmpty() && currentDirectory?.isRootDirectory == true
private fun shouldShowRecommendedFiles(): Boolean = shouldDisplayRecommendedFiles(
preferences.isShowRecommendationsEnabled,
recommendedFiles,
currentDirectory
)

private fun visibleRecommendedFilesAdapterFor(file: OCFile): RecommendedFilesAdapter? =
recommendedFilesAdapter?.takeIf { shouldShowRecommendedFiles() && file.isRecommendedFile }
Expand All @@ -674,3 +677,11 @@ class OCFileListAdapter(
private const val FOOTER_ITEM_COUNT = 1
}
}

internal fun shouldDisplayRecommendedFiles(
showRecommendations: Boolean,
recommendations: List<OCFile>,
currentDirectory: OCFile?
): Boolean = showRecommendations &&
recommendations.isNotEmpty() &&
currentDirectory?.isRootDirectory == true
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
<string name="prefs_lock_device_credentials_enabled">Device credentials enabled</string>
<string name="prefs_lock_device_credentials_not_setup">No device credentials have been set up.</string>
<string name="prefs_show_hidden_files">Show hidden files</string>
<string name="prefs_show_recommendations">Show recommendations</string>
<string name="prefs_show_ecosystem_apps">Show app switcher</string>
<string name="prefs_show_ecosystem_apps_summary">Nextcloud app suggestions in navigation heading</string>
<string name="prefs_enable_media_scan_notifications">Show media scan notifications</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
<com.owncloud.android.ui.ThemeableSwitchPreference
android:title="@string/prefs_show_hidden_files"
android:key="show_hidden_files" />
<com.owncloud.android.ui.ThemeableSwitchPreference
android:defaultValue="true"
android:title="@string/prefs_show_recommendations"
android:key="show_recommendations_pref" />
<com.owncloud.android.ui.ThemeableSwitchPreference
android:defaultValue="true"
android:title="@string/sort_folders_before_files"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.mockito.MockitoAnnotations;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
Expand Down Expand Up @@ -169,6 +171,30 @@ public void removeLegacyPreferences() {
inOrder.verify(editor).apply();
}

@Test
public void recommendationsAreShownByDefault() {
when(sharedPreferences.getBoolean("show_recommendations_pref", true)).thenReturn(true);

assertTrue(appPreferences.isShowRecommendationsEnabled());
}

@Test
public void recommendationsCanBeDisabled() {
when(sharedPreferences.getBoolean("show_recommendations_pref", true)).thenReturn(false);

assertFalse(appPreferences.isShowRecommendationsEnabled());
}

@Test
public void setShowRecommendationsEnabledPersistsSetting() {
when(editor.putBoolean("show_recommendations_pref", false)).thenReturn(editor);

appPreferences.setShowRecommendationsEnabled(false);

verify(editor).putBoolean("show_recommendations_pref", false);
verify(editor).apply();
}

@Test
public void testBruteForceDelay() {
assertEquals(0, appPreferences.computeBruteForceDelay(0));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package com.owncloud.android.ui.adapter.filelist

import com.owncloud.android.datamodel.OCFile
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test

class RecommendedFilesVisibilityTest {
private val rootDirectory = OCFile(OCFile.ROOT_PATH).apply {
decryptedRemotePath = OCFile.ROOT_PATH
}
private val recommendations = listOf(OCFile("/example.txt"))

@Test
fun `recommendations are hidden when setting is disabled`() {
assertFalse(shouldDisplayRecommendedFiles(false, recommendations, rootDirectory))
}

@Test
fun `recommendations are shown when enabled at root`() {
assertTrue(shouldDisplayRecommendedFiles(true, recommendations, rootDirectory))
}

@Test
fun `recommendations are hidden outside root`() {
val subdirectory = OCFile("/Documents/").apply {
decryptedRemotePath = "/Documents/"
}

assertFalse(shouldDisplayRecommendedFiles(true, recommendations, subdirectory))
}
}