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 @@ -278,6 +278,7 @@ class FileDisplayActivity :
observeWorkerState()
startMetadataSyncForRoot()
handleBackPress()
registerUnifiedSearchReceiver()
}

private fun loadSavedInstanceState(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -731,7 +732,13 @@ class FileDisplayActivity :
val transaction = fragmentManager.beginTransaction()
transaction.addToBackStack(null)
transaction.replace(R.id.left_fragment_container, fragment, TAG_LIST_OF_FILES)
transaction.commit()

if (fragmentManager.isStateSaved) {
transaction.commitAllowingStateLoss()
} else {
transaction.commit()
}

callback.onComplete(true)
} else {
callback.onComplete(false)
Expand Down Expand Up @@ -1280,7 +1287,9 @@ class FileDisplayActivity :
searchView?.setQuery("", false)
searchView?.onActionViewCollapsed()

if (isRoot(getCurrentDir()) && leftFragment is OCFileListFragment) {
val isRoot = isRoot(getCurrentDir())

if (isRoot && leftFragment is OCFileListFragment) {
// Remove the list to the original state
leftFragment.adapter?.let { adapter ->
val listOfHiddenFiles = adapter.listOfHiddenFiles
Expand All @@ -1292,7 +1301,17 @@ class FileDisplayActivity :

if (leftFragment is UnifiedSearchFragment) {
showSortListGroup(false)

// one pop or POP_BACK_STACK_INCLUSIVE is not showing the OCFileListFragment with correct state
supportFragmentManager.popBackStack()
supportFragmentManager.popBackStack()

// needed to set correct action bar style
if (isRoot) {
setupHomeSearchToolbarWithSortAndListButtons()
} else {
setupToolbar()
}
}
}

Expand Down Expand Up @@ -1953,7 +1972,7 @@ class FileDisplayActivity :
else -> VirtualFolderType.NONE
}

startImagePreview(file, type, file.isDown)
startImagePreview(file, file.isDown, type)
} else {
startImagePreview(file, file.isDown)
}
Expand Down Expand Up @@ -2482,44 +2501,33 @@ class FileDisplayActivity :
}
}

fun startImagePreview(file: OCFile, showPreview: Boolean) {
val showDetailsIntent = Intent(this, PreviewImageActivity::class.java)
showDetailsIntent.putExtra(EXTRA_FILE, file)
showDetailsIntent.putExtra(EXTRA_LIVE_PHOTO_FILE, file.livePhotoVideo)
showDetailsIntent.putExtra(
EXTRA_USER,
user.orElseThrow(Supplier { RuntimeException() })
)
if (showPreview) {
startActivity(showDetailsIntent)
} else {
val fileOperationsHelper =
FileOperationsHelper(this, userAccountManager, connectivityService, editorUtils)
fileOperationsHelper.startSyncForFileAndIntent(file, showDetailsIntent)
fun startImagePreview(file: OCFile, preview: Boolean, type: VirtualFolderType? = null) {
val optionalUser = user
if (optionalUser.isEmpty) {
Log_OC.e(TAG, "user is empty cannot preview image")
return
}
}

fun startImagePreview(file: OCFile, type: VirtualFolderType?, showPreview: Boolean) {
val showDetailsIntent = Intent(this, PreviewImageActivity::class.java)
showDetailsIntent.putExtra(EXTRA_FILE, file)
showDetailsIntent.putExtra(EXTRA_LIVE_PHOTO_FILE, file.livePhotoVideo)
showDetailsIntent.putExtra(
EXTRA_USER,
user.orElseThrow(Supplier { RuntimeException() })
)
showDetailsIntent.putExtra(PreviewImageActivity.EXTRA_VIRTUAL_TYPE, type)
val intent = Intent(this, PreviewImageActivity::class.java).apply {
putExtra(EXTRA_FILE, file)
putExtra(EXTRA_LIVE_PHOTO_FILE, file.livePhotoVideo)
putExtra(EXTRA_USER, optionalUser.get())
putExtra(PreviewImageActivity.EXTRA_VIRTUAL_TYPE, type)
putExtra(PreviewImageActivity.EXTRA_LAST_SEARCH_QUERY, listOfFilesFragment?.lastSearchQuery)
}

if (showPreview) {
startActivity(showDetailsIntent)
} else {
val fileOperationsHelper = FileOperationsHelper(
this,
userAccountManager,
connectivityService,
editorUtils
)
fileOperationsHelper.startSyncForFileAndIntent(file, showDetailsIntent)
if (preview) {
startActivity(intent)
return
}

val operation = FileOperationsHelper(
this,
userAccountManager,
connectivityService,
editorUtils
)
operation.startSyncForFileAndIntent(file, intent)
}

/**
Expand Down Expand Up @@ -2782,8 +2790,8 @@ class FileDisplayActivity :
val virtualType = bundle.get(PreviewImageActivity.EXTRA_VIRTUAL_TYPE) as VirtualFolderType?
startImagePreview(
file,
virtualType,
true
true,
virtualType
)
} else {
startImagePreview(file, true)
Expand Down Expand Up @@ -3043,23 +3051,38 @@ class FileDisplayActivity :
binding.fabMain.visibility = visibility
}

fun showFile(selectedFile: OCFile?, message: String?) {
dismissLoadingDialog()
private fun registerUnifiedSearchReceiver() {
val filter = IntentFilter(UNIFIED_SEARCH_EVENT_ACTION)
LocalBroadcastManager.getInstance(this).registerReceiver(unifiedSearchReceiver, filter)
}

private val unifiedSearchReceiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val query = intent.getStringExtra(PreviewImageActivity.EXTRA_LAST_SEARCH_QUERY) ?: return
listOfFilesFragment?.lastSearchQuery = null
performUnifiedSearch(query, null)
}
}

@JvmOverloads
fun showFile(selectedFile: OCFile?, message: String?, lastSearchQuery: String? = null) {
getOCFileListFragmentFromFile(object : TransactionInterface {
override fun onOCFileListFragmentComplete(listOfFiles: OCFileListFragment) {
if (TextUtils.isEmpty(message)) {
dismissLoadingDialog()

if (message?.isEmpty() == true) {
val temp = file
file = getCurrentDir()
listOfFiles.listDirectory(getCurrentDir(), temp, MainApp.isOnlyOnDevice())
updateActionBarTitleAndHomeButton(null)
} else {
val view = listOfFiles.view
if (view != null) {
DisplayUtils.showSnackMessage(view, message)
listOfFiles.view?.let {
DisplayUtils.showSnackMessage(it, message)
}
}

if (selectedFile != null) {
listOfFiles.lastSearchQuery = lastSearchQuery
listOfFiles.onItemClicked(selectedFile)
}
}
Expand Down Expand Up @@ -3124,6 +3147,8 @@ class FileDisplayActivity :

const val ACTION_DETAILS: String = "com.owncloud.android.ui.activity.action.DETAILS"

const val UNIFIED_SEARCH_EVENT_ACTION = "PHOTO_SEARCH_EVENT"

@JvmField
val REQUEST_CODE__SELECT_CONTENT_FROM_APPS: Int = REQUEST_CODE__LAST_SHARED + 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,35 @@ package com.owncloud.android.ui.adapter

import android.content.Context
import android.view.View
import androidx.lifecycle.lifecycleScope
import com.afollestad.sectionedrecyclerview.SectionedViewHolder
import com.nextcloud.android.common.ui.theme.utils.ColorRole
import com.nextcloud.common.NextcloudClient
import com.nextcloud.model.SearchResultEntryType
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.getTypedActivity
import com.owncloud.android.databinding.UnifiedSearchItemBinding
import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.lib.common.SearchResultEntry
import com.owncloud.android.ui.activity.FileActivity
import com.owncloud.android.ui.fragment.UnifiedSearchFragment
import com.owncloud.android.ui.interfaces.UnifiedSearchListInterface
import com.owncloud.android.utils.theme.ViewThemeUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

@Suppress("LongParameterList")
class UnifiedSearchItemViewHolder(
private val fragment: UnifiedSearchFragment,
private val supportsOpeningCalendarContactsLocally: Boolean,
val binding: UnifiedSearchItemBinding,
private val storageManager: FileDataStorageManager,
private val listInterface: UnifiedSearchListInterface,
private val filesAction: FilesAction,
val context: Context,
private val nextcloudClient: NextcloudClient,
private val viewThemeUtils: ViewThemeUtils
) : SectionedViewHolder(binding.root) {

Expand All @@ -54,14 +60,23 @@ class UnifiedSearchItemViewHolder(

val entryType = entry.getType()
viewThemeUtils.platform.colorImageView(binding.thumbnail, ColorRole.PRIMARY)
GlideHelper.loadIntoImageView(
context,
nextcloudClient,
entry.thumbnailUrl,
binding.thumbnail,
entryType.iconId(),
circleCrop = entry.rounded
)

fragment.lifecycleScope.launch(Dispatchers.IO) {
val client =
fragment.getTypedActivity(FileActivity::class.java)?.clientRepository?.getNextcloudClient()
?: return@launch

withContext(Dispatchers.Main) {
GlideHelper.loadIntoImageView(
context,
client,
entry.thumbnailUrl,
binding.thumbnail,
entryType.iconId(),
circleCrop = entry.rounded
)
}
}

if (entry.isFile) {
binding.more.visibility = View.VISIBLE
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 @@ -28,6 +27,7 @@ import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.datamodel.SyncedFolderProvider
import com.owncloud.android.datamodel.ThumbnailsCacheManager
import com.owncloud.android.ui.fragment.UnifiedSearchFragment
import com.owncloud.android.ui.interfaces.UnifiedSearchCurrentDirItemAction
import com.owncloud.android.ui.interfaces.UnifiedSearchListInterface
import com.owncloud.android.ui.unifiedsearch.UnifiedSearchSection
Expand All @@ -39,6 +39,7 @@ import com.owncloud.android.utils.theme.ViewThemeUtils
*/
@Suppress("LongParameterList")
class UnifiedSearchListAdapter(
private val fragment: UnifiedSearchFragment,
private val supportsOpeningCalendarContactsLocally: Boolean,
private val storageManager: FileDataStorageManager,
private val listInterface: UnifiedSearchListInterface,
Expand All @@ -48,7 +49,6 @@ class UnifiedSearchListAdapter(
private val viewThemeUtils: ViewThemeUtils,
private val appPreferences: AppPreferences,
private val syncedFolderProvider: SyncedFolderProvider,
private val nextcloudClient: NextcloudClient,
private val currentDirItemAction: UnifiedSearchCurrentDirItemAction
) : SectionedRecyclerViewAdapter<SectionedViewHolder>() {
companion object {
Expand Down Expand Up @@ -85,13 +85,13 @@ class UnifiedSearchListAdapter(
false
)
UnifiedSearchItemViewHolder(
fragment,
supportsOpeningCalendarContactsLocally,
binding,
storageManager,
listInterface,
filesAction,
context,
nextcloudClient,
viewThemeUtils
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

import javax.inject.Inject;
Expand Down Expand Up @@ -225,6 +226,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
protected String mLimitToMimeType;
private FloatingActionButton mFabMain;
public static boolean isMultipleFileSelectedForCopyOrMove = false;
private String lastSearchQuery = null;

@Inject DeviceInfo deviceInfo;

Expand Down Expand Up @@ -253,6 +255,15 @@ public void onCreate(Bundle savedInstanceState) {
searchFragment = currentSearchType != null && isSearchEventSet(searchEvent);
}

public void setLastSearchQuery(@Nullable String value) {
lastSearchQuery = value;
}

@Nullable
public String getLastSearchQuery() {
return lastSearchQuery;
}

@Override
public void onResume() {
// Don't handle search events if we're coming back from back stack
Expand Down
Loading
Loading