Search in sources :

Example 1 with GetCapabilitiesOperarion

use of com.owncloud.android.operations.GetCapabilitiesOperarion 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) {
                GetCapabilitiesOperarion getCapabilities = new GetCapabilitiesOperarion();
                getCapabilities.execute(getStorageManager(), getBaseContext());
            }
            Account account = AccountUtils.getCurrentOwnCloudAccount(DrawerActivity.this);
            if (account != null && getStorageManager() != null && getStorageManager().getCapability(account.name) != null && getStorageManager().getCapability(account.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(account, DrawerActivity.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(() -> updateExternalLinksInDrawer());
        });
        t.start();
    }
}
Also used : Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) GetCapabilitiesOperarion(com.owncloud.android.operations.GetCapabilitiesOperarion) 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 GetCapabilitiesOperarion

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

the class AccountUtils method setCurrentOwnCloudAccount.

public static boolean setCurrentOwnCloudAccount(final Context context, String accountName) {
    boolean result = false;
    if (accountName != null) {
        boolean found;
        for (final Account account : getAccounts(context)) {
            found = (account.name.equals(accountName));
            if (found) {
                SharedPreferences.Editor appPrefs = PreferenceManager.getDefaultSharedPreferences(context).edit();
                appPrefs.putString("select_oc_account", accountName);
                // update credentials
                Thread t = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        FileDataStorageManager storageManager = new FileDataStorageManager(account, context.getContentResolver());
                        GetCapabilitiesOperarion getCapabilities = new GetCapabilitiesOperarion();
                        RemoteOperationResult updateResult = getCapabilities.execute(storageManager, context);
                        Log_OC.w(TAG, "Update Capabilities: " + updateResult.isSuccess());
                    }
                });
                t.start();
                appPrefs.apply();
                result = true;
                break;
            }
        }
    }
    return result;
}
Also used : Account(android.accounts.Account) SharedPreferences(android.content.SharedPreferences) GetCapabilitiesOperarion(com.owncloud.android.operations.GetCapabilitiesOperarion) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager)

Aggregations

Account (android.accounts.Account)2 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)2 GetCapabilitiesOperarion (com.owncloud.android.operations.GetCapabilitiesOperarion)2 SharedPreferences (android.content.SharedPreferences)1 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)1 ExternalLink (com.owncloud.android.lib.common.ExternalLink)1 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)1 ExternalLinksOperation (com.owncloud.android.lib.common.accounts.ExternalLinksOperation)1 RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)1 ArrayList (java.util.ArrayList)1