Search in sources :

Example 11 with ArbitraryDataProvider

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

the class SetupEncryptionDialogFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    int accentColor = ThemeUtils.primaryAccentColor();
    account = getArguments().getParcelable(ARG_ACCOUNT);
    arbitraryDataProvider = new ArbitraryDataProvider(getContext().getContentResolver());
    // Inflate the layout for the dialog
    LayoutInflater inflater = getActivity().getLayoutInflater();
    // Setup layout
    View v = inflater.inflate(R.layout.setup_encryption_dialog, null);
    textView = v.findViewById(R.id.encryption_status);
    passphraseTextView = v.findViewById(R.id.encryption_passphrase);
    passwordField = v.findViewById(R.id.encryption_passwordInput);
    passwordField.getBackground().setColorFilter(accentColor, PorterDuff.Mode.SRC_ATOP);
    Drawable wrappedDrawable = DrawableCompat.wrap(passwordField.getBackground());
    DrawableCompat.setTint(wrappedDrawable, accentColor);
    passwordField.setBackgroundDrawable(wrappedDrawable);
    // Build the dialog
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(v).setPositiveButton(R.string.common_ok, null).setNegativeButton(R.string.common_cancel, null).setTitle(ThemeUtils.getColoredTitle(getString(R.string.end_to_end_encryption_title), accentColor));
    Dialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(final DialogInterface dialog) {
            Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
            button.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    switch(keyResult) {
                        case KEY_CREATED:
                            Log_OC.d(TAG, "New keys generated and stored.");
                            dialog.dismiss();
                            Intent intentCreated = new Intent();
                            intentCreated.putExtra(SUCCESS, true);
                            intentCreated.putExtra(ARG_POSITION, getArguments().getInt(ARG_POSITION));
                            getTargetFragment().onActivityResult(getTargetRequestCode(), SETUP_ENCRYPTION_RESULT_CODE, intentCreated);
                            break;
                        case KEY_EXISTING_USED:
                            Log_OC.d(TAG, "Decrypt private key");
                            textView.setText(R.string.end_to_end_encryption_decrypting);
                            try {
                                String privateKey = task.get();
                                String decryptedPrivateKey = EncryptionUtils.decryptPrivateKey(privateKey, passwordField.getText().toString().replaceAll("\\s", "").toLowerCase(Locale.ROOT));
                                arbitraryDataProvider.storeOrUpdateKeyValue(account.name, EncryptionUtils.PRIVATE_KEY, decryptedPrivateKey);
                                dialog.dismiss();
                                Log_OC.d(TAG, "Private key successfully decrypted and stored");
                                Intent intentExisting = new Intent();
                                intentExisting.putExtra(SUCCESS, true);
                                intentExisting.putExtra(ARG_POSITION, getArguments().getInt(ARG_POSITION));
                                getTargetFragment().onActivityResult(getTargetRequestCode(), SETUP_ENCRYPTION_RESULT_CODE, intentExisting);
                            } catch (Exception e) {
                                textView.setText(R.string.end_to_end_encryption_wrong_password);
                                Log_OC.d(TAG, "Error while decrypting private key: " + e.getMessage());
                            }
                            break;
                        case KEY_GENERATE:
                            passphraseTextView.setVisibility(View.GONE);
                            positiveButton.setVisibility(View.GONE);
                            negativeButton.setVisibility(View.GONE);
                            getDialog().setTitle(ThemeUtils.getColoredTitle(getString(R.string.end_to_end_encryption_storing_keys), ThemeUtils.primaryColor()));
                            GenerateNewKeysAsyncTask newKeysTask = new GenerateNewKeysAsyncTask();
                            newKeysTask.execute();
                            break;
                        default:
                            dialog.dismiss();
                            break;
                    }
                }
            });
        }
    });
    return dialog;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Drawable(android.graphics.drawable.Drawable) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) IOException(java.io.IOException) Button(android.widget.Button) Dialog(android.app.Dialog) AlertDialog(android.support.v7.app.AlertDialog) LayoutInflater(android.view.LayoutInflater)

Example 12 with ArbitraryDataProvider

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

the class OCFileListFragment method onItemClicked.

@Override
public void onItemClicked(OCFile file) {
    if (getAdapter().isMultiSelect()) {
        if (getAdapter().isCheckedFile(file)) {
            getAdapter().removeCheckedFile(file);
        } else {
            getAdapter().addCheckedFile(file);
        }
        mActiveActionMode.invalidate();
        mAdapter.notifyItemChanged(getAdapter().getItemPosition(file));
    } else {
        if (file != null) {
            int position = mAdapter.getItemPosition(file);
            if (file.isFolder()) {
                if (file.isEncrypted()) {
                    // check if API >= 19
                    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) {
                        Snackbar.make(getRecyclerView(), R.string.end_to_end_encryption_not_supported, Snackbar.LENGTH_LONG).show();
                        return;
                    }
                    Account account = ((FileActivity) mContainerActivity).getAccount();
                    // check if e2e app is enabled
                    OCCapability ocCapability = mContainerActivity.getStorageManager().getCapability(account.name);
                    if (ocCapability.getEndToEndEncryption().isFalse() || ocCapability.getEndToEndEncryption().isUnknown()) {
                        Snackbar.make(getRecyclerView(), R.string.end_to_end_encryption_not_enabled, Snackbar.LENGTH_LONG).show();
                        return;
                    }
                    // check if keys are stored
                    ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContext().getContentResolver());
                    String publicKey = arbitraryDataProvider.getValue(account, EncryptionUtils.PUBLIC_KEY);
                    String privateKey = arbitraryDataProvider.getValue(account, EncryptionUtils.PRIVATE_KEY);
                    if (publicKey.isEmpty() || privateKey.isEmpty()) {
                        Log_OC.d(TAG, "no public key for " + account.name);
                        SetupEncryptionDialogFragment dialog = SetupEncryptionDialogFragment.newInstance(account, position);
                        dialog.setTargetFragment(this, SetupEncryptionDialogFragment.SETUP_ENCRYPTION_REQUEST_CODE);
                        dialog.show(getFragmentManager(), SetupEncryptionDialogFragment.SETUP_ENCRYPTION_DIALOG_TAG);
                    } else {
                        // update state and view of this fragment
                        searchFragment = false;
                        if (mContainerActivity instanceof FolderPickerActivity && ((FolderPickerActivity) mContainerActivity).isDoNotEnterEncryptedFolder()) {
                            Snackbar.make(getRecyclerView(), R.string.copy_move_to_encrypted_folder_not_supported, Snackbar.LENGTH_LONG).show();
                        } else {
                            listDirectory(file, MainApp.isOnlyOnDevice(), false);
                            // then, notify parent activity to let it update its state and view
                            mContainerActivity.onBrowsedDownTo(file);
                            // save index and top position
                            saveIndexAndTopPosition(position);
                        }
                    }
                } else {
                    // update state and view of this fragment
                    searchFragment = false;
                    listDirectory(file, MainApp.isOnlyOnDevice(), false);
                    // then, notify parent activity to let it update its state and view
                    mContainerActivity.onBrowsedDownTo(file);
                    // save index and top position
                    saveIndexAndTopPosition(position);
                }
            } else if (!mOnlyFoldersClickable) {
                // Click on a file
                if (PreviewImageFragment.canBePreviewed(file)) {
                    // preview image - it handles the download, if needed
                    if (searchFragment) {
                        VirtualFolderType type;
                        switch(currentSearchType) {
                            case FAVORITE_SEARCH:
                                type = VirtualFolderType.FAVORITE;
                                break;
                            case PHOTO_SEARCH:
                                type = VirtualFolderType.PHOTOS;
                                break;
                            default:
                                type = VirtualFolderType.NONE;
                                break;
                        }
                        ((FileDisplayActivity) mContainerActivity).startImagePreview(file, type, !file.isDown());
                    } else {
                        ((FileDisplayActivity) mContainerActivity).startImagePreview(file, !file.isDown());
                    }
                } else if (file.isDown() && MimeTypeUtil.isVCard(file)) {
                    ((FileDisplayActivity) mContainerActivity).startContactListFragment(file);
                } else if (PreviewTextFragment.canBePreviewed(file)) {
                    ((FileDisplayActivity) mContainerActivity).startTextPreview(file, false);
                } else if (file.isDown()) {
                    if (PreviewMediaFragment.canBePreviewed(file)) {
                        // media preview
                        ((FileDisplayActivity) mContainerActivity).startMediaPreview(file, 0, true, false);
                    } else {
                        mContainerActivity.getFileOperationsHelper().openFile(file);
                    }
                } else {
                    // automatic download, preview on finish
                    ((FileDisplayActivity) mContainerActivity).startDownloadForPreview(file);
                }
            }
        } else {
            Log_OC.d(TAG, "Null object in ListAdapter!!");
        }
    }
}
Also used : Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) FolderPickerActivity(com.owncloud.android.ui.activity.FolderPickerActivity) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) FileActivity(com.owncloud.android.ui.activity.FileActivity) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) SetupEncryptionDialogFragment(com.owncloud.android.ui.dialog.SetupEncryptionDialogFragment) VirtualFolderType(com.owncloud.android.datamodel.VirtualFolderType)

Example 13 with ArbitraryDataProvider

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

the class ContactsBackupFragment method onCreateView.

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // use grey as fallback for elements where custom theming is not available
    if (ThemeUtils.themingEnabled()) {
        getContext().getTheme().applyStyle(R.style.FallbackThemingTheme, true);
    }
    View view = inflater.inflate(R.layout.contacts_backup_fragment, null);
    ButterKnife.bind(this, view);
    setHasOptionsMenu(true);
    if (getArguments() != null) {
        showSidebar = getArguments().getBoolean(ContactsPreferenceActivity.EXTRA_SHOW_SIDEBAR);
    }
    final ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity();
    account = (Account) getArguments().get(ContactListFragment.ACCOUNT);
    contactsPreferenceActivity.getSupportActionBar().setTitle(R.string.actionbar_contacts);
    contactsPreferenceActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    arbitraryDataProvider = new ArbitraryDataProvider(getContext().getContentResolver());
    ThemeUtils.tintSwitch(backupSwitch, ThemeUtils.primaryAccentColor());
    backupSwitch.setChecked(arbitraryDataProvider.getBooleanValue(account, PREFERENCE_CONTACTS_AUTOMATIC_BACKUP));
    onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (checkAndAskForContactsReadPermission()) {
                if (isChecked) {
                    setAutomaticBackup(true);
                } else {
                    setAutomaticBackup(false);
                }
            }
        }
    };
    backupSwitch.setOnCheckedChangeListener(onCheckedChangeListener);
    // display last backup
    Long lastBackupTimestamp = arbitraryDataProvider.getLongValue(account, PREFERENCE_CONTACTS_LAST_BACKUP);
    if (lastBackupTimestamp == -1) {
        lastBackup.setText(R.string.contacts_preference_backup_never);
    } else {
        lastBackup.setText(DisplayUtils.getRelativeTimestamp(contactsPreferenceActivity, lastBackupTimestamp));
    }
    if (savedInstanceState != null && savedInstanceState.getBoolean(KEY_CALENDAR_PICKER_OPEN, false)) {
        if (savedInstanceState.getInt(KEY_CALENDAR_YEAR, -1) != -1 && savedInstanceState.getInt(KEY_CALENDAR_MONTH, -1) != -1 && savedInstanceState.getInt(KEY_CALENDAR_DAY, -1) != -1) {
            selectedDate = new Date(savedInstanceState.getInt(KEY_CALENDAR_YEAR), savedInstanceState.getInt(KEY_CALENDAR_MONTH), savedInstanceState.getInt(KEY_CALENDAR_DAY));
        }
        calendarPickerOpen = true;
    }
    int accentColor = ThemeUtils.primaryAccentColor();
    contactsDatePickerBtn.getBackground().setColorFilter(accentColor, PorterDuff.Mode.SRC_ATOP);
    view.findViewById(R.id.contacts_backup_now).getBackground().setColorFilter(accentColor, PorterDuff.Mode.SRC_ATOP);
    AppCompatButton chooseDate = view.findViewById(R.id.contacts_datepicker);
    chooseDate.getBackground().setColorFilter(accentColor, PorterDuff.Mode.SRC_ATOP);
    chooseDate.setTextColor(ThemeUtils.fontColor());
    return view;
}
Also used : ContactsPreferenceActivity(com.owncloud.android.ui.activity.ContactsPreferenceActivity) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton) Date(java.util.Date) AppCompatButton(android.support.v7.widget.AppCompatButton)

Example 14 with ArbitraryDataProvider

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

the class DrawerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        mIsAccountChooserActive = savedInstanceState.getBoolean(KEY_IS_ACCOUNT_CHOOSER_ACTIVE, false);
        mCheckedMenuItem = savedInstanceState.getInt(KEY_CHECKED_MENU_ITEM, Menu.NONE);
    }
    mCurrentAccountAvatarRadiusDimension = getResources().getDimension(R.dimen.nav_drawer_header_avatar_radius);
    mOtherAccountAvatarRadiusDimension = getResources().getDimension(R.dimen.nav_drawer_header_avatar_other_accounts_radius);
    mMenuAccountAvatarRadiusDimension = getResources().getDimension(R.dimen.nav_drawer_menu_avatar_radius);
    externalLinksProvider = new ExternalLinksProvider(getContentResolver());
    arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
}
Also used : ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) ExternalLinksProvider(com.owncloud.android.datamodel.ExternalLinksProvider)

Example 15 with ArbitraryDataProvider

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

the class FileActivity method checkForNewDevVersionNecessary.

public void checkForNewDevVersionNecessary(View view, Context context) {
    if (getResources().getBoolean(R.bool.dev_version_direct_download_enabled)) {
        ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
        int count = arbitraryDataProvider.getIntegerValue(FilesSyncHelper.GLOBAL, APP_OPENED_COUNT);
        if (count > 10 || count == -1) {
            checkForNewDevVersion(view, context, false);
        }
    }
}
Also used : ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider)

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