Search in sources :

Example 16 with User

use of com.nextcloud.client.account.User in project android by nextcloud.

the class ConflictsResolveActivity method startDialog.

private void startDialog() {
    Optional<User> userOptional = getUser();
    if (!userOptional.isPresent()) {
        Log_OC.e(TAG, "User not present");
        showErrorAndFinish();
    }
    // Check whether the file is contained in the current Account
    Fragment prev = getSupportFragmentManager().findFragmentByTag("conflictDialog");
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    if (prev != null) {
        fragmentTransaction.remove(prev);
    }
    if (existingFile != null && getStorageManager().fileExists(newFile.getRemotePath())) {
        ConflictsResolveDialog dialog = ConflictsResolveDialog.newInstance(existingFile, newFile, userOptional.get());
        dialog.show(fragmentTransaction, "conflictDialog");
    } else {
        // Account was changed to a different one - just finish
        Log_OC.e(TAG, "Account was changed, finishing");
        showErrorAndFinish();
    }
}
Also used : User(com.nextcloud.client.account.User) FragmentTransaction(androidx.fragment.app.FragmentTransaction) Fragment(androidx.fragment.app.Fragment) ConflictsResolveDialog(com.owncloud.android.ui.dialog.ConflictsResolveDialog)

Example 17 with User

use of com.nextcloud.client.account.User in project android by nextcloud.

the class ManageAccountsActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == KEY_DELETE_CODE && data != null) {
        Bundle bundle = data.getExtras();
        if (bundle != null && bundle.containsKey(UserInfoActivity.KEY_ACCOUNT)) {
            final Account account = bundle.getParcelable(UserInfoActivity.KEY_ACCOUNT);
            if (account != null) {
                User user = accountManager.getUser(account.name).orElseThrow(RuntimeException::new);
                accountName = account.name;
                performAccountRemoval(user);
            }
        }
    }
}
Also used : Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) User(com.nextcloud.client.account.User) Bundle(android.os.Bundle)

Example 18 with User

use of com.nextcloud.client.account.User in project android by nextcloud.

the class ManageAccountsActivity method run.

@Override
public void run(AccountManagerFuture<Boolean> future) {
    if (future.isDone()) {
        // after remove account
        Account account = new Account(accountName, MainApp.getAccountType(this));
        if (!accountManager.exists(account)) {
            // Cancel transfers of the removed account
            if (mUploaderBinder != null) {
                mUploaderBinder.cancel(account);
            }
            if (mDownloaderBinder != null) {
                mDownloaderBinder.cancel(account);
            }
        }
        User user = getUserAccountManager().getUser();
        if (user.isAnonymous()) {
            String accountName = "";
            Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType(this));
            if (accounts.length != 0) {
                accountName = accounts[0].name;
            }
            accountManager.setCurrentOwnCloudAccount(accountName);
        }
        List<UserListItem> userListItemArray = getUserListItems();
        if (userListItemArray.size() > SINGLE_ACCOUNT) {
            userListAdapter = new UserListAdapter(this, accountManager, userListItemArray, this, multipleAccountsSupported, false);
            recyclerView.setAdapter(userListAdapter);
        } else {
            onBackPressed();
        }
    }
}
Also used : Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) User(com.nextcloud.client.account.User) UserListItem(com.owncloud.android.ui.adapter.UserListItem) UserListAdapter(com.owncloud.android.ui.adapter.UserListAdapter)

Example 19 with User

use of com.nextcloud.client.account.User in project android by nextcloud.

the class ManageAccountsActivity method performAccountRemoval.

private void performAccountRemoval(User user) {
    // disable account in recycler view
    for (int i = 0; i < userListAdapter.getItemCount(); i++) {
        UserListItem item = userListAdapter.getItem(i);
        if (item != null && item.getUser().getAccountName().equalsIgnoreCase(user.getAccountName())) {
            item.setEnabled(false);
            break;
        }
        userListAdapter.notifyDataSetChanged();
    }
    // store pending account removal
    ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
    arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), PENDING_FOR_REMOVAL, String.valueOf(true));
    // Cancel transfers
    if (mUploaderBinder != null) {
        mUploaderBinder.cancel(user.toPlatformAccount());
    }
    if (mDownloaderBinder != null) {
        mDownloaderBinder.cancel(user.toPlatformAccount());
    }
    backgroundJobManager.startAccountRemovalJob(user.getAccountName(), false);
    // immediately select a new account
    List<User> users = accountManager.getAllUsers();
    String newAccountName = "";
    for (User u : users) {
        if (!u.getAccountName().equalsIgnoreCase(u.getAccountName())) {
            newAccountName = u.getAccountName();
            break;
        }
    }
    if (newAccountName.isEmpty()) {
        Log_OC.d(TAG, "new account set to null");
        accountManager.resetOwnCloudAccount();
    } else {
        Log_OC.d(TAG, "new account set to: " + newAccountName);
        accountManager.setCurrentOwnCloudAccount(newAccountName);
    }
    // only one to be (deleted) account remaining
    if (users.size() < MIN_MULTI_ACCOUNT_SIZE) {
        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 : User(com.nextcloud.client.account.User) UserListItem(com.owncloud.android.ui.adapter.UserListItem) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) Intent(android.content.Intent)

Example 20 with User

use of com.nextcloud.client.account.User in project android by nextcloud.

the class ContactsPreferenceActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.contacts_preference);
    // setup toolbar
    setupToolbar();
    // setup drawer
    // setupDrawer(R.id.nav_contacts); // TODO needed?
    // show sidebar?
    boolean showSidebar = getIntent().getBooleanExtra(EXTRA_SHOW_SIDEBAR, true);
    if (!showSidebar) {
        setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }
        if (mDrawerToggle != null) {
            mDrawerToggle.setDrawerIndicatorEnabled(false);
        }
    }
    Intent intent = getIntent();
    if (savedInstanceState == null) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        if (intent == null || intent.getParcelableExtra(EXTRA_FILE) == null || intent.getParcelableExtra(EXTRA_USER) == null) {
            BackupFragment fragment = BackupFragment.create(showSidebar);
            transaction.add(R.id.frame_container, fragment);
        } else {
            OCFile file = intent.getParcelableExtra(EXTRA_FILE);
            User user = intent.getParcelableExtra(EXTRA_USER);
            BackupListFragment contactListFragment = BackupListFragment.newInstance(file, user);
            transaction.add(R.id.frame_container, contactListFragment);
        }
        transaction.commit();
    }
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) FragmentTransaction(androidx.fragment.app.FragmentTransaction) User(com.nextcloud.client.account.User) BackupFragment(com.owncloud.android.ui.fragment.contactsbackup.BackupFragment) Intent(android.content.Intent) BackupListFragment(com.owncloud.android.ui.fragment.contactsbackup.BackupListFragment)

Aggregations

User (com.nextcloud.client.account.User)84 OCFile (com.owncloud.android.datamodel.OCFile)21 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)19 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)19 Intent (android.content.Intent)14 Account (android.accounts.Account)12 ArrayList (java.util.ArrayList)12 Context (android.content.Context)9 Fragment (androidx.fragment.app.Fragment)9 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)9 File (java.io.File)9 ArbitraryDataProvider (com.owncloud.android.datamodel.ArbitraryDataProvider)7 Uri (android.net.Uri)6 Bundle (android.os.Bundle)6 OCCapability (com.owncloud.android.lib.resources.status.OCCapability)6 GalleryFragment (com.owncloud.android.ui.fragment.GalleryFragment)6 PreviewTextFileFragment (com.owncloud.android.ui.preview.PreviewTextFileFragment)6 PreviewTextFragment (com.owncloud.android.ui.preview.PreviewTextFragment)6 PreviewTextStringFragment (com.owncloud.android.ui.preview.PreviewTextStringFragment)6 View (android.view.View)5