|
@@ -24,9 +24,12 @@ import android.accounts.AccountManager;
|
|
|
import android.accounts.AccountManagerFuture;
|
|
|
import android.content.Intent;
|
|
|
import android.content.res.Configuration;
|
|
|
+import android.graphics.Bitmap;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.annotation.NonNull;
|
|
|
import android.support.design.widget.NavigationView;
|
|
|
+import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
|
|
|
+import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
|
|
|
import android.support.v4.view.GravityCompat;
|
|
|
import android.support.v4.widget.DrawerLayout;
|
|
|
import android.support.v7.app.ActionBarDrawerToggle;
|
|
@@ -41,6 +44,7 @@ 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.datamodel.ThumbnailsCacheManager;
|
|
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
|
|
import com.owncloud.android.ui.TextDrawable;
|
|
|
import com.owncloud.android.utils.BitmapUtils;
|
|
@@ -265,7 +269,7 @@ public abstract class DrawerActivity extends ToolbarActivity {
|
|
|
Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
|
|
|
if (accounts.length > 0 && mNavigationView != null) {
|
|
|
repopulateAccountList(accounts);
|
|
|
- setUsernameInDrawer(AccountUtils.getCurrentOwnCloudAccount(this).name);
|
|
|
+ setAccountInDrawer(AccountUtils.getCurrentOwnCloudAccount(this));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -333,27 +337,73 @@ public abstract class DrawerActivity extends ToolbarActivity {
|
|
|
* sets the given account name in the drawer in case the drawer is available. The account name is shortened
|
|
|
* beginning from the @-sign in the username.
|
|
|
*
|
|
|
- * @param accountName the account to be set in the drawer
|
|
|
+ * @param account the account to be set in the drawer
|
|
|
*/
|
|
|
- protected void setUsernameInDrawer(String accountName) {
|
|
|
- if (mDrawerLayout != null && accountName != null) {
|
|
|
+ protected void setAccountInDrawer(Account account) {
|
|
|
+ if (mDrawerLayout != null && account != null) {
|
|
|
TextView username = (TextView) findNavigationViewChildById(R.id.drawer_username);
|
|
|
TextView usernameFull = (TextView) findNavigationViewChildById(R.id.drawer_username_full);
|
|
|
- usernameFull.setText(accountName);
|
|
|
- int lastAtPos = accountName.lastIndexOf("@");
|
|
|
- username.setText(accountName.substring(0, lastAtPos));
|
|
|
+ usernameFull.setText(account.name);
|
|
|
+ int lastAtPos = account.name.lastIndexOf("@");
|
|
|
+ username.setText(account.name.substring(0, lastAtPos));
|
|
|
|
|
|
ImageView userIcon = (ImageView) findNavigationViewChildById(R.id.drawer_usericon);
|
|
|
- try {
|
|
|
- userIcon.setImageDrawable(
|
|
|
- createAvatar(
|
|
|
- accountName,
|
|
|
- getResources().getDimension(R.dimen.nav_drawer_header_avatar_radius)
|
|
|
- )
|
|
|
- );
|
|
|
- } catch (Exception e) {
|
|
|
- Log_OC.e(TAG, "Error calculating RGB value for active account icon.", e);
|
|
|
- userIcon.setImageResource(R.drawable.ic_account_circle);
|
|
|
+ setAvatarInDrawer(account);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * sets the avatar of the current account in the drawer in case the drawer is available.
|
|
|
+ *
|
|
|
+ * @param account the account to be set in the drawer
|
|
|
+ */
|
|
|
+ private void setAvatarInDrawer(Account account) {
|
|
|
+ if (mDrawerLayout != null && account != null) {
|
|
|
+ ImageView userIcon = (ImageView) findNavigationViewChildById(R.id.drawer_usericon);
|
|
|
+ int lastAtPos = account.name.lastIndexOf("@");
|
|
|
+ String username = account.name.substring(0, lastAtPos);
|
|
|
+
|
|
|
+ // Thumbnail in Cache?
|
|
|
+ Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache("a_" + username);
|
|
|
+
|
|
|
+ if (thumbnail != null) {
|
|
|
+ RoundedBitmapDrawable roundedAvatar = RoundedBitmapDrawableFactory.create
|
|
|
+ (MainApp.getAppContext().getResources(), thumbnail);
|
|
|
+ roundedAvatar.setCircular(true);
|
|
|
+ userIcon.setImageDrawable(roundedAvatar);
|
|
|
+ } else {
|
|
|
+ // generate new avatar
|
|
|
+ if (ThumbnailsCacheManager.cancelPotentialAvatarWork(username, userIcon)) {
|
|
|
+ final ThumbnailsCacheManager.AvatarGenerationTask task =
|
|
|
+ new ThumbnailsCacheManager.AvatarGenerationTask(
|
|
|
+ userIcon, getStorageManager(), account
|
|
|
+ );
|
|
|
+ if (thumbnail == null) {
|
|
|
+ try {
|
|
|
+ userIcon.setImageDrawable(
|
|
|
+ createAvatar(
|
|
|
+ account.name,
|
|
|
+ getResources().getDimension(R.dimen.nav_drawer_header_avatar_radius)
|
|
|
+ )
|
|
|
+ );
|
|
|
+ } catch (Exception e) {
|
|
|
+ Log_OC.e(TAG, "Error calculating RGB value for active account icon.", e);
|
|
|
+ userIcon.setImageResource(R.drawable.ic_account_circle);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ final ThumbnailsCacheManager.AsyncAvatarDrawable asyncDrawable =
|
|
|
+ new ThumbnailsCacheManager.AsyncAvatarDrawable(
|
|
|
+ getResources(),
|
|
|
+ thumbnail,
|
|
|
+ task
|
|
|
+ );
|
|
|
+ RoundedBitmapDrawable roundedAvatar = RoundedBitmapDrawableFactory.create
|
|
|
+ (MainApp.getAppContext().getResources(), asyncDrawable.getBitmap());
|
|
|
+ roundedAvatar.setCircular(true);
|
|
|
+ userIcon.setImageDrawable(roundedAvatar);
|
|
|
+ }
|
|
|
+ task.execute(username);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|