Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.6'
compile "com.android.support:support-v4:${supportLibraryVersion}"
compile "com.android.support:design:${supportLibraryVersion}"
compile 'com.jakewharton:disklrucache:2.0.2'
Expand Down
38 changes: 36 additions & 2 deletions res/layout/drawer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<LinearLayout
android:id="@+id/drawer_quota"
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"
android:paddingLeft="@dimen/standard_padding"
android:paddingRight="@dimen/standard_padding"
android:paddingTop="@dimen/standard_half_padding"
android:visibility="gone">

<ProgressBar
android:id="@+id/drawer_quota_ProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="false"
android:indeterminateOnly="false"
android:text="@string/drawer_quota"
/>

<TextView
android:id="@+id/drawer_quota_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/drawer_quota"/>
</LinearLayout>

</android.support.design.widget.NavigationView>

</merge>
11 changes: 11 additions & 0 deletions res/menu/drawer_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,15 @@
android:icon="@drawable/ic_settings"
android:title="@string/actionbar_settings"/>
</group>

<!--
dummy group/element as a workaround to see
the whole menu in case of quota being displayed
-->
<group>
<item
android:enabled="false"
android:orderInCategory="200"
android:title=""/>
</group>
</menu>
6 changes: 6 additions & 0 deletions res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@
<!-- special transparent action bar colors for image preview -->
<color name="owncloud_blue_transparent">#201D2D44</color>
<color name="owncloud_blue_dark_transparent">#40162233</color>

<!-- 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>

</resources>
1 change: 1 addition & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<string name="drawer_item_on_device">On device</string>
<string name="drawer_item_settings">Settings</string>
<string name="drawer_item_uploads_list">Uploads</string>
<string name="drawer_quota">%1$s of %2$s used</string>
<string name="drawer_close">Close</string>
<string name="drawer_open">Open</string>
<string name="prefs_category_general">General</string>
Expand Down
179 changes: 156 additions & 23 deletions src/com/owncloud/android/ui/activity/DrawerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,19 @@
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;
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;

Expand Down Expand Up @@ -121,6 +126,21 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
*/
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;

/**
* Initializes the drawer, its content and highlights the menu item with the given id.
* This method needs to be called after the content view has been set.
Expand All @@ -141,30 +161,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;
setupDrawerHeader();

mAccountMiddleAccountAvatar = (ImageView) findNavigationViewChildById(R.id.drawer_account_middle);
mAccountEndAccountAvatar = (ImageView) findNavigationViewChildById(R.id.drawer_account_end);
setupDrawerMenu(mNavigationView);

// 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);
}
setupQuotaElement();
}

setupDrawerContent(mNavigationView);
setupDrawerToggle();

findNavigationViewChildById(R.id.drawer_active_user)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
toggleAccountList();
}
});
}
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. */
Expand All @@ -188,15 +200,50 @@ 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);
}

/**
* setup drawer content, basically setting the item selected listener.
*
* @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
Expand Down Expand Up @@ -246,9 +293,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);
}
}

Expand Down Expand Up @@ -449,6 +496,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
getAndDisplayUserQuota();
}
}

Expand Down Expand Up @@ -477,6 +527,38 @@ 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 relative the percentage of space already used
*/
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)));

showQuota(true);
}

/**
* checks/highlights the provided menu item if the drawer has been initialized and the menu item exists.
*
Expand All @@ -492,6 +574,57 @@ protected void setDrawerMenuItemChecked(int menuItemId) {
}
}

/**
* Retrieves and shows the user quota if available
*/
private void getAndDisplayUserQuota() {
// 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) {
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 (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);
}
}
});
}
}
});

t.start();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
Loading