Skip to content
Merged
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 @@ -1259,8 +1259,6 @@ class FileDisplayActivity :
}

val ocFileListFragment = leftFragment

ocFileListFragment.setLoading(mSyncInProgress)
syncAndUpdateFolder(ignoreETag = true, ignoreFocus = true)

var startFile: OCFile? = null
Expand Down Expand Up @@ -1530,7 +1528,6 @@ class FileDisplayActivity :
return
}

ocFileListFragment.setLoading(mSyncInProgress)
if (mSyncInProgress || ocFileListFragment.isLoading) {
return
}
Expand Down Expand Up @@ -1684,9 +1681,6 @@ class FileDisplayActivity :
// TODO what about other kind of previews?
}
}

val ocFileListFragment: OCFileListFragment? = [email protected]
ocFileListFragment?.setLoading(false)
}

// TODO refactor this receiver, and maybe DownloadFinishReceiver; this method is duplicated :S
Expand Down Expand Up @@ -2363,12 +2357,8 @@ class FileDisplayActivity :
)

fetchRecommendedFilesIfNeeded(ignoreETag, folder)

val fragment = this.listOfFilesFragment
if (fragment != null && fragment !is GalleryFragment) {
fragment.setLoading(true)
}
mSyncInProgress = false
ocFileListFragment?.setLoading(false)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Needed for pull to refresh

}, DELAY_TO_REQUEST_REFRESH_OPERATION_LATER)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,13 @@ open class FolderPickerActivity :
).also {
it.execute(account, this, null, null)
}

listOfFilesFragment?.isLoading = true
setBackgroundText()
}

override fun onResume() {
super.onResume()
Log_OC.e(TAG, "onResume() start")

listOfFilesFragment?.isLoading = mSyncInProgress
refreshListOfFilesFragment(false)
file = listOfFilesFragment?.currentFile
updateUiElements()
Expand Down Expand Up @@ -585,7 +582,6 @@ open class FolderPickerActivity :

DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT))
Log_OC.d(TAG, "Setting progress visibility to $mSyncInProgress")
listOfFilesFragment?.isLoading = mSyncInProgress
setBackgroundText()
} catch (e: RuntimeException) {
Log_OC.e(TAG, "Error on broadcast receiver", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ open class ExtendedListFragment :
val localFileListAdapter = adapter
if (adapter is LocalFileListAdapter) {
localFileListAdapter.filter(query)
activity.fileListFragment.setLoading(false)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme

protected void setPhotoSearchQueryRunning(boolean value) {
this.photoSearchQueryRunning = value;
this.setLoading(value); // link the photoSearchQueryRunning variable with UI progress loading
}

public boolean isPhotoSearchQueryRunning() {
Expand Down Expand Up @@ -229,7 +228,6 @@ public CommonOCFileListAdapterInterface getCommonAdapter() {
public void onResume() {
super.onResume();

setLoading(this.isPhotoSearchQueryRunning());
if (getActivity() instanceof FileDisplayActivity fileDisplayActivity) {
fileDisplayActivity.updateActionBarTitleAndHomeButtonByString(getString(R.string.drawer_item_gallery));
fileDisplayActivity.setMainFabVisible(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,17 @@ import android.content.Intent
import android.content.Intent.ACTION_VIEW
import android.os.Bundle
import android.os.Handler
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.nextcloud.android.lib.resources.groupfolders.Groupfolder
import com.nextcloud.client.di.Injectable
import com.nextcloud.client.logger.Logger
import com.owncloud.android.MainApp
import com.owncloud.android.R
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation
import com.owncloud.android.lib.resources.files.model.RemoteFile
import com.owncloud.android.ui.EmptyRecyclerView
import com.owncloud.android.ui.activity.FileDisplayActivity
import com.owncloud.android.ui.adapter.GroupfolderListAdapter
import com.owncloud.android.ui.asynctasks.GroupfoldersSearchTask
import com.owncloud.android.ui.interfaces.GroupfolderListInterface
import com.owncloud.android.utils.DisplayUtils
import com.owncloud.android.utils.FileStorageUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject

/**
Expand Down Expand Up @@ -105,45 +96,6 @@ class GroupfolderListFragment :
adapter.notifyDataSetChanged()
}

private suspend fun fetchFileData(partialFile: OCFile): OCFile? = withContext(Dispatchers.IO) {
val user = accountManager.user
val fetchResult = ReadFileRemoteOperation(partialFile.remotePath).execute(user, context)
if (!fetchResult.isSuccess) {
logger.e(SHARED_TAG, "Error fetching file")
if (fetchResult.isException && fetchResult.exception != null) {
logger.e(SHARED_TAG, "exception: ", fetchResult.exception!!)
}
null
} else {
val remoteFile = fetchResult.data[0] as RemoteFile
val file = FileStorageUtils.fillOCFile(remoteFile)
FileStorageUtils.searchForLocalFileInDefaultPath(file, user.accountName)
val savedFile = mContainerActivity.storageManager.saveFileWithParent(file, context)
savedFile.apply {
isSharedViaLink = partialFile.isSharedViaLink
isSharedWithSharee = partialFile.isSharedWithSharee
sharees = partialFile.sharees
}
}
}

private fun fetchFileAndRun(partialFile: OCFile, block: (file: OCFile) -> Unit) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unused code

lifecycleScope.launch {
isLoading = true
val file = fetchFileData(partialFile)
isLoading = false
if (file != null) {
block(file)
} else {
DisplayUtils.showSnackMessage(requireActivity(), R.string.error_retrieving_file)
}
}
}

companion object {
private val SHARED_TAG = GroupfolderListFragment::class.java.simpleName
}

override fun onFolderClick(path: String) {
MainApp.showOnlyFilesOnDevice(false)
Intent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
Expand Down Expand Up @@ -381,22 +380,6 @@ public void switchToListView() {
super.switchToListView();
}

@Override
public void setLoading(boolean enabled) {
super.setLoading(enabled);
if (enabled) {
setEmptyListMessage(EmptyListState.LOADING);
} else {
// ugly hack because setEmptyListLoadingMessage also uses a handler and there's a race condition otherwise
new Handler().post(() -> {
mAdapter.notifyDataSetChanged();
if (mAdapter.getFilesCount() == 0) {
setEmptyListMessage(SearchType.LOCAL_SEARCH);
}
});
}
}

@VisibleForTesting
public void setFiles(List<File> newFiles) {
mAdapter.setFiles(newFiles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2063,7 +2063,6 @@ public void onMessageEvent(FileLockEvent event) {
final User user = accountManager.getUser();

try {
new Handler(Looper.getMainLooper()).post(() -> setLoading(true));
NextcloudClient client = clientFactory.createNextcloudClient(user);
ToggleFileLockRemoteOperation operation = new ToggleFileLockRemoteOperation(event.getShouldLock(), event.getFilePath());
RemoteOperationResult<Void> result = operation.execute(client);
Expand All @@ -2085,8 +2084,6 @@ public void onMessageEvent(FileLockEvent event) {
R.string.error_file_lock,
Snackbar.LENGTH_LONG).show();
}
} finally {
new Handler(Looper.getMainLooper()).post(() -> setLoading(false));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package com.owncloud.android.ui.fragment

import android.annotation.SuppressLint
import android.os.AsyncTask
import android.os.Handler
import android.os.Looper
Expand Down Expand Up @@ -35,7 +36,6 @@ class OCFileListSearchAsyncTask(
override fun onPreExecute() {
fragmentReference.get()?.let { fragment ->
Handler(Looper.getMainLooper()).post {
fragment.isLoading = true
fragment.setEmptyListMessage(EmptyListState.LOADING)
}
}
Expand All @@ -51,7 +51,7 @@ class OCFileListSearchAsyncTask(
lateinit var remoteOperationResult: RemoteOperationResult<List<Any>>
try {
remoteOperationResult = remoteOperation.execute(currentUser, fragment.context)
} catch (e: UnsupportedOperationException) {
} catch (_: UnsupportedOperationException) {
remoteOperationResult = remoteOperation.executeNextcloudClient(currentUser, fragment.requireContext())
}

Expand All @@ -72,9 +72,9 @@ class OCFileListSearchAsyncTask(
return remoteOperationResult.isSuccess
}

@SuppressLint("NotifyDataSetChanged")
override fun onPostExecute(bool: Boolean) {
fragmentReference.get()?.let { fragment ->
fragment.isLoading = false
if (!isCancelled) {
fragment.adapter.notifyDataSetChanged()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ class SharedListFragment :

private fun fetchFileAndRun(partialFile: OCFile, block: (file: OCFile) -> Unit) {
lifecycleScope.launch {
isLoading = true
val file = fetchFileData(partialFile)
isLoading = false
withContext(Dispatchers.Main) {
if (file != null) {
block(file)
Expand All @@ -119,7 +117,6 @@ class SharedListFragment :

private fun fetchAllAndRun(partialFiles: MutableSet<OCFile>?, callback: (MutableSet<OCFile>?) -> Unit) {
lifecycleScope.launch {
isLoading = true
if (partialFiles != null) {
val files = partialFiles.toMutableSet().mapNotNull { partialFile ->
fetchFileData(partialFile).also { fetched ->
Expand All @@ -128,10 +125,7 @@ class SharedListFragment :
}
}
}
isLoading = false
callback(files.toHashSet())
} else {
isLoading = false
}
}
}
Expand Down
Loading