|
@@ -46,6 +46,7 @@ import com.owncloud.android.datamodel.OCFile;
|
|
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
|
|
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
|
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
|
import com.owncloud.android.ui.TextDrawable;
|
|
import com.owncloud.android.ui.TextDrawable;
|
|
|
|
+import com.owncloud.android.utils.BitmapUtils;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Base class to handle setup of the drawer implementation including user switching and avatar fetching and fallback
|
|
* Base class to handle setup of the drawer implementation including user switching and avatar fetching and fallback
|
|
@@ -434,8 +435,7 @@ public abstract class DrawerActivity extends ToolbarActivity {
|
|
TextView username = (TextView) findNavigationViewChildById(R.id.drawer_username);
|
|
TextView username = (TextView) findNavigationViewChildById(R.id.drawer_username);
|
|
TextView usernameFull = (TextView) findNavigationViewChildById(R.id.drawer_username_full);
|
|
TextView usernameFull = (TextView) findNavigationViewChildById(R.id.drawer_username_full);
|
|
usernameFull.setText(account.name);
|
|
usernameFull.setText(account.name);
|
|
- int lastAtPos = account.name.lastIndexOf("@");
|
|
|
|
- username.setText(account.name.substring(0, lastAtPos));
|
|
|
|
|
|
+ username.setText(AccountUtils.getUsernameOfAccount(account.name));
|
|
|
|
|
|
setAvatar(account, R.id.drawer_current_account, true);
|
|
setAvatar(account, R.id.drawer_current_account, true);
|
|
}
|
|
}
|
|
@@ -450,23 +450,20 @@ public abstract class DrawerActivity extends ToolbarActivity {
|
|
*/
|
|
*/
|
|
private void setAvatar(Account account, int avatarViewId, boolean currentAccount) {
|
|
private void setAvatar(Account account, int avatarViewId, boolean currentAccount) {
|
|
if (mDrawerLayout != null && account != null) {
|
|
if (mDrawerLayout != null && account != null) {
|
|
- int lastAtPos = account.name.lastIndexOf("@");
|
|
|
|
- String username = account.name.substring(0, lastAtPos);
|
|
|
|
|
|
|
|
ImageView userIcon = (ImageView) findNavigationViewChildById(avatarViewId);
|
|
ImageView userIcon = (ImageView) findNavigationViewChildById(avatarViewId);
|
|
userIcon.setContentDescription(account.name);
|
|
userIcon.setContentDescription(account.name);
|
|
|
|
|
|
// Thumbnail in Cache?
|
|
// Thumbnail in Cache?
|
|
- Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache("a_" + username);
|
|
|
|
|
|
+ Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache("a_" + account.name);
|
|
|
|
|
|
if (thumbnail != null) {
|
|
if (thumbnail != null) {
|
|
- RoundedBitmapDrawable roundedAvatar = RoundedBitmapDrawableFactory.create
|
|
|
|
- (MainApp.getAppContext().getResources(), thumbnail);
|
|
|
|
- roundedAvatar.setCircular(true);
|
|
|
|
- userIcon.setImageDrawable(roundedAvatar);
|
|
|
|
|
|
+ userIcon.setImageDrawable(
|
|
|
|
+ BitmapUtils.bitmapToCircularBitmapDrawable(MainApp.getAppContext().getResources(), thumbnail)
|
|
|
|
+ );
|
|
} else {
|
|
} else {
|
|
// generate new avatar
|
|
// generate new avatar
|
|
- if (ThumbnailsCacheManager.cancelPotentialAvatarWork(username, userIcon)) {
|
|
|
|
|
|
+ if (ThumbnailsCacheManager.cancelPotentialAvatarWork(account.name, userIcon)) {
|
|
final ThumbnailsCacheManager.AvatarGenerationTask task =
|
|
final ThumbnailsCacheManager.AvatarGenerationTask task =
|
|
new ThumbnailsCacheManager.AvatarGenerationTask(
|
|
new ThumbnailsCacheManager.AvatarGenerationTask(
|
|
userIcon, getStorageManager(), account
|
|
userIcon, getStorageManager(), account
|
|
@@ -499,12 +496,12 @@ public abstract class DrawerActivity extends ToolbarActivity {
|
|
thumbnail,
|
|
thumbnail,
|
|
task
|
|
task
|
|
);
|
|
);
|
|
- RoundedBitmapDrawable roundedAvatar = RoundedBitmapDrawableFactory.create
|
|
|
|
- (MainApp.getAppContext().getResources(), asyncDrawable.getBitmap());
|
|
|
|
- roundedAvatar.setCircular(true);
|
|
|
|
- userIcon.setImageDrawable(roundedAvatar);
|
|
|
|
|
|
+ userIcon.setImageDrawable(
|
|
|
|
+ BitmapUtils.bitmapToCircularBitmapDrawable(
|
|
|
|
+ MainApp.getAppContext().getResources(), asyncDrawable.getBitmap())
|
|
|
|
+ );
|
|
}
|
|
}
|
|
- task.execute(username);
|
|
|
|
|
|
+ task.execute(account.name);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -518,20 +515,17 @@ public abstract class DrawerActivity extends ToolbarActivity {
|
|
*/
|
|
*/
|
|
private void setAvatar(Account account, MenuItem menuItem) {
|
|
private void setAvatar(Account account, MenuItem menuItem) {
|
|
if (mDrawerLayout != null && account != null) {
|
|
if (mDrawerLayout != null && account != null) {
|
|
- int lastAtPos = account.name.lastIndexOf("@");
|
|
|
|
- String username = account.name.substring(0, lastAtPos);
|
|
|
|
|
|
|
|
// Thumbnail in Cache?
|
|
// Thumbnail in Cache?
|
|
- Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache("a_" + username);
|
|
|
|
|
|
+ Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache("a_" + account.name);
|
|
|
|
|
|
if (thumbnail != null) {
|
|
if (thumbnail != null) {
|
|
- RoundedBitmapDrawable roundedAvatar = RoundedBitmapDrawableFactory.create
|
|
|
|
- (MainApp.getAppContext().getResources(), thumbnail);
|
|
|
|
- roundedAvatar.setCircular(true);
|
|
|
|
- menuItem.setIcon(roundedAvatar);
|
|
|
|
|
|
+ menuItem.setIcon(
|
|
|
|
+ BitmapUtils.bitmapToCircularBitmapDrawable(MainApp.getAppContext().getResources(), thumbnail)
|
|
|
|
+ );
|
|
} else {
|
|
} else {
|
|
// generate new avatar
|
|
// generate new avatar
|
|
- if (ThumbnailsCacheManager.cancelPotentialAvatarWork(username, menuItem)) {
|
|
|
|
|
|
+ if (ThumbnailsCacheManager.cancelPotentialAvatarWork(account.name, menuItem)) {
|
|
final ThumbnailsCacheManager.AvatarGenerationTask task =
|
|
final ThumbnailsCacheManager.AvatarGenerationTask task =
|
|
new ThumbnailsCacheManager.AvatarGenerationTask(
|
|
new ThumbnailsCacheManager.AvatarGenerationTask(
|
|
menuItem, getStorageManager(), account
|
|
menuItem, getStorageManager(), account
|
|
@@ -555,12 +549,12 @@ public abstract class DrawerActivity extends ToolbarActivity {
|
|
thumbnail,
|
|
thumbnail,
|
|
task
|
|
task
|
|
);
|
|
);
|
|
- RoundedBitmapDrawable roundedAvatar = RoundedBitmapDrawableFactory.create
|
|
|
|
- (MainApp.getAppContext().getResources(), asyncDrawable.getBitmap());
|
|
|
|
- roundedAvatar.setCircular(true);
|
|
|
|
- menuItem.setIcon(roundedAvatar);
|
|
|
|
|
|
+ menuItem.setIcon(
|
|
|
|
+ BitmapUtils.bitmapToCircularBitmapDrawable(
|
|
|
|
+ MainApp.getAppContext().getResources(), asyncDrawable.getBitmap())
|
|
|
|
+ );
|
|
}
|
|
}
|
|
- task.execute(username);
|
|
|
|
|
|
+ task.execute(account.name);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|