Search in sources :

Example 11 with OCCapability

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

the class GetCapabilitiesOperarion method run.

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    GetRemoteCapabilitiesOperation getCapabilities = new GetRemoteCapabilitiesOperation();
    RemoteOperationResult result = getCapabilities.execute(client);
    if (result.isSuccess()) {
        // Read data from the result
        if (result.getData() != null && result.getData().size() > 0) {
            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 12 with OCCapability

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

the class DrawerActivity method updateHeaderBackground.

public void updateHeaderBackground() {
    if (getAccount() != null && getStorageManager().getCapability(getAccount().name).getServerBackground() != null) {
        final ViewGroup navigationHeader = (ViewGroup) findNavigationViewChildById(R.id.drawer_header_view);
        if (navigationHeader != null) {
            OCCapability capability = getStorageManager().getCapability(getAccount().name);
            String background = capability.getServerBackground();
            CapabilityBooleanType backgroundDefault = capability.getServerBackgroundDefault();
            CapabilityBooleanType backgroundPlain = capability.getServerBackgroundPlain();
            int primaryColor = ThemeUtils.primaryColor(getAccount());
            if (backgroundDefault.isTrue() && backgroundPlain.isTrue()) {
                // use only solid color
                setNavigationHeaderBackground(new ColorDrawable(primaryColor), navigationHeader);
            } else if (backgroundDefault.isTrue() && backgroundPlain.isFalse()) {
                // use nc13 background image with themed color
                Drawable[] drawables = { new ColorDrawable(primaryColor), getResources().getDrawable(R.drawable.background_nc13) };
                LayerDrawable layerDrawable = new LayerDrawable(drawables);
                setNavigationHeaderBackground(layerDrawable, navigationHeader);
            } else {
                // use url
                if (URLUtil.isValidUrl(background) || background.isEmpty()) {
                    // background image
                    SimpleTarget target = new SimpleTarget<Drawable>() {

                        @Override
                        public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
                            Drawable[] drawables = { new ColorDrawable(primaryColor), resource };
                            LayerDrawable layerDrawable = new LayerDrawable(drawables);
                            setNavigationHeaderBackground(layerDrawable, navigationHeader);
                        }

                        @Override
                        public void onLoadFailed(Exception e, Drawable errorDrawable) {
                            Drawable[] drawables = { new ColorDrawable(primaryColor), errorDrawable };
                            LayerDrawable layerDrawable = new LayerDrawable(drawables);
                            setNavigationHeaderBackground(layerDrawable, navigationHeader);
                        }
                    };
                    int backgroundResource;
                    OwnCloudVersion ownCloudVersion = AccountUtils.getServerVersion(getAccount());
                    if (ownCloudVersion.compareTo(OwnCloudVersion.nextcloud_13) >= 0) {
                        backgroundResource = R.drawable.background_nc13;
                    } else {
                        backgroundResource = R.drawable.background;
                    }
                    Glide.with(this).load(background).centerCrop().placeholder(backgroundResource).error(backgroundResource).crossFade().into(target);
                } else {
                    // plain color
                    setNavigationHeaderBackground(new ColorDrawable(primaryColor), navigationHeader);
                }
            }
        }
    }
}
Also used : OCCapability(com.owncloud.android.lib.resources.status.OCCapability) ViewGroup(android.view.ViewGroup) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) TextDrawable(com.owncloud.android.ui.TextDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) MenuSimpleTarget(com.owncloud.android.utils.svg.MenuSimpleTarget) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) ColorDrawable(android.graphics.drawable.ColorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) CapabilityBooleanType(com.owncloud.android.lib.resources.status.CapabilityBooleanType) OwnCloudVersion(com.owncloud.android.lib.resources.status.OwnCloudVersion)

Example 13 with OCCapability

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

the class ThemeUtils method getCapability.

private static OCCapability getCapability(Account acc) {
    Account account;
    Context context = MainApp.getAppContext();
    if (context == null) {
        return new OCCapability();
    }
    if (acc != null) {
        account = acc;
    } else {
        account = AccountUtils.getCurrentOwnCloudAccount(context);
    }
    if (account != null) {
        FileDataStorageManager storageManager = new FileDataStorageManager(account, context.getContentResolver());
        return storageManager.getCapability(account.name);
    } else {
        return new OCCapability();
    }
}
Also used : Context(android.content.Context) Account(android.accounts.Account) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager)

Example 14 with OCCapability

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

the class EndToEndRandomIT method before.

@Before
public void before() throws IOException {
    OCCapability capability = getStorageManager().getCapability(account.name);
    if (capability.getVersion().equals(new OwnCloudVersion("0.0.0"))) {
        // fetch new one
        assertTrue(new GetCapabilitiesOperation(getStorageManager()).execute(client).isSuccess());
    }
    // tests only for NC19+
    assumeTrue(getStorageManager().getCapability(account.name).getVersion().isNewerOrEqual(nextcloud_19));
    // make sure that every file is available, even after tests that remove source file
    createDummyFiles();
}
Also used : GetCapabilitiesOperation(com.owncloud.android.operations.GetCapabilitiesOperation) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) OwnCloudVersion(com.owncloud.android.lib.resources.status.OwnCloudVersion) Before(org.junit.Before)

Example 15 with OCCapability

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

the class DialogFragmentIT method testAccountChooserDialog.

@Test
@ScreenshotTest
public void testAccountChooserDialog() throws AccountUtils.AccountNotFoundException {
    FileDisplayActivity activity = getFileDisplayActivity();
    UserAccountManager userAccountManager = activity.getUserAccountManager();
    AccountManager accountManager = AccountManager.get(targetContext);
    for (Account account : accountManager.getAccountsByType(MainApp.getAccountType(targetContext))) {
        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");
    User newUser = userAccountManager.getUser(newAccount.name).orElseThrow(RuntimeException::new);
    Account newAccount2 = new Account("user1@nextcloud.localhost", MainApp.getAccountType(targetContext));
    accountManager.addAccountExplicitly(newAccount2, "password", null);
    accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_OC_BASE_URL, SERVER_URL);
    accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_USER_ID, "user1");
    accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_OC_VERSION, "20.0.0");
    accountManager.setAuthToken(newAccount2, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password");
    FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(newUser, targetContext.getContentResolver());
    OCCapability capability = new OCCapability();
    capability.setUserStatus(CapabilityBooleanType.TRUE);
    capability.setUserStatusSupportsEmoji(CapabilityBooleanType.TRUE);
    fileDataStorageManager.saveCapabilities(capability);
    ChooseAccountDialogFragment sut = ChooseAccountDialogFragment.newInstance(new RegisteredUser(newAccount, new OwnCloudAccount(newAccount, targetContext), new Server(URI.create(SERVER_URL), OwnCloudVersion.nextcloud_20)));
    showDialog(activity, sut);
    activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.DND, "Busy fixing 🐛…", "", -1), targetContext));
    waitForIdleSync();
    shortSleep();
    screenshot(sut, "dnd");
    activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.ONLINE, "", "", -1), targetContext));
    waitForIdleSync();
    shortSleep();
    screenshot(sut, "online");
    activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.ONLINE, "Let's have some fun", "🎉", -1), targetContext));
    waitForIdleSync();
    shortSleep();
    screenshot(sut, "fun");
    activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.OFFLINE, "", "", -1), targetContext));
    waitForIdleSync();
    shortSleep();
    screenshot(sut, "offline");
    activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.AWAY, "Vacation", "🌴", -1), targetContext));
    waitForIdleSync();
    shortSleep();
    screenshot(sut, "away");
}
Also used : Status(com.owncloud.android.lib.resources.users.Status) Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) 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) ChooseAccountDialogFragment(com.nextcloud.ui.ChooseAccountDialogFragment) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) RegisteredUser(com.nextcloud.client.account.RegisteredUser) UserAccountManager(com.nextcloud.client.account.UserAccountManager) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) UserAccountManager(com.nextcloud.client.account.UserAccountManager) AccountManager(android.accounts.AccountManager) 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