1
0
mirror of https://github.com/NekoX-Dev/NekoX.git synced 2024-12-03 20:40:53 +01:00

Use avatar as drawer background

This commit is contained in:
NekoInverter 2020-03-26 17:02:35 +08:00
parent 9f38ff49d3
commit 0df8b45e59
No known key found for this signature in database
GPG Key ID: 280D6CCCF95715F9
4 changed files with 40 additions and 4 deletions

View File

@ -53,6 +53,7 @@ import tw.nekomimi.nekogram.NekoConfig;
public class DrawerProfileCell extends FrameLayout {
private BackupImageView avatarImageView;
private BackupImageView avatarBackgroundView;
private TextView nameTextView;
private TextView phoneTextView;
private ImageView shadowView;
@ -70,6 +71,10 @@ public class DrawerProfileCell extends FrameLayout {
public DrawerProfileCell(Context context) {
super(context);
avatarBackgroundView = new BackupImageView(context);
avatarBackgroundView.setVisibility(INVISIBLE);
addView(avatarBackgroundView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
shadowView = new ImageView(context);
shadowView.setVisibility(INVISIBLE);
shadowView.setScaleType(ImageView.ScaleType.FIT_XY);
@ -183,7 +188,7 @@ public class DrawerProfileCell extends FrameLayout {
boolean useImageBackground = !backgroundKey.equals(Theme.key_chats_menuTopBackground) && Theme.isCustomTheme() && !Theme.isPatternWallpaper() && backgroundDrawable != null && !(backgroundDrawable instanceof ColorDrawable) && !(backgroundDrawable instanceof GradientDrawable);
boolean drawCatsShadow = false;
int color;
if (!useImageBackground && Theme.hasThemeKey(Theme.key_chats_menuTopShadowCats)) {
if (!NekoConfig.avatarAsDrawerBackground && !useImageBackground && Theme.hasThemeKey(Theme.key_chats_menuTopShadowCats)) {
color = Theme.getColor(Theme.key_chats_menuTopShadowCats);
drawCatsShadow = true;
} else {
@ -203,7 +208,7 @@ public class DrawerProfileCell extends FrameLayout {
darkThemeView.getDrawable().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
}
nameTextView.setTextColor(Theme.getColor(Theme.key_chats_menuName));
if (useImageBackground) {
if (NekoConfig.avatarAsDrawerBackground || useImageBackground) {
phoneTextView.setTextColor(Theme.getColor(Theme.key_chats_menuPhone));
if (shadowView.getVisibility() != VISIBLE) {
shadowView.setVisibility(VISIBLE);
@ -271,6 +276,14 @@ public class DrawerProfileCell extends FrameLayout {
AvatarDrawable avatarDrawable = new AvatarDrawable(user);
avatarDrawable.setColor(Theme.getColor(Theme.key_avatar_backgroundInProfileBlue));
avatarImageView.setImage(ImageLocation.getForUser(user, false), "50_50", avatarDrawable, user);
if (NekoConfig.avatarAsDrawerBackground) {
avatarBackgroundView.setImage(ImageLocation.getForUser(user, true), "512_512", avatarDrawable, user);
avatarBackgroundView.setVisibility(VISIBLE);
avatarImageView.setVisibility(INVISIBLE);
} else {
avatarBackgroundView.setVisibility(INVISIBLE);
avatarImageView.setVisibility(VISIBLE);
}
applyBackground(true);
}

View File

@ -44,6 +44,7 @@ public class NekoConfig {
public static boolean transparentStatusBar = false;
public static boolean forceTablet = false;
public static boolean openArchiveOnPull = false;
public static boolean avatarAsDrawerBackground = false;
public static int nameOrder = 1;
public static int eventType = 0;
public static boolean newYear = false;
@ -91,6 +92,7 @@ public class NekoConfig {
editor.putBoolean("openFilterByActionBar", openFilterByActionBar);
editor.putBoolean("openFilterByFab", openFilterByFab);
editor.putBoolean("showHiddenFeature", showHiddenFeature);
editor.putBoolean("avatarAsDrawerBackground", avatarAsDrawerBackground);
editor.putFloat("stickerSize", stickerSize);
editor.putInt("typeface", typeface);
editor.putInt("nameOrder", nameOrder);
@ -146,6 +148,7 @@ public class NekoConfig {
openFilterByFab = preferences.getBoolean("openFilterByFab", false);
showHiddenFeature = preferences.getBoolean("showHiddenFeature", false);
hideKeyboardOnChatScroll = preferences.getBoolean("hideKeyboardOnChatScroll", false);
avatarAsDrawerBackground = preferences.getBoolean("avatarAsDrawerBackground", false);
configLoaded = true;
}
}
@ -424,4 +427,12 @@ public class NekoConfig {
editor.putBoolean("hideKeyboardOnChatScroll", hideKeyboardOnChatScroll);
editor.commit();
}
public static void toggleAvatarAsDrawerBackground() {
avatarAsDrawerBackground = !avatarAsDrawerBackground;
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("avatarAsDrawerBackground", avatarAsDrawerBackground);
editor.commit();
}
}

View File

@ -97,6 +97,7 @@ public class NekoSettingsActivity extends BaseFragment {
private int transparentStatusBarRow;
private int forceTabletRow;
private int openArchiveOnPullRow;
private int avatarAsDrawerBackgroundRow;
private int eventTypeRow;
private int newYearRow;
private int actionBarDecorationRow;
@ -529,6 +530,12 @@ public class NekoSettingsActivity extends BaseFragment {
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(NekoConfig.hideKeyboardOnChatScroll);
}
} else if (position == avatarAsDrawerBackgroundRow) {
NekoConfig.toggleAvatarAsDrawerBackground();
NotificationCenter.getInstance(UserConfig.selectedAccount).postNotificationName(NotificationCenter.mainUserInfoChanged);
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(NekoConfig.avatarAsDrawerBackground);
}
}
});
@ -574,6 +581,7 @@ public class NekoSettingsActivity extends BaseFragment {
transparentStatusBarRow = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? rowCount++ : -1;
forceTabletRow = rowCount++;
openArchiveOnPullRow = rowCount++;
avatarAsDrawerBackgroundRow = rowCount++;
nameOrderRow = rowCount++;
eventTypeRow = NekoConfig.showHiddenFeature ? rowCount++ : -1;
newYearRow = NekoConfig.showHiddenFeature ? rowCount++ : -1;
@ -1064,6 +1072,8 @@ public class NekoSettingsActivity extends BaseFragment {
textCell.setTextAndCheck(LocaleController.getString("TapOnFab", R.string.TapOnFab), NekoConfig.openFilterByFab, false);
} else if (position == hideKeyboardOnChatScrollRow) {
textCell.setTextAndCheck(LocaleController.getString("HideKeyboardOnChatScroll", R.string.HideKeyboardOnChatScroll), NekoConfig.hideKeyboardOnChatScroll, true);
} else if (position == avatarAsDrawerBackgroundRow) {
textCell.setTextAndCheck(LocaleController.getString("UseAvatarAsDrawerBackground", R.string.UseAvatarAsDrawerBackground), NekoConfig.avatarAsDrawerBackground, true);
}
break;
}
@ -1105,7 +1115,7 @@ public class NekoSettingsActivity extends BaseFragment {
position == translationProviderRow || position == smoothKeyboardRow || position == pauseMusicOnRecordRow ||
position == disablePhotoSideActionRow || position == unlimitedPinnedDialogsRow || position == openArchiveOnPullRow ||
position == openFilterByActionBarRow || position == openFilterByFabRow || position == connection2Row ||
position == hideKeyboardOnChatScrollRow;
position == hideKeyboardOnChatScrollRow || position == avatarAsDrawerBackgroundRow;
}
@Override
@ -1158,7 +1168,8 @@ public class NekoSettingsActivity extends BaseFragment {
position == saveCacheToPrivateDirectoryRow || position == unlimitedFavedStickersRow ||
position == disableFilteringRow || position == smoothKeyboardRow || position == pauseMusicOnRecordRow ||
position == disablePhotoSideActionRow || position == unlimitedPinnedDialogsRow || position == openArchiveOnPullRow ||
position == openFilterByActionBarRow || position == openFilterByFabRow || position == hideKeyboardOnChatScrollRow) {
position == openFilterByActionBarRow || position == openFilterByFabRow || position == hideKeyboardOnChatScrollRow ||
position == avatarAsDrawerBackgroundRow) {
return 3;
} else if (position == settingsRow || position == connectionRow || position == chatRow || position == experimentRow ||
position == dialogsFilterRow) {

View File

@ -93,4 +93,5 @@
<string name="HideKeyboardOnChatScroll">Hide keyboard on chat scroll</string>
<string name="UserRestrictionsSendStickers2">Send Stickers</string>
<string name="UserRestrictionsSendGifs">Send GIFs</string>
<string name="UseAvatarAsDrawerBackground">Use avatar as drawer background</string>
</resources>