Bottom sheet expands fully on landscape

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2023-05-05 10:38:22 +02:00 committed by Andy Scherzinger
parent 99127ad6b4
commit d12718f2b1
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
5 changed files with 110 additions and 114 deletions

View file

@ -34,8 +34,10 @@ import android.webkit.SslErrorHandler;
import android.widget.TextView;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.gson.Gson;
import com.nextcloud.android.common.ui.color.ColorUtil;
import com.nextcloud.android.common.ui.theme.MaterialSchemes;
import com.nextcloud.android.common.ui.theme.MaterialSchemesImpl;
import com.nextcloud.android.lib.resources.profile.Action;
import com.nextcloud.android.lib.resources.profile.HoverCard;
import com.nextcloud.client.account.RegisteredUser;
@ -43,10 +45,13 @@ import com.nextcloud.client.account.Server;
import com.nextcloud.client.account.User;
import com.nextcloud.client.account.UserAccountManager;
import com.nextcloud.client.device.DeviceInfo;
import com.nextcloud.client.documentscan.AppScanOptionalFeature;
import com.nextcloud.ui.ChooseAccountDialogFragment;
import com.nextcloud.ui.fileactions.FileActionsBottomSheet;
import com.nextcloud.utils.EditorUtils;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.ArbitraryDataProvider;
import com.owncloud.android.datamodel.ArbitraryDataProviderImpl;
import com.owncloud.android.datamodel.FileDataStorageManager;
@ -64,11 +69,13 @@ import com.owncloud.android.lib.resources.users.Status;
import com.owncloud.android.lib.resources.users.StatusType;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.fragment.OCFileListBottomSheetActions;
import com.owncloud.android.ui.fragment.OCFileListBottomSheetDialogFragment;
import com.owncloud.android.ui.fragment.OCFileListBottomSheetDialog;
import com.owncloud.android.ui.fragment.ProfileBottomSheetDialog;
import com.owncloud.android.utils.MimeTypeUtil;
import com.owncloud.android.utils.ScreenshotTest;
import com.owncloud.android.utils.theme.CapabilityUtils;
import com.owncloud.android.utils.theme.MaterialSchemesProvider;
import com.owncloud.android.utils.theme.ViewThemeUtils;
import org.junit.After;
import org.junit.Rule;
@ -81,8 +88,11 @@ import java.util.Collections;
import java.util.List;
import java.util.Objects;
import androidx.activity.result.contract.ActivityResultContract;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import kotlin.Unit;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
@ -369,31 +379,31 @@ public class DialogFragmentIT extends AbstractIT {
// add direct editing info
DirectEditing directEditing = new DirectEditing();
directEditing.getCreators().put("1", new Creator("1",
"text",
"text file",
".md",
"application/octet-stream",
false));
"text",
"text file",
".md",
"application/octet-stream",
false));
directEditing.getCreators().put("2", new Creator("2",
"md",
"markdown file",
".md",
"application/octet-stream",
false));
"md",
"markdown file",
".md",
"application/octet-stream",
false));
directEditing.getEditors().put("text",
new Editor("1",
"Text",
new ArrayList<>(Collections.singletonList(MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN)),
new ArrayList<>(),
false));
new Editor("1",
"Text",
new ArrayList<>(Collections.singletonList(MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN)),
new ArrayList<>(),
false));
String json = new Gson().toJson(directEditing);
new ArbitraryDataProviderImpl(targetContext).storeOrUpdateKeyValue(user.getAccountName(),
ArbitraryDataProvider.DIRECT_EDITING,
json);
ArbitraryDataProvider.DIRECT_EDITING,
json);
// activate templates
OCCapability capability = fda.getCapabilities();
@ -404,26 +414,76 @@ public class DialogFragmentIT extends AbstractIT {
CapabilityUtils.updateCapability(capability);
OCFileListBottomSheetDialogFragment sut = new OCFileListBottomSheetDialogFragment(fda,
action,
info,
user,
ocFile);
AppScanOptionalFeature appScanOptionalFeature = new AppScanOptionalFeature() {
@NonNull
@Override
public ActivityResultContract<Unit, String> getScanContract() {
throw new UnsupportedOperationException("Document scan is not available");
}
};
sut.show(fda.getSupportFragmentManager(), "");
MaterialSchemesProvider materialSchemesProvider = new MaterialSchemesProvider() {
@NonNull
@Override
public MaterialSchemes getMaterialSchemesForUser(@NonNull User user) {
return null;
}
@NonNull
@Override
public MaterialSchemes getMaterialSchemesForCapability(@NonNull OCCapability capability) {
return null;
}
@NonNull
@Override
public MaterialSchemes getMaterialSchemesForCurrentUser() {
return new MaterialSchemesImpl(R.color.primary, false);
}
@NonNull
@Override
public MaterialSchemes getDefaultMaterialSchemes() {
return null;
}
@NonNull
@Override
public MaterialSchemes getMaterialSchemesForPrimaryBackground() {
return null;
}
};
ViewThemeUtils viewThemeUtils = new ViewThemeUtils(materialSchemesProvider.getMaterialSchemesForCurrentUser(),
new ColorUtil(targetContext));
EditorUtils editorUtils = new EditorUtils(new ArbitraryDataProviderImpl(targetContext));
OCFileListBottomSheetDialog sut = new OCFileListBottomSheetDialog(fda,
action,
info,
user,
ocFile,
fda.themeUtils,
viewThemeUtils,
editorUtils,
appScanOptionalFeature);
fda.runOnUiThread(sut::show);
getInstrumentation().waitForIdleSync();
shortSleep();
((BottomSheetDialog) sut.requireDialog()).getBehavior().setState(BottomSheetBehavior.STATE_EXPANDED);
sut.getBehavior().setState(BottomSheetBehavior.STATE_EXPANDED);
getInstrumentation().waitForIdleSync();
shortSleep();
ViewGroup viewGroup = sut.requireDialog().getWindow().findViewById(android.R.id.content);
ViewGroup viewGroup = sut.getWindow().findViewById(android.R.id.content);
hideCursors(viewGroup);
screenshot(Objects.requireNonNull(sut.requireDialog().getWindow()).getDecorView());
screenshot(Objects.requireNonNull(sut.getWindow()).getDecorView());
}

View file

@ -111,7 +111,6 @@ import com.owncloud.android.ui.fragment.GalleryFragment;
import com.owncloud.android.ui.fragment.GalleryFragmentBottomSheetDialog;
import com.owncloud.android.ui.fragment.LocalFileListFragment;
import com.owncloud.android.ui.fragment.OCFileListBottomSheetDialog;
import com.owncloud.android.ui.fragment.OCFileListBottomSheetDialogFragment;
import com.owncloud.android.ui.fragment.OCFileListFragment;
import com.owncloud.android.ui.fragment.SharedListFragment;
import com.owncloud.android.ui.fragment.UnifiedSearchFragment;
@ -407,9 +406,6 @@ abstract class ComponentsModule {
@ContributesAndroidInjector
abstract NotificationWork notificationWork();
@ContributesAndroidInjector
abstract OCFileListBottomSheetDialog ocFileListBottomSheetDialog();
@ContributesAndroidInjector
abstract RemoveFilesDialogFragment removeFilesDialogFragment();
@ -435,7 +431,7 @@ abstract class ComponentsModule {
abstract StoragePermissionDialogFragment storagePermissionDialogFragment();
@ContributesAndroidInjector
abstract OCFileListBottomSheetDialogFragment ocfileListBottomSheetDialogFragment();
abstract OCFileListBottomSheetDialog ocfileListBottomSheetDialog();
@ContributesAndroidInjector
abstract RenameFileDialogFragment renameFileDialogFragment();

View file

@ -1,71 +0,0 @@
/*
* Nextcloud Android client application
*
* @author Álvaro Brey Vilas
* Copyright (C) 2022 Álvaro Brey Vilas
* Copyright (C) 2022 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.owncloud.android.ui.fragment
import android.app.Dialog
import android.os.Bundle
import androidx.fragment.app.DialogFragment
import com.nextcloud.client.account.User
import com.nextcloud.client.device.DeviceInfo
import com.nextcloud.client.di.Injectable
import com.nextcloud.client.documentscan.AppScanOptionalFeature
import com.nextcloud.utils.EditorUtils
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.ui.activity.FileActivity
import com.owncloud.android.utils.theme.ThemeUtils
import com.owncloud.android.utils.theme.ViewThemeUtils
import javax.inject.Inject
class OCFileListBottomSheetDialogFragment(
private val fileActivity: FileActivity,
private val actions: OCFileListBottomSheetActions,
private val deviceInfo: DeviceInfo,
private val user: User,
private val file: OCFile
) : DialogFragment(), Injectable {
@Inject
lateinit var themeUtils: ThemeUtils
@Inject
lateinit var viewThemeUtils: ViewThemeUtils
@Inject
lateinit var editorUtils: EditorUtils
@Inject
lateinit var appScanOptionalFeature: AppScanOptionalFeature
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return OCFileListBottomSheetDialog(
fileActivity,
actions,
deviceInfo,
user,
file,
themeUtils,
viewThemeUtils,
editorUtils,
appScanOptionalFeature
)
}
}

View file

@ -44,6 +44,7 @@ import android.widget.AbsListView;
import android.widget.Toast;
import com.google.android.material.behavior.HideBottomViewOnScrollBehavior;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.nextcloud.android.lib.resources.files.ToggleFileLockRemoteOperation;
@ -53,6 +54,7 @@ import com.nextcloud.client.account.UserAccountManager;
import com.nextcloud.client.core.Clock;
import com.nextcloud.client.device.DeviceInfo;
import com.nextcloud.client.di.Injectable;
import com.nextcloud.client.documentscan.AppScanOptionalFeature;
import com.nextcloud.client.documentscan.DocumentScanActivity;
import com.nextcloud.client.jobs.BackgroundJobManager;
import com.nextcloud.client.network.ClientFactory;
@ -206,6 +208,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
@Inject ShortcutUtil shortcutUtil;
@Inject Clock clock;
@Inject SyncedFolderProvider syncedFolderProvider;
@Inject AppScanOptionalFeature appScanOptionalFeature;
protected FileFragment.ContainerActivity mContainerActivity;
@ -477,13 +480,19 @@ public class OCFileListFragment extends ExtendedListFragment implements
if (mFabMain != null) { // is not available in FolderPickerActivity
viewThemeUtils.material.themeFAB(mFabMain);
mFabMain.setOnClickListener(v -> {
final OCFileListBottomSheetDialogFragment dialog =
new OCFileListBottomSheetDialogFragment(activity,
this,
deviceInfo,
accountManager.getUser(),
getCurrentFile());
dialog.show(getActivity().getSupportFragmentManager(), DIALOG_BOTTOM_SHEET);
final OCFileListBottomSheetDialog dialog =
new OCFileListBottomSheetDialog(activity,
this,
deviceInfo,
accountManager.getUser(),
getCurrentFile(),
themeUtils,
viewThemeUtils,
editorUtils,
appScanOptionalFeature);
dialog.getBehavior().setState(BottomSheetBehavior.STATE_EXPANDED);
dialog.show();
});
}
}

View file

@ -20,8 +20,10 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/standard_half_padding"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<com.google.android.material.bottomsheet.BottomSheetDragHandleView
android:layout_width="match_parent"