1
0
mirror of https://github.com/MGislv/NekoX.git synced 2024-07-04 11:13:36 +00:00

Set old profile photo ad current profile photo

This commit is contained in:
NekoInverter 2020-05-11 09:28:21 +08:00
parent 902ad01371
commit 25980c55ea
No known key found for this signature in database
GPG Key ID: 280D6CCCF95715F9
2 changed files with 50 additions and 0 deletions

View File

@ -701,6 +701,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
private final static int gallery_menu_openin = 11;
private final static int gallery_menu_masks = 13;
private final static int gallery_menu_savegif = 14;
private final static int gallery_menu_setascurrent = 94;
private static DecelerateInterpolator decelerateInterpolator;
private static Paint progressPaint;
@ -2437,6 +2438,47 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
TLRPC.Document document = currentMessageObject.getDocument();
MessagesController.getInstance(currentAccount).saveGif(currentMessageObject, document);
} else if (id == gallery_menu_setascurrent) {
if (!imagesArrLocations.isEmpty()) {
if (currentIndex < 0 || currentIndex >= imagesArrLocations.size()) {
return;
}
TLRPC.Photo photo = avatarsArr.get(currentIndex);
TLRPC.TL_inputPhoto inputPhoto = new TLRPC.TL_inputPhoto();
inputPhoto.id = photo.id;
inputPhoto.access_hash = photo.access_hash;
inputPhoto.file_reference = photo.file_reference;
if (inputPhoto.file_reference == null) {
inputPhoto.file_reference = new byte[0];
}
TLRPC.TL_photos_updateProfilePhoto req = new TLRPC.TL_photos_updateProfilePhoto();
req.id = inputPhoto;
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
if (error == null) {
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(UserConfig.getInstance(currentAccount).getClientUserId());
if (user == null) {
user = UserConfig.getInstance(currentAccount).getCurrentUser();
if (user == null) {
return;
}
MessagesController.getInstance(currentAccount).putUser(user, false);
} else {
UserConfig.getInstance(currentAccount).setCurrentUser(user);
}
MessagesStorage.getInstance(currentAccount).clearUserPhotos(user.id);
ArrayList<TLRPC.User> users = new ArrayList<>();
users.add(user);
MessagesStorage.getInstance(currentAccount).putUsersAndChats(users, null, false, true);
}
AndroidUtilities.runOnUIThread(() -> {
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_ALL);
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.mainUserInfoChanged);
UserConfig.getInstance(currentAccount).saveConfig(true);
});
});
closePhoto(false, false);
}
}
}
@ -2468,6 +2510,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
menuItem.addSubItem(gallery_menu_showinchat, R.drawable.msg_message, LocaleController.getString("ShowInChat", R.string.ShowInChat)).setColors(0xfffafafa, 0xfffafafa);
menuItem.addSubItem(gallery_menu_share, R.drawable.msg_shareout, LocaleController.getString("ShareFile", R.string.ShareFile)).setColors(0xfffafafa, 0xfffafafa);
menuItem.addSubItem(gallery_menu_save, R.drawable.msg_gallery, LocaleController.getString("SaveToGallery", R.string.SaveToGallery)).setColors(0xfffafafa, 0xfffafafa);
menuItem.addSubItem(gallery_menu_setascurrent, R.drawable.menu_camera, LocaleController.getString("SetAsCurrent", R.string.SetAsCurrent)).setColors(0xfffafafa, 0xfffafafa);
menuItem.addSubItem(gallery_menu_delete, R.drawable.msg_delete, LocaleController.getString("Delete", R.string.Delete)).setColors(0xfffafafa, 0xfffafafa);
menuItem.addSubItem(gallery_menu_cancel_loading, R.drawable.msg_cancel, LocaleController.getString("StopDownload", R.string.StopDownload)).setColors(0xfffafafa, 0xfffafafa);
menuItem.redrawPopup(0xf9222222);
@ -5995,6 +6038,9 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (!init && switchingToIndex == index) {
return;
}
menuItem.hideSubItem(gallery_menu_setascurrent);
switchingToIndex = index;
boolean isVideo = false;
@ -6168,6 +6214,9 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (index < 0 || index >= imagesArrLocations.size()) {
return;
}
if (avatarsDialogId == UserConfig.getInstance(currentAccount).getClientUserId() && index != 0) {
menuItem.showSubItem(gallery_menu_setascurrent);
}
if (avatarsDialogId < 0) {
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-avatarsDialogId);
if (chat != null) {

View File

@ -100,4 +100,5 @@
<string name="AskBeforeCalling">Ask before calling</string>
<string name="ConfirmCall">Confirm calling</string>
<string name="CallTo">Call to **%1$s**?</string>
<string name="SetAsCurrent">Set as current</string>
</resources>