소스 검색

Merge pull request #2887 from nextcloud/unlimitedQuota

show disk usage if no quota is set
Andy Scherzinger 6 년 전
부모
커밋
e564a297cf

+ 21 - 15
src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -305,7 +305,7 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
         mQuotaProgressBar = (ProgressBar) findQuotaViewById(R.id.drawer_quota_ProgressBar);
         mQuotaTextPercentage = (TextView) findQuotaViewById(R.id.drawer_quota_percentage);
         mQuotaTextLink = (TextView) findQuotaViewById(R.id.drawer_quota_link);
-        ThemeUtils.colorHorizontalProgressBar(mQuotaProgressBar, ThemeUtils.primaryAccentColor(this));
+        ThemeUtils.colorProgressBar(mQuotaProgressBar, ThemeUtils.primaryColor(this));
     }
 
     /**
@@ -800,22 +800,28 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
 
     /**
      * configured the quota to be displayed.
-     *
-     * @param usedSpace  the used space
+     *  @param usedSpace  the used space
      * @param totalSpace the total space
      * @param relative   the percentage of space already used
+     * @param quotaValue {@link GetRemoteUserInfoOperation#SPACE_UNLIMITED} or other to determinate state
      */
-    private void setQuotaInformation(long usedSpace, long totalSpace, int relative) {
-        mQuotaProgressBar.setProgress(relative);
-        ThemeUtils.colorHorizontalProgressBar(mQuotaProgressBar, DisplayUtils.getRelativeInfoColor(this, relative));
+    private void setQuotaInformation(long usedSpace, long totalSpace, int relative, long quotaValue) {
+        if (GetRemoteUserInfoOperation.SPACE_UNLIMITED == quotaValue) {
+            mQuotaTextPercentage.setText(String.format(
+                    getString(R.string.drawer_quota_unlimited),
+                    DisplayUtils.bytesToHumanReadable(usedSpace)));
+        } else {
+            mQuotaTextPercentage.setText(String.format(
+                    getString(R.string.drawer_quota),
+                    DisplayUtils.bytesToHumanReadable(usedSpace),
+                    DisplayUtils.bytesToHumanReadable(totalSpace)));
+        }
 
-        updateQuotaLink();
+        mQuotaProgressBar.setProgress(relative);
 
-        mQuotaTextPercentage.setText(String.format(
-                getString(R.string.drawer_quota),
-                DisplayUtils.bytesToHumanReadable(usedSpace),
-                DisplayUtils.bytesToHumanReadable(totalSpace)));
+        ThemeUtils.colorProgressBar(mQuotaProgressBar, DisplayUtils.getRelativeInfoColor(this, relative));
 
+        updateQuotaLink();
         showQuota(true);
     }
 
@@ -966,16 +972,16 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
                         runOnUiThread(new Runnable() {
                             @Override
                             public void run() {
-                                if (quotaValue > 0
+                                if (quotaValue > 0 || quotaValue == GetRemoteUserInfoOperation.SPACE_UNLIMITED
                                         || quotaValue == GetRemoteUserInfoOperation.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);
+                                    setQuotaInformation(used, total, relative, quotaValue);
                                 } else {
-                                    /**
+                                    /*
                                      * quotaValue < 0 means special cases like
                                      * {@link RemoteGetUserQuotaOperation.SPACE_NOT_COMPUTED},
                                      * {@link RemoteGetUserQuotaOperation.SPACE_UNKNOWN} or

+ 4 - 14
src/main/java/com/owncloud/android/utils/DisplayUtils.java

@@ -33,7 +33,6 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
-import android.graphics.Color;
 import android.graphics.Point;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.PictureDrawable;
@@ -108,8 +107,7 @@ public class DisplayUtils {
 
     private static final String[] sizeSuffixes = {"B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"};
     private static final int[] sizeScales = {0, 0, 1, 1, 1, 2, 2, 2, 2};
-    private static final int RELATIVE_THRESHOLD_WARNING = 90;
-    private static final int RELATIVE_THRESHOLD_CRITICAL = 95;
+    private static final int RELATIVE_THRESHOLD_WARNING = 80;
     private static final String MIME_TYPE_UNKNOWN = "Unknown type";
 
     private static final String HTTP_PROTOCOL = "http://";
@@ -319,8 +317,7 @@ public class DisplayUtils {
 
 
     /**
-     * determines the info level color based on certain thresholds
-     * {@link #RELATIVE_THRESHOLD_WARNING} and {@link #RELATIVE_THRESHOLD_CRITICAL}.
+     * determines the info level color based on {@link #RELATIVE_THRESHOLD_WARNING}.
      *
      * @param context  the app's context
      * @param relative relative value for which the info level color should be looked up
@@ -328,16 +325,9 @@ public class DisplayUtils {
      */
     public static int getRelativeInfoColor(Context context, int relative) {
         if (relative < RELATIVE_THRESHOLD_WARNING) {
-            if (ThemeUtils.colorToHexString(ThemeUtils.primaryColor(context)).equalsIgnoreCase(
-                    ThemeUtils.colorToHexString(context.getResources().getColor(R.color.primary)))) {
-                return context.getResources().getColor(R.color.infolevel_info);
-            } else {
-                return Color.GRAY;
-            }
-        } else if (relative >= RELATIVE_THRESHOLD_WARNING && relative < RELATIVE_THRESHOLD_CRITICAL) {
-            return context.getResources().getColor(R.color.infolevel_warning);
+            return ThemeUtils.primaryColor(context, true);
         } else {
-            return context.getResources().getColor(R.color.infolevel_critical);
+            return context.getResources().getColor(R.color.infolevel_warning);
         }
     }
 

+ 17 - 1
src/main/java/com/owncloud/android/utils/ThemeUtils.java

@@ -279,7 +279,7 @@ public class ThemeUtils {
     }
 
     /**
-     * sets the coloring of the given progress bar to color_accent.
+     * sets the coloring of the given progress bar to given color.
      *
      * @param progressBar the progress bar to be colored
      * @param color       the color to be used
@@ -291,6 +291,22 @@ public class ThemeUtils {
         }
     }
 
+    /**
+     * sets the coloring of the given progress bar's progress to given color.
+     *
+     * @param progressBar the progress bar to be colored
+     * @param color       the color to be used
+     */
+    public static void colorProgressBar(ProgressBar progressBar, @ColorInt int color) {
+        if (progressBar != null) {
+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+                progressBar.setProgressTintList(ColorStateList.valueOf(color));
+            } else {
+                ThemeUtils.colorHorizontalProgressBar(progressBar, color);
+            }
+        }
+    }
+
     /**
      * sets the coloring of the given seek bar to color_accent.
      *

+ 1 - 1
src/main/res/layout/drawer.xml

@@ -74,4 +74,4 @@
 
     </android.support.design.widget.NavigationView>
 
-</merge>
+</merge>

+ 2 - 4
src/main/res/values/colors.xml

@@ -41,8 +41,6 @@
     <!-- standard material color definitions -->
 
     <!-- level colors for info notifications/visualisations -->
-    <color name="infolevel_info">@color/color_accent</color>
-    <color name="infolevel_warning">#fdd835</color>
-    <color name="infolevel_critical">#e57373</color>
+    <color name="infolevel_warning">#e9322d</color>
 
-</resources>
+</resources>

+ 1 - 0
src/main/res/values/strings.xml

@@ -31,6 +31,7 @@
     <string name="drawer_item_activities">Activities</string>
     <string name="drawer_item_notifications">Notifications</string>
     <string name="drawer_quota">%1$s of %2$s used</string>
+    <string name="drawer_quota_unlimited">%1$s used</string>
 	<string name="drawer_close">Close sidebar</string>
     <string name="drawer_open">Open sidebar</string>
     <string name="prefs_category_general">General</string>