Search in sources :

Example 1 with OCCapability

use of com.owncloud.android.lib.resources.status.OCCapability in project android by owncloud.

the class FileDataStorageManager method getCapability.

public OCCapability getCapability(String accountName) {
    OCCapability capability = null;
    Cursor c = getCapabilityCursorForAccount(accountName);
    // default value with all UNKNOWN
    capability = new OCCapability();
    if (c != null) {
        if (c.moveToFirst()) {
            capability = createCapabilityInstance(c);
        }
        c.close();
    }
    return capability;
}
Also used : OCCapability(com.owncloud.android.lib.resources.status.OCCapability) Cursor(android.database.Cursor)

Example 2 with OCCapability

use of com.owncloud.android.lib.resources.status.OCCapability in project android by nextcloud.

the class GetCapabilitiesOperarion method run.

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    GetRemoteCapabilitiesOperation getCapabilities = new GetRemoteCapabilitiesOperation();
    RemoteOperationResult result = getCapabilities.execute(client);
    if (result.isSuccess() && result.getData() != null && result.getData().size() > 0) {
        // Read data from the result
        OCCapability capability = (OCCapability) result.getData().get(0);
        // Save the capabilities into database
        getStorageManager().saveCapabilities(capability);
    }
    return result;
}
Also used : OCCapability(com.owncloud.android.lib.resources.status.OCCapability) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) GetRemoteCapabilitiesOperation(com.owncloud.android.lib.resources.status.GetRemoteCapabilitiesOperation)

Example 3 with OCCapability

use of com.owncloud.android.lib.resources.status.OCCapability in project android by nextcloud.

the class AbstractIT method beforeAll.

@BeforeClass
public static void beforeAll() {
    try {
        // clean up
        targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
        AccountManager platformAccountManager = AccountManager.get(targetContext);
        for (Account account : platformAccountManager.getAccounts()) {
            if (account.type.equalsIgnoreCase("nextcloud")) {
                platformAccountManager.removeAccountExplicitly(account);
            }
        }
        Account temp = new Account("test@https://nextcloud.localhost", MainApp.getAccountType(targetContext));
        platformAccountManager.addAccountExplicitly(temp, "password", null);
        platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_BASE_URL, "https://nextcloud.localhost");
        platformAccountManager.setUserData(temp, KEY_USER_ID, "test");
        final UserAccountManager userAccountManager = UserAccountManagerImpl.fromContext(targetContext);
        account = userAccountManager.getAccountByName("test@https://nextcloud.localhost");
        if (account == null) {
            throw new ActivityNotFoundException();
        }
        Optional<User> optionalUser = userAccountManager.getUser(account.name);
        user = optionalUser.orElseThrow(IllegalAccessError::new);
        client = OwnCloudClientFactory.createOwnCloudClient(account, targetContext);
        nextcloudClient = OwnCloudClientFactory.createNextcloudClient(account, targetContext);
    } catch (OperationCanceledException e) {
        e.printStackTrace();
    } catch (AuthenticatorException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (AccountUtils.AccountNotFoundException e) {
        e.printStackTrace();
    }
    Bundle arguments = androidx.test.platform.app.InstrumentationRegistry.getArguments();
    // color
    String colorParameter = arguments.getString("COLOR");
    if (!TextUtils.isEmpty(colorParameter)) {
        FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(user, targetContext.getContentResolver());
        String colorHex = null;
        COLOR = colorParameter;
        switch(colorParameter) {
            case "red":
                colorHex = "#7c0000";
                break;
            case "green":
                colorHex = "#00ff00";
                break;
            case "white":
                colorHex = "#ffffff";
                break;
            case "black":
                colorHex = "#000000";
                break;
            case "lightgreen":
                colorHex = "#aaff00";
                break;
            default:
                break;
        }
        if (colorHex != null) {
            OCCapability capability = fileDataStorageManager.getCapability(account.name);
            capability.setServerColor(colorHex);
            fileDataStorageManager.saveCapabilities(capability);
        }
    }
    // dark / light
    String darkModeParameter = arguments.getString("DARKMODE");
    if (darkModeParameter != null) {
        if (darkModeParameter.equalsIgnoreCase("dark")) {
            DARK_MODE = "dark";
            AppPreferencesImpl.fromContext(targetContext).setDarkThemeMode(DarkMode.DARK);
            MainApp.setAppTheme(DarkMode.DARK);
        } else {
            DARK_MODE = "light";
        }
    }
    if (DARK_MODE.equalsIgnoreCase("light") && COLOR.equalsIgnoreCase("blue")) {
        // use already existing names
        DARK_MODE = "";
        COLOR = "";
    }
}
Also used : Account(android.accounts.Account) User(com.nextcloud.client.account.User) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) Bundle(android.os.Bundle) OperationCanceledException(android.accounts.OperationCanceledException) AccountUtils(com.owncloud.android.lib.common.accounts.AccountUtils) AuthenticatorException(android.accounts.AuthenticatorException) IOException(java.io.IOException) UserAccountManager(com.nextcloud.client.account.UserAccountManager) ActivityNotFoundException(android.content.ActivityNotFoundException) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) UserAccountManager(com.nextcloud.client.account.UserAccountManager) AccountManager(android.accounts.AccountManager) BeforeClass(org.junit.BeforeClass)

Example 4 with OCCapability

use of com.owncloud.android.lib.resources.status.OCCapability 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 5 with OCCapability

use of com.owncloud.android.lib.resources.status.OCCapability 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)

Aggregations

OCCapability (com.owncloud.android.lib.resources.status.OCCapability)26 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)9 User (com.nextcloud.client.account.User)6 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)6 Account (android.accounts.Account)5 AccountManager (android.accounts.AccountManager)3 Intent (android.content.Intent)3 UserAccountManager (com.nextcloud.client.account.UserAccountManager)3 FileDisplayActivity (com.owncloud.android.ui.activity.FileDisplayActivity)3 Test (org.junit.Test)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 Cursor (android.database.Cursor)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 Drawable (android.graphics.drawable.Drawable)2 LayerDrawable (android.graphics.drawable.LayerDrawable)2 GlideAnimation (com.bumptech.glide.request.animation.GlideAnimation)2 SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)2 Gson (com.google.gson.Gson)2 RegisteredUser (com.nextcloud.client.account.RegisteredUser)2 Server (com.nextcloud.client.account.Server)2