Skip to content

Commit 27ed93e

Browse files
committed
while setting toolbar check toolbar style as well
Signed-off-by: alperozturk <[email protected]>
1 parent 9f16063 commit 27ed93e

File tree

4 files changed

+63
-31
lines changed

4 files changed

+63
-31
lines changed

app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@
9393
import com.owncloud.android.ui.fragment.GalleryFragment;
9494
import com.owncloud.android.ui.fragment.GroupfolderListFragment;
9595
import com.owncloud.android.ui.fragment.OCFileListFragment;
96-
import com.owncloud.android.ui.fragment.SearchType;
9796
import com.owncloud.android.ui.fragment.SharedListFragment;
9897
import com.owncloud.android.ui.preview.PreviewTextStringFragment;
9998
import com.owncloud.android.ui.trashbin.TrashbinActivity;
@@ -832,13 +831,7 @@ public void setDrawerIndicatorEnabled(boolean enable) {
832831
* Updates title bar and home buttons (state and icon). Assumes that navigation drawer is NOT visible.
833832
*/
834833
protected void updateActionBarTitleAndHomeButton(OCFile chosenFile) {
835-
final var ocFileListFragment = getOCFileListFragment();
836-
SearchType searchType = SearchType.NO_SEARCH;
837-
if (ocFileListFragment != null) {
838-
searchType = ocFileListFragment.getCurrentSearchType();
839-
}
840-
841-
updateActionBarTitleAndHomeButton(chosenFile, searchType);
834+
super.updateActionBarTitleAndHomeButton(chosenFile);
842835

843836
// set home button properties
844837
if (mDrawerToggle != null) {
@@ -1458,4 +1451,10 @@ private void checkStoragePermissionWarningBannerVisibility() {
14581451
uploadFilesActivity.setupStoragePermissionWarningBanner();
14591452
}
14601453
}
1454+
1455+
public static boolean isToolbarStyleSearch() {
1456+
return menuItemId == Menu.NONE ||
1457+
menuItemId == R.id.nav_all_files ||
1458+
menuItemId == R.id.nav_personal_files;
1459+
}
14611460
}

app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,8 @@ class FileDisplayActivity :
791791
return null
792792
}
793793

794-
protected fun resetScrollingAndUpdateActionBar(searchType: SearchType = SearchType.NO_SEARCH) {
795-
updateActionBarTitleAndHomeButton(file, searchType)
794+
protected fun resetScrollingAndUpdateActionBar() {
795+
updateActionBarTitleAndHomeButton(file)
796796
resetScrolling(true)
797797
}
798798

@@ -1235,7 +1235,7 @@ class FileDisplayActivity :
12351235
listOfFiles.registerFabListener()
12361236
}
12371237

1238-
resetScrollingAndUpdateActionBar(listOfFilesFragment?.currentSearchType ?: SearchType.NO_SEARCH)
1238+
resetScrollingAndUpdateActionBar()
12391239
configureMenuItem()
12401240
startMetadataSyncForCurrentDir()
12411241
}
@@ -1799,7 +1799,7 @@ class FileDisplayActivity :
17991799
startSyncFolderOperation(root, false)
18001800
}
18011801
binding.fabMain.setImageResource(R.drawable.ic_plus)
1802-
resetScrollingAndUpdateActionBar(listOfFilesFragment?.currentSearchType ?: SearchType.NO_SEARCH)
1802+
resetScrollingAndUpdateActionBar()
18031803
}
18041804

18051805
override fun onBrowsedDownTo(directory: OCFile?) {

app/src/main/java/com/owncloud/android/ui/activity/ToolbarActivity.java

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
import com.owncloud.android.R;
3636
import com.owncloud.android.datamodel.FileDataStorageManager;
3737
import com.owncloud.android.datamodel.OCFile;
38+
import com.owncloud.android.datamodel.OCFileDepth;
3839
import com.owncloud.android.lib.common.utils.Log_OC;
40+
import com.owncloud.android.ui.fragment.OCFileListFragment;
3941
import com.owncloud.android.ui.fragment.SearchType;
4042
import com.owncloud.android.utils.theme.ThemeColorUtils;
4143
import 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);

app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
434434
}
435435

436436
if (getActivity() instanceof FileDisplayActivity fda) {
437-
fda.updateActionBarTitleAndHomeButton(fda.getCurrentDir(), currentSearchType);
437+
fda.updateActionBarTitleAndHomeButton(fda.getCurrentDir());
438438
}
439439
listDirectory(MainApp.isOnlyOnDevice(), false);
440440
}
@@ -1811,7 +1811,7 @@ public void onMessageEvent(ChangeMenuEvent changeMenuEvent) {
18111811
if (getActivity() instanceof FileDisplayActivity fda) {
18121812
fda.invalidateOptionsMenu();
18131813
fda.getIntent().removeExtra(OCFileListFragment.SEARCH_EVENT);
1814-
fda.updateActionBarTitleAndHomeButton(null, NO_SEARCH);
1814+
fda.updateActionBarTitleAndHomeButton(null);
18151815
}
18161816

18171817
if (mFile != null) {

0 commit comments

Comments
 (0)