3535import com .owncloud .android .R ;
3636import com .owncloud .android .datamodel .FileDataStorageManager ;
3737import com .owncloud .android .datamodel .OCFile ;
38+ import com .owncloud .android .datamodel .OCFileDepth ;
3839import com .owncloud .android .lib .common .utils .Log_OC ;
40+ import com .owncloud .android .ui .fragment .OCFileListFragment ;
3941import com .owncloud .android .ui .fragment .SearchType ;
4042import com .owncloud .android .utils .theme .ThemeColorUtils ;
4143import com .owncloud .android .utils .theme .ThemeUtils ;
@@ -136,6 +138,9 @@ public void setupToolbarShowOnlyMenuButtonAndTitle(String title, View.OnClickLis
136138 menuButton .setOnClickListener (toggleDrawer );
137139 }
138140
141+ /**
142+ * Shows plain action bar
143+ */
139144 public void setupToolbar () {
140145 if (mHomeSearchToolbar != null && mDefaultToolbar != null && mHomeSearchToolbar .getVisibility () == View .GONE && mDefaultToolbar .getVisibility () == View .VISIBLE ) {
141146 Log_OC .d (TAG , "Search toolbar is already hidden, skipping update." );
@@ -145,6 +150,9 @@ public void setupToolbar() {
145150 setupToolbar (false , false );
146151 }
147152
153+ /**
154+ * Shows action bar with search
155+ */
148156 public void setupHomeSearchToolbarWithSortAndListButtons () {
149157 if (mHomeSearchToolbar != null && mDefaultToolbar != null && mHomeSearchToolbar .getVisibility () == View .VISIBLE && mDefaultToolbar .getVisibility () == View .GONE ) {
150158 Log_OC .d (TAG , "Search toolbar is already visible, skipping update." );
@@ -154,22 +162,34 @@ public void setupHomeSearchToolbarWithSortAndListButtons() {
154162 setupToolbar (true , true );
155163 }
156164
157- public void updateActionBarTitleAndHomeButton ( OCFile chosenFile , SearchType searchType ) {
158- if (mAppBar == null ) {
159- return ;
165+ private OCFileListFragment getOCFileListFragment ( ) {
166+ if (this instanceof FileDisplayActivity fda ) {
167+ return fda . getListOfFilesFragment () ;
160168 }
161169
162- boolean isRoot = isRoot (chosenFile );
163- String title = getActionBarTitle (chosenFile , searchType );
164- updateActionBarTitleAndHomeButtonByString (title );
165- showHomeSearchToolbar (title , isRoot );
170+ return null ;
166171 }
167172
168- protected void updateActionBarTitleAndHomeButton (OCFile chosenFile ) {
169- updateActionBarTitleAndHomeButton (chosenFile , SearchType .NO_SEARCH );
173+ private OCFileDepth getCurrentDirDepth () {
174+ OCFileListFragment fragment = getOCFileListFragment ();
175+ if (fragment != null ) {
176+ return fragment .getFileDepth ();
177+ }
178+
179+ return null ;
170180 }
171181
172- public String getActionBarRootTitle (@ NonNull SearchType searchType ) {
182+ private SearchType getSearchType () {
183+ OCFileListFragment fragment = getOCFileListFragment ();
184+ if (fragment != null ) {
185+ return fragment .getCurrentSearchType ();
186+ }
187+
188+ return SearchType .NO_SEARCH ;
189+ }
190+
191+ public String getActionBarRootTitle () {
192+ final SearchType searchType = getSearchType ();
173193 Integer rootTitleId = searchType .titleId ();
174194 String result = themeUtils .getDefaultDisplayNameForRootFolder (this );
175195
@@ -180,9 +200,9 @@ public String getActionBarRootTitle(@NonNull SearchType searchType) {
180200 return result ;
181201 }
182202
183- public String getActionBarTitle (OCFile chosenFile , @ NonNull SearchType searchType ) {
203+ public String getActionBarTitle (OCFile chosenFile ) {
184204 if (isRoot (chosenFile )) {
185- return getActionBarRootTitle (searchType );
205+ return getActionBarRootTitle ();
186206 }
187207
188208 if (chosenFile .isFolder ()) {
@@ -198,6 +218,24 @@ public String getActionBarTitle(OCFile chosenFile, @NonNull SearchType searchTyp
198218 return fileDataStorageManager .getFilenameConsideringOfflineOperation (parentFile );
199219 }
200220
221+ protected void updateActionBarTitleAndHomeButton (OCFile chosenFile ) {
222+ if (mAppBar == null ) {
223+ return ;
224+ }
225+
226+ final OCFileDepth currentDirDepth = getCurrentDirDepth ();
227+ final boolean isRoot = isRoot (chosenFile ) || currentDirDepth == OCFileDepth .Root ;
228+ final String title = getActionBarTitle (chosenFile );
229+ updateActionBarTitleAndHomeButtonByString (title );
230+
231+ final boolean isToolbarStyleSearch = DrawerActivity .isToolbarStyleSearch ();
232+ final boolean canShowSearchBar = (isHomeSearchToolbarShow && isRoot && isToolbarStyleSearch );
233+
234+ showHomeSearchToolbar (canShowSearchBar );
235+ mSearchText .setText (getString (R .string .appbar_search_in , title ));
236+ }
237+
238+
201239 public void showSearchView () {
202240 if (isHomeSearchToolbarShow ) {
203241 showHomeSearchToolbar (false );
@@ -210,11 +248,6 @@ public void hideSearchView(OCFile chosenFile) {
210248 }
211249 }
212250
213- private void showHomeSearchToolbar (String title , boolean isRoot ) {
214- showHomeSearchToolbar (isHomeSearchToolbarShow && isRoot );
215- mSearchText .setText (getString (R .string .appbar_search_in , title ));
216- }
217-
218251 @ SuppressLint ("PrivateResource" )
219252 private void showHomeSearchToolbar (boolean isShow ) {
220253 viewThemeUtils .material .themeToolbar (mToolbar );
0 commit comments