From ba359781a10f5b43f80f5eb6633694dc441f2ea6 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 7 Jun 2024 12:03:12 +0200 Subject: [PATCH 1/8] Check mIndexes nullability is ExtendedListFragment.java Signed-off-by: alperozturk --- .../ui/fragment/ExtendedListFragment.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java index 7e18b4649cf2..71e4bbc169da 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java @@ -454,18 +454,21 @@ public int getColumnsCount() { * Restore index and position */ protected void restoreIndexAndTopPosition() { - if (mIndexes.size() > 0) { - // needs to be checked; not every browse-up had a browse-down before + if (mIndexes == null || mIndexes.isEmpty()) { + Log_OC.d(TAG,"Indexes is null or empty"); + return; + } - int index = mIndexes.remove(mIndexes.size() - 1); - final int firstPosition = mFirstPositions.remove(mFirstPositions.size() - 1); - int top = mTops.remove(mTops.size() - 1); + // needs to be checked; not every browse-up had a browse-down before - Log_OC.v(TAG, "Setting selection to position: " + firstPosition + "; top: " - + top + "; index: " + index); + int index = mIndexes.remove(mIndexes.size() - 1); + final int firstPosition = mFirstPositions.remove(mFirstPositions.size() - 1); + int top = mTops.remove(mTops.size() - 1); - scrollToPosition(firstPosition); - } + Log_OC.v(TAG, "Setting selection to position: " + firstPosition + "; top: " + + top + "; index: " + index); + + scrollToPosition(firstPosition); } private void scrollToPosition(int position) { From 9ad5feda6cab052bb5f9e7331cdde9f5daa710b1 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 7 Jun 2024 12:05:34 +0200 Subject: [PATCH 2/8] Check mLocalFolder nullability in RefreshFolderOperation.java Signed-off-by: alperozturk --- .../owncloud/android/operations/RefreshFolderOperation.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java b/app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java index 1f337d7e39bb..4fef8dc5cda0 100644 --- a/app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java @@ -453,6 +453,11 @@ private void synchronizeData(List folderAndFiles) { // get 'fresh data' from the database mLocalFolder = mStorageManager.getFileByPath(mLocalFolder.getRemotePath()); + if (mLocalFolder == null) { + Log_OC.d(TAG,"mLocalFolder cannot be null"); + return; + } + // parse data from remote folder OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) folderAndFiles.get(0)); remoteFolder.setParentId(mLocalFolder.getParentId()); From 2e0d4559050feda674111d6e51c88f2274bfc888 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 7 Jun 2024 12:11:50 +0200 Subject: [PATCH 3/8] Check listDirectory nullability in OCFileListFragment.java Signed-off-by: alperozturk --- .../ui/fragment/OCFileListFragment.java | 91 +++++++++++-------- 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index 30588ae801ec..149577e4082c 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -1292,6 +1292,24 @@ public void listDirectory(OCFile directory, boolean onlyOnDevice, boolean fromSe listDirectory(directory, null, onlyOnDevice, fromSearch); } + private OCFile getDirectoryForListDirectory(OCFile directory, FileDataStorageManager storageManager) { + if (directory == null) { + if (mFile != null) { + directory = mFile; + } else { + directory = storageManager.getFileByPath(ROOT_PATH); + } + } + + // If that's not a directory -> List its parent + if (!directory.isFolder()) { + Log_OC.w(TAG, "You see, that is not a directory -> " + directory); + directory = storageManager.getFileById(directory.getParentId()); + } + + return directory; + } + /** * Lists the given directory on the view. When the input parameter is null, it will either refresh the last known * directory. list the root if there never was a directory. @@ -1301,52 +1319,47 @@ public void listDirectory(OCFile directory, boolean onlyOnDevice, boolean fromSe public void listDirectory(OCFile directory, OCFile file, boolean onlyOnDevice, boolean fromSearch) { if (!searchFragment) { FileDataStorageManager storageManager = mContainerActivity.getStorageManager(); - if (storageManager != null) { - // Check input parameters for null - if (directory == null) { - if (mFile != null) { - directory = mFile; - } else { - directory = storageManager.getFileByPath(ROOT_PATH); - if (directory == null) { - return; // no files, wait for sync - } - } - } + if (storageManager == null) { + Log_OC.d(TAG, "fileDataStorageManager is null"); + return; + } - // If that's not a directory -> List its parent - if (!directory.isFolder()) { - Log_OC.w(TAG, "You see, that is not a directory -> " + directory); - directory = storageManager.getFileById(directory.getParentId()); + directory = getDirectoryForListDirectory(directory, storageManager); + if (directory == null) { + Log_OC.d(TAG, "directory is null, no files, wait for sync"); + return; + } - if (directory == null) { - return; // no files, wait for sync - } - } + if (mLimitToMimeType == null) { + Log_OC.d(TAG, "mLimitToMimeType is null"); + return; + } - mAdapter.swapDirectory( - accountManager.getUser(), - directory, - storageManager, - onlyOnDevice, - mLimitToMimeType - ); + if (mAdapter == null) { + Log_OC.d(TAG, "mAdapter is null"); + return; + } - OCFile previousDirectory = mFile; - mFile = directory; + mAdapter.swapDirectory( + accountManager.getUser(), + directory, + storageManager, + onlyOnDevice, + mLimitToMimeType); - updateLayout(); + OCFile previousDirectory = mFile; + mFile = directory; - if (file != null) { - mAdapter.setHighlightedItem(file); - int position = mAdapter.getItemPosition(file); - if (position != -1) { - getRecyclerView().scrollToPosition(position); - } - } else if (previousDirectory == null || !previousDirectory.equals(directory)) { - getRecyclerView().scrollToPosition(0); - } + updateLayout(); + if (file != null) { + mAdapter.setHighlightedItem(file); + int position = mAdapter.getItemPosition(file); + if (position != -1) { + getRecyclerView().scrollToPosition(position); + } + } else if (previousDirectory == null || !previousDirectory.equals(directory)) { + getRecyclerView().scrollToPosition(0); } } else if (isSearchEventSet(searchEvent)) { handleSearchEvent(searchEvent); From 4dd6a6d2779ca42cb2b63d3fc78321fbd2f23d81 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 7 Jun 2024 12:18:08 +0200 Subject: [PATCH 4/8] Add coroutineExceptionHandler to UnifiedSearchRemoteRepository Signed-off-by: alperozturk --- .../unifiedsearch/UnifiedSearchRemoteRepository.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/unifiedsearch/UnifiedSearchRemoteRepository.kt b/app/src/main/java/com/owncloud/android/ui/unifiedsearch/UnifiedSearchRemoteRepository.kt index 54b175d147d5..161dd8b6450e 100644 --- a/app/src/main/java/com/owncloud/android/ui/unifiedsearch/UnifiedSearchRemoteRepository.kt +++ b/app/src/main/java/com/owncloud/android/ui/unifiedsearch/UnifiedSearchRemoteRepository.kt @@ -13,6 +13,7 @@ import com.nextcloud.client.network.ClientFactory import com.nextcloud.common.NextcloudClient import com.owncloud.android.lib.common.SearchProviders import com.owncloud.android.lib.common.utils.Log_OC +import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -24,12 +25,19 @@ class UnifiedSearchRemoteRepository( ) : IUnifiedSearchRepository { private var providers: SearchProviders? = null + private val tag = "UnifiedSearchRemoteRepository" - private fun runAsyncWithNcClient(callback: (client: NextcloudClient) -> Unit) = - CoroutineScope(Dispatchers.IO).launch { + private fun runAsyncWithNcClient(callback: (client: NextcloudClient) -> Unit) { + val coroutineExceptionHandler = CoroutineExceptionHandler { _, exception -> + Log_OC.d(tag,"CoroutineExceptionHandler got at runAsyncWithNcClient $exception") + } + + CoroutineScope(Dispatchers.IO).launch(coroutineExceptionHandler) { val client = clientFactory.createNextcloudClient(currentAccountProvider.user) callback(client) } + } + override fun queryAll( query: String, From 04f0a00d6536f6a50fee8d0294df6dd28f54764e Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 7 Jun 2024 12:21:30 +0200 Subject: [PATCH 5/8] Check nullability of accountName in FileDisplayActivity.java Signed-off-by: alperozturk --- .../com/owncloud/android/ui/activity/FileDisplayActivity.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index a97f018db544..e42d01c3a91e 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -13,6 +13,7 @@ */ package com.owncloud.android.ui.activity; +import android.accounts.Account; import android.accounts.AuthenticatorException; import android.annotation.SuppressLint; import android.app.Activity; @@ -1354,7 +1355,8 @@ private class UploadFinishReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { String uploadedRemotePath = intent.getStringExtra(FileUploadWorker.EXTRA_REMOTE_PATH); String accountName = intent.getStringExtra(FileUploadWorker.ACCOUNT_NAME); - boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name); + Account account = getAccount(); + boolean sameAccount = accountName != null && account != null && accountName.equals(account.name); OCFile currentDir = getCurrentDir(); boolean isDescendant = currentDir != null && uploadedRemotePath != null && uploadedRemotePath.startsWith(currentDir.getRemotePath()); From 74d47b748404163584a3a7de8043363e2827dbc8 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 7 Jun 2024 12:27:14 +0200 Subject: [PATCH 6/8] Fix Scale must be within the range of minScale and maxScale exception Signed-off-by: alperozturk --- .../ui/preview/PreviewImageFragment.java | 46 +++++++++++++------ 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java b/app/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java index d823dadab4e5..1ca7f2dfaedf 100644 --- a/app/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java @@ -230,26 +230,42 @@ private void playLivePhoto(OCFile file) { @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - if (savedInstanceState != null) { - if (!ignoreFirstSavedState) { - OCFile file = BundleExtensionsKt.getParcelableArgument(savedInstanceState, EXTRA_FILE, OCFile.class); - if (file == null) { - return; - } + if (savedInstanceState == null) { + Log_OC.d(TAG, "savedInstanceState is null"); + return; + } - setFile(file); + if (ignoreFirstSavedState) { + Log_OC.d(TAG, "Saved state ignored"); + ignoreFirstSavedState = false; + return; + } - try { - binding.image.setScale(Math.min(binding.image.getMaximumScale(), savedInstanceState.getFloat(EXTRA_ZOOM))); - } catch (IllegalArgumentException e) { - Log_OC.d(TAG, "Error caught at setScale: " + e); - } - } else { - ignoreFirstSavedState = false; - } + OCFile file = BundleExtensionsKt.getParcelableArgument(savedInstanceState, EXTRA_FILE, OCFile.class); + if (file == null) { + Log_OC.d(TAG, "file cannot be found inside the savedInstanceState"); + return; + } + + setFile(file); + + float maxScale = binding.image.getMaximumScale(); + float minScale = binding.image.getMinimumScale(); + float savedScale = savedInstanceState.getFloat(EXTRA_ZOOM); + + if (savedScale < minScale || savedScale > maxScale) { + Log_OC.d(TAG, "Saved scale " + savedScale + " is out of bounds, setting to default scale."); + savedScale = Math.min(maxScale, Math.max(minScale, savedScale)); + } + + try { + binding.image.setScale(savedScale); + } catch (IllegalArgumentException e) { + Log_OC.d(TAG, "Error caught at setScale: " + e); } } + @Override public void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); From 1ec83e7f514e0179d71aff580fdf8f813c647294 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 7 Jun 2024 12:41:44 +0200 Subject: [PATCH 7/8] Check fragment manager executing transaction in FileDisplayActivity.java when user try to open file actions from search screen Signed-off-by: alperozturk --- .../ui/activity/FileDisplayActivity.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index e42d01c3a91e..17eaa3c75b79 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -32,7 +32,9 @@ import android.os.Build; import android.os.Bundle; import android.os.Environment; +import android.os.Handler; import android.os.IBinder; +import android.os.Looper; import android.os.Parcelable; import android.text.TextUtils; import android.view.Menu; @@ -610,7 +612,8 @@ private void setLeftFragment(Fragment fragment, boolean showSortListGroup) { private OCFileListFragment getOCFileListFragmentFromFile() { final Fragment leftFragment = getLeftFragment(); - OCFileListFragment listOfFiles = null; + OCFileListFragment listOfFiles; + if (leftFragment instanceof OCFileListFragment) { listOfFiles = (OCFileListFragment) leftFragment; } else { @@ -618,12 +621,25 @@ private OCFileListFragment getOCFileListFragmentFromFile() { Bundle args = new Bundle(); args.putBoolean(OCFileListFragment.ARG_ALLOW_CONTEXTUAL_ACTIONS, true); listOfFiles.setArguments(args); - setLeftFragment(listOfFiles); - getSupportFragmentManager().executePendingTransactions(); + + FragmentManager fm = getSupportFragmentManager(); + boolean isExecutingTransactions = !fm.isStateSaved() && !fm.executePendingTransactions(); + + if (isExecutingTransactions) { + setLeftFragment(listOfFiles); + fm.executePendingTransactions(); + } else { + new Handler(Looper.getMainLooper()).post(() -> { + setLeftFragment(listOfFiles); + fm.executePendingTransactions(); + }); + } } + return listOfFiles; } + public void showFileActions(OCFile file) { dismissLoadingDialog(); OCFileListFragment listOfFiles = getOCFileListFragmentFromFile(); From 331b7c2c6ee556b16c6a4b9cc156655d100e25a1 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 7 Jun 2024 13:17:12 +0200 Subject: [PATCH 8/8] Fix kotlin spotless check Signed-off-by: alperozturk --- .../android/ui/unifiedsearch/UnifiedSearchRemoteRepository.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/unifiedsearch/UnifiedSearchRemoteRepository.kt b/app/src/main/java/com/owncloud/android/ui/unifiedsearch/UnifiedSearchRemoteRepository.kt index 161dd8b6450e..d9f91aa025fe 100644 --- a/app/src/main/java/com/owncloud/android/ui/unifiedsearch/UnifiedSearchRemoteRepository.kt +++ b/app/src/main/java/com/owncloud/android/ui/unifiedsearch/UnifiedSearchRemoteRepository.kt @@ -29,7 +29,7 @@ class UnifiedSearchRemoteRepository( private fun runAsyncWithNcClient(callback: (client: NextcloudClient) -> Unit) { val coroutineExceptionHandler = CoroutineExceptionHandler { _, exception -> - Log_OC.d(tag,"CoroutineExceptionHandler got at runAsyncWithNcClient $exception") + Log_OC.d(tag, "CoroutineExceptionHandler got at runAsyncWithNcClient $exception") } CoroutineScope(Dispatchers.IO).launch(coroutineExceptionHandler) { @@ -38,7 +38,6 @@ class UnifiedSearchRemoteRepository( } } - override fun queryAll( query: String, onResult: (UnifiedSearchResult) -> Unit,