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
12 changes: 12 additions & 0 deletions app/src/main/java/com/nextcloud/client/di/AppModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import com.owncloud.android.ui.activities.data.files.FilesServiceApiImpl;
import com.owncloud.android.ui.activities.data.files.RemoteFilesRepository;
import com.owncloud.android.ui.dialog.setupEncryption.CertificateValidator;
import com.owncloud.android.utils.overlay.OverlayManager;
import com.owncloud.android.utils.theme.ViewThemeUtils;

import org.greenrobot.eventbus.EventBus;
Expand Down Expand Up @@ -268,4 +269,15 @@ UsersAndGroupsSearchConfig userAndGroupSearchConfig() {
CertificateValidator certificateValidator() {
return new CertificateValidator();
}

@Provides
@Singleton
OverlayManager overlayManager(
SyncedFolderProvider syncedFolderProvider,
AppPreferences appPreferences,
ViewThemeUtils viewThemeUtils,
Context context,
UserAccountManager accountManager) {
return new OverlayManager(syncedFolderProvider, appPreferences, viewThemeUtils, context, accountManager);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import com.owncloud.android.ui.activity.ComponentsGetter
import com.owncloud.android.utils.DisplayUtils
import com.owncloud.android.utils.DisplayUtils.AvatarGenerationListener
import com.owncloud.android.utils.FileStorageUtils
import com.owncloud.android.utils.overlay.OverlayManager
import com.owncloud.android.utils.theme.ViewThemeUtils
import javax.inject.Inject

Expand All @@ -68,6 +69,9 @@ class FileActionsBottomSheet :
@Inject
lateinit var syncedFolderProvider: SyncedFolderProvider

@Inject
lateinit var overlayManager: OverlayManager

private lateinit var viewModel: FileActionsViewModel

private var _binding: FileActionsBottomSheetBinding? = null
Expand Down Expand Up @@ -153,7 +157,7 @@ class FileActionsBottomSheet :
binding.thumbnailLayout.thumbnailShimmer,
syncedFolderProvider.preferences,
viewThemeUtils,
syncedFolderProvider
overlayManager
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.owncloud.android.datamodel.SyncedFolderProvider
import com.owncloud.android.datamodel.ThumbnailsCacheManager
import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile
import com.owncloud.android.utils.DisplayUtils
import com.owncloud.android.utils.overlay.OverlayManager
import com.owncloud.android.utils.theme.ViewThemeUtils
import javax.inject.Inject

Expand All @@ -57,6 +58,9 @@ class TrashbinFileActionsBottomSheet :
@Inject
lateinit var syncedFolderProvider: SyncedFolderProvider

@Inject
lateinit var overlayManager: OverlayManager

private lateinit var viewModel: TrashbinFileActionsViewModel

private var _binding: FileActionsBottomSheetBinding? = null
Expand Down Expand Up @@ -129,7 +133,7 @@ class TrashbinFileActionsBottomSheet :
binding.thumbnailLayout.thumbnailShimmer,
syncedFolderProvider.preferences,
viewThemeUtils,
syncedFolderProvider
overlayManager
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,24 @@ OCFile getFileByDecryptedRemotePath(String path) {
return getFileByPath(ProviderTableMeta.FILE_PATH_DECRYPTED, path);
}

/**
* Returns the {@link OCFile} for the given remote path.
* Tries the path as-is first; if not found, appends a trailing "/" for folders.
*
* @param path The file or folder path.
* @return The matching {@link OCFile}, or null if not found.
*/
@Nullable
public OCFile getFileByRemotePath(String path) {
OCFile file = getFileByDecryptedRemotePath(path);

if (file == null) {
file = getFileByDecryptedRemotePath(path + OCFile.PATH_SEPARATOR);
}

return file;
}

public void addCreateFileOfflineOperation(String[] localPaths, String[] remotePaths) {
if (localPaths.length != remotePaths.length) {
Log_OC.d(TAG, "Local path and remote path size do not match");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ private ContentValues createContentValuesFromSyncedFolder(SyncedFolder syncedFol
* @return <code>true</code> if exist, <code>false</code> otherwise
*/
public boolean findByRemotePathAndAccount(String remotePath, User user) {
if (user == null) {
return false;
}

boolean result = false;

//if path ends with / then remove the last / to work the query right way
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import com.owncloud.android.utils.FileSortOrder;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.MimeTypeUtil;
import com.owncloud.android.utils.overlay.OverlayManager;
import com.owncloud.android.utils.theme.CapabilityUtils;
import com.owncloud.android.utils.theme.ViewThemeUtils;

Expand Down Expand Up @@ -134,6 +135,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
private ArrayList<OCFile> recommendedFiles = new ArrayList<>();
private RecommendedFilesAdapter recommendedFilesAdapter;
private final OCFileListAdapterHelper helper = new OCFileListAdapterHelper();
private final OverlayManager overlayManager;

public OCFileListAdapter(
Activity activity,
Expand All @@ -144,7 +146,9 @@ public OCFileListAdapter(
OCFileListFragmentInterface ocFileListFragmentInterface,
boolean argHideItemOptions,
boolean gridView,
final ViewThemeUtils viewThemeUtils) {
final ViewThemeUtils viewThemeUtils,
OverlayManager overlayManager) {
this.overlayManager = overlayManager;
this.ocFileListFragmentInterface = ocFileListFragmentInterface;
this.activity = activity;
this.preferences = preferences;
Expand Down Expand Up @@ -476,7 +480,7 @@ public void bindRecommendedFilesHolder(OCFileListRecommendedItemViewHolder holde
}

private void bindHolder(@NonNull RecyclerView.ViewHolder holder, ListViewHolder viewHolder, OCFile file) {
ocFileListDelegate.bindViewHolder(viewHolder, file, currentDirectory, searchType);
ocFileListDelegate.bindViewHolder(viewHolder, file, currentDirectory, searchType, overlayManager);

if (holder instanceof ListItemViewHolder itemViewHolder) {
bindListItemViewHolder(itemViewHolder, file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.owncloud.android.ui.fragment.SearchType
import com.owncloud.android.ui.interfaces.OCFileListFragmentInterface
import com.owncloud.android.utils.DisplayUtils
import com.owncloud.android.utils.EncryptionUtils
import com.owncloud.android.utils.overlay.OverlayManager
import com.owncloud.android.utils.theme.ViewThemeUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -175,7 +176,12 @@ class OCFileListDelegate(
}
}

fun setThumbnail(thumbnail: ImageView, shimmerThumbnail: LoaderImageView?, file: OCFile) {
fun setThumbnail(
thumbnail: ImageView,
shimmerThumbnail: LoaderImageView?,
file: OCFile,
overlayManager: OverlayManager
) {
DisplayUtils.setThumbnail(
file,
thumbnail,
Expand All @@ -187,16 +193,22 @@ class OCFileListDelegate(
shimmerThumbnail,
preferences,
viewThemeUtils,
syncFolderProvider
overlayManager
)
}

@Suppress("MagicNumber")
fun bindViewHolder(viewHolder: ListViewHolder, file: OCFile, currentDirectory: OCFile?, searchType: SearchType?) {
fun bindViewHolder(
viewHolder: ListViewHolder,
file: OCFile,
currentDirectory: OCFile?,
searchType: SearchType?,
overlayManager: OverlayManager
) {
// thumbnail
viewHolder.imageFileName?.text = file.fileName
viewHolder.thumbnail.tag = file.fileId
setThumbnail(viewHolder.thumbnail, viewHolder.shimmerThumbnail, file)
setThumbnail(viewHolder.thumbnail, viewHolder.shimmerThumbnail, file, overlayManager)

// item layout + click listeners
bindGridItemLayout(file, viewHolder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.owncloud.android.datamodel.SyncedFolderProvider
import com.owncloud.android.ui.interfaces.UnifiedSearchCurrentDirItemAction
import com.owncloud.android.utils.DisplayUtils
import com.owncloud.android.utils.FileStorageUtils
import com.owncloud.android.utils.overlay.OverlayManager
import com.owncloud.android.utils.theme.ViewThemeUtils

@Suppress("LongParameterList")
Expand All @@ -32,7 +33,8 @@ class UnifiedSearchCurrentDirItemViewHolder(
private val user: User,
private val appPreferences: AppPreferences,
private val syncedFolderProvider: SyncedFolderProvider,
private val action: UnifiedSearchCurrentDirItemAction
private val action: UnifiedSearchCurrentDirItemAction,
private val overlayManager: OverlayManager
) : SectionedViewHolder(binding.unifiedSearchCurrentDirItemLayout) {

fun bind(file: OCFile) {
Expand Down Expand Up @@ -61,7 +63,7 @@ class UnifiedSearchCurrentDirItemViewHolder(
binding.thumbnailShimmer,
appPreferences,
viewThemeUtils,
syncedFolderProvider
overlayManager
)

binding.more.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ import com.nextcloud.utils.CalendarEventManager
import com.nextcloud.utils.ContactManager
import com.nextcloud.utils.GlideHelper
import com.nextcloud.utils.extensions.getType
import com.nextcloud.utils.extensions.setVisibleIf
import com.owncloud.android.R
import com.owncloud.android.databinding.UnifiedSearchItemBinding
import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.lib.common.SearchResultEntry
import com.owncloud.android.ui.interfaces.UnifiedSearchListInterface
import com.owncloud.android.utils.DisplayUtils
import com.owncloud.android.utils.overlay.OverlayManager
import com.owncloud.android.utils.theme.ViewThemeUtils

@Suppress("LongParameterList")
Expand All @@ -31,38 +35,76 @@ class UnifiedSearchItemViewHolder(
private val listInterface: UnifiedSearchListInterface,
private val filesAction: FilesAction,
val context: Context,
private val nextcloudClient: NextcloudClient,
private val viewThemeUtils: ViewThemeUtils
private val viewThemeUtils: ViewThemeUtils,
private val overlayManager: OverlayManager
) : SectionedViewHolder(binding.root) {

interface FilesAction {
fun showFilesAction(searchResultEntry: SearchResultEntry)
fun loadFileThumbnail(searchResultEntry: SearchResultEntry, onClientReady: (NextcloudClient) -> Unit)
}

private val contactManager = ContactManager(context)
private val calendarEventManager = CalendarEventManager(context)

fun bind(entry: SearchResultEntry) {
binding.title.text = entry.title
binding.subline.text = entry.subline
bindSubline(entry)
bindLocalFileIndicator(entry)

if (entry.isFile && storageManager.getFileByDecryptedRemotePath(entry.remotePath()) != null) {
binding.localFileIndicator.visibility = View.VISIBLE
val entryType = entry.getType()
bindThumbnail(entry, entryType)
bindMoreButton(entry)
binding.unifiedSearchItemLayout.setOnClickListener {
searchEntryOnClick(entry, entryType)
}
}

private fun bindSubline(entry: SearchResultEntry) {
if (entry.subline.isNotBlank()) {
binding.subline.visibility = View.VISIBLE
binding.subline.text = entry.subline
} else {
binding.localFileIndicator.visibility = View.GONE
binding.subline.visibility = View.GONE

val paddingInDp = context.resources.getDimension(R.dimen.standard_padding)
val paddingInPx = DisplayUtils.convertDpToPixel(paddingInDp, context)
binding.titleContainer.setPadding(0, paddingInPx, 0, 0)
}
}

val entryType = entry.getType()
viewThemeUtils.platform.colorImageView(binding.thumbnail, ColorRole.PRIMARY)
GlideHelper.loadIntoImageView(
context,
nextcloudClient,
entry.thumbnailUrl,
binding.thumbnail,
entryType.iconId(),
circleCrop = entry.rounded
)
private fun bindLocalFileIndicator(entry: SearchResultEntry) {
val showLocalFileIndicator =
(entry.isFile && storageManager.getFileByDecryptedRemotePath(entry.remotePath()) != null)
binding.localFileIndicator.setVisibleIf(showLocalFileIndicator)
}

private fun bindThumbnail(entry: SearchResultEntry, entryType: SearchResultEntryType) {
val file = storageManager.getFileByRemotePath(entry.remotePath())
if (file?.isFolder == true) {
viewThemeUtils.platform.colorImageView(binding.thumbnail, ColorRole.PRIMARY)
overlayManager.setFolderOverlayIcon(file, binding.thumbnailOverlayIcon)
} else {
filesAction.loadFileThumbnail(entry, onClientReady = {
if (binding.thumbnail.tag == entry.thumbnailUrl) {
return@loadFileThumbnail
}

binding.thumbnail.tag = entry.thumbnailUrl

GlideHelper.loadIntoImageView(
context,
it,
entry.thumbnailUrl,
binding.thumbnail,
entryType.iconId(),
circleCrop = entry.rounded
)
})
}
}

private fun bindMoreButton(entry: SearchResultEntry) {
if (entry.isFile) {
binding.more.visibility = View.VISIBLE
binding.more.setOnClickListener {
Expand All @@ -71,10 +113,6 @@ class UnifiedSearchItemViewHolder(
} else {
binding.more.visibility = View.GONE
}

binding.unifiedSearchItemLayout.setOnClickListener {
searchEntryOnClick(entry, entryType)
}
}

private fun searchEntryOnClick(entry: SearchResultEntry, entryType: SearchResultEntryType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import com.afollestad.sectionedrecyclerview.SectionedRecyclerViewAdapter
import com.afollestad.sectionedrecyclerview.SectionedViewHolder
import com.nextcloud.client.account.User
import com.nextcloud.client.preferences.AppPreferences
import com.nextcloud.common.NextcloudClient
import com.owncloud.android.R
import com.owncloud.android.databinding.UnifiedSearchCurrentDirectoryItemBinding
import com.owncloud.android.databinding.UnifiedSearchEmptyBinding
Expand All @@ -32,12 +31,13 @@ import com.owncloud.android.ui.interfaces.UnifiedSearchCurrentDirItemAction
import com.owncloud.android.ui.interfaces.UnifiedSearchListInterface
import com.owncloud.android.ui.unifiedsearch.UnifiedSearchSection
import com.owncloud.android.utils.DisplayUtils
import com.owncloud.android.utils.overlay.OverlayManager
import com.owncloud.android.utils.theme.ViewThemeUtils

/**
* This Adapter populates a SectionedRecyclerView with search results by unified search
*/
@Suppress("LongParameterList")
@Suppress("LongParameterList", "LongMethod")
class UnifiedSearchListAdapter(
private val supportsOpeningCalendarContactsLocally: Boolean,
private val storageManager: FileDataStorageManager,
Expand All @@ -48,8 +48,8 @@ class UnifiedSearchListAdapter(
private val viewThemeUtils: ViewThemeUtils,
private val appPreferences: AppPreferences,
private val syncedFolderProvider: SyncedFolderProvider,
private val nextcloudClient: NextcloudClient,
private val currentDirItemAction: UnifiedSearchCurrentDirItemAction
private val currentDirItemAction: UnifiedSearchCurrentDirItemAction,
private val overlayManager: OverlayManager
) : SectionedRecyclerViewAdapter<SectionedViewHolder>() {
companion object {
private const val VIEW_TYPE_EMPTY = Int.MAX_VALUE
Expand Down Expand Up @@ -93,8 +93,8 @@ class UnifiedSearchListAdapter(
listInterface,
filesAction,
context,
nextcloudClient,
viewThemeUtils
viewThemeUtils,
overlayManager
)
}

Expand All @@ -110,7 +110,8 @@ class UnifiedSearchListAdapter(
user,
appPreferences,
syncedFolderProvider,
currentDirItemAction
currentDirItemAction,
overlayManager
)
}

Expand Down
Loading
Loading