use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatRightsEditActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (currentType == TYPE_ADMIN) {
actionBar.setTitle(LocaleController.getString("EditAdmin", R.string.EditAdmin));
} else {
actionBar.setTitle(LocaleController.getString("UserRestrictions", R.string.UserRestrictions));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if (checkDiscard()) {
finishFragment();
}
} else if (id == done_button) {
onDonePressed();
}
}
});
if (canEdit || !isChannel && currentChat.creator && UserObject.isUserSelf(currentUser)) {
ActionBarMenu menu = actionBar.createMenu();
menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56), LocaleController.getString("Done", R.string.Done));
}
fragmentView = new FrameLayout(context);
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
FrameLayout frameLayout = (FrameLayout) fragmentView;
fragmentView.setFocusableInTouchMode(true);
listView = new RecyclerListView(context);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
((DefaultItemAnimator) listView.getItemAnimator()).setDelayAnimations(false);
listView.setLayoutManager(linearLayoutManager);
listView.setAdapter(listViewAdapter = new ListAdapter(context));
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? RecyclerListView.SCROLLBAR_POSITION_LEFT : RecyclerListView.SCROLLBAR_POSITION_RIGHT);
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
});
listView.setOnItemClickListener((view, position) -> {
if (!canEdit && (!currentChat.creator || currentType != TYPE_ADMIN || position != anonymousRow)) {
return;
}
if (position == 0) {
Bundle args = new Bundle();
args.putLong("user_id", currentUser.id);
presentFragment(new ProfileActivity(args));
} else if (position == removeAdminRow) {
if (currentType == TYPE_ADMIN) {
MessagesController.getInstance(currentAccount).setUserAdminRole(chatId, currentUser, new TLRPC.TL_chatAdminRights(), currentRank, isChannel, getFragmentForAlert(0), isAddingNew);
if (delegate != null) {
delegate.didSetRights(0, adminRights, bannedRights, currentRank);
}
finishFragment();
} else if (currentType == TYPE_BANNED) {
bannedRights = new TLRPC.TL_chatBannedRights();
bannedRights.view_messages = true;
bannedRights.send_media = true;
bannedRights.send_messages = true;
bannedRights.send_stickers = true;
bannedRights.send_gifs = true;
bannedRights.send_games = true;
bannedRights.send_inline = true;
bannedRights.embed_links = true;
bannedRights.pin_messages = true;
bannedRights.send_polls = true;
bannedRights.invite_users = true;
bannedRights.change_info = true;
bannedRights.until_date = 0;
onDonePressed();
}
} else if (position == transferOwnerRow) {
initTransfer(null, null);
} else if (position == untilDateRow) {
if (getParentActivity() == null) {
return;
}
BottomSheet.Builder builder = new BottomSheet.Builder(context);
builder.setApplyTopPadding(false);
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
HeaderCell headerCell = new HeaderCell(context, Theme.key_dialogTextBlue2, 23, 15, false);
headerCell.setHeight(47);
headerCell.setText(LocaleController.getString("UserRestrictionsDuration", R.string.UserRestrictionsDuration));
linearLayout.addView(headerCell);
LinearLayout linearLayoutInviteContainer = new LinearLayout(context);
linearLayoutInviteContainer.setOrientation(LinearLayout.VERTICAL);
linearLayout.addView(linearLayoutInviteContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
BottomSheet.BottomSheetCell[] buttons = new BottomSheet.BottomSheetCell[5];
for (int a = 0; a < buttons.length; a++) {
buttons[a] = new BottomSheet.BottomSheetCell(context, 0);
buttons[a].setPadding(AndroidUtilities.dp(7), 0, AndroidUtilities.dp(7), 0);
buttons[a].setTag(a);
buttons[a].setBackgroundDrawable(Theme.getSelectorDrawable(false));
String text;
switch(a) {
case 0:
text = LocaleController.getString("UserRestrictionsUntilForever", R.string.UserRestrictionsUntilForever);
break;
case 1:
text = LocaleController.formatPluralString("Days", 1);
break;
case 2:
text = LocaleController.formatPluralString("Weeks", 1);
break;
case 3:
text = LocaleController.formatPluralString("Months", 1);
break;
case 4:
default:
text = LocaleController.getString("UserRestrictionsCustom", R.string.UserRestrictionsCustom);
break;
}
buttons[a].setTextAndIcon(text, 0);
linearLayoutInviteContainer.addView(buttons[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
buttons[a].setOnClickListener(v2 -> {
Integer tag = (Integer) v2.getTag();
switch(tag) {
case 0:
bannedRights.until_date = 0;
listViewAdapter.notifyItemChanged(untilDateRow);
break;
case 1:
bannedRights.until_date = ConnectionsManager.getInstance(currentAccount).getCurrentTime() + 60 * 60 * 24;
listViewAdapter.notifyItemChanged(untilDateRow);
break;
case 2:
bannedRights.until_date = ConnectionsManager.getInstance(currentAccount).getCurrentTime() + 60 * 60 * 24 * 7;
listViewAdapter.notifyItemChanged(untilDateRow);
break;
case 3:
bannedRights.until_date = ConnectionsManager.getInstance(currentAccount).getCurrentTime() + 60 * 60 * 24 * 30;
listViewAdapter.notifyItemChanged(untilDateRow);
break;
case 4:
{
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int monthOfYear = calendar.get(Calendar.MONTH);
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
try {
DatePickerDialog dialog = new DatePickerDialog(getParentActivity(), (view1, year1, month, dayOfMonth1) -> {
Calendar calendar1 = Calendar.getInstance();
calendar1.clear();
calendar1.set(year1, month, dayOfMonth1);
final int time = (int) (calendar1.getTime().getTime() / 1000);
try {
TimePickerDialog dialog13 = new TimePickerDialog(getParentActivity(), (view11, hourOfDay, minute) -> {
bannedRights.until_date = time + hourOfDay * 3600 + minute * 60;
listViewAdapter.notifyItemChanged(untilDateRow);
}, 0, 0, true);
dialog13.setButton(DialogInterface.BUTTON_POSITIVE, LocaleController.getString("Set", R.string.Set), dialog13);
dialog13.setButton(DialogInterface.BUTTON_NEGATIVE, LocaleController.getString("Cancel", R.string.Cancel), (dialog131, which) -> {
});
showDialog(dialog13);
} catch (Exception e) {
FileLog.e(e);
}
}, year, monthOfYear, dayOfMonth);
final DatePicker datePicker = dialog.getDatePicker();
Calendar date = Calendar.getInstance();
date.setTimeInMillis(System.currentTimeMillis());
date.set(Calendar.HOUR_OF_DAY, date.getMinimum(Calendar.HOUR_OF_DAY));
date.set(Calendar.MINUTE, date.getMinimum(Calendar.MINUTE));
date.set(Calendar.SECOND, date.getMinimum(Calendar.SECOND));
date.set(Calendar.MILLISECOND, date.getMinimum(Calendar.MILLISECOND));
datePicker.setMinDate(date.getTimeInMillis());
date.setTimeInMillis(System.currentTimeMillis() + 31536000000L);
date.set(Calendar.HOUR_OF_DAY, date.getMaximum(Calendar.HOUR_OF_DAY));
date.set(Calendar.MINUTE, date.getMaximum(Calendar.MINUTE));
date.set(Calendar.SECOND, date.getMaximum(Calendar.SECOND));
date.set(Calendar.MILLISECOND, date.getMaximum(Calendar.MILLISECOND));
datePicker.setMaxDate(date.getTimeInMillis());
dialog.setButton(DialogInterface.BUTTON_POSITIVE, LocaleController.getString("Set", R.string.Set), dialog);
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, LocaleController.getString("Cancel", R.string.Cancel), (dialog1, which) -> {
});
if (Build.VERSION.SDK_INT >= 21) {
dialog.setOnShowListener(dialog12 -> {
int count = datePicker.getChildCount();
for (int b = 0; b < count; b++) {
View child = datePicker.getChildAt(b);
ViewGroup.LayoutParams layoutParams = child.getLayoutParams();
layoutParams.width = LayoutHelper.MATCH_PARENT;
child.setLayoutParams(layoutParams);
}
});
}
showDialog(dialog);
} catch (Exception e) {
FileLog.e(e);
}
break;
}
}
builder.getDismissRunnable().run();
});
}
builder.setCustomView(linearLayout);
showDialog(builder.create());
} else if (view instanceof TextCheckCell2) {
TextCheckCell2 checkCell = (TextCheckCell2) view;
if (checkCell.hasIcon()) {
Toast.makeText(getParentActivity(), LocaleController.getString("UserRestrictionsDisabled", R.string.UserRestrictionsDisabled), Toast.LENGTH_SHORT).show();
return;
}
if (!checkCell.isEnabled()) {
return;
}
checkCell.setChecked(!checkCell.isChecked());
if (position == changeInfoRow) {
if (currentType == TYPE_ADMIN) {
adminRights.change_info = !adminRights.change_info;
} else {
bannedRights.change_info = !bannedRights.change_info;
}
} else if (position == postMessagesRow) {
adminRights.post_messages = !adminRights.post_messages;
} else if (position == editMesagesRow) {
adminRights.edit_messages = !adminRights.edit_messages;
} else if (position == deleteMessagesRow) {
adminRights.delete_messages = !adminRights.delete_messages;
} else if (position == addAdminsRow) {
adminRights.add_admins = !adminRights.add_admins;
} else if (position == anonymousRow) {
adminRights.anonymous = !adminRights.anonymous;
} else if (position == banUsersRow) {
adminRights.ban_users = !adminRights.ban_users;
} else if (position == startVoiceChatRow) {
adminRights.manage_call = !adminRights.manage_call;
} else if (position == addUsersRow) {
if (currentType == TYPE_ADMIN) {
adminRights.invite_users = !adminRights.invite_users;
} else {
bannedRights.invite_users = !bannedRights.invite_users;
}
} else if (position == pinMessagesRow) {
if (currentType == TYPE_ADMIN) {
adminRights.pin_messages = !adminRights.pin_messages;
} else {
bannedRights.pin_messages = !bannedRights.pin_messages;
}
} else if (bannedRights != null) {
boolean disabled = !checkCell.isChecked();
if (position == sendMessagesRow) {
bannedRights.send_messages = !bannedRights.send_messages;
} else if (position == sendMediaRow) {
bannedRights.send_media = !bannedRights.send_media;
} else if (position == sendStickersRow) {
bannedRights.send_stickers = bannedRights.send_games = bannedRights.send_gifs = bannedRights.send_inline = !bannedRights.send_stickers;
} else if (position == embedLinksRow) {
bannedRights.embed_links = !bannedRights.embed_links;
} else if (position == sendPollsRow) {
bannedRights.send_polls = !bannedRights.send_polls;
}
if (disabled) {
if (bannedRights.view_messages && !bannedRights.send_messages) {
bannedRights.send_messages = true;
RecyclerListView.ViewHolder holder = listView.findViewHolderForAdapterPosition(sendMessagesRow);
if (holder != null) {
((TextCheckCell2) holder.itemView).setChecked(false);
}
}
if ((bannedRights.view_messages || bannedRights.send_messages) && !bannedRights.send_media) {
bannedRights.send_media = true;
RecyclerListView.ViewHolder holder = listView.findViewHolderForAdapterPosition(sendMediaRow);
if (holder != null) {
((TextCheckCell2) holder.itemView).setChecked(false);
}
}
if ((bannedRights.view_messages || bannedRights.send_messages) && !bannedRights.send_polls) {
bannedRights.send_polls = true;
RecyclerListView.ViewHolder holder = listView.findViewHolderForAdapterPosition(sendPollsRow);
if (holder != null) {
((TextCheckCell2) holder.itemView).setChecked(false);
}
}
if ((bannedRights.view_messages || bannedRights.send_messages) && !bannedRights.send_stickers) {
bannedRights.send_stickers = bannedRights.send_games = bannedRights.send_gifs = bannedRights.send_inline = true;
RecyclerListView.ViewHolder holder = listView.findViewHolderForAdapterPosition(sendStickersRow);
if (holder != null) {
((TextCheckCell2) holder.itemView).setChecked(false);
}
}
if ((bannedRights.view_messages || bannedRights.send_messages) && !bannedRights.embed_links) {
bannedRights.embed_links = true;
RecyclerListView.ViewHolder holder = listView.findViewHolderForAdapterPosition(embedLinksRow);
if (holder != null) {
((TextCheckCell2) holder.itemView).setChecked(false);
}
}
} else {
if ((!bannedRights.send_messages || !bannedRights.embed_links || !bannedRights.send_inline || !bannedRights.send_media || !bannedRights.send_polls) && bannedRights.view_messages) {
bannedRights.view_messages = false;
}
if ((!bannedRights.embed_links || !bannedRights.send_inline || !bannedRights.send_media || !bannedRights.send_polls) && bannedRights.send_messages) {
bannedRights.send_messages = false;
RecyclerListView.ViewHolder holder = listView.findViewHolderForAdapterPosition(sendMessagesRow);
if (holder != null) {
((TextCheckCell2) holder.itemView).setChecked(true);
}
}
}
}
updateRows(true);
}
});
return fragmentView;
}
use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatUsersActivity method createView.
@Override
public View createView(Context context) {
searching = false;
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (type == TYPE_KICKED) {
actionBar.setTitle(LocaleController.getString("ChannelPermissions", R.string.ChannelPermissions));
} else if (type == TYPE_BANNED) {
actionBar.setTitle(LocaleController.getString("ChannelBlacklist", R.string.ChannelBlacklist));
} else if (type == TYPE_ADMIN) {
actionBar.setTitle(LocaleController.getString("ChannelAdministrators", R.string.ChannelAdministrators));
} else if (type == TYPE_USERS) {
if (selectType == SELECT_TYPE_MEMBERS) {
if (isChannel) {
actionBar.setTitle(LocaleController.getString("ChannelSubscribers", R.string.ChannelSubscribers));
} else {
actionBar.setTitle(LocaleController.getString("ChannelMembers", R.string.ChannelMembers));
}
} else {
if (selectType == SELECT_TYPE_ADMIN) {
actionBar.setTitle(LocaleController.getString("ChannelAddAdmin", R.string.ChannelAddAdmin));
} else if (selectType == SELECT_TYPE_BLOCK) {
actionBar.setTitle(LocaleController.getString("ChannelBlockUser", R.string.ChannelBlockUser));
} else if (selectType == SELECT_TYPE_EXCEPTION) {
actionBar.setTitle(LocaleController.getString("ChannelAddException", R.string.ChannelAddException));
}
}
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if (checkDiscard()) {
finishFragment();
}
} else if (id == done_button) {
processDone();
}
}
});
if (selectType != SELECT_TYPE_MEMBERS || type == TYPE_USERS || type == TYPE_BANNED || type == TYPE_KICKED) {
searchListViewAdapter = new SearchAdapter(context);
ActionBarMenu menu = actionBar.createMenu();
searchItem = menu.addItem(search_button, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
searching = true;
if (doneItem != null) {
doneItem.setVisibility(View.GONE);
}
}
@Override
public void onSearchCollapse() {
searchListViewAdapter.searchUsers(null);
searching = false;
listView.setAnimateEmptyView(false, 0);
listView.setAdapter(listViewAdapter);
listViewAdapter.notifyDataSetChanged();
listView.setFastScrollVisible(true);
listView.setVerticalScrollBarEnabled(false);
if (doneItem != null) {
doneItem.setVisibility(View.VISIBLE);
}
}
@Override
public void onTextChanged(EditText editText) {
if (searchListViewAdapter == null) {
return;
}
String text = editText.getText().toString();
int oldItemsCount = listView.getAdapter() == null ? 0 : listView.getAdapter().getItemCount();
searchListViewAdapter.searchUsers(text);
if (TextUtils.isEmpty(text) && listView != null && listView.getAdapter() != listViewAdapter) {
listView.setAnimateEmptyView(false, 0);
listView.setAdapter(listViewAdapter);
if (oldItemsCount == 0) {
showItemsAnimated(0);
}
}
progressBar.setVisibility(View.GONE);
flickerLoadingView.setVisibility(View.VISIBLE);
}
});
if (type == TYPE_KICKED) {
searchItem.setSearchFieldHint(LocaleController.getString("ChannelSearchException", R.string.ChannelSearchException));
} else {
searchItem.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));
}
if (!(ChatObject.isChannel(currentChat) || currentChat.creator)) {
searchItem.setVisibility(View.GONE);
}
if (type == TYPE_KICKED) {
doneItem = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56), LocaleController.getString("Done", R.string.Done));
}
}
fragmentView = new FrameLayout(context) {
@Override
protected void dispatchDraw(Canvas canvas) {
canvas.drawColor(Theme.getColor(listView.getAdapter() == searchListViewAdapter ? Theme.key_windowBackgroundWhite : Theme.key_windowBackgroundGray));
super.dispatchDraw(canvas);
}
};
FrameLayout frameLayout = (FrameLayout) fragmentView;
FrameLayout progressLayout = new FrameLayout(context);
flickerLoadingView = new FlickerLoadingView(context);
flickerLoadingView.setViewType(FlickerLoadingView.USERS_TYPE);
flickerLoadingView.showDate(false);
flickerLoadingView.setUseHeaderOffset(true);
progressLayout.addView(flickerLoadingView);
progressBar = new RadialProgressView(context);
progressLayout.addView(progressBar, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
flickerLoadingView.setVisibility(View.GONE);
progressBar.setVisibility(View.GONE);
emptyView = new StickerEmptyView(context, progressLayout, StickerEmptyView.STICKER_TYPE_SEARCH);
emptyView.title.setText(LocaleController.getString("NoResult", R.string.NoResult));
emptyView.subtitle.setText(LocaleController.getString("SearchEmptyViewFilteredSubtitle2", R.string.SearchEmptyViewFilteredSubtitle2));
emptyView.setVisibility(View.GONE);
emptyView.setAnimateLayoutChange(true);
emptyView.showProgress(true, false);
frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
emptyView.addView(progressLayout, 0);
listView = new RecyclerListView(context) {
@Override
public void invalidate() {
super.invalidate();
if (fragmentView != null) {
fragmentView.invalidate();
}
}
};
listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) {
@Override
public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
if (!firstLoaded && type == TYPE_BANNED && participants.size() == 0) {
return 0;
}
return super.scrollVerticallyBy(dy, recycler, state);
}
});
DefaultItemAnimator itemAnimator = new DefaultItemAnimator() {
@Override
protected long getAddAnimationDelay(long removeDuration, long moveDuration, long changeDuration) {
return 0;
}
@Override
protected long getMoveAnimationDelay() {
return 0;
}
@Override
public long getMoveDuration() {
return 220;
}
@Override
public long getRemoveDuration() {
return 220;
}
@Override
public long getAddDuration() {
return 220;
}
int animationIndex = -1;
@Override
protected void onAllAnimationsDone() {
super.onAllAnimationsDone();
getNotificationCenter().onAnimationFinish(animationIndex);
}
@Override
public void runPendingAnimations() {
boolean removalsPending = !mPendingRemovals.isEmpty();
boolean movesPending = !mPendingMoves.isEmpty();
boolean changesPending = !mPendingChanges.isEmpty();
boolean additionsPending = !mPendingAdditions.isEmpty();
if (removalsPending || movesPending || additionsPending || changesPending) {
animationIndex = getNotificationCenter().setAnimationInProgress(animationIndex, null);
}
super.runPendingAnimations();
}
};
listView.setItemAnimator(itemAnimator);
itemAnimator.setSupportsChangeAnimations(false);
listView.setAnimateEmptyView(true, 0);
listView.setAdapter(listViewAdapter = new ListAdapter(context));
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? RecyclerListView.SCROLLBAR_POSITION_LEFT : RecyclerListView.SCROLLBAR_POSITION_RIGHT);
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView.setOnItemClickListener((view, position) -> {
boolean listAdapter = listView.getAdapter() == listViewAdapter;
if (listAdapter) {
if (position == addNewRow) {
if (type == TYPE_BANNED || type == TYPE_KICKED) {
Bundle bundle = new Bundle();
bundle.putLong("chat_id", chatId);
bundle.putInt("type", ChatUsersActivity.TYPE_USERS);
bundle.putInt("selectType", type == TYPE_BANNED ? ChatUsersActivity.SELECT_TYPE_BLOCK : ChatUsersActivity.SELECT_TYPE_EXCEPTION);
ChatUsersActivity fragment = new ChatUsersActivity(bundle);
fragment.setInfo(info);
fragment.setDelegate(new ChatUsersActivityDelegate() {
@Override
public void didAddParticipantToList(long uid, TLObject participant) {
if (participantsMap.get(uid) == null) {
DiffCallback diffCallback = saveState();
participants.add(participant);
participantsMap.put(uid, participant);
sortUsers(participants);
updateListAnimated(diffCallback);
}
}
@Override
public void didKickParticipant(long uid) {
if (participantsMap.get(uid) == null) {
DiffCallback diffCallback = saveState();
TLRPC.TL_channelParticipantBanned chatParticipant = new TLRPC.TL_channelParticipantBanned();
if (uid > 0) {
chatParticipant.peer = new TLRPC.TL_peerUser();
chatParticipant.peer.user_id = uid;
} else {
chatParticipant.peer = new TLRPC.TL_peerChannel();
chatParticipant.peer.channel_id = -uid;
}
chatParticipant.date = getConnectionsManager().getCurrentTime();
chatParticipant.kicked_by = getAccountInstance().getUserConfig().clientUserId;
info.kicked_count++;
participants.add(chatParticipant);
participantsMap.put(uid, chatParticipant);
sortUsers(participants);
updateListAnimated(diffCallback);
}
}
});
presentFragment(fragment);
} else if (type == TYPE_ADMIN) {
Bundle bundle = new Bundle();
bundle.putLong("chat_id", chatId);
bundle.putInt("type", ChatUsersActivity.TYPE_USERS);
bundle.putInt("selectType", ChatUsersActivity.SELECT_TYPE_ADMIN);
ChatUsersActivity fragment = new ChatUsersActivity(bundle);
fragment.setDelegate(new ChatUsersActivityDelegate() {
@Override
public void didAddParticipantToList(long uid, TLObject participant) {
if (participant != null && participantsMap.get(uid) == null) {
DiffCallback diffCallback = saveState();
participants.add(participant);
participantsMap.put(uid, participant);
sortAdmins(participants);
updateListAnimated(diffCallback);
}
}
@Override
public void didChangeOwner(TLRPC.User user) {
onOwnerChaged(user);
}
@Override
public void didSelectUser(long uid) {
final TLRPC.User user = getMessagesController().getUser(uid);
if (user != null) {
AndroidUtilities.runOnUIThread(() -> {
if (BulletinFactory.canShowBulletin(ChatUsersActivity.this)) {
BulletinFactory.createPromoteToAdminBulletin(ChatUsersActivity.this, user.first_name).show();
}
}, 200);
}
if (participantsMap.get(uid) == null) {
DiffCallback diffCallback = saveState();
TLRPC.TL_channelParticipantAdmin chatParticipant = new TLRPC.TL_channelParticipantAdmin();
chatParticipant.peer = new TLRPC.TL_peerUser();
chatParticipant.peer.user_id = user.id;
chatParticipant.date = getConnectionsManager().getCurrentTime();
chatParticipant.promoted_by = getAccountInstance().getUserConfig().clientUserId;
participants.add(chatParticipant);
participantsMap.put(user.id, chatParticipant);
sortAdmins(participants);
updateListAnimated(diffCallback);
}
}
});
fragment.setInfo(info);
presentFragment(fragment);
} else if (type == TYPE_USERS) {
Bundle args = new Bundle();
args.putBoolean("addToGroup", true);
args.putLong(isChannel ? "channelId" : "chatId", currentChat.id);
GroupCreateActivity fragment = new GroupCreateActivity(args);
fragment.setInfo(info);
fragment.setIgnoreUsers(contactsMap != null && contactsMap.size() != 0 ? contactsMap : participantsMap);
fragment.setDelegate(new GroupCreateActivity.ContactsAddActivityDelegate() {
@Override
public void didSelectUsers(ArrayList<TLRPC.User> users, int fwdCount) {
DiffCallback savedState = saveState();
ArrayList<TLObject> array = contactsMap != null && contactsMap.size() != 0 ? contacts : participants;
LongSparseArray<TLObject> map = contactsMap != null && contactsMap.size() != 0 ? contactsMap : participantsMap;
int k = 0;
for (int a = 0, N = users.size(); a < N; a++) {
TLRPC.User user = users.get(a);
getMessagesController().addUserToChat(chatId, user, fwdCount, null, ChatUsersActivity.this, null);
getMessagesController().putUser(user, false);
if (map.get(user.id) == null) {
if (ChatObject.isChannel(currentChat)) {
TLRPC.TL_channelParticipant channelParticipant1 = new TLRPC.TL_channelParticipant();
channelParticipant1.inviter_id = getUserConfig().getClientUserId();
channelParticipant1.peer = new TLRPC.TL_peerUser();
channelParticipant1.peer.user_id = user.id;
channelParticipant1.date = getConnectionsManager().getCurrentTime();
array.add(k, channelParticipant1);
k++;
map.put(user.id, channelParticipant1);
} else {
TLRPC.ChatParticipant participant = new TLRPC.TL_chatParticipant();
participant.user_id = user.id;
participant.inviter_id = getUserConfig().getClientUserId();
array.add(k, participant);
k++;
map.put(user.id, participant);
}
}
}
if (array == participants) {
sortAdmins(participants);
}
updateListAnimated(savedState);
}
@Override
public void needAddBot(TLRPC.User user) {
openRightsEdit(user.id, null, null, null, "", true, ChatRightsEditActivity.TYPE_ADMIN, false);
}
});
presentFragment(fragment);
}
return;
} else if (position == recentActionsRow) {
presentFragment(new ChannelAdminLogActivity(currentChat));
return;
} else if (position == removedUsersRow) {
Bundle args = new Bundle();
args.putLong("chat_id", chatId);
args.putInt("type", ChatUsersActivity.TYPE_BANNED);
ChatUsersActivity fragment = new ChatUsersActivity(args);
fragment.setInfo(info);
presentFragment(fragment);
return;
} else if (position == gigaConvertRow) {
showDialog(new GigagroupConvertAlert(getParentActivity(), ChatUsersActivity.this) {
@Override
protected void onCovert() {
getMessagesController().convertToGigaGroup(getParentActivity(), currentChat, ChatUsersActivity.this, (result) -> {
if (result && parentLayout != null) {
BaseFragment editActivity = parentLayout.fragmentsStack.get(parentLayout.fragmentsStack.size() - 2);
if (editActivity instanceof ChatEditActivity) {
editActivity.removeSelfFromStack();
Bundle args = new Bundle();
args.putLong("chat_id", chatId);
ChatEditActivity fragment = new ChatEditActivity(args);
fragment.setInfo(info);
parentLayout.addFragmentToStack(fragment, parentLayout.fragmentsStack.size() - 1);
finishFragment();
fragment.showConvertTooltip();
} else {
finishFragment();
}
}
});
}
@Override
protected void onCancel() {
}
});
} else if (position == addNew2Row) {
ManageLinksActivity fragment = new ManageLinksActivity(chatId, 0, 0);
fragment.setInfo(info, info.exported_invite);
presentFragment(fragment);
return;
} else if (position > permissionsSectionRow && position <= changeInfoRow) {
TextCheckCell2 checkCell = (TextCheckCell2) view;
if (!checkCell.isEnabled()) {
return;
}
if (checkCell.hasIcon()) {
if (!TextUtils.isEmpty(currentChat.username) && (position == pinMessagesRow || position == changeInfoRow)) {
BulletinFactory.of(this).createErrorBulletin(LocaleController.getString("EditCantEditPermissionsPublic", R.string.EditCantEditPermissionsPublic)).show();
} else {
BulletinFactory.of(this).createErrorBulletin(LocaleController.getString("EditCantEditPermissions", R.string.EditCantEditPermissions)).show();
}
return;
}
checkCell.setChecked(!checkCell.isChecked());
if (position == changeInfoRow) {
defaultBannedRights.change_info = !defaultBannedRights.change_info;
} else if (position == addUsersRow) {
defaultBannedRights.invite_users = !defaultBannedRights.invite_users;
} else if (position == pinMessagesRow) {
defaultBannedRights.pin_messages = !defaultBannedRights.pin_messages;
} else {
boolean disabled = !checkCell.isChecked();
if (position == sendMessagesRow) {
defaultBannedRights.send_messages = !defaultBannedRights.send_messages;
} else if (position == sendMediaRow) {
defaultBannedRights.send_media = !defaultBannedRights.send_media;
} else if (position == sendStickersRow) {
defaultBannedRights.send_stickers = defaultBannedRights.send_games = defaultBannedRights.send_gifs = defaultBannedRights.send_inline = !defaultBannedRights.send_stickers;
} else if (position == embedLinksRow) {
defaultBannedRights.embed_links = !defaultBannedRights.embed_links;
} else if (position == sendPollsRow) {
defaultBannedRights.send_polls = !defaultBannedRights.send_polls;
}
if (disabled) {
if (defaultBannedRights.view_messages && !defaultBannedRights.send_messages) {
defaultBannedRights.send_messages = true;
RecyclerListView.ViewHolder holder = listView.findViewHolderForAdapterPosition(sendMessagesRow);
if (holder != null) {
((TextCheckCell2) holder.itemView).setChecked(false);
}
}
if ((defaultBannedRights.view_messages || defaultBannedRights.send_messages) && !defaultBannedRights.send_media) {
defaultBannedRights.send_media = true;
RecyclerListView.ViewHolder holder = listView.findViewHolderForAdapterPosition(sendMediaRow);
if (holder != null) {
((TextCheckCell2) holder.itemView).setChecked(false);
}
}
if ((defaultBannedRights.view_messages || defaultBannedRights.send_messages) && !defaultBannedRights.send_polls) {
defaultBannedRights.send_polls = true;
RecyclerListView.ViewHolder holder = listView.findViewHolderForAdapterPosition(sendPollsRow);
if (holder != null) {
((TextCheckCell2) holder.itemView).setChecked(false);
}
}
if ((defaultBannedRights.view_messages || defaultBannedRights.send_messages) && !defaultBannedRights.send_stickers) {
defaultBannedRights.send_stickers = defaultBannedRights.send_games = defaultBannedRights.send_gifs = defaultBannedRights.send_inline = true;
RecyclerListView.ViewHolder holder = listView.findViewHolderForAdapterPosition(sendStickersRow);
if (holder != null) {
((TextCheckCell2) holder.itemView).setChecked(false);
}
}
if ((defaultBannedRights.view_messages || defaultBannedRights.send_messages) && !defaultBannedRights.embed_links) {
defaultBannedRights.embed_links = true;
RecyclerListView.ViewHolder holder = listView.findViewHolderForAdapterPosition(embedLinksRow);
if (holder != null) {
((TextCheckCell2) holder.itemView).setChecked(false);
}
}
} else {
if ((!defaultBannedRights.embed_links || !defaultBannedRights.send_inline || !defaultBannedRights.send_media || !defaultBannedRights.send_polls) && defaultBannedRights.send_messages) {
defaultBannedRights.send_messages = false;
RecyclerListView.ViewHolder holder = listView.findViewHolderForAdapterPosition(sendMessagesRow);
if (holder != null) {
((TextCheckCell2) holder.itemView).setChecked(true);
}
}
}
}
return;
}
}
TLRPC.TL_chatBannedRights bannedRights = null;
TLRPC.TL_chatAdminRights adminRights = null;
String rank = "";
final TLObject participant;
long peerId = 0;
long promoted_by = 0;
boolean canEditAdmin = false;
if (listAdapter) {
participant = listViewAdapter.getItem(position);
if (participant instanceof TLRPC.ChannelParticipant) {
TLRPC.ChannelParticipant channelParticipant = (TLRPC.ChannelParticipant) participant;
peerId = MessageObject.getPeerId(channelParticipant.peer);
bannedRights = channelParticipant.banned_rights;
adminRights = channelParticipant.admin_rights;
rank = channelParticipant.rank;
canEditAdmin = !(channelParticipant instanceof TLRPC.TL_channelParticipantAdmin || channelParticipant instanceof TLRPC.TL_channelParticipantCreator) || channelParticipant.can_edit;
if (participant instanceof TLRPC.TL_channelParticipantCreator) {
adminRights = ((TLRPC.TL_channelParticipantCreator) participant).admin_rights;
if (adminRights == null) {
adminRights = new TLRPC.TL_chatAdminRights();
adminRights.change_info = adminRights.post_messages = adminRights.edit_messages = adminRights.delete_messages = adminRights.ban_users = adminRights.invite_users = adminRights.pin_messages = adminRights.add_admins = true;
if (!isChannel) {
adminRights.manage_call = true;
}
}
}
} else if (participant instanceof TLRPC.ChatParticipant) {
TLRPC.ChatParticipant chatParticipant = (TLRPC.ChatParticipant) participant;
peerId = chatParticipant.user_id;
canEditAdmin = currentChat.creator;
if (participant instanceof TLRPC.TL_chatParticipantCreator) {
adminRights = new TLRPC.TL_chatAdminRights();
adminRights.change_info = adminRights.post_messages = adminRights.edit_messages = adminRights.delete_messages = adminRights.ban_users = adminRights.invite_users = adminRights.pin_messages = adminRights.add_admins = true;
if (!isChannel) {
adminRights.manage_call = true;
}
}
}
} else {
TLObject object = searchListViewAdapter.getItem(position);
if (object instanceof TLRPC.User) {
TLRPC.User user = (TLRPC.User) object;
getMessagesController().putUser(user, false);
participant = getAnyParticipant(peerId = user.id);
} else if (object instanceof TLRPC.ChannelParticipant || object instanceof TLRPC.ChatParticipant) {
participant = object;
} else {
participant = null;
}
if (participant instanceof TLRPC.ChannelParticipant) {
TLRPC.ChannelParticipant channelParticipant = (TLRPC.ChannelParticipant) participant;
peerId = MessageObject.getPeerId(channelParticipant.peer);
canEditAdmin = !(channelParticipant instanceof TLRPC.TL_channelParticipantAdmin || channelParticipant instanceof TLRPC.TL_channelParticipantCreator) || channelParticipant.can_edit;
bannedRights = channelParticipant.banned_rights;
adminRights = channelParticipant.admin_rights;
rank = channelParticipant.rank;
} else if (participant instanceof TLRPC.ChatParticipant) {
TLRPC.ChatParticipant chatParticipant = (TLRPC.ChatParticipant) participant;
peerId = chatParticipant.user_id;
canEditAdmin = currentChat.creator;
bannedRights = null;
adminRights = null;
} else if (participant == null) {
canEditAdmin = true;
}
}
if (peerId != 0) {
if (selectType != SELECT_TYPE_MEMBERS) {
if (selectType == SELECT_TYPE_EXCEPTION || selectType == SELECT_TYPE_ADMIN) {
if (selectType != SELECT_TYPE_ADMIN && canEditAdmin && (participant instanceof TLRPC.TL_channelParticipantAdmin || participant instanceof TLRPC.TL_chatParticipantAdmin)) {
final TLRPC.User user = getMessagesController().getUser(peerId);
final TLRPC.TL_chatBannedRights br = bannedRights;
final TLRPC.TL_chatAdminRights ar = adminRights;
final boolean canEdit = canEditAdmin;
final String rankFinal = rank;
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(LocaleController.formatString("AdminWillBeRemoved", R.string.AdminWillBeRemoved, UserObject.getUserName(user)));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialog, which) -> openRightsEdit(user.id, participant, ar, br, rankFinal, canEdit, selectType == SELECT_TYPE_ADMIN ? 0 : 1, false));
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
} else {
openRightsEdit(peerId, participant, adminRights, bannedRights, rank, canEditAdmin, selectType == SELECT_TYPE_ADMIN ? 0 : 1, selectType == SELECT_TYPE_ADMIN || selectType == SELECT_TYPE_EXCEPTION);
}
} else {
removeParticipant(peerId);
}
} else {
boolean canEdit = false;
if (type == TYPE_ADMIN) {
canEdit = peerId != getUserConfig().getClientUserId() && (currentChat.creator || canEditAdmin);
} else if (type == TYPE_BANNED || type == TYPE_KICKED) {
canEdit = ChatObject.canBlockUsers(currentChat);
}
if (type == TYPE_BANNED || type != TYPE_ADMIN && isChannel || type == TYPE_USERS && selectType == SELECT_TYPE_MEMBERS) {
if (peerId == getUserConfig().getClientUserId()) {
return;
}
Bundle args = new Bundle();
if (peerId > 0) {
args.putLong("user_id", peerId);
} else {
args.putLong("chat_id", -peerId);
}
presentFragment(new ProfileActivity(args));
} else {
if (bannedRights == null) {
bannedRights = new TLRPC.TL_chatBannedRights();
bannedRights.view_messages = true;
bannedRights.send_stickers = true;
bannedRights.send_media = true;
bannedRights.embed_links = true;
bannedRights.send_messages = true;
bannedRights.send_games = true;
bannedRights.send_inline = true;
bannedRights.send_gifs = true;
bannedRights.pin_messages = true;
bannedRights.send_polls = true;
bannedRights.invite_users = true;
bannedRights.change_info = true;
}
ChatRightsEditActivity fragment = new ChatRightsEditActivity(peerId, chatId, adminRights, defaultBannedRights, bannedRights, rank, type == TYPE_ADMIN ? ChatRightsEditActivity.TYPE_ADMIN : ChatRightsEditActivity.TYPE_BANNED, canEdit, participant == null);
fragment.setDelegate(new ChatRightsEditActivity.ChatRightsEditActivityDelegate() {
@Override
public void didSetRights(int rights, TLRPC.TL_chatAdminRights rightsAdmin, TLRPC.TL_chatBannedRights rightsBanned, String rank) {
if (participant instanceof TLRPC.ChannelParticipant) {
TLRPC.ChannelParticipant channelParticipant = (TLRPC.ChannelParticipant) participant;
channelParticipant.admin_rights = rightsAdmin;
channelParticipant.banned_rights = rightsBanned;
channelParticipant.rank = rank;
updateParticipantWithRights(channelParticipant, rightsAdmin, rightsBanned, 0, false);
}
}
@Override
public void didChangeOwner(TLRPC.User user) {
onOwnerChaged(user);
}
});
presentFragment(fragment);
}
}
}
});
listView.setOnItemLongClickListener((view, position) -> !(getParentActivity() == null || listView.getAdapter() != listViewAdapter) && createMenuForParticipant(listViewAdapter.getItem(position), false));
if (searchItem != null) {
listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
}
});
}
undoView = new UndoView(context);
frameLayout.addView(undoView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 8, 0, 8, 8));
updateRows();
listView.setEmptyView(emptyView);
listView.setAnimateEmptyView(false, 0);
if (needOpenSearch) {
searchItem.openSearch(false);
}
return fragmentView;
}
use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatEditActivity method createView.
@Override
public View createView(Context context) {
if (nameTextView != null) {
nameTextView.onDestroy();
}
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if (checkDiscard()) {
finishFragment();
}
} else if (id == done_button) {
processDone();
}
}
});
SizeNotifierFrameLayout sizeNotifierFrameLayout = new SizeNotifierFrameLayout(context) {
private boolean ignoreLayout;
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(widthSize, heightSize);
heightSize -= getPaddingTop();
measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0);
int keyboardSize = measureKeyboardHeight();
if (keyboardSize > AndroidUtilities.dp(20)) {
ignoreLayout = true;
nameTextView.hideEmojiView();
ignoreLayout = false;
}
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
if (child == null || child.getVisibility() == GONE || child == actionBar) {
continue;
}
if (nameTextView != null && nameTextView.isPopupView(child)) {
if (AndroidUtilities.isInMultiwindow || AndroidUtilities.isTablet()) {
if (AndroidUtilities.isTablet()) {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(Math.min(AndroidUtilities.dp(AndroidUtilities.isTablet() ? 200 : 320), heightSize - AndroidUtilities.statusBarHeight + getPaddingTop()), MeasureSpec.EXACTLY));
} else {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize - AndroidUtilities.statusBarHeight + getPaddingTop(), MeasureSpec.EXACTLY));
}
} else {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(child.getLayoutParams().height, MeasureSpec.EXACTLY));
}
} else {
measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
}
}
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int count = getChildCount();
int keyboardSize = measureKeyboardHeight();
int paddingBottom = keyboardSize <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow && !AndroidUtilities.isTablet() ? nameTextView.getEmojiPadding() : 0;
setBottomClip(paddingBottom);
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() == GONE) {
continue;
}
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final int width = child.getMeasuredWidth();
final int height = child.getMeasuredHeight();
int childLeft;
int childTop;
int gravity = lp.gravity;
if (gravity == -1) {
gravity = Gravity.TOP | Gravity.LEFT;
}
final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
switch(absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.CENTER_HORIZONTAL:
childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin;
break;
case Gravity.RIGHT:
childLeft = r - width - lp.rightMargin;
break;
case Gravity.LEFT:
default:
childLeft = lp.leftMargin;
}
switch(verticalGravity) {
case Gravity.TOP:
childTop = lp.topMargin + getPaddingTop();
break;
case Gravity.CENTER_VERTICAL:
childTop = ((b - paddingBottom) - t - height) / 2 + lp.topMargin - lp.bottomMargin;
break;
case Gravity.BOTTOM:
childTop = ((b - paddingBottom) - t) - height - lp.bottomMargin;
break;
default:
childTop = lp.topMargin;
}
if (nameTextView != null && nameTextView.isPopupView(child)) {
if (AndroidUtilities.isTablet()) {
childTop = getMeasuredHeight() - child.getMeasuredHeight();
} else {
childTop = getMeasuredHeight() + keyboardSize - child.getMeasuredHeight();
}
}
child.layout(childLeft, childTop, childLeft + width, childTop + height);
}
notifyHeightChanged();
}
@Override
public void requestLayout() {
if (ignoreLayout) {
return;
}
super.requestLayout();
}
};
sizeNotifierFrameLayout.setOnTouchListener((v, event) -> true);
fragmentView = sizeNotifierFrameLayout;
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
ScrollView scrollView = new ScrollView(context);
scrollView.setFillViewport(true);
sizeNotifierFrameLayout.addView(scrollView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
LinearLayout linearLayout1 = new LinearLayout(context);
scrollView.addView(linearLayout1, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
linearLayout1.setOrientation(LinearLayout.VERTICAL);
actionBar.setTitle(LocaleController.getString("ChannelEdit", R.string.ChannelEdit));
avatarContainer = new LinearLayout(context);
avatarContainer.setOrientation(LinearLayout.VERTICAL);
avatarContainer.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
linearLayout1.addView(avatarContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
FrameLayout frameLayout = new FrameLayout(context);
avatarContainer.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
avatarImage = new BackupImageView(context) {
@Override
public void invalidate() {
if (avatarOverlay != null) {
avatarOverlay.invalidate();
}
super.invalidate();
}
@Override
public void invalidate(int l, int t, int r, int b) {
if (avatarOverlay != null) {
avatarOverlay.invalidate();
}
super.invalidate(l, t, r, b);
}
};
avatarImage.setRoundRadius(AndroidUtilities.dp(32));
if (ChatObject.canChangeChatInfo(currentChat)) {
frameLayout.addView(avatarImage, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 8));
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(0x55000000);
avatarOverlay = new View(context) {
@Override
protected void onDraw(Canvas canvas) {
if (avatarImage != null && avatarImage.getImageReceiver().hasNotThumb()) {
paint.setAlpha((int) (0x55 * avatarImage.getImageReceiver().getCurrentAlpha()));
canvas.drawCircle(getMeasuredWidth() / 2.0f, getMeasuredHeight() / 2.0f, getMeasuredWidth() / 2.0f, paint);
}
}
};
frameLayout.addView(avatarOverlay, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 8));
avatarProgressView = new RadialProgressView(context);
avatarProgressView.setSize(AndroidUtilities.dp(30));
avatarProgressView.setProgressColor(0xffffffff);
avatarProgressView.setNoProgress(false);
frameLayout.addView(avatarProgressView, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 8));
showAvatarProgress(false, false);
avatarContainer.setOnClickListener(v -> {
if (imageUpdater.isUploadingImage()) {
return;
}
TLRPC.Chat chat = getMessagesController().getChat(chatId);
if (chat.photo != null && chat.photo.photo_big != null) {
PhotoViewer.getInstance().setParentActivity(getParentActivity());
if (chat.photo.dc_id != 0) {
chat.photo.photo_big.dc_id = chat.photo.dc_id;
}
ImageLocation videoLocation;
if (info != null && (info.chat_photo instanceof TLRPC.TL_photo) && !info.chat_photo.video_sizes.isEmpty()) {
videoLocation = ImageLocation.getForPhoto(info.chat_photo.video_sizes.get(0), info.chat_photo);
} else {
videoLocation = null;
}
PhotoViewer.getInstance().openPhotoWithVideo(chat.photo.photo_big, videoLocation, provider);
}
});
} else {
frameLayout.addView(avatarImage, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 12));
}
nameTextView = new EditTextEmoji(context, sizeNotifierFrameLayout, this, EditTextEmoji.STYLE_FRAGMENT);
if (isChannel) {
nameTextView.setHint(LocaleController.getString("EnterChannelName", R.string.EnterChannelName));
} else {
nameTextView.setHint(LocaleController.getString("GroupName", R.string.GroupName));
}
nameTextView.setEnabled(ChatObject.canChangeChatInfo(currentChat));
nameTextView.setFocusable(nameTextView.isEnabled());
nameTextView.getEditText().addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
avatarDrawable.setInfo(5, nameTextView.getText().toString(), null);
if (avatarImage != null) {
avatarImage.invalidate();
}
}
});
InputFilter[] inputFilters = new InputFilter[1];
inputFilters[0] = new InputFilter.LengthFilter(128);
nameTextView.setFilters(inputFilters);
frameLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 5 : 96, 0, LocaleController.isRTL ? 96 : 5, 0));
settingsContainer = new LinearLayout(context);
settingsContainer.setOrientation(LinearLayout.VERTICAL);
settingsContainer.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
linearLayout1.addView(settingsContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
if (ChatObject.canChangeChatInfo(currentChat)) {
setAvatarCell = new TextCell(context) {
@Override
protected void onDraw(Canvas canvas) {
canvas.drawLine(LocaleController.isRTL ? 0 : AndroidUtilities.dp(20), getMeasuredHeight() - 1, getMeasuredWidth() - (LocaleController.isRTL ? AndroidUtilities.dp(20) : 0), getMeasuredHeight() - 1, Theme.dividerPaint);
}
};
setAvatarCell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
setAvatarCell.setColors(Theme.key_windowBackgroundWhiteBlueIcon, Theme.key_windowBackgroundWhiteBlueButton);
setAvatarCell.setOnClickListener(v -> {
imageUpdater.openMenu(avatar != null, () -> {
avatar = null;
MessagesController.getInstance(currentAccount).changeChatAvatar(chatId, null, null, null, 0, null, null, null, null);
showAvatarProgress(false, true);
avatarImage.setImage(null, null, avatarDrawable, currentChat);
cameraDrawable.setCurrentFrame(0);
setAvatarCell.imageView.playAnimation();
}, dialogInterface -> {
if (!imageUpdater.isUploadingImage()) {
cameraDrawable.setCustomEndFrame(86);
setAvatarCell.imageView.playAnimation();
} else {
cameraDrawable.setCurrentFrame(0, false);
}
});
cameraDrawable.setCurrentFrame(0);
cameraDrawable.setCustomEndFrame(43);
setAvatarCell.imageView.playAnimation();
});
settingsContainer.addView(setAvatarCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
}
descriptionTextView = new EditTextBoldCursor(context);
descriptionTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
descriptionTextView.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
descriptionTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
descriptionTextView.setPadding(0, 0, 0, AndroidUtilities.dp(6));
descriptionTextView.setBackgroundDrawable(null);
descriptionTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
descriptionTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
descriptionTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
descriptionTextView.setEnabled(ChatObject.canChangeChatInfo(currentChat));
descriptionTextView.setFocusable(descriptionTextView.isEnabled());
inputFilters = new InputFilter[1];
inputFilters[0] = new InputFilter.LengthFilter(255);
descriptionTextView.setFilters(inputFilters);
descriptionTextView.setHint(LocaleController.getString("DescriptionOptionalPlaceholder", R.string.DescriptionOptionalPlaceholder));
descriptionTextView.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
descriptionTextView.setCursorSize(AndroidUtilities.dp(20));
descriptionTextView.setCursorWidth(1.5f);
if (descriptionTextView.isEnabled()) {
settingsContainer.addView(descriptionTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 23, 15, 23, 9));
} else {
settingsContainer.addView(descriptionTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 23, 12, 23, 6));
}
descriptionTextView.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
doneButton.performClick();
return true;
}
return false;
});
descriptionTextView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void afterTextChanged(Editable editable) {
}
});
settingsTopSectionCell = new ShadowSectionCell(context);
linearLayout1.addView(settingsTopSectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
typeEditContainer = new LinearLayout(context);
typeEditContainer.setOrientation(LinearLayout.VERTICAL);
typeEditContainer.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
linearLayout1.addView(typeEditContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
if (currentChat.megagroup && (info == null || info.can_set_location)) {
locationCell = new TextDetailCell(context);
locationCell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
typeEditContainer.addView(locationCell, LayoutHelper.createLinear(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
locationCell.setOnClickListener(v -> {
if (!AndroidUtilities.isGoogleMapsInstalled(ChatEditActivity.this)) {
return;
}
LocationActivity fragment = new LocationActivity(LocationActivity.LOCATION_TYPE_GROUP);
fragment.setDialogId(-chatId);
if (info != null && info.location instanceof TLRPC.TL_channelLocation) {
fragment.setInitialLocation((TLRPC.TL_channelLocation) info.location);
}
fragment.setDelegate((location, live, notify, scheduleDate) -> {
TLRPC.TL_channelLocation channelLocation = new TLRPC.TL_channelLocation();
channelLocation.address = location.address;
channelLocation.geo_point = location.geo;
info.location = channelLocation;
info.flags |= 32768;
updateFields(false);
getMessagesController().loadFullChat(chatId, 0, true);
});
presentFragment(fragment);
});
}
if (currentChat.creator && (info == null || info.can_set_username)) {
typeCell = new TextDetailCell(context);
typeCell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
typeEditContainer.addView(typeCell, LayoutHelper.createLinear(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
typeCell.setOnClickListener(v -> {
ChatEditTypeActivity fragment = new ChatEditTypeActivity(chatId, locationCell != null && locationCell.getVisibility() == View.VISIBLE);
fragment.setInfo(info);
presentFragment(fragment);
});
}
if (ChatObject.isChannel(currentChat) && (isChannel && ChatObject.canUserDoAdminAction(currentChat, ChatObject.ACTION_CHANGE_INFO) || !isChannel && ChatObject.canUserDoAdminAction(currentChat, ChatObject.ACTION_PIN))) {
linkedCell = new TextDetailCell(context);
linkedCell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
typeEditContainer.addView(linkedCell, LayoutHelper.createLinear(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
linkedCell.setOnClickListener(v -> {
ChatLinkActivity fragment = new ChatLinkActivity(chatId);
fragment.setInfo(info);
presentFragment(fragment);
});
}
if (!isChannel && ChatObject.canBlockUsers(currentChat) && (ChatObject.isChannel(currentChat) || currentChat.creator)) {
historyCell = new TextDetailCell(context);
historyCell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
typeEditContainer.addView(historyCell, LayoutHelper.createLinear(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
historyCell.setOnClickListener(v -> {
BottomSheet.Builder builder = new BottomSheet.Builder(context);
builder.setApplyTopPadding(false);
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
HeaderCell headerCell = new HeaderCell(context, Theme.key_dialogTextBlue2, 23, 15, false);
headerCell.setHeight(47);
headerCell.setText(LocaleController.getString("ChatHistory", R.string.ChatHistory));
linearLayout.addView(headerCell);
LinearLayout linearLayoutInviteContainer = new LinearLayout(context);
linearLayoutInviteContainer.setOrientation(LinearLayout.VERTICAL);
linearLayout.addView(linearLayoutInviteContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
RadioButtonCell[] buttons = new RadioButtonCell[2];
for (int a = 0; a < 2; a++) {
buttons[a] = new RadioButtonCell(context, true);
buttons[a].setTag(a);
buttons[a].setBackgroundDrawable(Theme.getSelectorDrawable(false));
if (a == 0) {
buttons[a].setTextAndValue(LocaleController.getString("ChatHistoryVisible", R.string.ChatHistoryVisible), LocaleController.getString("ChatHistoryVisibleInfo", R.string.ChatHistoryVisibleInfo), true, !historyHidden);
} else {
if (ChatObject.isChannel(currentChat)) {
buttons[a].setTextAndValue(LocaleController.getString("ChatHistoryHidden", R.string.ChatHistoryHidden), LocaleController.getString("ChatHistoryHiddenInfo", R.string.ChatHistoryHiddenInfo), false, historyHidden);
} else {
buttons[a].setTextAndValue(LocaleController.getString("ChatHistoryHidden", R.string.ChatHistoryHidden), LocaleController.getString("ChatHistoryHiddenInfo2", R.string.ChatHistoryHiddenInfo2), false, historyHidden);
}
}
linearLayoutInviteContainer.addView(buttons[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
buttons[a].setOnClickListener(v2 -> {
Integer tag = (Integer) v2.getTag();
buttons[0].setChecked(tag == 0, true);
buttons[1].setChecked(tag == 1, true);
historyHidden = tag == 1;
builder.getDismissRunnable().run();
updateFields(true);
});
}
builder.setCustomView(linearLayout);
showDialog(builder.create());
});
}
if (isChannel) {
signCell = new TextCheckCell(context);
signCell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
signCell.setTextAndValueAndCheck(LocaleController.getString("ChannelSignMessages", R.string.ChannelSignMessages), LocaleController.getString("ChannelSignMessagesInfo", R.string.ChannelSignMessagesInfo), signMessages, true, false);
typeEditContainer.addView(signCell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
signCell.setOnClickListener(v -> {
signMessages = !signMessages;
((TextCheckCell) v).setChecked(signMessages);
});
}
ActionBarMenu menu = actionBar.createMenu();
if (ChatObject.canChangeChatInfo(currentChat) || signCell != null || historyCell != null) {
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
doneButton.setContentDescription(LocaleController.getString("Done", R.string.Done));
}
if (locationCell != null || signCell != null || historyCell != null || typeCell != null || linkedCell != null) {
settingsSectionCell = new ShadowSectionCell(context);
linearLayout1.addView(settingsSectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
}
infoContainer = new LinearLayout(context);
infoContainer.setOrientation(LinearLayout.VERTICAL);
infoContainer.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
linearLayout1.addView(infoContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
blockCell = new TextCell(context);
blockCell.setBackground(Theme.getSelectorDrawable(false));
blockCell.setVisibility(ChatObject.isChannel(currentChat) || currentChat.creator || ChatObject.hasAdminRights(currentChat) && ChatObject.canChangeChatInfo(currentChat) ? View.VISIBLE : View.GONE);
blockCell.setOnClickListener(v -> {
Bundle args = new Bundle();
args.putLong("chat_id", chatId);
args.putInt("type", !isChannel && !currentChat.gigagroup ? ChatUsersActivity.TYPE_KICKED : ChatUsersActivity.TYPE_BANNED);
ChatUsersActivity fragment = new ChatUsersActivity(args);
fragment.setInfo(info);
presentFragment(fragment);
});
inviteLinksCell = new TextCell(context);
inviteLinksCell.setBackground(Theme.getSelectorDrawable(false));
inviteLinksCell.setOnClickListener(v -> {
ManageLinksActivity fragment = new ManageLinksActivity(chatId, 0, 0);
fragment.setInfo(info, info.exported_invite);
presentFragment(fragment);
});
reactionsCell = new TextCell(context);
reactionsCell.setBackground(Theme.getSelectorDrawable(false));
reactionsCell.setOnClickListener(v -> {
Bundle args = new Bundle();
args.putLong(ChatReactionsEditActivity.KEY_CHAT_ID, chatId);
ChatReactionsEditActivity reactionsEditActivity = new ChatReactionsEditActivity(args);
reactionsEditActivity.setInfo(info);
presentFragment(reactionsEditActivity);
});
adminCell = new TextCell(context);
adminCell.setBackground(Theme.getSelectorDrawable(false));
adminCell.setOnClickListener(v -> {
Bundle args = new Bundle();
args.putLong("chat_id", chatId);
args.putInt("type", ChatUsersActivity.TYPE_ADMIN);
ChatUsersActivity fragment = new ChatUsersActivity(args);
fragment.setInfo(info);
presentFragment(fragment);
});
membersCell = new TextCell(context);
membersCell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
membersCell.setOnClickListener(v -> {
Bundle args = new Bundle();
args.putLong("chat_id", chatId);
args.putInt("type", ChatUsersActivity.TYPE_USERS);
ChatUsersActivity fragment = new ChatUsersActivity(args);
fragment.setInfo(info);
presentFragment(fragment);
});
if (!ChatObject.isChannelAndNotMegaGroup(currentChat)) {
memberRequestsCell = new TextCell(context);
memberRequestsCell.setBackground(Theme.getSelectorDrawable(false));
memberRequestsCell.setOnClickListener(v -> {
MemberRequestsActivity activity = new MemberRequestsActivity(chatId);
presentFragment(activity);
});
}
if (ChatObject.isChannel(currentChat) || currentChat.gigagroup) {
logCell = new TextCell(context);
logCell.setTextAndIcon(LocaleController.getString("EventLog", R.string.EventLog), R.drawable.group_log, false);
logCell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
logCell.setOnClickListener(v -> presentFragment(new ChannelAdminLogActivity(currentChat)));
}
infoContainer.addView(reactionsCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
if (!isChannel && !currentChat.gigagroup) {
infoContainer.addView(blockCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
}
if (!isChannel) {
infoContainer.addView(inviteLinksCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
}
infoContainer.addView(adminCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
infoContainer.addView(membersCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
if (memberRequestsCell != null && info != null && info.requests_pending > 0) {
infoContainer.addView(memberRequestsCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
}
if (isChannel) {
infoContainer.addView(inviteLinksCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
}
if (isChannel || currentChat.gigagroup) {
infoContainer.addView(blockCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
}
if (logCell != null) {
infoContainer.addView(logCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
}
infoSectionCell = new ShadowSectionCell(context);
linearLayout1.addView(infoSectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
if (!ChatObject.hasAdminRights(currentChat)) {
infoContainer.setVisibility(View.GONE);
settingsTopSectionCell.setVisibility(View.GONE);
}
if (!isChannel && info != null && info.can_set_stickers) {
stickersContainer = new FrameLayout(context);
stickersContainer.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
linearLayout1.addView(stickersContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
stickersCell = new TextSettingsCell(context);
stickersCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
stickersCell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
stickersContainer.addView(stickersCell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
stickersCell.setOnClickListener(v -> {
GroupStickersActivity groupStickersActivity = new GroupStickersActivity(currentChat.id);
groupStickersActivity.setInfo(info);
presentFragment(groupStickersActivity);
});
stickersInfoCell3 = new TextInfoPrivacyCell(context);
stickersInfoCell3.setText(LocaleController.getString("GroupStickersInfo", R.string.GroupStickersInfo));
linearLayout1.addView(stickersInfoCell3, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
}
if (currentChat.creator) {
deleteContainer = new FrameLayout(context);
deleteContainer.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
linearLayout1.addView(deleteContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
deleteCell = new TextSettingsCell(context);
deleteCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText5));
deleteCell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
if (isChannel) {
deleteCell.setText(LocaleController.getString("ChannelDelete", R.string.ChannelDelete), false);
} else {
deleteCell.setText(LocaleController.getString("DeleteAndExitButton", R.string.DeleteAndExitButton), false);
}
deleteContainer.addView(deleteCell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
deleteCell.setOnClickListener(v -> AlertsCreator.createClearOrDeleteDialogAlert(ChatEditActivity.this, false, true, false, currentChat, null, false, true, (param) -> {
if (AndroidUtilities.isTablet()) {
getNotificationCenter().postNotificationName(NotificationCenter.closeChats, -chatId);
} else {
getNotificationCenter().postNotificationName(NotificationCenter.closeChats);
}
finishFragment();
getNotificationCenter().postNotificationName(NotificationCenter.needDeleteDialog, -currentChat.id, null, currentChat, param);
}, null));
deleteInfoCell = new ShadowSectionCell(context);
deleteInfoCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
linearLayout1.addView(deleteInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
} else {
if (!isChannel) {
if (stickersInfoCell3 == null) {
infoSectionCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
}
}
}
if (stickersInfoCell3 != null) {
if (deleteInfoCell == null) {
stickersInfoCell3.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
} else {
stickersInfoCell3.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
}
}
undoView = new UndoView(context);
sizeNotifierFrameLayout.addView(undoView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 8, 0, 8, 8));
nameTextView.setText(currentChat.title);
nameTextView.setSelection(nameTextView.length());
if (info != null) {
descriptionTextView.setText(info.about);
}
setAvatar();
updateFields(true);
return fragmentView;
}
use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatEditTypeActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
processDone();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56), LocaleController.getString("Done", R.string.Done));
fragmentView = new ScrollView(context) {
@Override
public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
rectangle.bottom += AndroidUtilities.dp(60);
return super.requestChildRectangleOnScreen(child, rectangle, immediate);
}
};
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
ScrollView scrollView = (ScrollView) fragmentView;
scrollView.setFillViewport(true);
linearLayout = new LinearLayout(context);
scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
linearLayout.setOrientation(LinearLayout.VERTICAL);
if (isForcePublic) {
actionBar.setTitle(LocaleController.getString("TypeLocationGroup", R.string.TypeLocationGroup));
} else if (isChannel) {
actionBar.setTitle(LocaleController.getString("ChannelSettingsTitle", R.string.ChannelSettingsTitle));
} else {
actionBar.setTitle(LocaleController.getString("GroupSettingsTitle", R.string.GroupSettingsTitle));
}
linearLayoutTypeContainer = new LinearLayout(context);
linearLayoutTypeContainer.setOrientation(LinearLayout.VERTICAL);
linearLayoutTypeContainer.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
linearLayout.addView(linearLayoutTypeContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
headerCell2 = new HeaderCell(context, 23);
headerCell2.setHeight(46);
if (isChannel) {
headerCell2.setText(LocaleController.getString("ChannelTypeHeader", R.string.ChannelTypeHeader));
} else {
headerCell2.setText(LocaleController.getString("GroupTypeHeader", R.string.GroupTypeHeader));
}
linearLayoutTypeContainer.addView(headerCell2);
radioButtonCell2 = new RadioButtonCell(context);
radioButtonCell2.setBackgroundDrawable(Theme.getSelectorDrawable(false));
if (isChannel) {
radioButtonCell2.setTextAndValue(LocaleController.getString("ChannelPrivate", R.string.ChannelPrivate), LocaleController.getString("ChannelPrivateInfo", R.string.ChannelPrivateInfo), false, isPrivate);
} else {
radioButtonCell2.setTextAndValue(LocaleController.getString("MegaPrivate", R.string.MegaPrivate), LocaleController.getString("MegaPrivateInfo", R.string.MegaPrivateInfo), false, isPrivate);
}
linearLayoutTypeContainer.addView(radioButtonCell2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
radioButtonCell2.setOnClickListener(v -> {
if (isPrivate) {
return;
}
isPrivate = true;
updatePrivatePublic();
});
radioButtonCell1 = new RadioButtonCell(context);
radioButtonCell1.setBackgroundDrawable(Theme.getSelectorDrawable(false));
if (isChannel) {
radioButtonCell1.setTextAndValue(LocaleController.getString("ChannelPublic", R.string.ChannelPublic), LocaleController.getString("ChannelPublicInfo", R.string.ChannelPublicInfo), false, !isPrivate);
} else {
radioButtonCell1.setTextAndValue(LocaleController.getString("MegaPublic", R.string.MegaPublic), LocaleController.getString("MegaPublicInfo", R.string.MegaPublicInfo), false, !isPrivate);
}
linearLayoutTypeContainer.addView(radioButtonCell1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
radioButtonCell1.setOnClickListener(v -> {
if (!isPrivate) {
return;
}
isPrivate = false;
updatePrivatePublic();
});
sectionCell2 = new ShadowSectionCell(context);
linearLayout.addView(sectionCell2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
if (isForcePublic) {
radioButtonCell2.setVisibility(View.GONE);
radioButtonCell1.setVisibility(View.GONE);
sectionCell2.setVisibility(View.GONE);
headerCell2.setVisibility(View.GONE);
}
linkContainer = new LinearLayout(context);
linkContainer.setOrientation(LinearLayout.VERTICAL);
linkContainer.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
linearLayout.addView(linkContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
headerCell = new HeaderCell(context, 23);
linkContainer.addView(headerCell);
publicContainer = new LinearLayout(context);
publicContainer.setOrientation(LinearLayout.HORIZONTAL);
linkContainer.addView(publicContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 23, 7, 23, 0));
editText = new EditTextBoldCursor(context);
editText.setText(getMessagesController().linkPrefix + "/");
editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
editText.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
editText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
editText.setMaxLines(1);
editText.setLines(1);
editText.setEnabled(false);
editText.setBackgroundDrawable(null);
editText.setPadding(0, 0, 0, 0);
editText.setSingleLine(true);
editText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
publicContainer.addView(editText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 36));
usernameTextView = new EditTextBoldCursor(context);
usernameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
usernameTextView.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
usernameTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
usernameTextView.setMaxLines(1);
usernameTextView.setLines(1);
usernameTextView.setBackgroundDrawable(null);
usernameTextView.setPadding(0, 0, 0, 0);
usernameTextView.setSingleLine(true);
usernameTextView.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
usernameTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
usernameTextView.setHint(LocaleController.getString("ChannelUsernamePlaceholder", R.string.ChannelUsernamePlaceholder));
usernameTextView.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
usernameTextView.setCursorSize(AndroidUtilities.dp(20));
usernameTextView.setCursorWidth(1.5f);
publicContainer.addView(usernameTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36));
usernameTextView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
if (ignoreTextChanges) {
return;
}
checkUserName(usernameTextView.getText().toString());
}
@Override
public void afterTextChanged(Editable editable) {
checkDoneButton();
}
});
privateContainer = new LinearLayout(context);
privateContainer.setOrientation(LinearLayout.VERTICAL);
linkContainer.addView(privateContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
permanentLinkView = new LinkActionView(context, this, null, chatId, true, ChatObject.isChannel(currentChat));
permanentLinkView.setDelegate(new LinkActionView.Delegate() {
@Override
public void revokeLink() {
ChatEditTypeActivity.this.generateLink(true);
}
@Override
public void showUsersForPermanentLink() {
inviteLinkBottomSheet = new InviteLinkBottomSheet(context, invite, info, usersMap, ChatEditTypeActivity.this, chatId, true, ChatObject.isChannel(currentChat));
inviteLinkBottomSheet.show();
}
});
permanentLinkView.setUsers(0, null);
privateContainer.addView(permanentLinkView);
checkTextView = new TextInfoPrivacyCell(context);
checkTextView.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
checkTextView.setBottomPadding(6);
linearLayout.addView(checkTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
typeInfoCell = new TextInfoPrivacyCell(context);
linearLayout.addView(typeInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
loadingAdminedCell = new LoadingCell(context);
linearLayout.addView(loadingAdminedCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
adminnedChannelsLayout = new LinearLayout(context);
adminnedChannelsLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
adminnedChannelsLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.addView(adminnedChannelsLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
adminedInfoCell = new ShadowSectionCell(context);
linearLayout.addView(adminedInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
manageLinksTextView = new TextCell(context);
manageLinksTextView.setBackgroundDrawable(Theme.getSelectorDrawable(true));
manageLinksTextView.setTextAndIcon(LocaleController.getString("ManageInviteLinks", R.string.ManageInviteLinks), R.drawable.actions_link, false);
manageLinksTextView.setOnClickListener(v -> {
ManageLinksActivity fragment = new ManageLinksActivity(chatId, 0, 0);
fragment.setInfo(info, invite);
presentFragment(fragment);
});
linearLayout.addView(manageLinksTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
manageLinksInfoCell = new TextInfoPrivacyCell(context);
linearLayout.addView(manageLinksInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
saveContainer = new LinearLayout(context);
saveContainer.setOrientation(LinearLayout.VERTICAL);
linearLayout.addView(saveContainer);
saveHeaderCell = new HeaderCell(context, 23);
saveHeaderCell.setHeight(46);
saveHeaderCell.setText(LocaleController.getString("SavingContentTitle", R.string.SavingContentTitle));
saveHeaderCell.setBackgroundDrawable(Theme.getSelectorDrawable(true));
saveContainer.addView(saveHeaderCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
saveRestrictCell = new TextCheckCell(context);
saveRestrictCell.setBackgroundDrawable(Theme.getSelectorDrawable(true));
saveRestrictCell.setTextAndCheck(LocaleController.getString("RestrictSavingContent", R.string.RestrictSavingContent), isSaveRestricted, false);
saveRestrictCell.setOnClickListener(v -> {
isSaveRestricted = !isSaveRestricted;
((TextCheckCell) v).setChecked(isSaveRestricted);
});
saveContainer.addView(saveRestrictCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
saveRestrictInfoCell = new TextInfoPrivacyCell(context);
if (isChannel && !ChatObject.isMegagroup(currentChat)) {
saveRestrictInfoCell.setText(LocaleController.getString("RestrictSavingContentInfoChannel", R.string.RestrictSavingContentInfoChannel));
} else {
saveRestrictInfoCell.setText(LocaleController.getString("RestrictSavingContentInfoGroup", R.string.RestrictSavingContentInfoGroup));
}
saveContainer.addView(saveRestrictInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
if (!isPrivate && currentChat.username != null) {
ignoreTextChanges = true;
usernameTextView.setText(currentChat.username);
usernameTextView.setSelection(currentChat.username.length());
ignoreTextChanges = false;
}
updatePrivatePublic();
return fragmentView;
}
use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatLinkActivity method createView.
@Override
public View createView(Context context) {
searching = false;
searchWas = false;
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("Discussion", R.string.Discussion));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
searchItem = menu.addItem(search_button, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
searching = true;
emptyView.setShowAtCenter(true);
}
@Override
public void onSearchCollapse() {
searchAdapter.searchDialogs(null);
searching = false;
searchWas = false;
listView.setAdapter(listViewAdapter);
listViewAdapter.notifyDataSetChanged();
listView.setFastScrollVisible(true);
listView.setVerticalScrollBarEnabled(false);
emptyView.setShowAtCenter(false);
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
fragmentView.setTag(Theme.key_windowBackgroundGray);
emptyView.showProgress();
}
@Override
public void onTextChanged(EditText editText) {
if (searchAdapter == null) {
return;
}
String text = editText.getText().toString();
if (text.length() != 0) {
searchWas = true;
if (listView != null && listView.getAdapter() != searchAdapter) {
listView.setAdapter(searchAdapter);
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
fragmentView.setTag(Theme.key_windowBackgroundWhite);
searchAdapter.notifyDataSetChanged();
listView.setFastScrollVisible(false);
listView.setVerticalScrollBarEnabled(true);
emptyView.showProgress();
}
}
searchAdapter.searchDialogs(text);
}
});
searchItem.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));
searchAdapter = new SearchAdapter(context);
fragmentView = new FrameLayout(context);
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
fragmentView.setTag(Theme.key_windowBackgroundGray);
FrameLayout frameLayout = (FrameLayout) fragmentView;
emptyView = new EmptyTextProgressView(context);
emptyView.showProgress();
emptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView = new RecyclerListView(context);
listView.setEmptyView(emptyView);
listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
listView.setAdapter(listViewAdapter = new ListAdapter(context));
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? RecyclerListView.SCROLLBAR_POSITION_LEFT : RecyclerListView.SCROLLBAR_POSITION_RIGHT);
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView.setOnItemClickListener((view, position) -> {
if (getParentActivity() == null) {
return;
}
final TLRPC.Chat chat;
if (listView.getAdapter() == searchAdapter) {
chat = searchAdapter.getItem(position);
} else if (position >= chatStartRow && position < chatEndRow) {
chat = chats.get(position - chatStartRow);
} else {
chat = null;
}
if (chat != null) {
if (isChannel && info.linked_chat_id == 0) {
showLinkAlert(chat, true);
} else {
Bundle args = new Bundle();
args.putLong("chat_id", chat.id);
presentFragment(new ChatActivity(args));
}
return;
}
if (position == createChatRow) {
if (isChannel && info.linked_chat_id == 0) {
Bundle args = new Bundle();
long[] array = new long[] { getUserConfig().getClientUserId() };
args.putLongArray("result", array);
args.putInt("chatType", ChatObject.CHAT_TYPE_MEGAGROUP);
GroupCreateFinalActivity activity = new GroupCreateFinalActivity(args);
activity.setDelegate(new GroupCreateFinalActivity.GroupCreateFinalActivityDelegate() {
@Override
public void didStartChatCreation() {
}
@Override
public void didFinishChatCreation(GroupCreateFinalActivity fragment, long chatId) {
linkChat(getMessagesController().getChat(chatId), fragment);
}
@Override
public void didFailChatCreation() {
}
});
presentFragment(activity);
} else {
if (chats.isEmpty()) {
return;
}
TLRPC.Chat c = chats.get(0);
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
String title;
String message;
if (isChannel) {
title = LocaleController.getString("DiscussionUnlinkGroup", R.string.DiscussionUnlinkGroup);
message = LocaleController.formatString("DiscussionUnlinkChannelAlert", R.string.DiscussionUnlinkChannelAlert, c.title);
} else {
title = LocaleController.getString("DiscussionUnlink", R.string.DiscussionUnlinkChannel);
message = LocaleController.formatString("DiscussionUnlinkGroupAlert", R.string.DiscussionUnlinkGroupAlert, c.title);
}
builder.setTitle(title);
builder.setMessage(AndroidUtilities.replaceTags(message));
builder.setPositiveButton(LocaleController.getString("DiscussionUnlink", R.string.DiscussionUnlink), (dialogInterface, i) -> {
if (!isChannel || info.linked_chat_id != 0) {
final AlertDialog[] progressDialog = new AlertDialog[] { new AlertDialog(getParentActivity(), 3) };
TLRPC.TL_channels_setDiscussionGroup req = new TLRPC.TL_channels_setDiscussionGroup();
if (isChannel) {
req.broadcast = MessagesController.getInputChannel(currentChat);
req.group = new TLRPC.TL_inputChannelEmpty();
} else {
req.broadcast = new TLRPC.TL_inputChannelEmpty();
req.group = MessagesController.getInputChannel(currentChat);
}
int requestId = getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog[0].dismiss();
} catch (Throwable ignore) {
}
progressDialog[0] = null;
info.linked_chat_id = 0;
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.chatInfoDidLoad, info, 0, false, false);
AndroidUtilities.runOnUIThread(() -> getMessagesController().loadFullChat(currentChatId, 0, true), 1000);
if (!isChannel) {
finishFragment();
}
}));
AndroidUtilities.runOnUIThread(() -> {
if (progressDialog[0] == null) {
return;
}
progressDialog[0].setOnCancelListener(dialog -> ConnectionsManager.getInstance(currentAccount).cancelRequest(requestId, true));
showDialog(progressDialog[0]);
}, 500);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog dialog = builder.create();
showDialog(dialog);
TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
}
}
});
updateRows();
return fragmentView;
}
Aggregations