Search in sources :

Example 41 with User

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

the class MultipleAccountsDialog method getAccountListItems.

/**
 * creates the account list items list including the add-account action in case
 * multiaccount_support is enabled.
 *
 * @return list of account list items
 */
private List<UserListItem> getAccountListItems() {
    List<User> users = accountManager.getAllUsers();
    List<UserListItem> adapterUserList = new ArrayList<>(users.size());
    for (User user : users) {
        adapterUserList.add(new UserListItem(user));
    }
    return adapterUserList;
}
Also used : User(com.nextcloud.client.account.User) ArrayList(java.util.ArrayList) UserListItem(com.owncloud.android.ui.adapter.UserListItem)

Example 42 with User

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

the class UploadStorageManagerTest method testDeleteAllUploads.

@Test
public void testDeleteAllUploads() {
    // Clean
    for (User user : userAccountManager.getAllUsers()) {
        uploadsStorageManager.removeUserUploads(user);
    }
    int accountRowsA = 3;
    int accountRowsB = 4;
    insertUploads(account, accountRowsA);
    insertUploads(user2.toPlatformAccount(), accountRowsB);
    assertEquals("Expected 4 removed uploads files", 4, uploadsStorageManager.removeUserUploads(user2));
}
Also used : User(com.nextcloud.client.account.User) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 43 with User

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

the class DialogFragmentIT method testAccountChooserDialog.

@Test
@ScreenshotTest
public void testAccountChooserDialog() throws AccountUtils.AccountNotFoundException {
    FileDisplayActivity activity = getFileDisplayActivity();
    UserAccountManager userAccountManager = activity.getUserAccountManager();
    AccountManager accountManager = AccountManager.get(targetContext);
    for (Account account : accountManager.getAccountsByType(MainApp.getAccountType(targetContext))) {
        accountManager.removeAccountExplicitly(account);
    }
    Account newAccount = new Account("test@https://nextcloud.localhost", MainApp.getAccountType(targetContext));
    accountManager.addAccountExplicitly(newAccount, "password", null);
    accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_OC_BASE_URL, SERVER_URL);
    accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_USER_ID, "test");
    accountManager.setAuthToken(newAccount, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password");
    User newUser = userAccountManager.getUser(newAccount.name).orElseThrow(RuntimeException::new);
    Account newAccount2 = new Account("user1@nextcloud.localhost", MainApp.getAccountType(targetContext));
    accountManager.addAccountExplicitly(newAccount2, "password", null);
    accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_OC_BASE_URL, SERVER_URL);
    accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_USER_ID, "user1");
    accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_OC_VERSION, "20.0.0");
    accountManager.setAuthToken(newAccount2, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password");
    FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(newUser, targetContext.getContentResolver());
    OCCapability capability = new OCCapability();
    capability.setUserStatus(CapabilityBooleanType.TRUE);
    capability.setUserStatusSupportsEmoji(CapabilityBooleanType.TRUE);
    fileDataStorageManager.saveCapabilities(capability);
    ChooseAccountDialogFragment sut = ChooseAccountDialogFragment.newInstance(new RegisteredUser(newAccount, new OwnCloudAccount(newAccount, targetContext), new Server(URI.create(SERVER_URL), OwnCloudVersion.nextcloud_20)));
    showDialog(activity, sut);
    activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.DND, "Busy fixing 🐛…", "", -1), targetContext));
    waitForIdleSync();
    shortSleep();
    screenshot(sut, "dnd");
    activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.ONLINE, "", "", -1), targetContext));
    waitForIdleSync();
    shortSleep();
    screenshot(sut, "online");
    activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.ONLINE, "Let's have some fun", "🎉", -1), targetContext));
    waitForIdleSync();
    shortSleep();
    screenshot(sut, "fun");
    activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.OFFLINE, "", "", -1), targetContext));
    waitForIdleSync();
    shortSleep();
    screenshot(sut, "offline");
    activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.AWAY, "Vacation", "🌴", -1), targetContext));
    waitForIdleSync();
    shortSleep();
    screenshot(sut, "away");
}
Also used : Status(com.owncloud.android.lib.resources.users.Status) Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) User(com.nextcloud.client.account.User) RegisteredUser(com.nextcloud.client.account.RegisteredUser) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) Server(com.nextcloud.client.account.Server) ChooseAccountDialogFragment(com.nextcloud.ui.ChooseAccountDialogFragment) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) RegisteredUser(com.nextcloud.client.account.RegisteredUser) UserAccountManager(com.nextcloud.client.account.UserAccountManager) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) UserAccountManager(com.nextcloud.client.account.UserAccountManager) AccountManager(android.accounts.AccountManager) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest) Test(org.junit.Test) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest)

Example 44 with User

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

the class ErrorMessageAdapterIT method getErrorCauseMessageForForbiddenRemoval.

@Test
public void getErrorCauseMessageForForbiddenRemoval() {
    Resources resources = InstrumentationRegistry.getInstrumentation().getTargetContext().getResources();
    User user = new MockUser("name", ACCOUNT_TYPE);
    Context context = MainApp.getAppContext();
    String errorMessage = ErrorMessageAdapter.getErrorCauseMessage(new RemoteOperationResult(RemoteOperationResult.ResultCode.FORBIDDEN), new RemoveFileOperation(new OCFile(PATH_TO_DELETE), false, user.toPlatformAccount(), false, context, new FileDataStorageManager(user, context.getContentResolver())), resources);
    assertEquals(EXPECTED_ERROR_MESSAGE, errorMessage);
}
Also used : Context(android.content.Context) OCFile(com.owncloud.android.datamodel.OCFile) User(com.nextcloud.client.account.User) MockUser(com.nextcloud.client.account.MockUser) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) Resources(android.content.res.Resources) RemoveFileOperation(com.owncloud.android.operations.RemoveFileOperation) MockUser(com.nextcloud.client.account.MockUser) Test(org.junit.Test)

Example 45 with User

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

the class MainApp method initContactsBackup.

public static void initContactsBackup(UserAccountManager accountManager, BackgroundJobManager backgroundJobManager) {
    ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(mContext.getContentResolver());
    List<User> users = accountManager.getAllUsers();
    for (User user : users) {
        if (arbitraryDataProvider.getBooleanValue(user, PREFERENCE_CONTACTS_AUTOMATIC_BACKUP)) {
            backgroundJobManager.schedulePeriodicContactsBackup(user);
        }
    }
}
Also used : User(com.nextcloud.client.account.User) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider)

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