From 638fbbe19734c9f18a843aafc0860ad719b2f93b Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Thu, 2 Jan 2020 17:06:01 +0100 Subject: [PATCH 1/4] code format and minor lint issues --- .../android/services/OperationsService.java | 105 +++++++----------- .../android/services/SyncFolderHandler.java | 14 +-- 2 files changed, 42 insertions(+), 77 deletions(-) diff --git a/owncloudApp/src/main/java/com/owncloud/android/services/OperationsService.java b/owncloudApp/src/main/java/com/owncloud/android/services/OperationsService.java index 5f73f1dd649..4d75389fb32 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/services/OperationsService.java +++ b/owncloudApp/src/main/java/com/owncloud/android/services/OperationsService.java @@ -6,16 +6,16 @@ * @author Christian Schabesberger * @author Shashvat Kedia * Copyright (C) 2019 ownCloud GmbH. - * + *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, * as published by the Free Software Foundation. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + *

* You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -69,7 +69,6 @@ import com.owncloud.android.operations.common.SyncOperation; import java.io.IOException; -import java.util.Iterator; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentMap; @@ -109,14 +108,11 @@ public class OperationsService extends Service { public static final String ACTION_COPY_FILE = "COPY_FILE"; public static final String ACTION_CHECK_CURRENT_CREDENTIALS = "CHECK_CURRENT_CREDENTIALS"; - public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() + - ".OPERATION_ADDED"; - public static final String ACTION_OPERATION_FINISHED = OperationsService.class.getName() + - ".OPERATION_FINISHED"; + public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() + ".OPERATION_ADDED"; + public static final String ACTION_OPERATION_FINISHED = OperationsService.class.getName() + ".OPERATION_FINISHED"; private ConcurrentMap> - mUndispatchedFinishedOperations = - new ConcurrentHashMap<>(); + mUndispatchedFinishedOperations = new ConcurrentHashMap<>(); private static class Target { public Uri mServerUrl; @@ -146,8 +142,7 @@ public void onCreate() { Log_OC.d(TAG, "Creating service"); /// First worker thread for most of operations - HandlerThread thread = new HandlerThread("Operations thread", - Process.THREAD_PRIORITY_BACKGROUND); + HandlerThread thread = new HandlerThread("Operations thread", Process.THREAD_PRIORITY_BACKGROUND); thread.start(); mOperationsHandler = new ServiceHandler(thread.getLooper(), this); mOperationsBinder = new OperationsServiceBinder(mOperationsHandler); @@ -163,7 +158,7 @@ public void onCreate() { /** * Entry point to add a new operation to the queue of operations. - * + *

* New operations are added calling to startService(), resulting in a call to this method. * This ensures the service will keep on working although the caller activity goes away. */ @@ -186,8 +181,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { Pair itemToQueue = newOperation(intent); if (itemToQueue != null) { - mSyncFolderHandler.add(account, remotePath, - (SynchronizeFolderOperation) itemToQueue.second); + mSyncFolderHandler.add(account, remotePath, (SynchronizeFolderOperation) itemToQueue.second); Message msg = mSyncFolderHandler.obtainMessage(); msg.arg1 = startId; msg.obj = itemSyncKey; @@ -254,16 +248,15 @@ public boolean onUnbind(Intent intent) { *

* It provides by itself the available operations. */ - public class OperationsServiceBinder extends Binder /* implements OnRemoteOperationListener */ { + public class OperationsServiceBinder extends Binder { /** * Map of listeners that will be reported about the end of operations from a * {@link OperationsServiceBinder} instance */ - private final ConcurrentMap mBoundListeners = - new ConcurrentHashMap<>(); + private final ConcurrentMap mBoundListeners = new ConcurrentHashMap<>(); - private ServiceHandler mServiceHandler = null; + private ServiceHandler mServiceHandler; public OperationsServiceBinder(ServiceHandler serviceHandler) { mServiceHandler = serviceHandler; @@ -280,7 +273,6 @@ public void cancel(Account account, OCFile file) { } public void clearListeners() { - mBoundListeners.clear(); } @@ -291,8 +283,7 @@ public void clearListeners() { * @param callbackHandler {@link Handler} to access the listener without * breaking Android threading protection. */ - public void addOperationListener(OnRemoteOperationListener listener, - Handler callbackHandler) { + public void addOperationListener(OnRemoteOperationListener listener, Handler callbackHandler) { synchronized (mBoundListeners) { mBoundListeners.put(listener, callbackHandler); } @@ -322,7 +313,7 @@ public boolean isPerformingBlockingOperation() { /** * Creates and adds to the queue a new operation, as described by operationIntent. - * + *

* Calls startService to make the operation is processed by the ServiceHandler. * * @param operationIntent Intent describing a new operation to queue and execute. @@ -342,23 +333,21 @@ public long queueNewOperation(Intent operationIntent) { } } - public boolean dispatchResultIfFinished(int operationId, - OnRemoteOperationListener listener) { + public boolean dispatchResultIfFinished(int operationId, OnRemoteOperationListener listener) { Pair undispatched = mUndispatchedFinishedOperations.remove(operationId); if (undispatched != null) { listener.onRemoteOperationFinish(undispatched.first, undispatched.second); return true; - //Log_OC.e(TAG, "Sending callback later"); } else { - return (!mServiceHandler.mPendingOperations.isEmpty()); + return !mServiceHandler.mPendingOperations.isEmpty(); } } /** * Returns True when the file described by 'file' in the ownCloud account 'account' is * downloading or waiting to download. - * + *

* If 'file' is a directory, returns 'true' if some of its descendant files is downloading * or waiting to download. * @@ -374,7 +363,7 @@ public boolean isSynchronizing(Account account, OCFile file) { /** * Operations worker. Performs the pending operations in the order they were requested. - * + *

* Created with the Looper of a new thread, started in {@link OperationsService#onCreate()}. */ private static class ServiceHandler extends Handler { @@ -383,9 +372,8 @@ private static class ServiceHandler extends Handler { OperationsService mService; - private ConcurrentLinkedQueue> mPendingOperations = + private final ConcurrentLinkedQueue> mPendingOperations = new ConcurrentLinkedQueue<>(); - private RemoteOperation mCurrentOperation = null; private Target mLastTarget = null; private OwnCloudClient mOwnCloudClient = null; private FileDataStorageManager mStorageManager; @@ -419,7 +407,7 @@ private void nextOperation() { if (next != null) { - mCurrentOperation = next.second; + RemoteOperation currentOperation = next.second; RemoteOperationResult result; try { /// prepare client object to send the request to the ownCloud server @@ -451,11 +439,10 @@ private void nextOperation() { } /// perform the operation - if (mCurrentOperation instanceof SyncOperation) { - result = ((SyncOperation) mCurrentOperation).execute(mOwnCloudClient, - mStorageManager); + if (currentOperation instanceof SyncOperation) { + result = ((SyncOperation) currentOperation).execute(mOwnCloudClient, mStorageManager); } else { - result = mCurrentOperation.execute(mOwnCloudClient); + result = currentOperation.execute(mOwnCloudClient); } } catch (AccountsException | IOException e) { @@ -482,14 +469,14 @@ private void nextOperation() { } } - mService.dispatchResultToOperationListeners(mCurrentOperation, result); + mService.dispatchResultToOperationListeners(currentOperation, result); } } } /** * Creates a new operation, as described by operationIntent. - * + *

* TODO - move to ServiceHandler (probably) * * @param operationIntent Intent describing a new operation to queue and execute. @@ -544,24 +531,20 @@ private Pair newOperation(Intent operationIntent) { } else if (action.equals(ACTION_REMOVE)) { // Remove file or folder String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH); - boolean onlyLocalCopy = operationIntent.getBooleanExtra(EXTRA_REMOVE_ONLY_LOCAL, - false); + boolean onlyLocalCopy = operationIntent.getBooleanExtra(EXTRA_REMOVE_ONLY_LOCAL, false); operation = new RemoveFileOperation(remotePath, onlyLocalCopy, operationIntent.getBooleanExtra(EXTRA_IS_LAST_FILE_TO_REMOVE, false)); } else if (action.equals(ACTION_CREATE_FOLDER)) { // Create Folder String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH); - boolean createFullPath = operationIntent.getBooleanExtra(EXTRA_CREATE_FULL_PATH, - true); + boolean createFullPath = operationIntent.getBooleanExtra(EXTRA_CREATE_FULL_PATH, true); operation = new CreateFolderOperation(remotePath, createFullPath); } else if (action.equals(ACTION_SYNC_FILE)) { // Sync file String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH); - operation = new SynchronizeFileOperation( - remotePath, account, getApplicationContext() - ); + operation = new SynchronizeFileOperation(remotePath, account, getApplicationContext()); } else if (action.equals(ACTION_SYNC_FOLDER)) { // Sync folder (all its descendant files are sync'ed) @@ -612,14 +595,13 @@ remotePath, account, getApplicationContext() /** * Sends a broadcast when a new operation is added to the queue. - * + *

* Local broadcasts are only delivered to activities in the same process, but can't be * done sticky :\ * - * @param target Account or URL pointing to an OC server. - * @param operation Added operation. + * @param target Account or URL pointing to an OC server. */ - private void sendBroadcastNewOperation(Target target, RemoteOperation operation) { + private void sendBroadcastNewOperation(Target target) { Intent intent = new Intent(ACTION_OPERATION_ADDED); if (target.mAccount != null) { intent.putExtra(EXTRA_ACCOUNT, target.mAccount); @@ -634,15 +616,13 @@ private void sendBroadcastNewOperation(Target target, RemoteOperation operation) /** * Sends a LOCAL broadcast when an operations finishes in order to the interested activities c * an update their view - * + *

* Local broadcasts are only delivered to activities in the same process. * - * @param target Account or URL pointing to an OC server. - * @param operation Finished operation. - * @param result Result of the operation. + * @param target Account or URL pointing to an OC server. + * @param result Result of the operation. */ - private void sendBroadcastOperationFinished(Target target, RemoteOperation operation, - RemoteOperationResult result) { + private void sendBroadcastOperationFinished(Target target, RemoteOperationResult result) { Intent intent = new Intent(ACTION_OPERATION_FINISHED); intent.putExtra(EXTRA_RESULT, result); if (target.mAccount != null) { @@ -663,24 +643,15 @@ protected void dispatchResultToOperationListeners( final RemoteOperation operation, final RemoteOperationResult result ) { int count = 0; - Iterator listeners = - mOperationsBinder.mBoundListeners.keySet().iterator(); - while (listeners.hasNext()) { - final OnRemoteOperationListener listener = listeners.next(); + for (OnRemoteOperationListener listener : mOperationsBinder.mBoundListeners.keySet()) { final Handler handler = mOperationsBinder.mBoundListeners.get(listener); if (handler != null) { - handler.post(new Runnable() { - @Override - public void run() { - listener.onRemoteOperationFinish(operation, result); - } - }); + handler.post(() -> listener.onRemoteOperationFinish(operation, result)); count += 1; } } if (count == 0) { - Pair undispatched = - new Pair<>(operation, result); + Pair undispatched = new Pair<>(operation, result); mUndispatchedFinishedOperations.put(operation.hashCode(), undispatched); } Log_OC.d(TAG, "Called " + count + " listeners"); diff --git a/owncloudApp/src/main/java/com/owncloud/android/services/SyncFolderHandler.java b/owncloudApp/src/main/java/com/owncloud/android/services/SyncFolderHandler.java index cd86ab6b824..12810fe54a8 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/services/SyncFolderHandler.java +++ b/owncloudApp/src/main/java/com/owncloud/android/services/SyncFolderHandler.java @@ -138,8 +138,7 @@ private void doOperation(Account account, String remotePath) { } } - public void add(Account account, String remotePath, - SynchronizeFolderOperation syncFolderOperation) { + public void add(Account account, String remotePath, SynchronizeFolderOperation syncFolderOperation) { Pair putResult = mPendingOperations.putIfAbsent(account.name, remotePath, syncFolderOperation); if (putResult != null) { @@ -171,8 +170,6 @@ public void cancel(Account account, OCFile file) { mCurrentSyncOperation.cancel(); } } - - //sendBroadcastFinishedSyncFolder(account, file.getRemotePath()); } /** @@ -183,8 +180,7 @@ private void sendBroadcastNewSyncFolder(Account account, String remotePath) { Intent added = new Intent(FileDownloader.getDownloadAddedMessage()); added.putExtra(Extras.EXTRA_ACCOUNT_NAME, account.name); added.putExtra(Extras.EXTRA_REMOTE_PATH, remotePath); - added.putExtra(Extras.EXTRA_FILE_PATH, FileStorageUtils.getSavePath(account.name) - + remotePath); + added.putExtra(Extras.EXTRA_FILE_PATH, FileStorageUtils.getSavePath(account.name) + remotePath); mLocalBroadcastManager.sendBroadcast(added); } @@ -192,13 +188,11 @@ private void sendBroadcastNewSyncFolder(Account account, String remotePath) { * TODO review this method when "folder synchronization" replaces "folder download"; * this is a fast and ugly patch. */ - private void sendBroadcastFinishedSyncFolder(Account account, String remotePath, - boolean success) { + private void sendBroadcastFinishedSyncFolder(Account account, String remotePath, boolean success) { Intent finished = new Intent(FileDownloader.getDownloadFinishMessage()); finished.putExtra(Extras.EXTRA_ACCOUNT_NAME, account.name); finished.putExtra(Extras.EXTRA_REMOTE_PATH, remotePath); - finished.putExtra(Extras.EXTRA_FILE_PATH, - FileStorageUtils.getSavePath(account.name) + remotePath); + finished.putExtra(Extras.EXTRA_FILE_PATH, FileStorageUtils.getSavePath(account.name) + remotePath); finished.putExtra(Extras.EXTRA_DOWNLOAD_RESULT, success); mLocalBroadcastManager.sendBroadcast(finished); } From 59c4a2ad34e603dfe9a1ea6b8cb6fc1967f60102 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Sat, 4 Jan 2020 09:51:45 +0100 Subject: [PATCH 2/4] fix lint warnings (cherry picked from commit 44769d0b24a98dc1a1053ef1ff3bc5fbd7a75c1b) --- .../ui/fragment/ExtendedListFragment.java | 14 +-- .../ui/fragment/OCFileListFragment.java | 106 ++++++++---------- .../android/ui/helpers/FilesUploadHelper.java | 2 +- .../src/main/res/layout/list_fragment.xml | 1 + 4 files changed, 55 insertions(+), 68 deletions(-) diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java b/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java index 9f20b44189a..887516e297f 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java @@ -34,6 +34,7 @@ import android.widget.ProgressBar; import android.widget.TextView; +import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.getbase.floatingactionbutton.FloatingActionButton; @@ -140,10 +141,7 @@ public boolean isGridEnabled() { } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - Log_OC.d("onCreateView"); - + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.list_fragment, null); mProgressBar = v.findViewById(R.id.syncProgressBar); @@ -216,15 +214,15 @@ public void onActivityCreated(Bundle savedInstanceState) { setMessageForEmptyList(savedInstanceState.getString(KEY_EMPTY_LIST_MESSAGE)); } else { - mIndexes = new ArrayList(); - mFirstPositions = new ArrayList(); - mTops = new ArrayList(); + mIndexes = new ArrayList<>(); + mFirstPositions = new ArrayList<>(); + mTops = new ArrayList<>(); mHeightCell = 0; } } @Override - public void onSaveInstanceState(Bundle savedInstanceState) { + public void onSaveInstanceState(@NonNull Bundle savedInstanceState) { super.onSaveInstanceState(savedInstanceState); Log_OC.d("onSaveInstanceState()"); savedInstanceState.putBoolean(KEY_IS_GRID_VISIBLE, isGridEnabled()); diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index 3d0dcfffc6d..8045cb71f89 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -52,6 +52,7 @@ import android.widget.ListView; import android.widget.TextView; +import androidx.annotation.NonNull; import androidx.appcompat.widget.SearchView; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.drawerlayout.widget.DrawerLayout; @@ -170,7 +171,7 @@ public void onCreate(Bundle savedInstanceState) { * {@inheritDoc} */ @Override - public void onAttach(Context context) { + public void onAttach(@NonNull Context context) { super.onAttach(context); Log_OC.v(TAG, "onAttach"); try { @@ -262,14 +263,14 @@ public void onActivityCreated(Bundle savedInstanceState) { } // Allow or disallow touches with other visible windows - CoordinatorLayout coordinatorLayout = getActivity().findViewById(R.id.coordinator_layout); + CoordinatorLayout coordinatorLayout = requireActivity().findViewById(R.id.coordinator_layout); coordinatorLayout.setFilterTouchesWhenObscured( PreferenceUtils.shouldDisallowTouchesWithOtherVisibleWindows(getContext()) ); } @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); mSearchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); mSearchView.setMaxWidth(Integer.MAX_VALUE); @@ -302,36 +303,28 @@ private void registerFabUploadListeners() { getFabUpload().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Log_OC.i(TAG, "Clicked" + getContext().toString()); final View uploadBottomSheet = getLayoutInflater().inflate(R.layout.upload_bottom_sheet_fragment, null); - final BottomSheetDialog dialog = new BottomSheetDialog(getContext()); + final BottomSheetDialog dialog = new BottomSheetDialog(requireContext()); dialog.setContentView(uploadBottomSheet); final LinearLayout uploadFilesLinearLayout = uploadBottomSheet.findViewById(R.id.files_linear_layout); LinearLayout uploadFromCameraLinearLayout = uploadBottomSheet.findViewById(R.id.upload_from_camera_linear_layout); TextView uploadToTextView = uploadBottomSheet.findViewById(R.id.upload_to_text_view); - uploadFilesLinearLayout.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - Intent action = new Intent(Intent.ACTION_GET_CONTENT); - action = action.setType(ALL_FILES_SAF_REGEX).addCategory(Intent.CATEGORY_OPENABLE); - action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); - getActivity().startActivityForResult( - Intent.createChooser(action, getString(R.string.upload_chooser_title)), - FileDisplayActivity.REQUEST_CODE__SELECT_CONTENT_FROM_APPS - ); - dialog.hide(); - return false; - } + uploadFilesLinearLayout.setOnTouchListener((v13, event) -> { + Intent action = new Intent(Intent.ACTION_GET_CONTENT); + action = action.setType(ALL_FILES_SAF_REGEX).addCategory(Intent.CATEGORY_OPENABLE); + action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); + getActivity().startActivityForResult( + Intent.createChooser(action, getString(R.string.upload_chooser_title)), + FileDisplayActivity.REQUEST_CODE__SELECT_CONTENT_FROM_APPS + ); + dialog.hide(); + return false; }); - uploadFromCameraLinearLayout.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - - ((FileDisplayActivity) getActivity()).getFilesUploadHelper().uploadFromCamera(FileDisplayActivity.REQUEST_CODE__UPLOAD_FROM_CAMERA); - dialog.hide(); - return false; - } + uploadFromCameraLinearLayout.setOnTouchListener((v12, event) -> { + ((FileDisplayActivity) getActivity()).getFilesUploadHelper().uploadFromCamera(FileDisplayActivity.REQUEST_CODE__UPLOAD_FROM_CAMERA); + dialog.hide(); + return false; }); uploadToTextView.setText(String.format(getResources().getString(R.string.upload_to), getResources().getString(R.string.app_name))); @@ -366,9 +359,8 @@ private void registerFabMkDirListeners() { getFabMkdir().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - CreateFolderDialogFragment dialog = - CreateFolderDialogFragment.newInstance(mFile); - dialog.show(getActivity().getSupportFragmentManager(), DIALOG_CREATE_FOLDER); + CreateFolderDialogFragment dialog = CreateFolderDialogFragment.newInstance(mFile); + dialog.show(requireActivity().getSupportFragmentManager(), DIALOG_CREATE_FOLDER); getFabMain().collapse(); recordMiniFabClick(); } @@ -394,7 +386,7 @@ private void recordMiniFabClick() { // only record if it hasn't been done already at some other time if (!miniFabClicked) { final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); - sp.edit().putLong(KEY_FAB_EVER_CLICKED, 1).commit(); + sp.edit().putLong(KEY_FAB_EVER_CLICKED, 1).apply(); miniFabClicked = true; } } @@ -405,10 +397,8 @@ private void recordMiniFabClick() { private void removeFabLabels() { getFabUpload().setTitle(null); getFabMkdir().setTitle(null); - ((TextView) getFabUpload().getTag( - com.getbase.floatingactionbutton.R.id.fab_label)).setVisibility(View.GONE); - ((TextView) getFabMkdir().getTag( - com.getbase.floatingactionbutton.R.id.fab_label)).setVisibility(View.GONE); + ((TextView) getFabUpload().getTag(com.getbase.floatingactionbutton.R.id.fab_label)).setVisibility(View.GONE); + ((TextView) getFabMkdir().getTag(com.getbase.floatingactionbutton.R.id.fab_label)).setVisibility(View.GONE); } @Override @@ -427,7 +417,7 @@ public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { setMessageForEmptyList(getString(R.string.local_file_list_search_with_no_matches)); } else { // Set default message for empty list of files - ((FileDisplayActivity) getActivity()).setBackgroundText(); + ((FileDisplayActivity) requireActivity()).setBackgroundText(); } } @@ -460,12 +450,12 @@ private class MultiChoiceModeListener private SparseBooleanArray mSelectionWhenActionModeClosedByDrawer = null; @Override - public void onDrawerSlide(View drawerView, float slideOffset) { + public void onDrawerSlide(@NonNull View drawerView, float slideOffset) { // nothing to do } @Override - public void onDrawerOpened(View drawerView) { + public void onDrawerOpened(@NonNull View drawerView) { clearLocalSearchView(); } @@ -476,7 +466,7 @@ public void onDrawerOpened(View drawerView) { * @param drawerView Navigation drawer just closed. */ @Override - public void onDrawerClosed(View drawerView) { + public void onDrawerClosed(@NonNull View drawerView) { if (mSelectionWhenActionModeClosedByDrawer != null && mActionModeClosedByDrawer) { for (int i = 0; i < mSelectionWhenActionModeClosedByDrawer.size(); i++) { if (mSelectionWhenActionModeClosedByDrawer.valueAt(i)) { @@ -528,7 +518,7 @@ public void onItemCheckedStateChanged(ActionMode mode, int position, long id, bo public boolean onCreateActionMode(ActionMode mode, Menu menu) { mActiveActionMode = mode; - MenuInflater inflater = getActivity().getMenuInflater(); + MenuInflater inflater = requireActivity().getMenuInflater(); inflater.inflate(R.menu.file_actions_menu, menu); mode.invalidate(); @@ -558,7 +548,7 @@ public boolean onPrepareActionMode(ActionMode mode, Menu menu) { mode.setTitle(title); FileMenuFilter mf = new FileMenuFilter( checkedFiles, - ((FileActivity) getActivity()).getAccount(), + ((FileActivity) requireActivity()).getAccount(), mContainerActivity, getActivity() ); @@ -582,7 +572,7 @@ public void onDestroyActionMode(ActionMode mode) { mActiveActionMode = null; // reset to previous color - getActivity().getWindow().setStatusBarColor(mStatusBarColor); + requireActivity().getWindow().setStatusBarColor(mStatusBarColor); // show FAB on multi selection mode exit if (!mHideFab) { @@ -615,7 +605,7 @@ public void loadStateFrom(Bundle savedInstanceState) { } private void clearLocalSearchView() { - ((FileActivity) getActivity()).hideSoftKeyboard(); + ((FileActivity) requireActivity()).hideSoftKeyboard(); mFileListAdapter.clearFilterBySearch(); if (mSearchView != null) { mSearchView.onActionViewCollapsed(); @@ -632,7 +622,7 @@ private void setChoiceModeAsMultipleModal(Bundle savedInstanceState) { mMultiChoiceModeListener.loadStateFrom(savedInstanceState); } setMultiChoiceModeListener(mMultiChoiceModeListener); - ((FileActivity) getActivity()).addDrawerListener(mMultiChoiceModeListener); + ((FileActivity) requireActivity()).addDrawerListener(mMultiChoiceModeListener); } /** @@ -651,7 +641,7 @@ public void onSaveInstanceState(Bundle outState) { } @Override - public void onPrepareOptionsMenu(Menu menu) { + public void onPrepareOptionsMenu(@NonNull Menu menu) { if (isShowingOnlyAvailableOffline() || isShowingSharedByLinkFiles()) { super.onPrepareOptionsMenu(menu); @@ -738,9 +728,12 @@ private void listDirectoryWithAnimationDown(final OCFile file) { } private boolean isInPowerSaveMode() { - PowerManager powerManager = (PowerManager) - getActivity().getSystemService(Context.POWER_SERVICE); - return powerManager.isPowerSaveMode(); + PowerManager powerManager = (PowerManager) requireActivity().getSystemService(Context.POWER_SERVICE); + if (powerManager != null) { + return powerManager.isPowerSaveMode(); + } else { + return false; + } } private void listDirectoryWidthAnimationUp(final OCFile file) { @@ -823,7 +816,6 @@ public void onItemClick(AdapterView l, View v, int position, long id) { } /** - * @param file * @return 'true' if the file is being downloaded, 'false' otherwise. */ private boolean fileIsDownloading(OCFile file) { @@ -939,13 +931,13 @@ public boolean onFileActionChosen(int menuId) { case R.id.action_move: { Intent action = new Intent(getActivity(), FolderPickerActivity.class); action.putParcelableArrayListExtra(FolderPickerActivity.EXTRA_FILES, checkedFiles); - getActivity().startActivityForResult(action, FileDisplayActivity.REQUEST_CODE__MOVE_FILES); + requireActivity().startActivityForResult(action, FileDisplayActivity.REQUEST_CODE__MOVE_FILES); return true; } case R.id.action_copy: Intent action = new Intent(getActivity(), FolderPickerActivity.class); action.putParcelableArrayListExtra(FolderPickerActivity.EXTRA_FILES, checkedFiles); - getActivity().startActivityForResult(action, FileDisplayActivity.REQUEST_CODE__COPY_FILES); + requireActivity().startActivityForResult(action, FileDisplayActivity.REQUEST_CODE__COPY_FILES); return true; default: return false; @@ -1038,10 +1030,8 @@ private void updateLayout() { } // decide grid vs list view - OwnCloudVersion version = AccountUtils.getServerVersion( - ((FileActivity) mContainerActivity).getAccount()); - if (version != null && version.supportsRemoteThumbnails() && - isGridViewPreferred(mFile)) { + OwnCloudVersion version = AccountUtils.getServerVersion(((FileActivity) mContainerActivity).getAccount()); + if (version != null && version.supportsRemoteThumbnails() && isGridViewPreferred(mFile)) { switchToGridView(); } else { switchToListView(); @@ -1127,9 +1117,7 @@ public boolean isGridViewPreferred(OCFile file) { FileDataStorageManager storageManager = mContainerActivity.getStorageManager(); SharedPreferences setting = - getActivity().getSharedPreferences( - GRID_IS_PREFERED_PREFERENCE, Context.MODE_PRIVATE - ); + requireActivity().getSharedPreferences(GRID_IS_PREFERED_PREFERENCE, Context.MODE_PRIVATE); if (setting.contains(String.valueOf(fileToTest.getFileId()))) { return setting.getBoolean(String.valueOf(fileToTest.getFileId()), false); @@ -1189,7 +1177,7 @@ public void setGridAsPreferred() { } private void saveGridAsPreferred(boolean setGrid) { - SharedPreferences setting = getActivity().getSharedPreferences( + SharedPreferences setting = requireActivity().getSharedPreferences( GRID_IS_PREFERED_PREFERENCE, Context.MODE_PRIVATE ); @@ -1205,7 +1193,7 @@ private void saveGridAsPreferred(boolean setGrid) { */ private void showSnackMessage(int messageResource) { Snackbar snackbar = Snackbar.make( - getActivity().findViewById(R.id.coordinator_layout), + requireActivity().findViewById(R.id.coordinator_layout), messageResource, Snackbar.LENGTH_LONG ); diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/helpers/FilesUploadHelper.java b/owncloudApp/src/main/java/com/owncloud/android/ui/helpers/FilesUploadHelper.java index 2cabe3bc595..083060b73dc 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/helpers/FilesUploadHelper.java +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/helpers/FilesUploadHelper.java @@ -170,7 +170,7 @@ private File createImageFile() { /** * Function to send an intent to the device's camera to capture a picture - * */ + */ public void uploadFromCamera(final int requestCode) { Intent pictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File photoFile = createImageFile(); diff --git a/owncloudApp/src/main/res/layout/list_fragment.xml b/owncloudApp/src/main/res/layout/list_fragment.xml index 55257df2a95..fd99ed76ced 100644 --- a/owncloudApp/src/main/res/layout/list_fragment.xml +++ b/owncloudApp/src/main/res/layout/list_fragment.xml @@ -121,6 +121,7 @@ fab:fab_icon="@drawable/ic_action_create_dir" fab:fab_size="mini" fab:fab_title="" /> + From 0f7534c15e7cb3362af6ef5101cb42dc651f1b57 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Fri, 10 Jan 2020 15:51:11 +0100 Subject: [PATCH 3/4] apply code review wish --- .../owncloud/android/ui/fragment/OCFileListFragment.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index 8045cb71f89..5b1432accf4 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -729,11 +729,7 @@ private void listDirectoryWithAnimationDown(final OCFile file) { private boolean isInPowerSaveMode() { PowerManager powerManager = (PowerManager) requireActivity().getSystemService(Context.POWER_SERVICE); - if (powerManager != null) { - return powerManager.isPowerSaveMode(); - } else { - return false; - } + return (powerManager != null) && powerManager.isPowerSaveMode(); } private void listDirectoryWidthAnimationUp(final OCFile file) { From db58c3ea013ba991a471df1b43dfbc9fc62a43fe Mon Sep 17 00:00:00 2001 From: davigonz Date: Tue, 14 Jan 2020 16:39:49 +0100 Subject: [PATCH 4/4] Update library reference with latest changes --- owncloud-android-library | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/owncloud-android-library b/owncloud-android-library index a1d4c781aeb..a63dd63b394 160000 --- a/owncloud-android-library +++ b/owncloud-android-library @@ -1 +1 @@ -Subproject commit a1d4c781aeb3f40b1f4c570af9708214054d22ac +Subproject commit a63dd63b39492d6f5ddf30312fd9feaf5a190409