浏览代码

add possibility to move quota to navigation header

tobiasKaminsky 8 年之前
父节点
当前提交
9dc3229f31
共有 1 个文件被更改,包括 20 次插入4 次删除
  1. 20 4
      src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

+ 20 - 4
src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -274,10 +274,10 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
      * setup quota elements of the drawer.
      */
     private void setupQuotaElement() {
-        mQuotaView = (LinearLayout) findViewById(R.id.drawer_quota);
-        mQuotaProgressBar = (ProgressBar) findViewById(R.id.drawer_quota_ProgressBar);
-        mQuotaTextPercentage = (TextView) findViewById(R.id.drawer_quota_percentage);
-        mQuotaTextLink = (TextView) findViewById(R.id.drawer_quota_link);
+        mQuotaView = (LinearLayout) findQuotaViewById(R.id.drawer_quota);
+        mQuotaProgressBar = (ProgressBar) findQuotaViewById(R.id.drawer_quota_ProgressBar);
+        mQuotaTextPercentage = (TextView) findQuotaViewById(R.id.drawer_quota_percentage);
+        mQuotaTextLink = (TextView) findQuotaViewById(R.id.drawer_quota_link);
         DisplayUtils.colorPreLollipopHorizontalProgressBar(mQuotaProgressBar);
     }
 
@@ -1101,6 +1101,22 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
         return ((NavigationView) findViewById(R.id.nav_view)).getHeaderView(0).findViewById(id);
     }
 
+    /**
+     * Quota view can be either at navigation bottom or header
+     *
+     * @param id the view's id
+     * @return The view if found or <code>null</code> otherwise.
+     */
+    private View findQuotaViewById(int id) {
+        View v = ((NavigationView) findViewById(R.id.nav_view)).getHeaderView(0).findViewById(id);
+
+        if (v != null) {
+            return v;
+        } else {
+            return findViewById(id);
+        }
+    }
+
     /**
      * restart helper method which is called after a changing the current account.
      */