Search in sources :

Example 6 with ArbitraryDataProvider

use of com.owncloud.android.datamodel.ArbitraryDataProvider in project android by nextcloud.

the class PushUtils method deleteRegistrationForAccount.

private static void deleteRegistrationForAccount(Account account) {
    Context context = MainApp.getAppContext();
    OwnCloudAccount ocAccount = null;
    arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext().getContentResolver());
    try {
        ocAccount = new OwnCloudAccount(account, context);
        OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, context);
        RemoteOperation unregisterAccountDeviceForNotificationsOperation = new UnregisterAccountDeviceForNotificationsOperation();
        RemoteOperationResult remoteOperationResult = unregisterAccountDeviceForNotificationsOperation.execute(mClient);
        if (remoteOperationResult.getHttpCode() == HttpStatus.SC_ACCEPTED) {
            String arbitraryValue;
            if (!TextUtils.isEmpty(arbitraryValue = arbitraryDataProvider.getValue(account, KEY_PUSH))) {
                Gson gson = new Gson();
                PushConfigurationState pushArbitraryData = gson.fromJson(arbitraryValue, PushConfigurationState.class);
                RemoteOperation unregisterAccountDeviceForProxyOperation = new UnregisterAccountDeviceForProxyOperation(context.getResources().getString(R.string.push_server_url), pushArbitraryData.getDeviceIdentifier(), pushArbitraryData.getDeviceIdentifierSignature(), pushArbitraryData.getUserPublicKey());
                remoteOperationResult = unregisterAccountDeviceForProxyOperation.execute(mClient);
                if (remoteOperationResult.isSuccess()) {
                    arbitraryDataProvider.deleteKeyForAccount(account.name, KEY_PUSH);
                }
            }
        }
    } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
        Log_OC.d(TAG, "Failed to find an account");
    } catch (AuthenticatorException e) {
        Log_OC.d(TAG, "Failed via AuthenticatorException");
    } catch (IOException e) {
        Log_OC.d(TAG, "Failed via IOException");
    } catch (OperationCanceledException e) {
        Log_OC.d(TAG, "Failed via OperationCanceledException");
    }
}
Also used : Context(android.content.Context) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) UnregisterAccountDeviceForProxyOperation(com.owncloud.android.lib.resources.notifications.UnregisterAccountDeviceForProxyOperation) OperationCanceledException(android.accounts.OperationCanceledException) AccountUtils(com.owncloud.android.authentication.AccountUtils) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) Gson(com.google.gson.Gson) AuthenticatorException(android.accounts.AuthenticatorException) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) IOException(java.io.IOException) PushConfigurationState(com.owncloud.android.datamodel.PushConfigurationState) UnregisterAccountDeviceForNotificationsOperation(com.owncloud.android.lib.resources.notifications.UnregisterAccountDeviceForNotificationsOperation) OwnCloudClient(com.owncloud.android.lib.common.OwnCloudClient)

Example 7 with ArbitraryDataProvider

use of com.owncloud.android.datamodel.ArbitraryDataProvider in project android by nextcloud.

the class MainApp method initContactsBackup.

public static void initContactsBackup() {
    ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(mContext.getContentResolver());
    Account[] accounts = AccountUtils.getAccounts(mContext);
    for (Account account : accounts) {
        if (arbitraryDataProvider.getBooleanValue(account, PREFERENCE_CONTACTS_AUTOMATIC_BACKUP)) {
            ContactsPreferenceActivity.startContactBackupJob(account);
        }
    }
}
Also used : Account(android.accounts.Account) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider)

Example 8 with ArbitraryDataProvider

use of com.owncloud.android.datamodel.ArbitraryDataProvider in project android by nextcloud.

the class AccountUtils method getCurrentOwnCloudAccount.

/**
 * Can be used to get the currently selected ownCloud {@link Account} in the
 * application preferences.
 *
 * @param   context     The current application {@link Context}
 * @return              The ownCloud {@link Account} currently saved in preferences, or the first
 *                      {@link Account} available, if valid (still registered in the system as ownCloud
 *                      account). If none is available and valid, returns null.
 */
@Nullable
public static Account getCurrentOwnCloudAccount(Context context) {
    Account[] ocAccounts = getAccounts(context);
    Account defaultAccount = null;
    ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver());
    SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    String accountName = appPreferences.getString("select_oc_account", null);
    // account validation: the saved account MUST be in the list of ownCloud Accounts known by the AccountManager
    if (accountName != null) {
        for (Account account : ocAccounts) {
            if (account.name.equals(accountName)) {
                defaultAccount = account;
                break;
            }
        }
    }
    if (defaultAccount == null && ocAccounts.length > 0) {
        // take first which is not pending for removal account as fallback
        for (Account account : ocAccounts) {
            boolean pendingForRemoval = arbitraryDataProvider.getBooleanValue(account, ManageAccountsActivity.PENDING_FOR_REMOVAL);
            if (!pendingForRemoval) {
                defaultAccount = account;
                break;
            }
        }
    }
    return defaultAccount;
}
Also used : Account(android.accounts.Account) SharedPreferences(android.content.SharedPreferences) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) Nullable(android.support.annotation.Nullable)

Example 9 with ArbitraryDataProvider

use of com.owncloud.android.datamodel.ArbitraryDataProvider in project android by nextcloud.

the class SyncedFoldersActivity method onSyncStatusToggleClick.

@Override
public void onSyncStatusToggleClick(int section, SyncedFolderDisplayItem syncedFolderDisplayItem) {
    ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext().getContentResolver());
    if (syncedFolderDisplayItem.getId() > UNPERSISTED_ID) {
        mSyncedFolderProvider.updateSyncedFolderEnabled(syncedFolderDisplayItem.getId(), syncedFolderDisplayItem.isEnabled());
    } else {
        long storedId = mSyncedFolderProvider.storeSyncedFolder(syncedFolderDisplayItem);
        if (storedId != -1) {
            syncedFolderDisplayItem.setId(storedId);
        }
    }
    if (syncedFolderDisplayItem.isEnabled()) {
        FilesSyncHelper.insertAllDBEntriesForSyncedFolder(syncedFolderDisplayItem);
    } else {
        String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + syncedFolderDisplayItem.getId();
        arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey);
    }
    FilesSyncHelper.scheduleNJobs(false, getApplicationContext());
}
Also used : ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider)

Example 10 with ArbitraryDataProvider

use of com.owncloud.android.datamodel.ArbitraryDataProvider in project android by nextcloud.

the class SyncedFoldersActivity method onSaveSyncedFolderPreference.

@Override
public void onSaveSyncedFolderPreference(SyncedFolderParcelable syncedFolder) {
    ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext().getContentResolver());
    // so triggering a refresh
    if (MediaFolderType.CUSTOM.equals(syncedFolder.getType()) && syncedFolder.getId() == UNPERSISTED_ID) {
        SyncedFolderDisplayItem newCustomFolder = new SyncedFolderDisplayItem(SyncedFolder.UNPERSISTED_ID, syncedFolder.getLocalPath(), syncedFolder.getRemotePath(), syncedFolder.getWifiOnly(), syncedFolder.getChargingOnly(), syncedFolder.getSubfolderByDate(), syncedFolder.getAccount(), syncedFolder.getUploadAction(), syncedFolder.getEnabled(), new File(syncedFolder.getLocalPath()).getName(), syncedFolder.getType());
        long storedId = mSyncedFolderProvider.storeSyncedFolder(newCustomFolder);
        if (storedId != -1) {
            newCustomFolder.setId(storedId);
            if (newCustomFolder.isEnabled()) {
                FilesSyncHelper.insertAllDBEntriesForSyncedFolder(newCustomFolder);
            } else {
                String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + newCustomFolder.getId();
                arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey);
            }
            FilesSyncHelper.scheduleNJobs(false, getApplicationContext());
        }
        mAdapter.addSyncFolderItem(newCustomFolder);
    } else {
        SyncedFolderDisplayItem item = mAdapter.get(syncedFolder.getSection());
        item = updateSyncedFolderItem(item, syncedFolder.getLocalPath(), syncedFolder.getRemotePath(), syncedFolder.getWifiOnly(), syncedFolder.getChargingOnly(), syncedFolder.getSubfolderByDate(), syncedFolder.getUploadAction(), syncedFolder.getEnabled());
        if (syncedFolder.getId() == UNPERSISTED_ID) {
            // newly set up folder sync config
            long storedId = mSyncedFolderProvider.storeSyncedFolder(item);
            if (storedId != -1) {
                item.setId(storedId);
                if (item.isEnabled()) {
                    FilesSyncHelper.insertAllDBEntriesForSyncedFolder(item);
                } else {
                    String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + item.getId();
                    arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey);
                }
                FilesSyncHelper.scheduleNJobs(false, getApplicationContext());
            }
        } else {
            // existing synced folder setup to be updated
            mSyncedFolderProvider.updateSyncFolder(item);
            if (item.isEnabled()) {
                FilesSyncHelper.insertAllDBEntriesForSyncedFolder(item);
            } else {
                String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + item.getId();
                arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey);
            }
            FilesSyncHelper.scheduleNJobs(false, getApplicationContext());
        }
        mAdapter.setSyncFolderItem(syncedFolder.getSection(), item);
    }
    mSyncedFolderPreferencesDialogFragment = null;
}
Also used : ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) SyncedFolderDisplayItem(com.owncloud.android.datamodel.SyncedFolderDisplayItem) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File)

Aggregations

ArbitraryDataProvider (com.owncloud.android.datamodel.ArbitraryDataProvider)26 Account (android.accounts.Account)14 Context (android.content.Context)8 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)8 IOException (java.io.IOException)8 File (java.io.File)6 Intent (android.content.Intent)5 View (android.view.View)4 PersistableBundleCompat (com.evernote.android.job.util.support.PersistableBundleCompat)4 FilesystemDataProvider (com.owncloud.android.datamodel.FilesystemDataProvider)4 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)4 ContentResolver (android.content.ContentResolver)3 NonNull (android.support.annotation.NonNull)3 Gson (com.google.gson.Gson)3 PushConfigurationState (com.owncloud.android.datamodel.PushConfigurationState)3 AuthenticatorException (android.accounts.AuthenticatorException)2 OperationCanceledException (android.accounts.OperationCanceledException)2 Drawable (android.graphics.drawable.Drawable)2 Nullable (android.support.annotation.Nullable)2 RequiresApi (android.support.annotation.RequiresApi)2