Search in sources :

Example 1 with FileDisplayActivity

use of com.owncloud.android.ui.activity.FileDisplayActivity in project android by owncloud.

the class OCFileListFragment method registerFabUploadListeners.

/**
 * registers {@link android.view.View.OnClickListener} and {@link android.view.View.OnLongClickListener}
 * on the Upload mini FAB for the linked action an {@link Snackbar} showing the underlying action.
 */
private void registerFabUploadListeners() {
    getFabUpload().setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final View uploadBottomSheet = getLayoutInflater().inflate(R.layout.upload_bottom_sheet_fragment, null);
            final BottomSheetDialog dialog = new BottomSheetDialog(requireContext());
            dialog.setContentView(uploadBottomSheet);
            final BottomSheetFragmentItemView uploadFromFilesItemView = uploadBottomSheet.findViewById(R.id.upload_from_files_item_view);
            BottomSheetFragmentItemView uploadFromCameraItemView = uploadBottomSheet.findViewById(R.id.upload_from_camera_item_view);
            TextView uploadToTextView = uploadBottomSheet.findViewById(R.id.upload_to_text_view);
            uploadFromFilesItemView.setOnTouchListener((v13, event) -> {
                Intent action = new Intent(Intent.ACTION_GET_CONTENT);
                action = action.setType(ALL_FILES_SAF_REGEX).addCategory(Intent.CATEGORY_OPENABLE);
                action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                getActivity().startActivityForResult(Intent.createChooser(action, getString(R.string.upload_chooser_title)), FileDisplayActivity.REQUEST_CODE__SELECT_CONTENT_FROM_APPS);
                dialog.hide();
                return false;
            });
            uploadFromCameraItemView.setOnTouchListener((v12, event) -> {
                ((FileDisplayActivity) getActivity()).getFilesUploadHelper().uploadFromCamera(FileDisplayActivity.REQUEST_CODE__UPLOAD_FROM_CAMERA);
                dialog.hide();
                return false;
            });
            uploadToTextView.setText(String.format(getResources().getString(R.string.upload_to), getResources().getString(R.string.app_name)));
            final BottomSheetBehavior uploadBottomSheetBehavior = BottomSheetBehavior.from((View) uploadBottomSheet.getParent());
            dialog.setOnShowListener(dialog1 -> uploadBottomSheetBehavior.setPeekHeight(uploadBottomSheet.getMeasuredHeight()));
            dialog.show();
            getFabMain().collapse();
            recordMiniFabClick();
        }
    });
    getFabUpload().setOnLongClickListener(v -> {
        showSnackMessage(R.string.actionbar_upload);
        return true;
    });
}
Also used : BottomSheetDialog(com.google.android.material.bottomsheet.BottomSheetDialog) ActionMode(android.view.ActionMode) Bundle(android.os.Bundle) CreateFolderDialogFragment(com.owncloud.android.ui.dialog.CreateFolderDialogFragment) NonNull(androidx.annotation.NonNull) OCFile(com.owncloud.android.datamodel.OCFile) PreferenceUtils(com.owncloud.android.utils.PreferenceUtils) OnEnforceableRefreshListener(com.owncloud.android.ui.activity.OnEnforceableRefreshListener) PowerManager(android.os.PowerManager) SortType(com.owncloud.android.presentation.ui.files.SortType) Handler(android.os.Handler) View(android.view.View) OwnCloudVersion(com.owncloud.android.lib.resources.status.OwnCloudVersion) Animation(android.view.animation.Animation) AdapterView(android.widget.AdapterView) ConfirmationDialogFragment(com.owncloud.android.ui.dialog.ConfirmationDialogFragment) PreferenceManager(android.preference.PreferenceManager) CoordinatorLayout(androidx.coordinatorlayout.widget.CoordinatorLayout) FileMenuFilter(com.owncloud.android.files.FileMenuFilter) FolderPickerActivity(com.owncloud.android.ui.activity.FolderPickerActivity) BottomSheetFragmentItemView(com.owncloud.android.presentation.ui.common.BottomSheetFragmentItemView) SearchView(androidx.appcompat.widget.SearchView) PreviewAudioFragment(com.owncloud.android.ui.preview.PreviewAudioFragment) ViewGroup(android.view.ViewGroup) Timber(timber.log.Timber) SparseBooleanArrayParcelable(com.owncloud.android.ui.helpers.SparseBooleanArrayParcelable) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) SortOrder(com.owncloud.android.presentation.ui.files.SortOrder) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) FragmentExtKt(com.owncloud.android.extensions.FragmentExtKt) ListView(android.widget.ListView) NotNull(org.jetbrains.annotations.NotNull) Window(android.view.Window) Snackbar(com.google.android.material.snackbar.Snackbar) R(com.owncloud.android.R) FileListListAdapter(com.owncloud.android.ui.adapter.FileListListAdapter) Context(android.content.Context) DrawerLayout(androidx.drawerlayout.widget.DrawerLayout) ViewType(com.owncloud.android.presentation.ui.files.ViewType) BottomSheetBehavior(com.google.android.material.bottomsheet.BottomSheetBehavior) FileActivity(com.owncloud.android.ui.activity.FileActivity) Intent(android.content.Intent) RenameFileDialogFragment(com.owncloud.android.ui.dialog.RenameFileDialogFragment) FileListOption(com.owncloud.android.ui.activity.FileListOption) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) AnimationUtils(android.view.animation.AnimationUtils) SortBottomSheetFragment(com.owncloud.android.presentation.ui.files.SortBottomSheetFragment) MenuInflater(android.view.MenuInflater) PreviewImageFragment(com.owncloud.android.ui.preview.PreviewImageFragment) Menu(android.view.Menu) PreviewVideoFragment(com.owncloud.android.ui.preview.PreviewVideoFragment) SortOptionsView(com.owncloud.android.presentation.ui.files.SortOptionsView) LayoutInflater(android.view.LayoutInflater) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) PreviewTextFragment(com.owncloud.android.ui.preview.PreviewTextFragment) AbsListView(android.widget.AbsListView) AccountUtils(com.owncloud.android.authentication.AccountUtils) File(java.io.File) FileStorageUtils(com.owncloud.android.utils.FileStorageUtils) SparseBooleanArray(android.util.SparseBooleanArray) SharedPreferences(android.content.SharedPreferences) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) RemoveFilesDialogFragment(com.owncloud.android.ui.dialog.RemoveFilesDialogFragment) BottomSheetDialog(com.google.android.material.bottomsheet.BottomSheetDialog) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) BottomSheetBehavior(com.google.android.material.bottomsheet.BottomSheetBehavior) TextView(android.widget.TextView) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) BottomSheetFragmentItemView(com.owncloud.android.presentation.ui.common.BottomSheetFragmentItemView) SearchView(androidx.appcompat.widget.SearchView) TextView(android.widget.TextView) ListView(android.widget.ListView) SortOptionsView(com.owncloud.android.presentation.ui.files.SortOptionsView) AbsListView(android.widget.AbsListView) BottomSheetFragmentItemView(com.owncloud.android.presentation.ui.common.BottomSheetFragmentItemView)

Example 2 with FileDisplayActivity

use of com.owncloud.android.ui.activity.FileDisplayActivity in project android by nextcloud.

the class DialogFragmentIT method testAccountChooserDialogWithStatusDisabled.

@Test
@ScreenshotTest
public void testAccountChooserDialogWithStatusDisabled() throws AccountUtils.AccountNotFoundException {
    AccountManager accountManager = AccountManager.get(targetContext);
    for (Account account : accountManager.getAccounts()) {
        accountManager.removeAccountExplicitly(account);
    }
    Account newAccount = new Account("test@https://nextcloud.localhost", MainApp.getAccountType(targetContext));
    accountManager.addAccountExplicitly(newAccount, "password", null);
    accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_OC_BASE_URL, SERVER_URL);
    accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_USER_ID, "test");
    accountManager.setAuthToken(newAccount, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password");
    FileDisplayActivity fda = getFileDisplayActivity();
    UserAccountManager userAccountManager = fda.getUserAccountManager();
    User newUser = userAccountManager.getUser(newAccount.name).get();
    FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(newUser, targetContext.getContentResolver());
    OCCapability capability = new OCCapability();
    capability.setUserStatus(CapabilityBooleanType.FALSE);
    fileDataStorageManager.saveCapabilities(capability);
    ChooseAccountDialogFragment sut = ChooseAccountDialogFragment.newInstance(new RegisteredUser(newAccount, new OwnCloudAccount(newAccount, targetContext), new Server(URI.create(SERVER_URL), OwnCloudVersion.nextcloud_20)));
    showDialog(fda, sut);
}
Also used : UserAccountManager(com.nextcloud.client.account.UserAccountManager) Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) User(com.nextcloud.client.account.User) RegisteredUser(com.nextcloud.client.account.RegisteredUser) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) Server(com.nextcloud.client.account.Server) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) ChooseAccountDialogFragment(com.nextcloud.ui.ChooseAccountDialogFragment) UserAccountManager(com.nextcloud.client.account.UserAccountManager) AccountManager(android.accounts.AccountManager) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) RegisteredUser(com.nextcloud.client.account.RegisteredUser) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest) Test(org.junit.Test) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest)

Example 3 with FileDisplayActivity

use of com.owncloud.android.ui.activity.FileDisplayActivity in project android by nextcloud.

the class DialogFragmentIT method testBottomSheet.

@Test
@ScreenshotTest
public void testBottomSheet() {
    if (Looper.myLooper() == null) {
        Looper.prepare();
    }
    OCFileListBottomSheetActions action = new OCFileListBottomSheetActions() {

        @Override
        public void createFolder() {
        }

        @Override
        public void uploadFromApp() {
        }

        @Override
        public void uploadFiles() {
        }

        @Override
        public void newDocument() {
        }

        @Override
        public void newSpreadsheet() {
        }

        @Override
        public void newPresentation() {
        }

        @Override
        public void directCameraUpload() {
        }

        @Override
        public void scanDocUpload() {
        }

        @Override
        public void showTemplate(Creator creator, String headline) {
        }

        @Override
        public void createRichWorkspace() {
        }
    };
    DeviceInfo info = new DeviceInfo();
    OCFile ocFile = new OCFile("/test.md");
    Intent intent = new Intent(targetContext, FileDisplayActivity.class);
    FileDisplayActivity fda = activityRule.launchActivity(intent);
    // add direct editing info
    DirectEditing directEditing = new DirectEditing();
    directEditing.getCreators().put("1", new Creator("1", "text", "text file", ".md", "application/octet-stream", false));
    directEditing.getCreators().put("2", new Creator("2", "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));
    String json = new Gson().toJson(directEditing);
    new ArbitraryDataProvider(targetContext.getContentResolver()).storeOrUpdateKeyValue(user.getAccountName(), ArbitraryDataProvider.DIRECT_EDITING, json);
    // activate templates
    OCCapability capability = fda.getCapabilities();
    capability.setRichDocuments(CapabilityBooleanType.TRUE);
    capability.setRichDocumentsDirectEditing(CapabilityBooleanType.TRUE);
    capability.setRichDocumentsTemplatesAvailable(CapabilityBooleanType.TRUE);
    OCFileListBottomSheetDialog sut = new OCFileListBottomSheetDialog(fda, action, info, user, ocFile);
    fda.runOnUiThread(sut::show);
    waitForIdleSync();
    screenshot(sut.getWindow().getDecorView());
}
Also used : DirectEditing(com.owncloud.android.lib.common.DirectEditing) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) OCFileListBottomSheetDialog(com.owncloud.android.ui.fragment.OCFileListBottomSheetDialog) ArrayList(java.util.ArrayList) OCFileListBottomSheetActions(com.owncloud.android.ui.fragment.OCFileListBottomSheetActions) Gson(com.google.gson.Gson) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) Intent(android.content.Intent) Creator(com.owncloud.android.lib.common.Creator) OCFile(com.owncloud.android.datamodel.OCFile) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) DeviceInfo(com.nextcloud.client.device.DeviceInfo) Editor(com.owncloud.android.lib.common.Editor) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest) Test(org.junit.Test) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest)

Example 4 with FileDisplayActivity

use of com.owncloud.android.ui.activity.FileDisplayActivity in project android by nextcloud.

the class PreviewTextFileFragmentTest method displaySimpleTextFile.

@Test
public // @ScreenshotTest // todo run without real server
void displaySimpleTextFile() throws IOException {
    FileDisplayActivity sut = activityRule.launchActivity(null);
    shortSleep();
    File file = getDummyFile("nonEmpty.txt");
    OCFile test = new OCFile("/text.md");
    test.setMimeType(MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN);
    test.setStoragePath(file.getAbsolutePath());
    sut.startTextPreview(test, false);
    shortSleep();
    screenshot(sut);
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File) Test(org.junit.Test)

Example 5 with FileDisplayActivity

use of com.owncloud.android.ui.activity.FileDisplayActivity in project android by nextcloud.

the class SyncFileNotEnoughSpaceDialogFragmentTest method showNotEnoughSpaceDialogForFile.

@Test
public void showNotEnoughSpaceDialogForFile() {
    FileDisplayActivity test = activityRule.launchActivity(null);
    OCFile ocFile = new OCFile("/Video.mp4");
    ocFile.setFileLength(1000000);
    SyncFileNotEnoughSpaceDialogFragment dialog = SyncFileNotEnoughSpaceDialogFragment.newInstance(ocFile, 2000);
    dialog.show(test.getListOfFilesFragment().getFragmentManager(), "2");
    getInstrumentation().waitForIdleSync();
    screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) Test(org.junit.Test)

Aggregations

FileDisplayActivity (com.owncloud.android.ui.activity.FileDisplayActivity)26 OCFile (com.owncloud.android.datamodel.OCFile)11 Test (org.junit.Test)9 Intent (android.content.Intent)8 FolderPickerActivity (com.owncloud.android.ui.activity.FolderPickerActivity)7 Activity (android.app.Activity)4 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)4 OCCapability (com.owncloud.android.lib.resources.status.OCCapability)4 UploadFilesActivity (com.owncloud.android.ui.activity.UploadFilesActivity)4 ScreenshotTest (com.owncloud.android.utils.ScreenshotTest)4 View (android.view.View)3 FragmentActivity (androidx.fragment.app.FragmentActivity)3 User (com.nextcloud.client.account.User)3 ArrayList (java.util.ArrayList)3 Account (android.accounts.Account)2 AccountManager (android.accounts.AccountManager)2 Bundle (android.os.Bundle)2 Handler (android.os.Handler)2 MenuItem (android.view.MenuItem)2 AdapterView (android.widget.AdapterView)2