Search in sources :

Example 1 with Quota

use of com.owncloud.android.lib.common.Quota in project android by nextcloud.

the class DrawerActivity method getAndDisplayUserQuota.

/**
 * Retrieves and shows the user quota if available
 */
private void getAndDisplayUserQuota() {
    // set user space information
    Thread t = new Thread(() -> {
        final User user = accountManager.getUser();
        if (user.isAnonymous()) {
            return;
        }
        final Context context = MainApp.getAppContext();
        NextcloudClient nextcloudClient = null;
        try {
            nextcloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().getNextcloudClientFor(user.toOwnCloudAccount(), context);
        } catch (OperationCanceledException | AuthenticatorException | IOException e) {
            Log_OC.e(this, "Error retrieving user quota", e);
        }
        if (nextcloudClient == null) {
            return;
        }
        RemoteOperationResult<UserInfo> result = new GetUserInfoRemoteOperation().execute(nextcloudClient);
        if (result.isSuccess() && result.getResultData() != null) {
            final UserInfo userInfo = result.getResultData();
            final Quota quota = userInfo.getQuota();
            if (quota != null) {
                final long used = quota.getUsed();
                final long total = quota.getTotal();
                final int relative = (int) Math.ceil(quota.getRelative());
                final long quotaValue = quota.getQuota();
                runOnUiThread(() -> {
                    if (quotaValue > 0 || quotaValue == GetUserInfoRemoteOperation.SPACE_UNLIMITED || quotaValue == GetUserInfoRemoteOperation.QUOTA_LIMIT_INFO_NOT_AVAILABLE) {
                        /*
                             * show quota in case
                             * it is available and calculated (> 0) or
                             * in case of legacy servers (==QUOTA_LIMIT_INFO_NOT_AVAILABLE)
                             */
                        setQuotaInformation(used, total, relative, quotaValue);
                    } else {
                        /*
                             * quotaValue < 0 means special cases like
                             * {@link RemoteGetUserQuotaOperation.SPACE_NOT_COMPUTED},
                             * {@link RemoteGetUserQuotaOperation.SPACE_UNKNOWN} or
                             * {@link RemoteGetUserQuotaOperation.SPACE_UNLIMITED}
                             * thus don't display any quota information.
                             */
                        showQuota(false);
                    }
                });
            }
        }
    });
    t.start();
}
Also used : Context(android.content.Context) User(com.nextcloud.client.account.User) NextcloudClient(com.nextcloud.common.NextcloudClient) GetUserInfoRemoteOperation(com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation) OperationCanceledException(android.accounts.OperationCanceledException) AuthenticatorException(android.accounts.AuthenticatorException) UserInfo(com.owncloud.android.lib.common.UserInfo) IOException(java.io.IOException) Quota(com.owncloud.android.lib.common.Quota)

Example 2 with Quota

use of com.owncloud.android.lib.common.Quota in project android by nextcloud.

the class ManageAccountsActivityIT method userInfoDetail.

@Test
@ScreenshotTest
public void userInfoDetail() {
    ManageAccountsActivity sut = activityRule.launchActivity(null);
    User user = sut.accountManager.getUser();
    UserInfo userInfo = new UserInfo("test", true, "Test User", "test@nextcloud.com", "+49 123 456", "Address 123, Berlin", "https://www.nextcloud.com", "https://twitter.com/Nextclouders", new Quota(), new ArrayList<>());
    sut.showUser(user, userInfo);
    shortSleep();
    shortSleep();
    screenshot(getCurrentActivity());
}
Also used : User(com.nextcloud.client.account.User) Quota(com.owncloud.android.lib.common.Quota) UserInfo(com.owncloud.android.lib.common.UserInfo) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest) Test(org.junit.Test) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest)

Aggregations

User (com.nextcloud.client.account.User)2 Quota (com.owncloud.android.lib.common.Quota)2 UserInfo (com.owncloud.android.lib.common.UserInfo)2 AuthenticatorException (android.accounts.AuthenticatorException)1 OperationCanceledException (android.accounts.OperationCanceledException)1 Context (android.content.Context)1 NextcloudClient (com.nextcloud.common.NextcloudClient)1 GetUserInfoRemoteOperation (com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation)1 ScreenshotTest (com.owncloud.android.utils.ScreenshotTest)1 IOException (java.io.IOException)1 Test (org.junit.Test)1