From 217658740f7ab945eb09ecb3a5aeecc9037f7e56 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Tue, 9 Aug 2016 19:09:00 +0200 Subject: [PATCH] get and show quota information --- .../android/ui/activity/DrawerActivity.java | 50 +++++++++++++++++-- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/src/com/owncloud/android/ui/activity/DrawerActivity.java b/src/com/owncloud/android/ui/activity/DrawerActivity.java index 33cc82f9ee..dd85aa68da 100644 --- a/src/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/src/com/owncloud/android/ui/activity/DrawerActivity.java @@ -47,7 +47,10 @@ import com.owncloud.android.R; import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.OwnCloudAccount; +import com.owncloud.android.lib.common.operations.RemoteOperation; +import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.lib.resources.users.RemoteGetUserQuotaOperation; import com.owncloud.android.ui.TextDrawable; import com.owncloud.android.utils.DisplayUtils; @@ -459,6 +462,9 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU DisplayUtils.setAvatar(account, this, mCurrentAccountAvatarRadiusDimension, getResources(), getStorageManager(), findNavigationViewChildById(R.id.drawer_current_account)); + + // check and show quota info if available + getUserQuota(); } } @@ -505,11 +511,10 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU * * @param usedSpace the used space * @param totalSpace the total space - * @param percent the percentage of space already used + * @param relative the percentage of space already used */ - private void setQuotaInformation(long usedSpace, long totalSpace, Double percent) { - int progress = (int) Math.ceil(percent); - mQuotaProgressBar.setProgress(progress); + private void setQuotaInformation(long usedSpace, long totalSpace, int relative) { + mQuotaProgressBar.setProgress(relative); mQuotaTextView.setText(String.format( getString(R.string.drawer_quota), DisplayUtils.bytesToHumanReadable(usedSpace), @@ -535,6 +540,43 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU } } + /** + * Retrieves and shows the user quota if available + */ + private void getUserQuota() { + // set user space information + Thread t = new Thread(new Runnable() { + public void run() { + + RemoteOperation getQuotaInfoOperation = new RemoteGetUserQuotaOperation(); + RemoteOperationResult result = getQuotaInfoOperation.execute( + AccountUtils.getCurrentOwnCloudAccount(DrawerActivity.this), DrawerActivity.this); + + if (result.isSuccess() && result.getData() != null) { + RemoteGetUserQuotaOperation.Quota quota = (RemoteGetUserQuotaOperation.Quota) result.getData().get + (0); + + final long used = quota.getUsed(); + final long total = quota.getTotal(); + final int relative = (int) Math.ceil(quota.getRelative()); + + runOnUiThread(new Runnable() { + @Override + public void run() { + if (mQuotaView != null) { + setQuotaInformation(used,total,relative); + } else { + showQuota(false); + } + } + }); + } + } + }); + + t.start(); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);