use of com.owncloud.android.datamodel.ArbitraryDataProvider in project android by nextcloud.
the class ManageAccountsActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mTintedCheck = DrawableCompat.wrap(ContextCompat.getDrawable(this, R.drawable.ic_account_circle_white_18dp));
int tint = ThemeUtils.primaryColor();
DrawableCompat.setTint(mTintedCheck, tint);
setContentView(R.layout.accounts_layout);
mListView = (ListView) findViewById(R.id.account_list);
setupToolbar();
updateActionBarTitleAndHomeButtonByString(getResources().getString(R.string.prefs_manage_accounts));
Account[] accountList = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
mOriginalAccounts = DisplayUtils.toAccountNameSet(Arrays.asList(accountList));
mOriginalCurrentAccount = AccountUtils.getCurrentOwnCloudAccount(this).name;
setAccount(AccountUtils.getCurrentOwnCloudAccount(this));
onAccountSet(false);
arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
mAccountListAdapter = new AccountListAdapter(this, getAccountListItems(), mTintedCheck);
mListView.setAdapter(mAccountListAdapter);
final Intent intent = new Intent(this, UserInfoActivity.class);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
AccountListItem item = mAccountListAdapter.getItem(position);
if (item != null && item.isEnabled()) {
Account account = item.getAccount();
intent.putExtra(UserInfoActivity.KEY_ACCOUNT, Parcels.wrap(account));
try {
OwnCloudAccount oca = new OwnCloudAccount(account, MainApp.getAppContext());
intent.putExtra(KEY_DISPLAY_NAME, oca.getDisplayName());
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
Log_OC.d(TAG, "Failed to find NC account");
}
startActivityForResult(intent, KEY_USER_INFO_REQUEST_CODE);
}
}
});
initializeComponentGetters();
}
use of com.owncloud.android.datamodel.ArbitraryDataProvider in project android by nextcloud.
the class ManageAccountsActivity method performAccountRemoval.
private void performAccountRemoval(Account account) {
// disable account in list view
for (int i = 0; i < mAccountListAdapter.getCount(); i++) {
AccountListItem item = mAccountListAdapter.getItem(i);
if (item != null && item.getAccount().equals(account)) {
item.setEnabled(false);
break;
}
mAccountListAdapter.notifyDataSetChanged();
}
// store pending account removal
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
arbitraryDataProvider.storeOrUpdateKeyValue(account.name, PENDING_FOR_REMOVAL, String.valueOf(true));
// Cancel transfers
if (mUploaderBinder != null) {
mUploaderBinder.cancel(account);
}
if (mDownloaderBinder != null) {
mDownloaderBinder.cancel(account);
}
// schedule job
PersistableBundleCompat bundle = new PersistableBundleCompat();
bundle.putString(AccountRemovalJob.ACCOUNT, account.name);
new JobRequest.Builder(AccountRemovalJob.TAG).startNow().setExtras(bundle).setUpdateCurrent(false).build().schedule();
// immediately select a new account
Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
String newAccountName = "";
for (Account acc : accounts) {
if (!account.name.equalsIgnoreCase(acc.name)) {
newAccountName = acc.name;
break;
}
}
if (newAccountName.isEmpty()) {
Log_OC.d(TAG, "new account set to null");
AccountUtils.resetOwnCloudAccount(this);
} else {
Log_OC.d(TAG, "new account set to: " + newAccountName);
AccountUtils.setCurrentOwnCloudAccount(this, newAccountName);
}
// only one to be (deleted) account remaining
if (accounts.length < 2) {
Intent resultIntent = new Intent();
resultIntent.putExtra(KEY_ACCOUNT_LIST_CHANGED, true);
resultIntent.putExtra(KEY_CURRENT_ACCOUNT_CHANGED, true);
setResult(RESULT_OK, resultIntent);
super.onBackPressed();
}
}
use of com.owncloud.android.datamodel.ArbitraryDataProvider in project android by nextcloud.
the class NotificationsActivity method setupPushWarning.
private void setupPushWarning() {
if (snackbar != null) {
if (!snackbar.isShown()) {
snackbar.show();
}
} else {
Context context = getApplicationContext();
String pushUrl = context.getResources().getString(R.string.push_server_url);
if (pushUrl.isEmpty()) {
snackbar = Snackbar.make(emptyContentContainer, R.string.push_notifications_not_implemented, Snackbar.LENGTH_INDEFINITE);
} else {
Account account = AccountUtils.getCurrentOwnCloudAccount(context);
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
if (account != null) {
boolean usesOldLogin = arbitraryDataProvider.getBooleanValue(account.name, AccountUtils.ACCOUNT_USES_STANDARD_PASSWORD);
if (usesOldLogin) {
snackbar = Snackbar.make(emptyContentContainer, R.string.push_notifications_old_login, Snackbar.LENGTH_INDEFINITE);
} else {
String pushValue = arbitraryDataProvider.getValue(account.name, PushUtils.KEY_PUSH);
if (pushValue == null || pushValue.isEmpty()) {
snackbar = Snackbar.make(emptyContentContainer, R.string.push_notifications_temp_error, Snackbar.LENGTH_INDEFINITE);
}
}
}
}
if (snackbar != null && !snackbar.isShown()) {
snackbar.show();
}
}
}
use of com.owncloud.android.datamodel.ArbitraryDataProvider in project android by nextcloud.
the class DisplayUtils method setAvatar.
/**
* fetches and sets the avatar of the current account in the drawer in case the drawer is available.
*
* @param account the account to be set in the drawer
* @param avatarRadius the avatar radius
* @param resources reference for density information
* @param storageManager reference for caching purposes
*/
public static void setAvatar(Account account, AvatarGenerationListener listener, float avatarRadius, Resources resources, FileDataStorageManager storageManager, Object callContext) {
if (account != null) {
if (callContext instanceof View) {
((View) callContext).setContentDescription(account.name);
}
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext().getContentResolver());
String eTag = arbitraryDataProvider.getValue(account, ThumbnailsCacheManager.AVATAR);
// first show old one
Drawable avatar = BitmapUtils.bitmapToCircularBitmapDrawable(resources, ThumbnailsCacheManager.getBitmapFromDiskCache("a_" + account.name + "_" + eTag));
// if no one exists, show colored icon with initial char
if (avatar == null) {
try {
avatar = TextDrawable.createAvatar(account.name, avatarRadius);
} catch (Exception e) {
Log_OC.e(TAG, "Error calculating RGB value for active account icon.", e);
avatar = resources.getDrawable(R.drawable.ic_account_circle);
}
}
// check for new avatar, eTag is compared, so only new one is downloaded
if (ThumbnailsCacheManager.cancelPotentialAvatarWork(account.name, callContext)) {
final ThumbnailsCacheManager.AvatarGenerationTask task = new ThumbnailsCacheManager.AvatarGenerationTask(listener, callContext, storageManager, account, resources, avatarRadius);
final ThumbnailsCacheManager.AsyncAvatarDrawable asyncDrawable = new ThumbnailsCacheManager.AsyncAvatarDrawable(resources, avatar, task);
listener.avatarGenerated(asyncDrawable, callContext);
task.execute(account.name);
}
}
}
use of com.owncloud.android.datamodel.ArbitraryDataProvider in project android by nextcloud.
the class EncryptionUtils method downloadFolderMetadata.
/**
* Download metadata for folder and decrypt it
*
* @return decrypted metadata or null
*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Nullable
public static DecryptedFolderMetadata downloadFolderMetadata(OCFile folder, OwnCloudClient client, Context context, Account account) {
GetMetadataOperation getMetadataOperation = new GetMetadataOperation(folder.getLocalId());
RemoteOperationResult getMetadataOperationResult = getMetadataOperation.execute(client, true);
if (!getMetadataOperationResult.isSuccess()) {
return null;
}
// decrypt metadata
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver());
String serializedEncryptedMetadata = (String) getMetadataOperationResult.getData().get(0);
String privateKey = arbitraryDataProvider.getValue(account.name, EncryptionUtils.PRIVATE_KEY);
EncryptedFolderMetadata encryptedFolderMetadata = EncryptionUtils.deserializeJSON(serializedEncryptedMetadata, new TypeToken<EncryptedFolderMetadata>() {
});
try {
return EncryptionUtils.decryptFolderMetaData(encryptedFolderMetadata, privateKey);
} catch (Exception e) {
Log_OC.e(TAG, e.getMessage());
return null;
}
}
Aggregations