From e790d4a52073ccfef292f454dc55af5e9221c9a1 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Mon, 8 Aug 2016 17:27:47 +0200 Subject: [PATCH 01/11] initial layout changes for in drawer quota display --- res/layout/drawer.xml | 38 ++++++++++++++++++++++++++++++++++++-- res/menu/drawer_menu.xml | 11 +++++++++++ res/values/strings.xml | 1 + 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/res/layout/drawer.xml b/res/layout/drawer.xml index 843a1ebdf3df..ff17ea3e5d0f 100644 --- a/res/layout/drawer.xml +++ b/res/layout/drawer.xml @@ -24,9 +24,43 @@ android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" + android:layout_weight="1" android:fitsSystemWindows="true" - app:theme="@style/NavigationView_ItemTextAppearance" app:headerLayout="@layout/drawer_header" - app:menu="@menu/drawer_menu"/> + app:menu="@menu/drawer_menu" + app:theme="@style/NavigationView_ItemTextAppearance"> + + + + + + + + + \ No newline at end of file diff --git a/res/menu/drawer_menu.xml b/res/menu/drawer_menu.xml index 9551b98274dd..7c6462f8e8c6 100644 --- a/res/menu/drawer_menu.xml +++ b/res/menu/drawer_menu.xml @@ -67,4 +67,15 @@ android:icon="@drawable/ic_settings" android:title="@string/actionbar_settings"/> + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 10b3b8aa4e67..4f6d9d7cf60f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -23,6 +23,7 @@ On device Settings Uploads + %1$s%2$s of %3$s%4$s used Close Open General From f8e0ee9ce1a89c3b724c70d794396245fb976fb3 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Mon, 8 Aug 2016 18:41:45 +0200 Subject: [PATCH 02/11] initial quota display implementation --- res/values/strings.xml | 2 +- .../android/ui/activity/DrawerActivity.java | 49 +++++++++++++++++-- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 4f6d9d7cf60f..259a93884dd5 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -23,7 +23,7 @@ On device Settings Uploads - %1$s%2$s of %3$s%4$s used + %1$s of %2$s used Close Open General diff --git a/src/com/owncloud/android/ui/activity/DrawerActivity.java b/src/com/owncloud/android/ui/activity/DrawerActivity.java index bab0cde0a382..e8663796edff 100644 --- a/src/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/src/com/owncloud/android/ui/activity/DrawerActivity.java @@ -38,6 +38,8 @@ import android.view.MenuItem; import android.view.View; import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.ProgressBar; import android.widget.TextView; import com.owncloud.android.MainApp; @@ -120,6 +122,9 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU * accounts for the (max) three displayed accounts in the drawer header. */ private Account[] mAvatars = new Account[3]; + private LinearLayout mQuotaView; + private ProgressBar mQuotaProgressBar; + private TextView mQuotaTextView; /** * Initializes the drawer, its content and highlights the menu item with the given id. @@ -144,9 +149,8 @@ protected void setupDrawer() { mAccountChooserToggle = (ImageView) findNavigationViewChildById(R.id.drawer_account_chooser_toogle); mAccountChooserToggle.setImageResource(R.drawable.ic_down); mIsAccountChooserActive = false; - - mAccountMiddleAccountAvatar = (ImageView) findNavigationViewChildById(R.id.drawer_account_middle); - mAccountEndAccountAvatar = (ImageView) findNavigationViewChildById(R.id.drawer_account_end); + mAccountMiddleAccountAvatar = (ImageView) findViewById(R.id.drawer_account_middle); + mAccountEndAccountAvatar = (ImageView) findViewById(R.id.drawer_account_end); // on pre lollipop the light theme adds a black tint to icons with white coloring // ruining the generic avatars, so tinting for icons is deactivated pre lollipop @@ -163,6 +167,12 @@ public void onClick(View v) { toggleAccountList(); } }); + + // Quota UI elements + mQuotaView = (LinearLayout) findNavigationViewChildById(R.id.drawer_quota); + mQuotaProgressBar = (ProgressBar) findNavigationViewChildById(R.id.drawer_quota_ProgressBar); + mQuotaTextView = (TextView) findNavigationViewChildById(R.id.drawer_quota_text); + DisplayUtils.colorPreLollipopHorizontalProgressBar(mQuotaProgressBar); } mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) { @@ -477,6 +487,39 @@ private void showMenu() { } } + /** + * shows or hides the quota UI elements. + * + * @param showQuota show/hide quota information + */ + private void showQuota(boolean showQuota) { + if (showQuota) { + mQuotaView.setVisibility(View.VISIBLE); + } else { + mQuotaView.setVisibility(View.GONE); + } + } + + /** + * configured the quota to be displayed. + * + * @param usedSpace the used space + * @param totalSpace the total space + * @param percent the percentage of space already used + */ + private void setQuotaInformation(long usedSpace, long totalSpace, Double percent) { + int progress = (int) Math.ceil(percent); + mQuotaProgressBar.setProgress(progress); + mQuotaTextView.setText(String.format( + getString(R.string.drawer_quota), + DisplayUtils.bytesToHumanReadable(usedSpace), + DisplayUtils.bytesToHumanReadable(totalSpace))); + + // TODO Think about coloring of the progressbar at certain thresholds + + showQuota(true); + } + /** * checks/highlights the provided menu item if the drawer has been initialized and the menu item exists. * From 3658becdf58c6b5ea1fd12f34d5ce56d878e4fb8 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Tue, 9 Aug 2016 00:32:34 +0200 Subject: [PATCH 03/11] view elements fix --- .../owncloud/android/ui/activity/DrawerActivity.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/com/owncloud/android/ui/activity/DrawerActivity.java b/src/com/owncloud/android/ui/activity/DrawerActivity.java index e8663796edff..33cc82f9ee8c 100644 --- a/src/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/src/com/owncloud/android/ui/activity/DrawerActivity.java @@ -149,8 +149,8 @@ protected void setupDrawer() { mAccountChooserToggle = (ImageView) findNavigationViewChildById(R.id.drawer_account_chooser_toogle); mAccountChooserToggle.setImageResource(R.drawable.ic_down); mIsAccountChooserActive = false; - mAccountMiddleAccountAvatar = (ImageView) findViewById(R.id.drawer_account_middle); - mAccountEndAccountAvatar = (ImageView) findViewById(R.id.drawer_account_end); + mAccountMiddleAccountAvatar = (ImageView) findNavigationViewChildById(R.id.drawer_account_middle); + mAccountEndAccountAvatar = (ImageView) findNavigationViewChildById(R.id.drawer_account_end); // on pre lollipop the light theme adds a black tint to icons with white coloring // ruining the generic avatars, so tinting for icons is deactivated pre lollipop @@ -169,9 +169,9 @@ public void onClick(View v) { }); // Quota UI elements - mQuotaView = (LinearLayout) findNavigationViewChildById(R.id.drawer_quota); - mQuotaProgressBar = (ProgressBar) findNavigationViewChildById(R.id.drawer_quota_ProgressBar); - mQuotaTextView = (TextView) findNavigationViewChildById(R.id.drawer_quota_text); + mQuotaView = (LinearLayout) findViewById(R.id.drawer_quota); + mQuotaProgressBar = (ProgressBar) findViewById(R.id.drawer_quota_ProgressBar); + mQuotaTextView = (TextView) findViewById(R.id.drawer_quota_text); DisplayUtils.colorPreLollipopHorizontalProgressBar(mQuotaProgressBar); } From 07c3ebdf84bff52292562b9c1b1cc1dc0429ab73 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Tue, 9 Aug 2016 10:58:13 +0200 Subject: [PATCH 04/11] update to Nc Android library 1.0.4 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 6e80c65cc5c8..b62cc2eab7a3 100644 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,7 @@ dependencies { /// dependencies for app building compile name: 'touch-image-view' - compile 'com.github.nextcloud:android-library:1.0.2' + compile 'com.github.nextcloud:android-library:1.0.4' compile "com.android.support:support-v4:${supportLibraryVersion}" compile "com.android.support:design:${supportLibraryVersion}" compile 'com.jakewharton:disklrucache:2.0.2' From 217658740f7ab945eb09ecb3a5aeecc9037f7e56 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Tue, 9 Aug 2016 19:09:00 +0200 Subject: [PATCH 05/11] 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 33cc82f9ee8c..dd85aa68da8a 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.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 @@ protected void setAccountInDrawer(Account account) { 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 @@ private void showQuota(boolean showQuota) { * * @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 @@ protected void setDrawerMenuItemChecked(int menuItemId) { } } + /** + * 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); From 2c941a574996fbbb6be8798b19d7c9b215c2fffe Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Wed, 10 Aug 2016 12:22:48 +0200 Subject: [PATCH 06/11] minor code refactoring extracting setup code into dedicated methods --- .../android/ui/activity/DrawerActivity.java | 84 ++++++++++++------- 1 file changed, 53 insertions(+), 31 deletions(-) diff --git a/src/com/owncloud/android/ui/activity/DrawerActivity.java b/src/com/owncloud/android/ui/activity/DrawerActivity.java index dd85aa68da8a..7cee535fb0b6 100644 --- a/src/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/src/com/owncloud/android/ui/activity/DrawerActivity.java @@ -149,35 +149,22 @@ protected void setupDrawer() { mNavigationView = (NavigationView) findViewById(R.id.nav_view); if (mNavigationView != null) { - mAccountChooserToggle = (ImageView) findNavigationViewChildById(R.id.drawer_account_chooser_toogle); - mAccountChooserToggle.setImageResource(R.drawable.ic_down); - mIsAccountChooserActive = false; - mAccountMiddleAccountAvatar = (ImageView) findNavigationViewChildById(R.id.drawer_account_middle); - mAccountEndAccountAvatar = (ImageView) findNavigationViewChildById(R.id.drawer_account_end); - - // on pre lollipop the light theme adds a black tint to icons with white coloring - // ruining the generic avatars, so tinting for icons is deactivated pre lollipop - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - mNavigationView.setItemIconTintList(null); - } + setupDrawerHeader(); - setupDrawerContent(mNavigationView); + setupDrawerMenu(mNavigationView); - findNavigationViewChildById(R.id.drawer_active_user) - .setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - toggleAccountList(); - } - }); - - // Quota UI elements - mQuotaView = (LinearLayout) findViewById(R.id.drawer_quota); - mQuotaProgressBar = (ProgressBar) findViewById(R.id.drawer_quota_ProgressBar); - mQuotaTextView = (TextView) findViewById(R.id.drawer_quota_text); - DisplayUtils.colorPreLollipopHorizontalProgressBar(mQuotaProgressBar); + setupQuotaElement(); } + setupDrawerToggle(); + + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + } + + /** + * initializes and sets up the drawer toggle. + */ + private void setupDrawerToggle() { mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ @@ -201,7 +188,35 @@ public void onDrawerOpened(View drawerView) { // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerToggle.setDrawerIndicatorEnabled(true); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); + } + + /** + * initializes and sets up the drawer header. + */ + private void setupDrawerHeader() { + mAccountChooserToggle = (ImageView) findNavigationViewChildById(R.id.drawer_account_chooser_toogle); + mAccountChooserToggle.setImageResource(R.drawable.ic_down); + mIsAccountChooserActive = false; + mAccountMiddleAccountAvatar = (ImageView) findNavigationViewChildById(R.id.drawer_account_middle); + mAccountEndAccountAvatar = (ImageView) findNavigationViewChildById(R.id.drawer_account_end); + + findNavigationViewChildById(R.id.drawer_active_user) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + toggleAccountList(); + } + }); + } + + /** + * setup quota elements of the drawer. + */ + private void setupQuotaElement() { + mQuotaView = (LinearLayout) findViewById(R.id.drawer_quota); + mQuotaProgressBar = (ProgressBar) findViewById(R.id.drawer_quota_ProgressBar); + mQuotaTextView = (TextView) findViewById(R.id.drawer_quota_text); + DisplayUtils.colorPreLollipopHorizontalProgressBar(mQuotaProgressBar); } /** @@ -209,7 +224,14 @@ public void onDrawerOpened(View drawerView) { * * @param navigationView the drawers navigation view */ - protected void setupDrawerContent(NavigationView navigationView) { + protected void setupDrawerMenu(NavigationView navigationView) { + // on pre lollipop the light theme adds a black tint to icons with white coloring + // ruining the generic avatars, so tinting for icons is deactivated pre lollipop + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + navigationView.setItemIconTintList(null); + } + + // setup actions for drawer menu items navigationView.setNavigationItemSelectedListener( new NavigationView.OnNavigationItemSelectedListener() { @Override @@ -259,9 +281,9 @@ public boolean onNavigationItemSelected(MenuItem menuItem) { // handle correct state if (mIsAccountChooserActive) { - mNavigationView.getMenu().setGroupVisible(R.id.drawer_menu_accounts, true); + navigationView.getMenu().setGroupVisible(R.id.drawer_menu_accounts, true); } else { - mNavigationView.getMenu().setGroupVisible(R.id.drawer_menu_accounts, false); + navigationView.getMenu().setGroupVisible(R.id.drawer_menu_accounts, false); } } @@ -464,7 +486,7 @@ mCurrentAccountAvatarRadiusDimension, getResources(), getStorageManager(), findNavigationViewChildById(R.id.drawer_current_account)); // check and show quota info if available - getUserQuota(); + getAndDisplayUserQuota(); } } @@ -543,7 +565,7 @@ protected void setDrawerMenuItemChecked(int menuItemId) { /** * Retrieves and shows the user quota if available */ - private void getUserQuota() { + private void getAndDisplayUserQuota() { // set user space information Thread t = new Thread(new Runnable() { public void run() { From 5280d66139c3198c592890479bf90e5ec5ccfb9f Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Wed, 10 Aug 2016 14:55:13 +0200 Subject: [PATCH 07/11] colorize quota progress bar depending on thresholds met, reformattings --- res/values/colors.xml | 6 ++ .../android/ui/activity/DrawerActivity.java | 16 +++- .../owncloud/android/utils/DisplayUtils.java | 75 +++++++++++++------ 3 files changed, 71 insertions(+), 26 deletions(-) diff --git a/res/values/colors.xml b/res/values/colors.xml index 201060c8c6f9..3252a60f75dc 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -52,4 +52,10 @@ #201D2D44 #40162233 + + + @color/color_accent + #fdd835 + #e57373 + \ No newline at end of file diff --git a/src/com/owncloud/android/ui/activity/DrawerActivity.java b/src/com/owncloud/android/ui/activity/DrawerActivity.java index 7cee535fb0b6..77b9ba37be7f 100644 --- a/src/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/src/com/owncloud/android/ui/activity/DrawerActivity.java @@ -125,8 +125,20 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU * accounts for the (max) three displayed accounts in the drawer header. */ private Account[] mAvatars = new Account[3]; + + /** + * container layout of the quota view. + */ private LinearLayout mQuotaView; + + /** + * progress bar of the quota view. + */ private ProgressBar mQuotaProgressBar; + + /** + * text view of the quota view. + */ private TextView mQuotaTextView; /** @@ -537,13 +549,13 @@ private void showQuota(boolean showQuota) { */ private void setQuotaInformation(long usedSpace, long totalSpace, int relative) { mQuotaProgressBar.setProgress(relative); + DisplayUtils.colorHorizontalProgressBar(mQuotaProgressBar, DisplayUtils.getRelativeInfoColor(this, relative)); + mQuotaTextView.setText(String.format( getString(R.string.drawer_quota), DisplayUtils.bytesToHumanReadable(usedSpace), DisplayUtils.bytesToHumanReadable(totalSpace))); - // TODO Think about coloring of the progressbar at certain thresholds - showQuota(true); } diff --git a/src/com/owncloud/android/utils/DisplayUtils.java b/src/com/owncloud/android/utils/DisplayUtils.java index c9a81a9a614e..949ea69ba218 100644 --- a/src/com/owncloud/android/utils/DisplayUtils.java +++ b/src/com/owncloud/android/utils/DisplayUtils.java @@ -64,16 +64,16 @@ */ public class DisplayUtils { private static final String TAG = DisplayUtils.class.getSimpleName(); - - private static final String OWNCLOUD_APP_NAME = "ownCloud"; - + 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 }; + public static final int RELATIVE_THRESHOLD_WARNING = 90; + public static final int RELATIVE_THRESHOLD_CRITICAL = 95; private static Map mimeType2HumanReadable; static { - mimeType2HumanReadable = new HashMap(); + mimeType2HumanReadable = new HashMap<>(); // images mimeType2HumanReadable.put("image/jpeg", "JPEG image"); mimeType2HumanReadable.put("image/jpg", "JPEG image"); @@ -155,9 +155,9 @@ public static String convertIdn(String url, boolean toASCII) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { // Find host name after '//' or '@' int hostStart = 0; - if (urlNoDots.indexOf("//") != -1) { + if (urlNoDots.contains("//")) { hostStart = url.indexOf("//") + "//".length(); - } else if (url.indexOf("@") != -1) { + } else if (url.contains("@")) { hostStart = url.indexOf("@") + "@".length(); } @@ -207,17 +207,33 @@ public static CharSequence getRelativeTimestamp(Context context, long modificati DateUtils.WEEK_IN_MILLIS, 0); } - @SuppressWarnings("deprecation") - public static CharSequence getRelativeDateTimeString ( - Context c, long time, long minResolution, long transitionResolution, int flags - ){ - + /** + * determines the info level color based on certain thresholds + * {@link #RELATIVE_THRESHOLD_WARNING} and {@link #RELATIVE_THRESHOLD_CRITICAL}. + * + * @param context the app's context + * @param relative relative value for which the info level color should be looked up + * @return info level color + */ + public static int getRelativeInfoColor(Context context, int relative) { + if (relative < RELATIVE_THRESHOLD_WARNING) { + return context.getResources().getColor(R.color.infolevel_info); + } else if (relative >= RELATIVE_THRESHOLD_WARNING && relative < RELATIVE_THRESHOLD_CRITICAL) { + return context.getResources().getColor(R.color.infolevel_warning); + } else { + return context.getResources().getColor(R.color.infolevel_critical); + } + } + + public static CharSequence getRelativeDateTimeString( + Context c, long time, long minResolution, long transitionResolution, int flags) { + CharSequence dateString = ""; - + // in Future - if (time > System.currentTimeMillis()){ + if (time > System.currentTimeMillis()) { return DisplayUtils.unixTimeToHumanReadable(time); - } + } // < 60 seconds -> seconds ago else if ((System.currentTimeMillis() - time) < 60 * 1000) { return c.getString(R.string.file_list_seconds_ago); @@ -238,8 +254,9 @@ else if ((System.currentTimeMillis() - time) < 60 * 1000) { } /** - * Update the passed path removing the last "/" if it is not the root folder - * @param path + * Update the passed path removing the last "/" if it is not the root folder. + * + * @param path the path to be trimmed */ public static String getPathWithoutLastSlash(String path) { @@ -250,12 +267,11 @@ public static String getPathWithoutLastSlash(String path) { return path; } - /** - * Gets the screen size in pixels in a backwards compatible way + * Gets the screen size in pixels in a backwards compatible way. * - * @param caller Activity calling; needed to get access to the {@link android.view.WindowManager} - * @return Size in pixels of the screen, or default {@link Point} if caller is null + * @param caller Activity calling; needed to get access to the {@link android.view.WindowManager} + * @return Size in pixels of the screen, or default {@link Point} if caller is null */ public static Point getScreenSize(Activity caller) { Point size = new Point(); @@ -277,7 +293,18 @@ public static Point getScreenSize(Activity caller) { */ public static void colorPreLollipopHorizontalProgressBar(ProgressBar progressBar) { if (progressBar != null && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - int color = progressBar.getResources().getColor(R.color.color_accent); + colorHorizontalProgressBar(progressBar, progressBar.getResources().getColor(R.color.color_accent)); + } + } + + /** + * sets the coloring of the given progress bar to color_accent. + * + * @param progressBar the progress bar to be colored + * @param color the color to be used + */ + public static void colorHorizontalProgressBar(ProgressBar progressBar, @ColorInt int color) { + if (progressBar != null) { progressBar.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN); progressBar.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN); } @@ -315,7 +342,7 @@ public static void colorSnackbar(Context context, Snackbar snackbar) { * Sets the color of the status bar to {@code color} on devices with OS version lollipop or higher. * * @param fragmentActivity fragment activity - * @param color the color + * @param color the color */ public static void colorStatusBar(FragmentActivity fragmentActivity, @ColorInt int color) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { @@ -326,11 +353,11 @@ public static void colorStatusBar(FragmentActivity fragmentActivity, @ColorInt i /** * Sets the color of the progressbar to {@code color} within the given toolbar. * - * @param activity the toolbar activity instance + * @param activity the toolbar activity instance * @param progressBarColor the color to be used for the toolbar's progress bar */ public static void colorToolbarProgressBar(FragmentActivity activity, int progressBarColor) { - if(activity instanceof ToolbarActivity) { + if (activity instanceof ToolbarActivity) { ((ToolbarActivity) activity).setProgressBarBackgroundColor(progressBarColor); } } From 0f80bdc894346ac9362f1e6e19a30acc2da3f33f Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Sun, 14 Aug 2016 20:13:47 +0200 Subject: [PATCH 08/11] CR changes --- res/layout/drawer.xml | 1 - .../android/ui/activity/DrawerActivity.java | 4 +- .../owncloud/android/utils/DisplayUtils.java | 41 ++++++++++++++++--- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/res/layout/drawer.xml b/res/layout/drawer.xml index ff17ea3e5d0f..3892505f3c5f 100644 --- a/res/layout/drawer.xml +++ b/res/layout/drawer.xml @@ -35,7 +35,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" - android:background="#F5F5F5" android:clickable="false" android:orientation="vertical" android:paddingBottom="@dimen/standard_half_padding" diff --git a/src/com/owncloud/android/ui/activity/DrawerActivity.java b/src/com/owncloud/android/ui/activity/DrawerActivity.java index 77b9ba37be7f..78270003f5fa 100644 --- a/src/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/src/com/owncloud/android/ui/activity/DrawerActivity.java @@ -553,8 +553,8 @@ private void setQuotaInformation(long usedSpace, long totalSpace, int relative) mQuotaTextView.setText(String.format( getString(R.string.drawer_quota), - DisplayUtils.bytesToHumanReadable(usedSpace), - DisplayUtils.bytesToHumanReadable(totalSpace))); + DisplayUtils.quotaBytesToHumanReadable(usedSpace), + DisplayUtils.quotaBytesToHumanReadable(totalSpace))); showQuota(true); } diff --git a/src/com/owncloud/android/utils/DisplayUtils.java b/src/com/owncloud/android/utils/DisplayUtils.java index 949ea69ba218..0a89597ce145 100644 --- a/src/com/owncloud/android/utils/DisplayUtils.java +++ b/src/com/owncloud/android/utils/DisplayUtils.java @@ -67,6 +67,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[] quotaSizeScales = { 0, 0, 0, 1, 1, 2, 2, 2, 2 }; public static final int RELATIVE_THRESHOLD_WARNING = 90; public static final int RELATIVE_THRESHOLD_CRITICAL = 95; @@ -95,18 +96,48 @@ public class DisplayUtils { * * * @param bytes Input file size - * @return Like something readable like "12 MB" + * @return something readable like "12 MB" */ public static String bytesToHumanReadable(long bytes) { + return bytesToHumanReadable(bytes, sizeScales, sizeSuffixes); + } + + /** + * Converts the file size in bytes to human readable output. + *
    + *
  • appends a size suffix, e.g. B, KB, MB etc.
  • + *
  • rounds the size based on the suffix to 0,1 or 2 decimals
  • + *
+ * + * @param bytes Input file size + * @return something readable like "12 MB" + */ + public static String quotaBytesToHumanReadable(long bytes) { + return bytesToHumanReadable(bytes, quotaSizeScales, sizeSuffixes); + } + + /** + * Converts the file size in bytes to human readable output. + *
    + *
  • appends a size suffix, e.g. B, KB, MB etc.
  • + *
  • rounds the size based on the suffix to 0,1 or 2 decimals
  • + *
+ * + * @param bytes Input file size + * @param sizeScales scales for the different size units + * @param sizeSuffixes suffixes for the different size units + * @return something readable like "12 MB" + */ + private static String bytesToHumanReadable(long bytes, int[] sizeScales, String[] sizeSuffixes) { double result = bytes; - int attachedSuff = 0; - while (result > 1024 && attachedSuff < sizeSuffixes.length) { + int suffixIndex = 0; + while (result > 1024 && suffixIndex < sizeSuffixes.length) { result /= 1024.; - attachedSuff++; + suffixIndex++; } return new BigDecimal(result).setScale( - sizeScales[attachedSuff], BigDecimal.ROUND_HALF_UP) + " " + sizeSuffixes[attachedSuff]; + sizeScales[suffixIndex], BigDecimal.ROUND_HALF_UP) + " " + sizeSuffixes[suffixIndex]; } /** From 457027a1968250d46d02c93998e8e0aedccb789d Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Sun, 14 Aug 2016 20:26:08 +0200 Subject: [PATCH 09/11] fixed the background color --- res/layout/drawer.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/res/layout/drawer.xml b/res/layout/drawer.xml index 3892505f3c5f..cca0b25ba328 100644 --- a/res/layout/drawer.xml +++ b/res/layout/drawer.xml @@ -35,6 +35,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" + android:background="@color/white" android:clickable="false" android:orientation="vertical" android:paddingBottom="@dimen/standard_half_padding" From b29744c00487dcf1831295a660389a3af088debb Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Wed, 31 Aug 2016 19:05:50 +0200 Subject: [PATCH 10/11] show quota for server without quota-unlimited info capability --- build.gradle | 2 +- .../android/ui/activity/DrawerActivity.java | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index b62cc2eab7a3..098dc8ed7592 100644 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,7 @@ dependencies { /// dependencies for app building compile name: 'touch-image-view' - compile 'com.github.nextcloud:android-library:1.0.4' + compile 'com.github.nextcloud:android-library:1.0.6' compile "com.android.support:support-v4:${supportLibraryVersion}" compile "com.android.support:design:${supportLibraryVersion}" compile 'com.jakewharton:disklrucache:2.0.2' diff --git a/src/com/owncloud/android/ui/activity/DrawerActivity.java b/src/com/owncloud/android/ui/activity/DrawerActivity.java index 78270003f5fa..555aa9044f89 100644 --- a/src/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/src/com/owncloud/android/ui/activity/DrawerActivity.java @@ -587,19 +587,33 @@ public void run() { AccountUtils.getCurrentOwnCloudAccount(DrawerActivity.this), DrawerActivity.this); if (result.isSuccess() && result.getData() != null) { - RemoteGetUserQuotaOperation.Quota quota = (RemoteGetUserQuotaOperation.Quota) result.getData().get - (0); + final 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()); + final long quotaValue = quota.getQuota(); runOnUiThread(new Runnable() { @Override public void run() { - if (mQuotaView != null) { - setQuotaInformation(used,total,relative); + if (quotaValue > 0 + || quotaValue == RemoteGetUserQuotaOperation.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); } 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); } } From 4f32abfafe1ba0f57679576d00cd1bc68948e05e Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Thu, 1 Sep 2016 10:12:02 +0200 Subject: [PATCH 11/11] sizeScale 1 for MB, code removed for unsupported legacy Android versions --- .../android/ui/activity/DrawerActivity.java | 4 +- .../owncloud/android/utils/DisplayUtils.java | 74 ++++++------------- 2 files changed, 23 insertions(+), 55 deletions(-) diff --git a/src/com/owncloud/android/ui/activity/DrawerActivity.java b/src/com/owncloud/android/ui/activity/DrawerActivity.java index 555aa9044f89..7b81013aad2a 100644 --- a/src/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/src/com/owncloud/android/ui/activity/DrawerActivity.java @@ -553,8 +553,8 @@ private void setQuotaInformation(long usedSpace, long totalSpace, int relative) mQuotaTextView.setText(String.format( getString(R.string.drawer_quota), - DisplayUtils.quotaBytesToHumanReadable(usedSpace), - DisplayUtils.quotaBytesToHumanReadable(totalSpace))); + DisplayUtils.bytesToHumanReadable(usedSpace), + DisplayUtils.bytesToHumanReadable(totalSpace))); showQuota(true); } diff --git a/src/com/owncloud/android/utils/DisplayUtils.java b/src/com/owncloud/android/utils/DisplayUtils.java index 0a89597ce145..6ad06093fd7c 100644 --- a/src/com/owncloud/android/utils/DisplayUtils.java +++ b/src/com/owncloud/android/utils/DisplayUtils.java @@ -1,23 +1,25 @@ /** - * ownCloud Android client application + * Nextcloud Android client application * + * @author Andy Scherzinger * @author Bartek Przybylski * @author David A. Velasco * Copyright (C) 2011 Bartek Przybylski * Copyright (C) 2015 ownCloud Inc. + * Copyright (C) 2016 Andy Scherzinger * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2, - * as published by the Free Software Foundation. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * + * You should have received a copy of the GNU Affero General Public + * License along with this program. If not, see . */ package com.owncloud.android.utils; @@ -37,7 +39,6 @@ import android.support.v4.app.FragmentActivity; import android.support.v4.content.ContextCompat; import android.text.format.DateUtils; -import android.view.Display; import android.view.View; import android.widget.ProgressBar; import android.widget.SeekBar; @@ -60,16 +61,16 @@ import java.util.Map; /** - * A helper class for some string operations. + * A helper class for UI/display related operations. */ public class DisplayUtils { private static final String TAG = DisplayUtils.class.getSimpleName(); 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[] quotaSizeScales = { 0, 0, 0, 1, 1, 2, 2, 2, 2 }; public static final int RELATIVE_THRESHOLD_WARNING = 90; public static final int RELATIVE_THRESHOLD_CRITICAL = 95; + public static final String MIME_TYPE_UNKNOWN = "Unknown type"; private static Map mimeType2HumanReadable; @@ -88,34 +89,6 @@ public class DisplayUtils { mimeType2HumanReadable.put("application/ogg", "OGG music file"); } - /** - * Converts the file size in bytes to human readable output. - *
    - *
  • appends a size suffix, e.g. B, KB, MB etc.
  • - *
  • rounds the size based on the suffix to 0,1 or 2 decimals
  • - *
- * - * @param bytes Input file size - * @return something readable like "12 MB" - */ - public static String bytesToHumanReadable(long bytes) { - return bytesToHumanReadable(bytes, sizeScales, sizeSuffixes); - } - - /** - * Converts the file size in bytes to human readable output. - *
    - *
  • appends a size suffix, e.g. B, KB, MB etc.
  • - *
  • rounds the size based on the suffix to 0,1 or 2 decimals
  • - *
- * - * @param bytes Input file size - * @return something readable like "12 MB" - */ - public static String quotaBytesToHumanReadable(long bytes) { - return bytesToHumanReadable(bytes, quotaSizeScales, sizeSuffixes); - } - /** * Converts the file size in bytes to human readable output. *
    @@ -124,11 +97,9 @@ public static String quotaBytesToHumanReadable(long bytes) { *
* * @param bytes Input file size - * @param sizeScales scales for the different size units - * @param sizeSuffixes suffixes for the different size units * @return something readable like "12 MB" */ - private static String bytesToHumanReadable(long bytes, int[] sizeScales, String[] sizeSuffixes) { + public static String bytesToHumanReadable(long bytes) { double result = bytes; int suffixIndex = 0; while (result > 1024 && suffixIndex < sizeSuffixes.length) { @@ -145,7 +116,7 @@ private static String bytesToHumanReadable(long bytes, int[] sizeScales, String[ * like "JPG image". * * @param mimetype MIME type to convert - * @return A human friendly version of the MIME type + * @return A human friendly version of the MIME type, {@link #MIME_TYPE_UNKNOWN} if it can't be converted */ public static String convertMIMEtoPrettyPrint(String mimetype) { if (mimeType2HumanReadable.containsKey(mimetype)) { @@ -153,11 +124,12 @@ public static String convertMIMEtoPrettyPrint(String mimetype) { } if (mimetype.split("/").length >= 2) return mimetype.split("/")[1].toUpperCase() + " file"; - return "Unknown type"; + return MIME_TYPE_UNKNOWN; } /** * Converts Unix time to human readable format + * * @param milliseconds that have passed since 01/01/1970 * @return The human readable time for the users locale */ @@ -169,6 +141,7 @@ public static String unixTimeToHumanReadable(long milliseconds) { /** * Converts an internationalized domain name (IDN) in an URL to and from ASCII/Unicode. + * * @param url the URL where the domain name should be converted * @param toASCII if true converts from Unicode to ASCII, if false converts from ASCII to Unicode * @return the URL containing the converted domain name @@ -299,7 +272,7 @@ public static String getPathWithoutLastSlash(String path) { } /** - * Gets the screen size in pixels in a backwards compatible way. + * Gets the screen size in pixels. * * @param caller Activity calling; needed to get access to the {@link android.view.WindowManager} * @return Size in pixels of the screen, or default {@link Point} if caller is null @@ -307,12 +280,7 @@ public static String getPathWithoutLastSlash(String path) { public static Point getScreenSize(Activity caller) { Point size = new Point(); if (caller != null) { - Display display = caller.getWindowManager().getDefaultDisplay(); - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { - display.getSize(size); - } else { - size.set(display.getWidth(), display.getHeight()); - } + caller.getWindowManager().getDefaultDisplay().getSize(size); } return size; } @@ -359,9 +327,9 @@ public static void colorPreLollipopHorizontalSeekBar(SeekBar seekBar) { } /** - * set the owncloud standard colors for the snackbar. + * set the Nextcloud standard colors for the snackbar. * - * @param context the context relevant for setting the color according to the context's theme + * @param context the context relevant for setting the color according to the context's theme * @param snackbar the snackbar to be colored */ public static void colorSnackbar(Context context, Snackbar snackbar) {