Search in sources :

Example 1 with GetCapabilitiesOperation

use of com.owncloud.android.operations.GetCapabilitiesOperation in project android by nextcloud.

the class DrawerActivity method fetchExternalLinks.

/**
 * Retrieves external links via api from 'external' app
 */
public void fetchExternalLinks(final boolean force) {
    if (getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
        Thread t = new Thread(() -> {
            // fetch capabilities as early as possible
            if ((getCapabilities() == null || getCapabilities().getAccountName().isEmpty()) && getStorageManager() != null) {
                GetCapabilitiesOperation getCapabilities = new GetCapabilitiesOperation(getStorageManager());
                getCapabilities.execute(getBaseContext());
            }
            User user = accountManager.getUser();
            String name = user.getAccountName();
            if (getStorageManager() != null && getStorageManager().getCapability(name).getExternalLinks().isTrue()) {
                int count = arbitraryDataProvider.getIntegerValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT);
                if (count > 10 || count == -1 || force) {
                    if (force) {
                        Log_OC.d("ExternalLinks", "force update");
                    }
                    arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT, "0");
                    Log_OC.d("ExternalLinks", "update via api");
                    RemoteOperation getExternalLinksOperation = new ExternalLinksOperation();
                    RemoteOperationResult result = getExternalLinksOperation.execute(user.toPlatformAccount(), this);
                    if (result.isSuccess() && result.getData() != null) {
                        externalLinksProvider.deleteAllExternalLinks();
                        ArrayList<ExternalLink> externalLinks = (ArrayList<ExternalLink>) (Object) result.getData();
                        for (ExternalLink link : externalLinks) {
                            externalLinksProvider.storeExternalLink(link);
                        }
                    }
                } else {
                    arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT, String.valueOf(count + 1));
                }
            } else {
                externalLinksProvider.deleteAllExternalLinks();
                Log_OC.d("ExternalLinks", "links disabled");
            }
            runOnUiThread(this::updateExternalLinksInDrawer);
        });
        t.start();
    }
}
Also used : GetUserInfoRemoteOperation(com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation) SearchRemoteOperation(com.owncloud.android.lib.resources.files.SearchRemoteOperation) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) GetCapabilitiesOperation(com.owncloud.android.operations.GetCapabilitiesOperation) User(com.nextcloud.client.account.User) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ArrayList(java.util.ArrayList) ExternalLinksOperation(com.owncloud.android.lib.common.accounts.ExternalLinksOperation) ExternalLink(com.owncloud.android.lib.common.ExternalLink)

Example 2 with GetCapabilitiesOperation

use of com.owncloud.android.operations.GetCapabilitiesOperation 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)

Aggregations

GetCapabilitiesOperation (com.owncloud.android.operations.GetCapabilitiesOperation)2 User (com.nextcloud.client.account.User)1 ExternalLink (com.owncloud.android.lib.common.ExternalLink)1 ExternalLinksOperation (com.owncloud.android.lib.common.accounts.ExternalLinksOperation)1 RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)1 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)1 SearchRemoteOperation (com.owncloud.android.lib.resources.files.SearchRemoteOperation)1 OCCapability (com.owncloud.android.lib.resources.status.OCCapability)1 OwnCloudVersion (com.owncloud.android.lib.resources.status.OwnCloudVersion)1 GetUserInfoRemoteOperation (com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1