Merge pull request #9898 from nextcloud/chore/no-more-second-fragment

FileDisplayActivity: finally get rid of secondFragment
This commit is contained in:
Álvaro Brey 2022-03-08 10:23:26 +01:00 committed by GitHub
commit fb6d8f8263
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 202 deletions

View file

@ -922,13 +922,7 @@ public abstract class FileActivity extends DrawerActivity
Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDisplayActivity.TAG_LIST_OF_FILES); Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDisplayActivity.TAG_LIST_OF_FILES);
if (fragment instanceof FileDetailFragment) { if (fragment instanceof FileDetailFragment) {
return (FileDetailFragment) fragment; return (FileDetailFragment) fragment;
} else {
fragment = getSupportFragmentManager().findFragmentByTag(FileDisplayActivity.TAG_SECOND_FRAGMENT);
if (fragment instanceof FileDetailFragment) {
return (FileDetailFragment) fragment;
} else {
return null;
}
} }
return null;
} }
} }

View file

@ -136,7 +136,6 @@ import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.SearchView;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
@ -170,8 +169,6 @@ public class FileDisplayActivity extends FileActivity
private RemoteOperationResult mLastSslUntrustedServerResult; private RemoteOperationResult mLastSslUntrustedServerResult;
@Inject LocalBroadcastManager localBroadcastManager; @Inject LocalBroadcastManager localBroadcastManager;
private boolean mDualPane;
public static final String TAG_PUBLIC_LINK = "PUBLIC_LINK"; public static final String TAG_PUBLIC_LINK = "PUBLIC_LINK";
public static final String FTAG_CHOOSER_DIALOG = "CHOOSER_DIALOG"; public static final String FTAG_CHOOSER_DIALOG = "CHOOSER_DIALOG";
public static final String KEY_FILE_ID = "KEY_FILE_ID"; public static final String KEY_FILE_ID = "KEY_FILE_ID";
@ -198,7 +195,6 @@ public class FileDisplayActivity extends FileActivity
private static final String TAG = FileDisplayActivity.class.getSimpleName(); private static final String TAG = FileDisplayActivity.class.getSimpleName();
public static final String TAG_LIST_OF_FILES = "LIST_OF_FILES"; public static final String TAG_LIST_OF_FILES = "LIST_OF_FILES";
public static final String TAG_SECOND_FRAGMENT = "SECOND_FRAGMENT";
public static final String TEXT_PREVIEW = "TEXT_PREVIEW"; public static final String TEXT_PREVIEW = "TEXT_PREVIEW";
@ -270,7 +266,6 @@ public class FileDisplayActivity extends FileActivity
mSwitchAccountButton.setOnClickListener(v -> showManageAccountsDialog()); mSwitchAccountButton.setOnClickListener(v -> showManageAccountsDialog());
mDualPane = getResources().getBoolean(R.bool.large_land_layout);
// Init Fragment without UI to retain AsyncTask across configuration changes // Init Fragment without UI to retain AsyncTask across configuration changes
FragmentManager fm = getSupportFragmentManager(); FragmentManager fm = getSupportFragmentManager();
@ -467,7 +462,7 @@ public class FileDisplayActivity extends FileActivity
} }
} }
private void initFragmentsWithFile(User user, OCFile file) { private void initFragments() {
/// First fragment /// First fragment
OCFileListFragment listOfFiles = getListOfFilesFragment(); OCFileListFragment listOfFiles = getListOfFilesFragment();
if (listOfFiles != null && TextUtils.isEmpty(searchQuery)) { if (listOfFiles != null && TextUtils.isEmpty(searchQuery)) {
@ -476,28 +471,8 @@ public class FileDisplayActivity extends FileActivity
Log_OC.e(TAG, "Still have a chance to lose the initialization of list fragment >("); Log_OC.e(TAG, "Still have a chance to lose the initialization of list fragment >(");
} }
/// Second fragment /// reset views
if (mDualPane) { resetTitleBarAndScrolling();
Fragment secondFragment = getSecondFragment();
if (secondFragment == null) {
secondFragment = chooseInitialSecondFragment(file, user);
}
if (secondFragment != null) {
setSecondFragment(secondFragment);
updateFragmentsVisibility(true);
updateActionBarTitleAndHomeButton(file);
} else {
cleanSecondFragment();
if (file.isDown() && MimeTypeUtil.isVCard(file.getMimeType())) {
startContactListFragment(file);
} else if (file.isDown() && PreviewTextFileFragment.canBePreviewed(file)) {
startTextPreview(file, false);
}
}
} else {
cleanSecondFragment();
}
} }
// Is called with the flag FLAG_ACTIVITY_SINGLE_TOP and set the new file and intent // Is called with the flag FLAG_ACTIVITY_SINGLE_TOP and set the new file and intent
@ -548,23 +523,6 @@ public class FileDisplayActivity extends FileActivity
} }
} }
@Deprecated
private Fragment chooseInitialSecondFragment(OCFile file, User user) {
Fragment secondFragment = null;
if (file != null && !file.isFolder()) {
if (file.isDown() && PreviewMediaFragment.canBePreviewed(file)) {
long startPlaybackPosition = getIntent().getLongExtra(PreviewVideoActivity.EXTRA_START_POSITION, 0);
boolean autoplay = getIntent().getBooleanExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, true);
secondFragment = PreviewMediaFragment.newInstance(file, user, startPlaybackPosition, autoplay);
} else if (file.isDown() && PreviewTextFileFragment.canBePreviewed(file)) {
secondFragment = null;
} else {
secondFragment = FileDetailFragment.newInstance(file, user);
}
}
return secondFragment;
}
/** /**
* Replaces the first fragment managed by the activity with the received as a parameter. * Replaces the first fragment managed by the activity with the received as a parameter.
* *
@ -588,58 +546,6 @@ public class FileDisplayActivity extends FileActivity
} }
/**
* 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() {
@Override
public void run() {
searchView.setQuery(searchQuery, true);
}
});
}
setDrawerIndicatorEnabled(false);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.right_fragment_container, fragment, TAG_SECOND_FRAGMENT);
transaction.commit();
}
@Deprecated
private void updateFragmentsVisibility(boolean existsSecondFragment) {
if (mDualPane) {
if (binding.leftFragmentContainer.getVisibility() != View.VISIBLE) {
binding.leftFragmentContainer.setVisibility(View.VISIBLE);
}
if (binding.rightFragmentContainer.getVisibility() != View.VISIBLE) {
binding.rightFragmentContainer.setVisibility(View.VISIBLE);
}
} else if (existsSecondFragment) {
if (binding.leftFragmentContainer.getVisibility() != View.GONE) {
binding.leftFragmentContainer.setVisibility(View.GONE);
}
if (binding.rightFragmentContainer.getVisibility() != View.VISIBLE) {
binding.rightFragmentContainer.setVisibility(View.VISIBLE);
}
} else {
if (binding.leftFragmentContainer.getVisibility() != View.VISIBLE) {
binding.leftFragmentContainer.setVisibility(View.VISIBLE);
}
if (binding.rightFragmentContainer.getVisibility() != View.GONE) {
binding.rightFragmentContainer.setVisibility(View.GONE);
}
}
}
public @androidx.annotation.Nullable public @androidx.annotation.Nullable
Fragment getLeftFragment() { Fragment getLeftFragment() {
return getSupportFragmentManager().findFragmentByTag(FileDisplayActivity.TAG_LIST_OF_FILES); return getSupportFragmentManager().findFragmentByTag(FileDisplayActivity.TAG_LIST_OF_FILES);
@ -657,27 +563,9 @@ public class FileDisplayActivity extends FileActivity
return null; return null;
} }
public @Nullable
@Deprecated
FileFragment getSecondFragment() {
Fragment second = getSupportFragmentManager().findFragmentByTag(FileDisplayActivity.TAG_SECOND_FRAGMENT);
if (second != null) {
return (FileFragment) second;
}
return null;
}
@Deprecated protected void resetTitleBarAndScrolling() {
protected void cleanSecondFragment() {
Fragment second = getSecondFragment();
if (second != null) {
FragmentTransaction tr = getSupportFragmentManager().beginTransaction();
tr.remove(second);
tr.commit();
}
updateFragmentsVisibility(false);
updateActionBarTitleAndHomeButton(null); updateActionBarTitleAndHomeButton(null);
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) findViewById(R.id.root_layout).getLayoutParams(); CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) findViewById(R.id.root_layout).getLayoutParams();
params.setBehavior(new AppBarLayout.ScrollingViewBehavior()); params.setBehavior(new AppBarLayout.ScrollingViewBehavior());
} }
@ -711,12 +599,12 @@ public class FileDisplayActivity extends FileActivity
mWaitingToPreview = null; mWaitingToPreview = null;
} else if (downloadEvent.equals(FileDownloader.getDownloadAddedMessage())) { } else if (downloadEvent.equals(FileDownloader.getDownloadAddedMessage())) {
// grant that the right panel updates the progress bar // grant that the details fragment updates the progress bar
detailsFragment.listenForTransferProgress(); detailsFragment.listenForTransferProgress();
detailsFragment.updateFileDetails(true, false); detailsFragment.updateFileDetails(true, false);
} else if (downloadEvent.equals(FileDownloader.getDownloadFinishMessage())) { } else if (downloadEvent.equals(FileDownloader.getDownloadFinishMessage())) {
// update the right panel // update the details panel
boolean detailsFragmentChanged = false; boolean detailsFragmentChanged = false;
if (waitedPreview) { if (waitedPreview) {
if (success) { if (success) {
@ -839,13 +727,11 @@ public class FileDisplayActivity extends FileActivity
int itemId = item.getItemId(); int itemId = item.getItemId();
if (itemId == android.R.id.home) { if (itemId == android.R.id.home) {
FileFragment second = getSecondFragment();
OCFile currentDir = getCurrentDir(); OCFile currentDir = getCurrentDir();
if (isDrawerOpen()) { if (isDrawerOpen()) {
closeDrawer(); closeDrawer();
} else if ( } else if (
currentDir != null && currentDir.getParentId() != 0 || currentDir != null && currentDir.getParentId() != 0 ||
second != null && second.getFile() != null ||
isSearchOpen()) { isSearchOpen()) {
onBackPressed(); onBackPressed();
} else if (getLeftFragment() instanceof FileDetailFragment || } else if (getLeftFragment() instanceof FileDetailFragment ||
@ -1139,19 +1025,17 @@ public class FileDisplayActivity extends FileActivity
super.onBackPressed(); super.onBackPressed();
} else { } else {
// all closed // all closed
if (mDualPane || getSecondFragment() == null) { OCFile currentDir = getCurrentDir();
OCFile currentDir = getCurrentDir(); if (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID) {
if (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID) { finish();
finish(); return;
return;
}
listOfFiles.onBrowseUp();
} }
listOfFiles.onBrowseUp();
setFile(listOfFiles.getCurrentFile()); setFile(listOfFiles.getCurrentFile());
listOfFiles.setFabVisible(true); listOfFiles.setFabVisible(true);
listOfFiles.registerFabListener(); listOfFiles.registerFabListener();
showSortListGroup(true); showSortListGroup(true);
cleanSecondFragment(); resetTitleBarAndScrolling();
} }
} else if (leftFragment instanceof PreviewTextStringFragment) { } else if (leftFragment instanceof PreviewTextStringFragment) {
createMinFragments(null); createMinFragments(null);
@ -1349,7 +1233,7 @@ public class FileDisplayActivity extends FileActivity
if (currentFile == null && !getFile().isFolder()) { if (currentFile == null && !getFile().isFolder()) {
// currently selected file was removed in the server, and now we // currently selected file was removed in the server, and now we
// know it // know it
cleanSecondFragment(); resetTitleBarAndScrolling();
currentFile = currentDir; currentFile = currentDir;
} }
@ -1612,23 +1496,20 @@ public class FileDisplayActivity extends FileActivity
setFile(listOfFiles.getCurrentFile()); setFile(listOfFiles.getCurrentFile());
startSyncFolderOperation(root, false); startSyncFolderOperation(root, false);
} }
cleanSecondFragment(); resetTitleBarAndScrolling();
} }
/**
* {@inheritDoc} Updates action bar and second fragment, if in dual pane mode.
*/
@Override @Override
public void onBrowsedDownTo(OCFile directory) { public void onBrowsedDownTo(OCFile directory) {
setFile(directory); setFile(directory);
cleanSecondFragment(); resetTitleBarAndScrolling();
// Sync Folder // Sync Folder
startSyncFolderOperation(directory, false); startSyncFolderOperation(directory, false);
} }
/** /**
* Shows the information of the {@link OCFile} received as a parameter in the second fragment. * Shows the information of the {@link OCFile} received as a parameter.
* *
* @param file {@link OCFile} whose details will be shown * @param file {@link OCFile} whose details will be shown
*/ */
@ -1638,7 +1519,7 @@ public class FileDisplayActivity extends FileActivity
} }
/** /**
* Shows the information of the {@link OCFile} received as a parameter in the second fragment. * Shows the information of the {@link OCFile} received as a parameter.
* *
* @param file {@link OCFile} whose details will be shown * @param file {@link OCFile} whose details will be shown
* @param activeTab the active tab in the details view * @param activeTab the active tab in the details view
@ -1666,18 +1547,11 @@ public class FileDisplayActivity extends FileActivity
} }
@Override @Override
@Deprecated // in future no dual pane
public void updateActionBarTitleAndHomeButton(OCFile chosenFile) { public void updateActionBarTitleAndHomeButton(OCFile chosenFile) {
if (chosenFile == null) { if (chosenFile == null) {
chosenFile = getFile(); // if no file is passed, current file decides chosenFile = getFile(); // if no file is passed, current file decides
} }
if (mDualPane) { super.updateActionBarTitleAndHomeButton(chosenFile);
// in dual pane mode, keep the focus of title an action bar in the current folder
super.updateActionBarTitleAndHomeButton(getCurrentDir());
} else {
super.updateActionBarTitleAndHomeButton(chosenFile);
}
} }
@Override @Override
@ -1816,7 +1690,7 @@ public class FileDisplayActivity extends FileActivity
((PreviewMediaFragment) leftFragment).stopPreview(true); ((PreviewMediaFragment) leftFragment).stopPreview(true);
} }
setFile(getStorageManager().getFileById(removedFile.getParentId())); setFile(getStorageManager().getFileById(removedFile.getParentId()));
cleanSecondFragment(); resetTitleBarAndScrolling();
} }
OCFile parentFile = getStorageManager().getFileById(removedFile.getParentId()); OCFile parentFile = getStorageManager().getFileById(removedFile.getParentId());
if (parentFile != null && parentFile.equals(getCurrentDir())) { if (parentFile != null && parentFile.equals(getCurrentDir())) {
@ -2016,13 +1890,13 @@ public class FileDisplayActivity extends FileActivity
updateListOfFilesFragment(false); updateListOfFilesFragment(false);
Fragment leftFragment = getLeftFragment(); Fragment leftFragment = getLeftFragment();
Optional<User> optionalUser = getUser(); Optional<User> optionalUser = getUser();
if (leftFragment instanceof FileDetailFragment && file.equals(((FileDetailFragment)leftFragment).getFile()) && optionalUser.isPresent()) { if (leftFragment instanceof FileDetailFragment && file.equals(((FileDetailFragment) leftFragment).getFile()) && optionalUser.isPresent()) {
final User currentUser = optionalUser.get(); final User currentUser = optionalUser.get();
if (downloading || uploading) { if (downloading || uploading) {
((FileDetailFragment) leftFragment).updateFileDetails(file, currentUser); ((FileDetailFragment) leftFragment).updateFileDetails(file, currentUser);
} else { } else {
if (!file.fileExists()) { if (!file.fileExists()) {
cleanSecondFragment(); resetTitleBarAndScrolling();
} else { } else {
((FileDetailFragment) leftFragment).updateFileDetails(false, true); ((FileDetailFragment) leftFragment).updateFileDetails(false, true);
} }
@ -2165,8 +2039,6 @@ public class FileDisplayActivity extends FileActivity
String activityName) { String activityName) {
mWaitingToSend = file; mWaitingToSend = file;
requestForDownload(mWaitingToSend, downloadBehaviour, packageName, activityName); requestForDownload(mWaitingToSend, downloadBehaviour, packageName, activityName);
boolean hasSecondFragment = getSecondFragment() != null;
updateFragmentsVisibility(hasSecondFragment);
} }
/** /**
@ -2244,7 +2116,6 @@ public class FileDisplayActivity extends FileActivity
public void configureToolbarForMediaPreview(OCFile file) { public void configureToolbarForMediaPreview(OCFile file) {
showSortListGroup(false); showSortListGroup(false);
binding.rightFragmentContainer.setVisibility(View.GONE);
((CoordinatorLayout.LayoutParams) binding.rootLayout.getLayoutParams()).setBehavior(null); ((CoordinatorLayout.LayoutParams) binding.rootLayout.getLayoutParams()).setBehavior(null);
super.updateActionBarTitleAndHomeButton(file); super.updateActionBarTitleAndHomeButton(file);
} }
@ -2265,7 +2136,6 @@ public class FileDisplayActivity extends FileActivity
showSortListGroup(false); showSortListGroup(false);
PreviewTextFileFragment fragment = PreviewTextFileFragment.create(user, file, searchOpen, searchQuery); PreviewTextFileFragment fragment = PreviewTextFileFragment.create(user, file, searchOpen, searchQuery);
setLeftFragment(fragment); setLeftFragment(fragment);
binding.rightFragmentContainer.setVisibility(View.GONE);
super.updateActionBarTitleAndHomeButton(file); super.updateActionBarTitleAndHomeButton(file);
} else { } else {
Intent previewIntent = new Intent(); Intent previewIntent = new Intent();
@ -2291,7 +2161,6 @@ public class FileDisplayActivity extends FileActivity
PreviewTextStringFragment.class.getName(), PreviewTextStringFragment.class.getName(),
args); args);
setLeftFragment(textPreviewFragment); setLeftFragment(textPreviewFragment);
binding.rightFragmentContainer.setVisibility(View.GONE);
super.updateActionBarTitleAndHomeButton(folder); super.updateActionBarTitleAndHomeButton(folder);
} }
@ -2308,7 +2177,6 @@ public class FileDisplayActivity extends FileActivity
final Fragment pdfFragment = PreviewPdfFragment.newInstance(file); final Fragment pdfFragment = PreviewPdfFragment.newInstance(file);
setLeftFragment(pdfFragment); setLeftFragment(pdfFragment);
updateFragmentsVisibility(false);
updateActionBarTitleAndHomeButton(file); updateActionBarTitleAndHomeButton(file);
showSortListGroup(false); showSortListGroup(false);
@ -2473,7 +2341,7 @@ public class FileDisplayActivity extends FileActivity
final boolean userChanged = !user.nameEquals(lastDisplayedUser.orElse(null)); final boolean userChanged = !user.nameEquals(lastDisplayedUser.orElse(null));
if (userChanged) { if (userChanged) {
Log_OC.d(TAG, "Initializing Fragments in onAccountChanged.."); Log_OC.d(TAG, "Initializing Fragments in onAccountChanged..");
initFragmentsWithFile(user, file); initFragments();
if (file.isFolder() && TextUtils.isEmpty(searchQuery)) { if (file.isFolder() && TextUtils.isEmpty(searchQuery)) {
startSyncFolderOperation(file, false); startSyncFolderOperation(file, false);
} }

View file

@ -278,14 +278,7 @@ public class ExtendedListFragment extends Fragment implements
if (query.isEmpty()) { if (query.isEmpty()) {
closeButton.setVisibility(View.INVISIBLE); closeButton.setVisibility(View.INVISIBLE);
} }
return false;
if (getFragmentManager() != null && getFragmentManager().
findFragmentByTag(FileDisplayActivity.TAG_SECOND_FRAGMENT) instanceof ExtendedListFragment) {
performSearch(query, false);
return true;
} else {
return false;
}
} }
@Override @Override

View file

@ -43,17 +43,11 @@
<FrameLayout <FrameLayout
android:id="@+id/left_fragment_container" android:id="@+id/left_fragment_container"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
app:layout_behavior="@string/appbar_scrolling_view_behavior" /> app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<FrameLayout
android:id="@+id/right_fragment_container"
android:layout_width="@dimen/zero"
android:layout_height="match_parent"
android:layout_weight="2"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</LinearLayout> </LinearLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton <com.google.android.material.floatingactionbutton.FloatingActionButton

View file

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
~
~ Nextcloud Android client application
~
~ @author Tobias Kaminsky
~ Copyright (C) 2020 Tobias Kaminsky
~ Copyright (C) 2020 Nextcloud GmbH
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Affero General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU Affero General Public License for more details.
~
~ You should have received a copy of the GNU Affero General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<resources>
<bool name="large_land_layout">true</bool>
</resources>

View file

@ -18,6 +18,5 @@
--> -->
<!-- Default boolean values --> <!-- Default boolean values -->
<resources> <resources>
<bool name="large_land_layout">false</bool>
<bool name="show_push_warning">true</bool> <bool name="show_push_warning">true</bool>
</resources> </resources>