mirror of
https://github.com/NekoX-Dev/NekoX.git
synced 2024-11-23 02:55:23 +01:00
fix ProfileActivity avatar and edit button
This commit is contained in:
parent
1497c7ddd3
commit
0ee46c7b1c
@ -72,7 +72,8 @@ public class ImageUpdater implements NotificationCenter.NotificationCenterDelega
|
||||
ID_UPLOAD_FROM_GALLERY = 1,
|
||||
ID_SEARCH_WEB = 2,
|
||||
ID_REMOVE_PHOTO = 3,
|
||||
ID_RECORD_VIDEO = 4;
|
||||
ID_RECORD_VIDEO = 4,
|
||||
ID_OPEN_AVATAR = 5;
|
||||
|
||||
public BaseFragment parentFragment;
|
||||
private ImageUpdaterDelegate delegate;
|
||||
@ -227,7 +228,7 @@ public class ImageUpdater implements NotificationCenter.NotificationCenterDelega
|
||||
openAttachMenu(onDismiss);
|
||||
return;
|
||||
}
|
||||
BottomSheet.Builder builder = new BottomSheet.Builder(parentFragment.getParentActivity());
|
||||
BottomSheet.NekoXBuilder builder = new BottomSheet.NekoXBuilder(parentFragment.getParentActivity());
|
||||
|
||||
if (type == TYPE_SET_PHOTO_FOR_USER) {
|
||||
builder.setTitle(LocaleController.formatString("SetPhotoFor", R.string.SetPhotoFor, user.first_name), true);
|
||||
@ -241,23 +242,29 @@ public class ImageUpdater implements NotificationCenter.NotificationCenterDelega
|
||||
ArrayList<Integer> icons = new ArrayList<>();
|
||||
ArrayList<Integer> ids = new ArrayList<>();
|
||||
|
||||
if (hasAvatar && parentFragment instanceof ProfileActivity) {
|
||||
items.add(LocaleController.getString("Open", R.string.Open));
|
||||
icons.add(R.drawable.baseline_visibility_24);
|
||||
ids.add(ID_OPEN_AVATAR);
|
||||
}
|
||||
|
||||
items.add(LocaleController.getString("UploadImage", R.string.UploadImage));
|
||||
icons.add(R.drawable.baseline_image_24);
|
||||
ids.add(ID_UPLOAD_FROM_GALLERY);
|
||||
|
||||
items.add(LocaleController.getString("ChooseTakePhoto", R.string.ChooseTakePhoto));
|
||||
icons.add(R.drawable.msg_camera);
|
||||
icons.add(R.drawable.baseline_camera_alt_24);
|
||||
ids.add(ID_TAKE_PHOTO);
|
||||
|
||||
if (canSelectVideo) {
|
||||
items.add(LocaleController.getString("ChooseRecordVideo", R.string.ChooseRecordVideo));
|
||||
icons.add(R.drawable.msg_video);
|
||||
icons.add(R.drawable.baseline_videocam_24);
|
||||
ids.add(ID_RECORD_VIDEO);
|
||||
}
|
||||
|
||||
items.add(LocaleController.getString("ChooseFromGallery", R.string.ChooseFromGallery));
|
||||
icons.add(R.drawable.msg_photos);
|
||||
ids.add(ID_UPLOAD_FROM_GALLERY);
|
||||
|
||||
if (searchAvailable) {
|
||||
items.add(LocaleController.getString("ChooseFromSearch", R.string.ChooseFromSearch));
|
||||
icons.add(R.drawable.msg_search);
|
||||
icons.add(R.drawable.baseline_search_24);
|
||||
ids.add(ID_SEARCH_WEB);
|
||||
}
|
||||
if (hasAvatar) {
|
||||
@ -274,6 +281,16 @@ public class ImageUpdater implements NotificationCenter.NotificationCenterDelega
|
||||
builder.setItems(items.toArray(new CharSequence[0]), iconsRes, (dialogInterface, i) -> {
|
||||
int id = ids.get(i);
|
||||
switch (id) {
|
||||
case ID_OPEN_AVATAR:
|
||||
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(UserConfig.getInstance(currentAccount).getClientUserId());
|
||||
if (user != null && user.photo != null && user.photo.photo_big != null) {
|
||||
PhotoViewer.getInstance().setParentActivity(parentFragment.getParentActivity());
|
||||
if (user.photo.dc_id != 0) {
|
||||
user.photo.photo_big.dc_id = user.photo.dc_id;
|
||||
}
|
||||
PhotoViewer.getInstance().openPhoto(user.photo.photo_big, ((ProfileActivity) parentFragment).provider);
|
||||
}
|
||||
break;
|
||||
case ID_TAKE_PHOTO:
|
||||
openCamera();
|
||||
break;
|
||||
@ -299,64 +316,6 @@ public class ImageUpdater implements NotificationCenter.NotificationCenterDelega
|
||||
}
|
||||
}
|
||||
|
||||
public void openMenu(boolean hasAvatar, Runnable onDeleteAvatar, DialogInterface.OnDismissListener onDismiss) {
|
||||
if (parentFragment == null || parentFragment.getParentActivity() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (useAttachMenu) {
|
||||
openAttachMenu(onDismiss);
|
||||
return;
|
||||
}
|
||||
|
||||
BottomBuilder builder = new BottomBuilder(parentFragment.getParentActivity());
|
||||
|
||||
if (hasAvatar && parentFragment instanceof ProfileActivity) {
|
||||
|
||||
builder.addItem(LocaleController.getString("Open", R.string.Open), R.drawable.baseline_visibility_24, __ -> {
|
||||
|
||||
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(UserConfig.getInstance(currentAccount).getClientUserId());
|
||||
if (user != null && user.photo != null && user.photo.photo_big != null) {
|
||||
PhotoViewer.getInstance().setParentActivity(parentFragment.getParentActivity());
|
||||
if (user.photo.dc_id != 0) {
|
||||
user.photo.photo_big.dc_id = user.photo.dc_id;
|
||||
}
|
||||
PhotoViewer.getInstance().openPhoto(user.photo.photo_big, ((ProfileActivity) parentFragment).provider);
|
||||
}
|
||||
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
builder.addItem(LocaleController.getString("UploadImage", R.string.UploadImage), R.drawable.baseline_image_24, __ -> {
|
||||
openAttachMenu(onDismiss);
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
|
||||
if (searchAvailable) {
|
||||
|
||||
builder.addItem(LocaleController.getString("ChooseFromSearch", R.string.ChooseFromSearch), R.drawable.baseline_search_24, __ -> {
|
||||
openSearch();
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (hasAvatar) {
|
||||
|
||||
builder.addItem(LocaleController.getString("DeletePhoto", R.string.DeletePhoto), R.drawable.baseline_delete_24, true, __ -> {
|
||||
onDeleteAvatar.run();
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
BottomSheet sheet = builder.create();
|
||||
sheet.setOnHideListener(onDismiss);
|
||||
parentFragment.showDialog(sheet);
|
||||
}
|
||||
|
||||
public void setSearchAvailable(boolean value) {
|
||||
useAttachMenu = searchAvailable = value;
|
||||
}
|
||||
|
@ -1119,8 +1119,10 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
imageUpdater.openMenu(user.photo != null && user.photo.photo_big != null && !(user.photo instanceof TLRPC.TL_userProfilePhotoEmpty), () -> MessagesController.getInstance(currentAccount).deleteUserPhoto(null), dialog -> {
|
||||
});
|
||||
imageUpdater.openMenu(
|
||||
user.photo != null && user.photo.photo_big != null && !(user.photo instanceof TLRPC.TL_userProfilePhotoEmpty),
|
||||
() -> MessagesController.getInstance(currentAccount).deleteUserPhoto(null), dialog -> {},
|
||||
ImageUpdater.TYPE_DEFAULT);
|
||||
} else {
|
||||
openAvatar();
|
||||
}
|
||||
@ -4733,7 +4735,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
|
||||
// avatarImage's onClick event should call this openAvatar method.
|
||||
if (userId == UserConfig.getInstance(currentAccount).getClientUserId() && imageUpdater != null) {
|
||||
imageUpdater.openMenu(false, () -> MessagesController.getInstance(currentAccount).deleteUserPhoto(null), dialog -> {
|
||||
});
|
||||
}, ImageUpdater.TYPE_DEFAULT);
|
||||
}
|
||||
}
|
||||
} else if (chatId != 0) {
|
||||
@ -4757,38 +4759,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
|
||||
private void onWriteButtonClick() {
|
||||
if (userId != 0) {
|
||||
if (imageUpdater != null) {
|
||||
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(UserConfig.getInstance(currentAccount).getClientUserId());
|
||||
if (user == null) {
|
||||
user = UserConfig.getInstance(currentAccount).getCurrentUser();
|
||||
}
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
imageUpdater.openMenu(user.photo != null && user.photo.photo_big != null && !(user.photo instanceof TLRPC.TL_userProfilePhotoEmpty), () -> {
|
||||
MessagesController.getInstance(currentAccount).deleteUserPhoto(null);
|
||||
cameraDrawable.setCurrentFrame(0);
|
||||
cellCameraDrawable.setCurrentFrame(0);
|
||||
}, dialog -> {
|
||||
if (!imageUpdater.isUploadingImage()) {
|
||||
cameraDrawable.setCustomEndFrame(86);
|
||||
cellCameraDrawable.setCustomEndFrame(86);
|
||||
writeButton.playAnimation();
|
||||
if (setAvatarCell != null) {
|
||||
setAvatarCell.getImageView().playAnimation();
|
||||
}
|
||||
} else {
|
||||
cameraDrawable.setCurrentFrame(0, false);
|
||||
cellCameraDrawable.setCurrentFrame(0, false);
|
||||
}
|
||||
}, 0);
|
||||
cameraDrawable.setCurrentFrame(0);
|
||||
cameraDrawable.setCustomEndFrame(43);
|
||||
cellCameraDrawable.setCurrentFrame(0);
|
||||
cellCameraDrawable.setCustomEndFrame(43);
|
||||
writeButton.playAnimation();
|
||||
if (setAvatarCell != null) {
|
||||
setAvatarCell.getImageView().playAnimation();
|
||||
}
|
||||
presentFragment(new ChangeNameActivity(resourcesProvider));
|
||||
} else {
|
||||
if (playProfileAnimation != 0 && parentLayout.getFragmentStack().get(parentLayout.getFragmentStack().size() - 2) instanceof ChatActivity) {
|
||||
finishFragment();
|
||||
|
@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#000000"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M17,10.5V7c0,-0.55 -0.45,-1 -1,-1H4c-0.55,0 -1,0.45 -1,1v10c0,0.55 0.45,1 1,1h12c0.55,0 1,-0.45 1,-1v-3.5l4,4v-11l-4,4z"/>
|
||||
</vector>
|
Loading…
Reference in New Issue
Block a user