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();
}
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());
}
Aggregations