@@ -462,7 +462,9 @@ protected void setAdapter(Bundle args) {
462462
463463 setRecyclerViewAdapter (mAdapter );
464464
465- fastScrollUtils .applyFastScroll (getRecyclerView ());
465+ if (getRecyclerView () != null ) {
466+ fastScrollUtils .applyFastScroll (getRecyclerView ());
467+ }
466468 }
467469
468470 protected void prepareCurrentSearch (SearchEvent event ) {
@@ -788,7 +790,7 @@ public void onDrawerStateChanged(int newState) {
788790 return ;
789791 }
790792
791- if (getRecyclerView ().getAdapter () instanceof OCFileListAdapter fileListAdapter ) {
793+ if (getRecyclerView () != null && getRecyclerView () .getAdapter () instanceof OCFileListAdapter fileListAdapter ) {
792794 mSelectionWhenActionModeClosedByDrawer .addAll (fileListAdapter .getCheckedItems ());
793795 }
794796
@@ -1156,8 +1158,12 @@ private void folderOnItemClick(OCFile file, int position) {
11561158
11571159 if (ocCapability .getEndToEndEncryption ().isFalse () ||
11581160 ocCapability .getEndToEndEncryption ().isUnknown ()) {
1159- Snackbar .make (getRecyclerView (), R .string .end_to_end_encryption_not_enabled ,
1160- Snackbar .LENGTH_LONG ).show ();
1161+
1162+ if (getRecyclerView () != null ) {
1163+ Snackbar .make (getRecyclerView (), R .string .end_to_end_encryption_not_enabled ,
1164+ Snackbar .LENGTH_LONG ).show ();
1165+ }
1166+
11611167 return ;
11621168 }
11631169 // check if keys are stored
@@ -1169,9 +1175,12 @@ private void folderOnItemClick(OCFile file, int position) {
11691175 if (mContainerActivity instanceof FolderPickerActivity &&
11701176 ((FolderPickerActivity ) mContainerActivity )
11711177 .isDoNotEnterEncryptedFolder ()) {
1172- Snackbar .make (getRecyclerView (),
1173- R .string .copy_move_to_encrypted_folder_not_supported ,
1174- Snackbar .LENGTH_LONG ).show ();
1178+
1179+ if (getRecyclerView () != null ) {
1180+ Snackbar .make (getRecyclerView (),
1181+ R .string .copy_move_to_encrypted_folder_not_supported ,
1182+ Snackbar .LENGTH_LONG ).show ();
1183+ }
11751184 } else {
11761185 browseToFolder (file , position );
11771186 }
@@ -1211,7 +1220,7 @@ private Integer checkFileBeforeOpen(OCFile file) {
12111220
12121221 private void fileOnItemClick (OCFile file ) {
12131222 Integer errorMessageId = checkFileBeforeOpen (file );
1214- if (errorMessageId != null ) {
1223+ if (errorMessageId != null && getRecyclerView () != null ) {
12151224 Snackbar .make (getRecyclerView (),
12161225 errorMessageId ,
12171226 Snackbar .LENGTH_LONG ).show ();
@@ -1583,10 +1592,10 @@ public void listDirectory(OCFile directory, OCFile file, boolean onlyOnDevice, b
15831592 if (file != null ) {
15841593 mAdapter .setHighlightedItem (file );
15851594 int position = mAdapter .getItemPosition (file );
1586- if (position != -1 ) {
1595+ if (position != -1 && getRecyclerView () != null ) {
15871596 getRecyclerView ().scrollToPosition (position );
15881597 }
1589- } else if (previousDirectory == null || !previousDirectory .equals (directory )) {
1598+ } else if (getRecyclerView () != null && ( previousDirectory == null || !previousDirectory .equals (directory ) )) {
15901599 getRecyclerView ().scrollToPosition (0 );
15911600 }
15921601 } else if (isSearchEventSet (searchEvent )) {
@@ -1682,10 +1691,11 @@ public void switchToGridView() {
16821691 }
16831692 }
16841693
1694+ @ SuppressLint ("NotifyDataSetChanged" )
16851695 public void switchLayoutManager (boolean grid ) {
16861696 int position = 0 ;
16871697
1688- if (getRecyclerView ().getLayoutManager () != null ) {
1698+ if (getRecyclerView () != null && getRecyclerView () .getLayoutManager () != null ) {
16891699 position = ((LinearLayoutManager ) getRecyclerView ().getLayoutManager ())
16901700 .findFirstCompletelyVisibleItemPosition ();
16911701 }
@@ -1709,11 +1719,13 @@ public int getSpanSize(int position) {
17091719 layoutManager = new LinearLayoutManager (getContext ());
17101720 }
17111721
1712- getRecyclerView ().setLayoutManager (layoutManager );
1713- getRecyclerView ().scrollToPosition (position );
1714- getAdapter ().setGridView (grid );
1715- getRecyclerView ().setAdapter (getAdapter ());
1716- getAdapter ().notifyDataSetChanged ();
1722+ if (getRecyclerView () != null ) {
1723+ getRecyclerView ().setLayoutManager (layoutManager );
1724+ getRecyclerView ().scrollToPosition (position );
1725+ getAdapter ().setGridView (grid );
1726+ getRecyclerView ().setAdapter (getAdapter ());
1727+ getAdapter ().notifyDataSetChanged ();
1728+ }
17171729 }
17181730
17191731 public CommonOCFileListAdapterInterface getCommonAdapter () {
@@ -2034,14 +2046,18 @@ private void encryptFolder(OCFile folder,
20342046 }
20352047
20362048 requireActivity ().runOnUiThread (() -> mAdapter .setEncryptionAttributeForItemID (remoteId , shouldBeEncrypted ));
2037- } else if (remoteOperationResult .getHttpCode () == HttpStatus .SC_FORBIDDEN ) {
2049+ } else if (remoteOperationResult .getHttpCode () == HttpStatus .SC_FORBIDDEN && getRecyclerView () != null ) {
20382050 requireActivity ().runOnUiThread (() -> Snackbar .make (getRecyclerView (),
20392051 R .string .end_to_end_encryption_folder_not_empty ,
20402052 Snackbar .LENGTH_LONG ).show ());
20412053 } else {
2042- requireActivity ().runOnUiThread (() -> Snackbar .make (getRecyclerView (),
2043- R .string .common_error_unknown ,
2044- Snackbar .LENGTH_LONG ).show ());
2054+ requireActivity ().runOnUiThread (() -> {{
2055+ if (getRecyclerView () != null ) {
2056+ Snackbar .make (getRecyclerView (),
2057+ R .string .common_error_unknown ,
2058+ Snackbar .LENGTH_LONG ).show ();
2059+ }
2060+ }});
20452061 }
20462062
20472063 } catch (Throwable e ) {
@@ -2062,17 +2078,20 @@ public void onMessageEvent(FileLockEvent event) {
20622078 if (result .isSuccess ()) {
20632079 // TODO only refresh the modified file?
20642080 new Handler (Looper .getMainLooper ()).post (this ::onRefresh );
2065- } else {
2081+ } else if ( getRecyclerView () != null ) {
20662082 Snackbar .make (getRecyclerView (),
20672083 R .string .error_file_lock ,
20682084 Snackbar .LENGTH_LONG ).show ();
20692085 }
20702086
20712087 } catch (ClientFactory .CreationException e ) {
20722088 Log_OC .e (TAG , "Cannot create client" , e );
2073- Snackbar .make (getRecyclerView (),
2074- R .string .error_file_lock ,
2075- Snackbar .LENGTH_LONG ).show ();
2089+
2090+ if (getRecyclerView () != null ) {
2091+ Snackbar .make (getRecyclerView (),
2092+ R .string .error_file_lock ,
2093+ Snackbar .LENGTH_LONG ).show ();
2094+ }
20762095 } finally {
20772096 new Handler (Looper .getMainLooper ()).post (() -> setLoading (false ));
20782097 }
@@ -2148,6 +2167,10 @@ public boolean isSearchFragment() {
21482167 */
21492168 @ SuppressLint ("NotifyDataSetChanged" )
21502169 public void selectAllFiles (boolean select ) {
2170+ if (getRecyclerView () == null ) {
2171+ return ;
2172+ }
2173+
21512174 final var adapter = getRecyclerView ().getAdapter ();
21522175 if (adapter instanceof CommonOCFileListAdapterInterface commonInterface ) {
21532176 commonInterface .selectAll (select );
0 commit comments