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");
}
}
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);
}
}
}
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;
}
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());
}
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;
}
Aggregations