@@ -462,7 +462,9 @@ protected void setAdapter(Bundle args) {
462
462
463
463
setRecyclerViewAdapter (mAdapter );
464
464
465
- fastScrollUtils .applyFastScroll (getRecyclerView ());
465
+ if (getRecyclerView () != null ) {
466
+ fastScrollUtils .applyFastScroll (getRecyclerView ());
467
+ }
466
468
}
467
469
468
470
protected void prepareCurrentSearch (SearchEvent event ) {
@@ -788,7 +790,7 @@ public void onDrawerStateChanged(int newState) {
788
790
return ;
789
791
}
790
792
791
- if (getRecyclerView ().getAdapter () instanceof OCFileListAdapter fileListAdapter ) {
793
+ if (getRecyclerView () != null && getRecyclerView () .getAdapter () instanceof OCFileListAdapter fileListAdapter ) {
792
794
mSelectionWhenActionModeClosedByDrawer .addAll (fileListAdapter .getCheckedItems ());
793
795
}
794
796
@@ -1156,8 +1158,12 @@ private void folderOnItemClick(OCFile file, int position) {
1156
1158
1157
1159
if (ocCapability .getEndToEndEncryption ().isFalse () ||
1158
1160
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
+
1161
1167
return ;
1162
1168
}
1163
1169
// check if keys are stored
@@ -1169,9 +1175,12 @@ private void folderOnItemClick(OCFile file, int position) {
1169
1175
if (mContainerActivity instanceof FolderPickerActivity &&
1170
1176
((FolderPickerActivity ) mContainerActivity )
1171
1177
.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
+ }
1175
1184
} else {
1176
1185
browseToFolder (file , position );
1177
1186
}
@@ -1211,7 +1220,7 @@ private Integer checkFileBeforeOpen(OCFile file) {
1211
1220
1212
1221
private void fileOnItemClick (OCFile file ) {
1213
1222
Integer errorMessageId = checkFileBeforeOpen (file );
1214
- if (errorMessageId != null ) {
1223
+ if (errorMessageId != null && getRecyclerView () != null ) {
1215
1224
Snackbar .make (getRecyclerView (),
1216
1225
errorMessageId ,
1217
1226
Snackbar .LENGTH_LONG ).show ();
@@ -1583,10 +1592,10 @@ public void listDirectory(OCFile directory, OCFile file, boolean onlyOnDevice, b
1583
1592
if (file != null ) {
1584
1593
mAdapter .setHighlightedItem (file );
1585
1594
int position = mAdapter .getItemPosition (file );
1586
- if (position != -1 ) {
1595
+ if (position != -1 && getRecyclerView () != null ) {
1587
1596
getRecyclerView ().scrollToPosition (position );
1588
1597
}
1589
- } else if (previousDirectory == null || !previousDirectory .equals (directory )) {
1598
+ } else if (getRecyclerView () != null && ( previousDirectory == null || !previousDirectory .equals (directory ) )) {
1590
1599
getRecyclerView ().scrollToPosition (0 );
1591
1600
}
1592
1601
} else if (isSearchEventSet (searchEvent )) {
@@ -1682,10 +1691,11 @@ public void switchToGridView() {
1682
1691
}
1683
1692
}
1684
1693
1694
+ @ SuppressLint ("NotifyDataSetChanged" )
1685
1695
public void switchLayoutManager (boolean grid ) {
1686
1696
int position = 0 ;
1687
1697
1688
- if (getRecyclerView ().getLayoutManager () != null ) {
1698
+ if (getRecyclerView () != null && getRecyclerView () .getLayoutManager () != null ) {
1689
1699
position = ((LinearLayoutManager ) getRecyclerView ().getLayoutManager ())
1690
1700
.findFirstCompletelyVisibleItemPosition ();
1691
1701
}
@@ -1709,11 +1719,13 @@ public int getSpanSize(int position) {
1709
1719
layoutManager = new LinearLayoutManager (getContext ());
1710
1720
}
1711
1721
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
+ }
1717
1729
}
1718
1730
1719
1731
public CommonOCFileListAdapterInterface getCommonAdapter () {
@@ -2034,14 +2046,18 @@ private void encryptFolder(OCFile folder,
2034
2046
}
2035
2047
2036
2048
requireActivity ().runOnUiThread (() -> mAdapter .setEncryptionAttributeForItemID (remoteId , shouldBeEncrypted ));
2037
- } else if (remoteOperationResult .getHttpCode () == HttpStatus .SC_FORBIDDEN ) {
2049
+ } else if (remoteOperationResult .getHttpCode () == HttpStatus .SC_FORBIDDEN && getRecyclerView () != null ) {
2038
2050
requireActivity ().runOnUiThread (() -> Snackbar .make (getRecyclerView (),
2039
2051
R .string .end_to_end_encryption_folder_not_empty ,
2040
2052
Snackbar .LENGTH_LONG ).show ());
2041
2053
} 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
+ }});
2045
2061
}
2046
2062
2047
2063
} catch (Throwable e ) {
@@ -2062,17 +2078,20 @@ public void onMessageEvent(FileLockEvent event) {
2062
2078
if (result .isSuccess ()) {
2063
2079
// TODO only refresh the modified file?
2064
2080
new Handler (Looper .getMainLooper ()).post (this ::onRefresh );
2065
- } else {
2081
+ } else if ( getRecyclerView () != null ) {
2066
2082
Snackbar .make (getRecyclerView (),
2067
2083
R .string .error_file_lock ,
2068
2084
Snackbar .LENGTH_LONG ).show ();
2069
2085
}
2070
2086
2071
2087
} catch (ClientFactory .CreationException e ) {
2072
2088
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
+ }
2076
2095
} finally {
2077
2096
new Handler (Looper .getMainLooper ()).post (() -> setLoading (false ));
2078
2097
}
@@ -2148,6 +2167,10 @@ public boolean isSearchFragment() {
2148
2167
*/
2149
2168
@ SuppressLint ("NotifyDataSetChanged" )
2150
2169
public void selectAllFiles (boolean select ) {
2170
+ if (getRecyclerView () == null ) {
2171
+ return ;
2172
+ }
2173
+
2151
2174
final var adapter = getRecyclerView ().getAdapter ();
2152
2175
if (adapter instanceof CommonOCFileListAdapterInterface commonInterface ) {
2153
2176
commonInterface .selectAll (select );
0 commit comments