Search in sources :

Example 16 with ArbitraryDataProvider

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();
}
Also used : Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) Intent(android.content.Intent) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) AccountListItem(com.owncloud.android.ui.adapter.AccountListItem) AdapterView(android.widget.AdapterView) AccountListAdapter(com.owncloud.android.ui.adapter.AccountListAdapter)

Example 17 with ArbitraryDataProvider

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();
    }
}
Also used : AccountListItem(com.owncloud.android.ui.adapter.AccountListItem) Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) PersistableBundleCompat(com.evernote.android.job.util.support.PersistableBundleCompat) JobRequest(com.evernote.android.job.JobRequest) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) Intent(android.content.Intent)

Example 18 with ArbitraryDataProvider

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();
        }
    }
}
Also used : Context(android.content.Context) Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) BindString(butterknife.BindString)

Example 19 with ArbitraryDataProvider

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);
        }
    }
}
Also used : ThumbnailsCacheManager(com.owncloud.android.datamodel.ThumbnailsCacheManager) Drawable(android.graphics.drawable.Drawable) TextDrawable(com.owncloud.android.ui.TextDrawable) PictureDrawable(android.graphics.drawable.PictureDrawable) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) View(android.view.View) BottomNavigationView(android.support.design.widget.BottomNavigationView) IOException(java.io.IOException)

Example 20 with ArbitraryDataProvider

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;
    }
}
Also used : RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) EncryptedFolderMetadata(com.owncloud.android.datamodel.EncryptedFolderMetadata) GetMetadataOperation(com.owncloud.android.lib.resources.files.GetMetadataOperation) ShortBufferException(javax.crypto.ShortBufferException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) BadPaddingException(javax.crypto.BadPaddingException) NoSuchProviderException(java.security.NoSuchProviderException) RequiresApi(android.support.annotation.RequiresApi) Nullable(android.support.annotation.Nullable)

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