Dbrant has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/365294 )

Change subject: Introduce a disk usage component, and use it for Compilations.
......................................................................

Introduce a disk usage component, and use it for Compilations.

The only difficulty encountered in the making of this component is that it
doesn't seem to be possible for us to determine how much space our app
uses. The system doesn't provide this information easily.

Instead this component currently only states the amount of space used by
compilations, whose magnitude will likely overshadow the storage footprint
of the app itself.

Bug: T164387
Change-Id: Ia97c84cf6c43d9fdf4e4b47513fbc972ea32382b
---
A app/src/main/java/org/wikipedia/offline/DiskUsageView.java
M app/src/main/java/org/wikipedia/offline/LocalCompilationsFragment.java
A app/src/main/res/drawable/shape_circle_outline.xml
A app/src/main/res/drawable/shape_disk_usage.xml
M app/src/main/res/layout/fragment_local_compilations.xml
A app/src/main/res/layout/view_disk_usage.xml
M app/src/main/res/values-qq/strings.xml
M app/src/main/res/values/strings.xml
8 files changed, 295 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia 
refs/changes/94/365294/1

diff --git a/app/src/main/java/org/wikipedia/offline/DiskUsageView.java 
b/app/src/main/java/org/wikipedia/offline/DiskUsageView.java
new file mode 100644
index 0000000..b58380a
--- /dev/null
+++ b/app/src/main/java/org/wikipedia/offline/DiskUsageView.java
@@ -0,0 +1,103 @@
+package org.wikipedia.offline;
+
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.content.res.ColorStateList;
+import android.os.Build;
+import android.os.Environment;
+import android.support.v4.content.ContextCompat;
+import android.support.v4.view.ViewCompat;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import org.wikipedia.R;
+import org.wikipedia.util.ResourceUtil;
+
+import java.io.File;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+
+public class DiskUsageView extends LinearLayout {
+    private static final int KILOBYTE = 1000;
+
+    @BindView(R.id.view_disk_usage_size_text) TextView sizeText;
+    @BindView(R.id.view_disk_usage_text_app) TextView usageAppText;
+    @BindView(R.id.view_disk_usage_text_free) TextView usageFreeText;
+    @BindView(R.id.view_disk_usage_bar_other) View otherBar;
+    @BindView(R.id.view_disk_usage_bar_used) View usedBar;
+    @BindView(R.id.view_disk_usage_bar_free) View freeBar;
+    @BindView(R.id.view_disk_usage_dot_other) View otherDot;
+    @BindView(R.id.view_disk_usage_dot_used) View usedDot;
+    @BindView(R.id.view_disk_usage_dot_free) View freeDot;
+
+    public DiskUsageView(Context context) {
+        super(context);
+        init();
+    }
+
+    public DiskUsageView(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        init();
+    }
+
+    public DiskUsageView(Context context, AttributeSet attrs, int 
defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+        init();
+    }
+
+    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+    public DiskUsageView(Context context, AttributeSet attrs, int 
defStyleAttr, int defStyleRes) {
+        super(context, attrs, defStyleAttr, defStyleRes);
+        init();
+    }
+
+    public void update(long usedBytes) {
+        File path = Environment.getDataDirectory();
+        float availableGB = bytesToGB(path.getFreeSpace());
+        float otherGB = bytesToGB(path.getTotalSpace());
+        float usedGB = bytesToGB(usedBytes);
+        otherGB -= usedGB;
+
+        
sizeText.setText(getResources().getString(R.string.storage_size_format, 
usedGB));
+        
usageFreeText.setText(getResources().getString(R.string.storage_size_free, 
availableGB));
+
+        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) 
otherBar.getLayoutParams();
+        params.weight = otherGB;
+        otherBar.setLayoutParams(params);
+
+        params = (LinearLayout.LayoutParams) freeBar.getLayoutParams();
+        params.weight = availableGB;
+        freeBar.setLayoutParams(params);
+
+        params = (LinearLayout.LayoutParams) usedBar.getLayoutParams();
+        params.weight = usedGB;
+        usedBar.setLayoutParams(params);
+    }
+
+    private void init() {
+        inflate(getContext(), R.layout.view_disk_usage, this);
+        ButterKnife.bind(this);
+        setOrientation(VERTICAL);
+
+        ViewCompat.setBackgroundTintList(otherDot, new ColorStateList(new 
int[][]{new int[]{}},
+                new int[]{ContextCompat.getColor(getContext(),
+                        ResourceUtil.getThemedAttributeId(getContext(), 
R.attr.window_inverse_color))}));
+
+        ViewCompat.setBackgroundTintList(usedDot, new ColorStateList(new 
int[][]{new int[]{}},
+                new int[]{ContextCompat.getColor(getContext(),
+                        ResourceUtil.getThemedAttributeId(getContext(), 
R.attr.colorAccent))}));
+
+        ViewCompat.setBackgroundTintList(freeDot, new ColorStateList(new 
int[][]{new int[]{}},
+                new int[]{ContextCompat.getColor(getContext(),
+                        ResourceUtil.getThemedAttributeId(getContext(), 
R.attr.window_background_color))}));
+
+        update(0);
+    }
+
+    private float bytesToGB(long bytes) {
+        return (float) bytes / KILOBYTE / KILOBYTE / KILOBYTE;
+    }
+}
diff --git 
a/app/src/main/java/org/wikipedia/offline/LocalCompilationsFragment.java 
b/app/src/main/java/org/wikipedia/offline/LocalCompilationsFragment.java
index 3d8b502..523ddf9 100644
--- a/app/src/main/java/org/wikipedia/offline/LocalCompilationsFragment.java
+++ b/app/src/main/java/org/wikipedia/offline/LocalCompilationsFragment.java
@@ -39,6 +39,7 @@
     @BindView(R.id.search_empty_view) SearchEmptyView searchEmptyView;
     @BindView(R.id.compilation_search_progress_bar) ProgressBar progressBar;
     @BindView(R.id.compilations_count_text) TextView countText;
+    @BindView(R.id.disk_usage_view) DiskUsageView diskUsageView;
     private Unbinder unbinder;
 
     private boolean updating;
@@ -127,6 +128,11 @@
 
     private void update() {
         setSearchQuery(currentSearchQuery);
+        long totalBytes = 0;
+        for (Compilation c : OfflineManager.instance().compilations()) {
+            totalBytes += c.size();
+        }
+        diskUsageView.update(totalBytes);
     }
 
     private void setSearchQuery(@Nullable String query) {
diff --git a/app/src/main/res/drawable/shape_circle_outline.xml 
b/app/src/main/res/drawable/shape_circle_outline.xml
new file mode 100644
index 0000000..61d0024
--- /dev/null
+++ b/app/src/main/res/drawable/shape_circle_outline.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android";
+    android:shape="oval">
+    <stroke android:width="0.5dp" android:color="@color/base50"/>
+</shape>
\ No newline at end of file
diff --git a/app/src/main/res/drawable/shape_disk_usage.xml 
b/app/src/main/res/drawable/shape_disk_usage.xml
new file mode 100644
index 0000000..b33b86a
--- /dev/null
+++ b/app/src/main/res/drawable/shape_disk_usage.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android";
+    android:shape="rectangle">
+    <stroke android:width="0.5dp" android:color="@color/base50"/>
+    <corners android:radius="1dp" />
+</shape>
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_local_compilations.xml 
b/app/src/main/res/layout/fragment_local_compilations.xml
index 3000263..d46f054 100644
--- a/app/src/main/res/layout/fragment_local_compilations.xml
+++ b/app/src/main/res/layout/fragment_local_compilations.xml
@@ -9,6 +9,15 @@
     android:layout_marginTop="?attr/actionBarSize"
     android:background="?attr/window_background_color">
 
+    <org.wikipedia.offline.DiskUsageView
+        android:id="@+id/disk_usage_view"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="16dp"
+        android:layout_marginBottom="16dp"
+        android:layout_marginLeft="24dp"
+        android:layout_marginRight="24dp"/>
+
     <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent">
diff --git a/app/src/main/res/layout/view_disk_usage.xml 
b/app/src/main/res/layout/view_disk_usage.xml
new file mode 100644
index 0000000..19bcbb0
--- /dev/null
+++ b/app/src/main/res/layout/view_disk_usage.xml
@@ -0,0 +1,154 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<merge
+    xmlns:android="http://schemas.android.com/apk/res/android";
+    xmlns:tools="http://schemas.android.com/tools";
+    xmlns:app="http://schemas.android.com/apk/res-auto";
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:parentTag="LinearLayout"
+    tools:orientation="vertical"
+    tools:background="@color/window_background_light">
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content">
+
+        <TextView
+            android:id="@+id/view_disk_usage_size_text"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textSize="32sp"
+            android:textColor="?attr/feed_text_secondary_color"
+            tools:text="12.3"/>
+
+        <TextView
+            android:id="@+id/view_disk_usage_units_text"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginLeft="8dp"
+            android:layout_marginRight="8dp"
+            android:textSize="24sp"
+            android:textColor="?attr/feed_text_secondary_color"
+            android:text="@string/storage_size_gb"/>
+
+        <TextView
+            android:id="@+id/view_disk_usage_by_text"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_weight="1"
+            android:textSize="12sp"
+            android:textColor="?attr/feed_text_tertiary_color"
+            android:text="@string/storage_used_by_compilations"/>
+
+    </LinearLayout>
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="8dp"
+        android:layout_marginTop="4dp"
+        android:layout_marginBottom="8dp"
+        android:padding="0.5dp"
+        android:foreground="@drawable/shape_disk_usage">
+
+        <View
+            android:id="@+id/view_disk_usage_bar_other"
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_weight="1"
+            android:background="?attr/window_inverse_color"/>
+
+        <View
+            android:id="@+id/view_disk_usage_bar_used"
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_weight="2"
+            android:background="?attr/colorAccent"/>
+
+        <View
+            android:id="@+id/view_disk_usage_bar_free"
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_weight="3"
+            android:background="?attr/window_background_color"/>
+
+    </LinearLayout>
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content">
+        
+        <View
+            android:id="@+id/view_disk_usage_dot_other"
+            android:layout_width="8dp"
+            android:layout_height="8dp"
+            android:layout_gravity="center_vertical"
+            android:background="@drawable/shape_circle"
+            android:foreground="@drawable/shape_circle_outline"
+            tools:backgroundTint="?attr/window_inverse_color" />
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginLeft="8dp"
+            android:layout_marginRight="8dp"
+            android:textColor="?attr/window_inverse_color"
+            android:textSize="12sp"
+            android:fontFamily="sans-serif-medium"
+            android:text="@string/storage_other_apps"/>
+
+    </LinearLayout>
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content">
+
+        <View
+            android:id="@+id/view_disk_usage_dot_used"
+            android:layout_width="8dp"
+            android:layout_height="8dp"
+            android:layout_gravity="center_vertical"
+            android:background="@drawable/shape_circle"
+            android:foreground="@drawable/shape_circle_outline"
+            tools:backgroundTint="?attr/colorAccent" />
+
+        <TextView
+            android:id="@+id/view_disk_usage_text_app"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginLeft="8dp"
+            android:layout_marginRight="8dp"
+            android:textColor="?attr/colorAccent"
+            android:textSize="12sp"
+            android:fontFamily="sans-serif-medium"
+            android:text="@string/storage_compilations"/>
+
+    </LinearLayout>
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content">
+
+        <View
+            android:id="@+id/view_disk_usage_dot_free"
+            android:layout_width="8dp"
+            android:layout_height="8dp"
+            android:layout_gravity="center_vertical"
+            android:background="@drawable/shape_circle"
+            android:foreground="@drawable/shape_circle_outline"
+            tools:backgroundTint="?attr/window_background_color" />
+
+        <TextView
+            android:id="@+id/view_disk_usage_text_free"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginLeft="8dp"
+            android:layout_marginRight="8dp"
+            android:textColor="?attr/feed_text_tertiary_color"
+            android:textSize="12sp"
+            android:fontFamily="sans-serif-medium"
+            tools:text="123.4 GB free"/>
+
+    </LinearLayout>
+
+</merge>
diff --git a/app/src/main/res/values-qq/strings.xml 
b/app/src/main/res/values-qq/strings.xml
index 72aff20..28f0bd4 100644
--- a/app/src/main/res/values-qq/strings.xml
+++ b/app/src/main/res/values-qq/strings.xml
@@ -421,6 +421,12 @@
   <string name="offline_compilations_search_by_name">Menu item for searching 
compilations by name.</string>
   <string name="offline_compilations_found_count">Label that states how many 
compilations the user has available. The %d symbol is replaced with the number 
of compilations detected.</string>
   <string name="offline_compilations_add">Button text for adding an offline 
compilation.</string>
+  <string name="storage_size_gb">Abbreviated form for the unit of a 
gigabyte.</string>
+  <string name="storage_size_format">Format specifier where %.2f represents a 
decimal number with two significant figures to the right of the decimal 
point.</string>
+  <string name="storage_size_free">Label that says how much free space is 
available on the device. The %.2f symbol is replaced with the number in 
gigabytes.</string>
+  <string name="storage_used_by_compilations">Label that appears next to the 
number of gigabytes used by compilations.</string>
+  <string name="storage_other_apps">Legend label for the amount of space used 
by other applications on the device.</string>
+  <string name="storage_compilations">Legend label for the amount of space 
used by compilations.</string>
   <string name="onboarding_skip">Button label to skip the current onboarding 
or tutorial screen.\n{{Identical|Skip}}</string>
   <string name="onboarding_continue">Button label to continue to the next 
onboarding or tutorial screen.\n{{Identical|Continue}}</string>
   <string name="onboarding_get_started">Button label to finish the current 
onboarding or tutorial workflow.\n{{Identical|Get started}}</string>
diff --git a/app/src/main/res/values/strings.xml 
b/app/src/main/res/values/strings.xml
index 07d958b..dfbb40f 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -475,6 +475,12 @@
     <string name="offline_compilations_search_by_name">Search compilations by 
name</string>
     <string name="offline_compilations_found_count">My compilations 
(%d)</string>
     <string name="offline_compilations_add">Add offline compilation</string>
+    <string name="storage_size_format">%.2f</string>
+    <string name="storage_size_gb">GB</string>
+    <string name="storage_size_free">%.2f GB free</string>
+    <string name="storage_used_by_compilations">used by Wikipedia 
compilations</string>
+    <string name="storage_other_apps">Other applications</string>
+    <string name="storage_compilations">Wikipedia compilations</string>
     <!-- /Offline -->
 
     <!-- Onboarding -->

-- 
To view, visit https://gerrit.wikimedia.org/r/365294
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia97c84cf6c43d9fdf4e4b47513fbc972ea32382b
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <dbr...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to