open PreviewTextFragment within left fragment

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2020-09-10 10:49:39 +02:00
parent edaffa4c0f
commit 27277f1970
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
2 changed files with 73 additions and 42 deletions

View file

@ -542,15 +542,31 @@ public class FileDisplayActivity extends FileActivity
return secondFragment;
}
/**
* Replaces the first fragment managed by the activity with the received as a parameter.
*
* @param fragment New Fragment to set.
*/
private void setLeftFragment(Fragment fragment) {
if (searchView != null) {
searchView.post(() -> searchView.setQuery(searchQuery, true));
}
setDrawerIndicatorEnabled(false);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.addToBackStack(null);
transaction.replace(R.id.left_fragment_container, fragment, TAG_LIST_OF_FILES);
transaction.commit();
}
/**
* Replaces the second fragment managed by the activity with the received as
* a parameter.
*
* Replaces the second fragment managed by the activity with the received as a parameter.
* <p>
* Assumes never will be more than two fragments managed at the same time.
*
* @param fragment New second Fragment to set.
*/
@Deprecated // in future no dual pane
private void setSecondFragment(Fragment fragment) {
if (searchView != null) {
searchView.post(new Runnable() {
@ -594,11 +610,15 @@ public class FileDisplayActivity extends FileActivity
}
}
public @androidx.annotation.Nullable
Fragment getLeftFragment() {
return getSupportFragmentManager().findFragmentByTag(FileDisplayActivity.TAG_LIST_OF_FILES);
}
public @androidx.annotation.Nullable
OCFileListFragment getListOfFilesFragment() {
Fragment listOfFiles = getSupportFragmentManager().findFragmentByTag(
FileDisplayActivity.TAG_LIST_OF_FILES);
FileDisplayActivity.TAG_LIST_OF_FILES);
if (listOfFiles != null) {
return (OCFileListFragment) listOfFiles;
}
@ -785,10 +805,13 @@ public class FileDisplayActivity extends FileActivity
OCFile currentDir = getCurrentDir();
if (isDrawerOpen()) {
closeDrawer();
} else if ((currentDir != null && currentDir.getParentId() != 0) ||
(second != null && second.getFile() != null) || isSearchOpen()) {
} else if (
(currentDir != null && currentDir.getParentId() != 0) ||
(second != null && second.getFile() != null) ||
isSearchOpen() ||
second == null
) {
onBackPressed();
} else {
openDrawer();
}
@ -1022,45 +1045,45 @@ public class FileDisplayActivity extends FileActivity
boolean isDrawerOpen = isDrawerOpen();
boolean isSearchOpen = isSearchOpen();
OCFileListFragment listOfFiles = getListOfFilesFragment();
Fragment leftFragment = getLeftFragment();
if (isSearchOpen && searchView != null) {
searchView.setQuery("", true);
searchView.onActionViewCollapsed();
searchView.clearFocus();
if (leftFragment instanceof OCFileListFragment) {
OCFileListFragment listOfFiles = (OCFileListFragment) leftFragment;
// Remove the list to the original state
if (listOfFiles != null) {
if (isSearchOpen && searchView != null) {
searchView.setQuery("", true);
searchView.onActionViewCollapsed();
searchView.clearFocus();
// Remove the list to the original state
listOfFiles.performSearch("", true);
}
hideSearchView(getCurrentDir());
hideSearchView(getCurrentDir());
setDrawerIndicatorEnabled(isDrawerIndicatorAvailable());
} else if (isDrawerOpen) {
// close drawer first
super.onBackPressed();
} else {
// all closed
listOfFiles = getListOfFilesFragment();
if (mDualPane || getSecondFragment() == null) {
OCFile currentDir = getCurrentDir();
if (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID) {
finish();
return;
}
if (listOfFiles != null) { // should never be null, indeed
setDrawerIndicatorEnabled(isDrawerIndicatorAvailable());
} else if (isDrawerOpen) {
// close drawer first
super.onBackPressed();
} else {
// all closed
if (mDualPane || getSecondFragment() == null) {
OCFile currentDir = getCurrentDir();
if (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID) {
finish();
return;
}
listOfFiles.onBrowseUp();
}
}
if (listOfFiles != null) { // should never be null, indeed
setFile(listOfFiles.getCurrentFile());
listOfFiles.setFabVisible(true);
listOfFiles.registerFabListener();
showSortListGroup(true);
cleanSecondFragment();
}
cleanSecondFragment();
} else {
// pop back
hideSearchView(getCurrentDir());
super.onBackPressed();
}
}
@ -1565,6 +1588,7 @@ public class FileDisplayActivity extends FileActivity
}
@Override
@Deprecated // in future no dual pane
public void updateActionBarTitleAndHomeButton(OCFile chosenFile) {
if (chosenFile == null) {
chosenFile = getFile(); // if no file is passed, current file decides
@ -1576,7 +1600,6 @@ public class FileDisplayActivity extends FileActivity
} else {
super.updateActionBarTitleAndHomeButton(chosenFile);
}
}
@Override
@ -2181,10 +2204,12 @@ public class FileDisplayActivity extends FileActivity
args.putString(EXTRA_SEARCH_QUERY, searchQuery);
Fragment textPreviewFragment = Fragment.instantiate(getApplicationContext(),
PreviewTextFileFragment.class.getName(), args);
setSecondFragment(textPreviewFragment);
updateFragmentsVisibility(true);
updateActionBarTitleAndHomeButton(file);
setFile(file);
setLeftFragment(textPreviewFragment);
binding.rightFragmentContainer.setVisibility(View.GONE);
//updateFragmentsVisibility(true);
super.updateActionBarTitleAndHomeButton(file);
//setFile(file);
} else {
Intent previewIntent = new Intent();
previewIntent.putExtra(EXTRA_FILE, file);

View file

@ -329,7 +329,6 @@ public class OCFileListFragment extends ExtendedListFragment implements
super.onActivityCreated(savedInstanceState);
Log_OC.i(TAG, "onActivityCreated() start");
if (savedInstanceState != null) {
mFile = savedInstanceState.getParcelable(KEY_FILE);
}
@ -389,6 +388,13 @@ public class OCFileListFragment extends ExtendedListFragment implements
if (searchEvent != null) {
onMessageEvent(searchEvent);
}
FragmentActivity fragmentActivity;
if ((fragmentActivity = getActivity()) != null && fragmentActivity instanceof FileDisplayActivity) {
FileDisplayActivity fileDisplayActivity = (FileDisplayActivity) fragmentActivity;
fileDisplayActivity.updateActionBarTitleAndHomeButton(fileDisplayActivity.getCurrentDir());
}
listDirectory(false, false);
}
protected void prepareCurrentSearch(SearchEvent event) {
@ -771,6 +777,8 @@ public class OCFileListFragment extends ExtendedListFragment implements
*/
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(KEY_FILE, mFile);
if (searchFragment) {
outState.putParcelable(KEY_CURRENT_SEARCH_TYPE, Parcels.wrap(currentSearchType));
@ -779,8 +787,6 @@ public class OCFileListFragment extends ExtendedListFragment implements
}
}
mMultiChoiceModeListener.storeStateIn(outState);
super.onSaveInstanceState(outState);
}
@Override