use of org.telegram.ui.Cells.PollEditTextCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatAttachAlertPollLayout method setTextLeft.
private void setTextLeft(View cell, int index) {
if (!(cell instanceof PollEditTextCell)) {
return;
}
PollEditTextCell textCell = (PollEditTextCell) cell;
int max;
int left;
if (index == questionRow) {
max = MAX_QUESTION_LENGTH;
left = MAX_QUESTION_LENGTH - (questionString != null ? questionString.length() : 0);
} else if (index == solutionRow) {
max = MAX_SOLUTION_LENGTH;
left = MAX_SOLUTION_LENGTH - (solutionString != null ? solutionString.length() : 0);
} else if (index >= answerStartRow && index < answerStartRow + answersCount) {
index -= answerStartRow;
max = MAX_ANSWER_LENGTH;
left = MAX_ANSWER_LENGTH - (answers[index] != null ? answers[index].length() : 0);
} else {
return;
}
if (left <= max - max * 0.7f) {
textCell.setText2(String.format("%d", left));
SimpleTextView textView = textCell.getTextView2();
String key = left < 0 ? Theme.key_windowBackgroundWhiteRedText5 : Theme.key_windowBackgroundWhiteGrayText3;
textView.setTextColor(getThemedColor(key));
textView.setTag(key);
} else {
textCell.setText2("");
}
}
use of org.telegram.ui.Cells.PollEditTextCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class FilterCreateActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
ActionBarMenu menu = actionBar.createMenu();
if (creatingNew) {
actionBar.setTitle(LocaleController.getString("FilterNew", R.string.FilterNew));
} else {
TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
paint.setTextSize(AndroidUtilities.dp(20));
actionBar.setTitle(Emoji.replaceEmoji(filter.name, paint.getFontMetricsInt(), AndroidUtilities.dp(20), false));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if (checkDiscard()) {
finishFragment();
}
} else if (id == done_button) {
processDone();
}
}
});
doneItem = menu.addItem(done_button, LocaleController.getString("Save", R.string.Save).toUpperCase());
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
listView = new RecyclerListView(context) {
@Override
public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
return false;
}
};
listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
listView.setVerticalScrollBarEnabled(false);
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView.setAdapter(adapter = new ListAdapter(context));
listView.setOnItemClickListener((view, position) -> {
if (getParentActivity() == null) {
return;
}
if (position == includeShowMoreRow) {
includeExpanded = true;
updateRows();
} else if (position == excludeShowMoreRow) {
excludeExpanded = true;
updateRows();
} else if (position == includeAddRow || position == excludeAddRow) {
ArrayList<Long> arrayList = position == excludeAddRow ? newNeverShow : newAlwaysShow;
FilterUsersActivity fragment = new FilterUsersActivity(position == includeAddRow, arrayList, newFilterFlags);
fragment.setDelegate((ids, flags) -> {
newFilterFlags = flags;
if (position == excludeAddRow) {
newNeverShow = ids;
for (int a = 0; a < newNeverShow.size(); a++) {
Long id = newNeverShow.get(a);
newAlwaysShow.remove(id);
newPinned.delete(id);
}
} else {
newAlwaysShow = ids;
for (int a = 0; a < newAlwaysShow.size(); a++) {
newNeverShow.remove(newAlwaysShow.get(a));
}
ArrayList<Long> toRemove = new ArrayList<>();
for (int a = 0, N = newPinned.size(); a < N; a++) {
Long did = newPinned.keyAt(a);
if (DialogObject.isEncryptedDialog(did)) {
continue;
}
if (newAlwaysShow.contains(did)) {
continue;
}
toRemove.add(did);
}
for (int a = 0, N = toRemove.size(); a < N; a++) {
newPinned.delete(toRemove.get(a));
}
}
fillFilterName();
checkDoneButton(false);
updateRows();
});
presentFragment(fragment);
} else if (position == removeRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("FilterDelete", R.string.FilterDelete));
builder.setMessage(LocaleController.getString("FilterDeleteAlert", R.string.FilterDeleteAlert));
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialog, which) -> {
AlertDialog progressDialog = null;
if (getParentActivity() != null) {
progressDialog = new AlertDialog(getParentActivity(), 3);
progressDialog.setCanCacnel(false);
progressDialog.show();
}
final AlertDialog progressDialogFinal = progressDialog;
TLRPC.TL_messages_updateDialogFilter req = new TLRPC.TL_messages_updateDialogFilter();
req.id = filter.id;
getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
try {
if (progressDialogFinal != null) {
progressDialogFinal.dismiss();
}
} catch (Exception e) {
FileLog.e(e);
}
getMessagesController().removeFilter(filter);
getMessagesStorage().deleteDialogFilter(filter);
finishFragment();
}));
});
AlertDialog alertDialog = builder.create();
showDialog(alertDialog);
TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
} else if (position == nameRow) {
PollEditTextCell cell = (PollEditTextCell) view;
cell.getTextView().requestFocus();
AndroidUtilities.showKeyboard(cell.getTextView());
} else if (view instanceof UserCell) {
UserCell cell = (UserCell) view;
showRemoveAlert(position, cell.getName(), cell.getCurrentObject(), position < includeSectionRow);
}
});
listView.setOnItemLongClickListener((view, position) -> {
if (view instanceof UserCell) {
UserCell cell = (UserCell) view;
showRemoveAlert(position, cell.getName(), cell.getCurrentObject(), position < includeSectionRow);
return true;
}
return false;
});
checkDoneButton(false);
return fragmentView;
}
use of org.telegram.ui.Cells.PollEditTextCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class FilterCreateActivity method setTextLeft.
private void setTextLeft(View cell) {
if (cell instanceof PollEditTextCell) {
PollEditTextCell textCell = (PollEditTextCell) cell;
int left = MAX_NAME_LENGTH - (newFilterName != null ? newFilterName.length() : 0);
if (left <= MAX_NAME_LENGTH - MAX_NAME_LENGTH * 0.7f) {
textCell.setText2(String.format("%d", left));
SimpleTextView textView = textCell.getTextView2();
String key = left < 0 ? Theme.key_windowBackgroundWhiteRedText5 : Theme.key_windowBackgroundWhiteGrayText3;
textView.setTextColor(Theme.getColor(key));
textView.setTag(key);
textView.setAlpha(((PollEditTextCell) cell).getTextView().isFocused() || left < 0 ? 1.0f : 0.0f);
} else {
textCell.setText2("");
}
}
}
use of org.telegram.ui.Cells.PollEditTextCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class PollCreateActivity method setTextLeft.
private void setTextLeft(View cell, int index) {
if (!(cell instanceof PollEditTextCell)) {
return;
}
PollEditTextCell textCell = (PollEditTextCell) cell;
int max;
int left;
if (index == questionRow) {
max = ChatAttachAlertPollLayout.MAX_QUESTION_LENGTH;
left = ChatAttachAlertPollLayout.MAX_QUESTION_LENGTH - (questionString != null ? questionString.length() : 0);
} else if (index == solutionRow) {
max = ChatAttachAlertPollLayout.MAX_SOLUTION_LENGTH;
left = ChatAttachAlertPollLayout.MAX_SOLUTION_LENGTH - (solutionString != null ? solutionString.length() : 0);
} else if (index >= answerStartRow && index < answerStartRow + answersCount) {
index -= answerStartRow;
max = ChatAttachAlertPollLayout.MAX_ANSWER_LENGTH;
left = ChatAttachAlertPollLayout.MAX_ANSWER_LENGTH - (answers[index] != null ? answers[index].length() : 0);
} else {
return;
}
if (left <= max - max * 0.7f) {
textCell.setText2(String.format("%d", left));
SimpleTextView textView = textCell.getTextView2();
String key = left < 0 ? Theme.key_windowBackgroundWhiteRedText5 : Theme.key_windowBackgroundWhiteGrayText3;
textView.setTextColor(Theme.getColor(key));
textView.setTag(key);
} else {
textCell.setText2("");
}
}
use of org.telegram.ui.Cells.PollEditTextCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class PollCreateActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
if (quizOnly == 1) {
actionBar.setTitle(LocaleController.getString("NewQuiz", R.string.NewQuiz));
} else {
actionBar.setTitle(LocaleController.getString("NewPoll", R.string.NewPoll));
}
if (AndroidUtilities.isTablet()) {
actionBar.setOccupyStatusBar(false);
}
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) {
if (quizPoll && doneItem.getAlpha() != 1.0f) {
int checksCount = 0;
for (int a = 0; a < answersChecks.length; a++) {
if (!TextUtils.isEmpty(ChatAttachAlertPollLayout.getFixedString(answers[a])) && answersChecks[a]) {
checksCount++;
}
}
if (checksCount <= 0) {
showQuizHint();
}
return;
}
TLRPC.TL_messageMediaPoll poll = new TLRPC.TL_messageMediaPoll();
poll.poll = new TLRPC.TL_poll();
poll.poll.multiple_choice = multipleChoise;
poll.poll.quiz = quizPoll;
poll.poll.public_voters = !anonymousPoll;
poll.poll.question = ChatAttachAlertPollLayout.getFixedString(questionString).toString();
SerializedData serializedData = new SerializedData(10);
for (int a = 0; a < answers.length; a++) {
if (TextUtils.isEmpty(ChatAttachAlertPollLayout.getFixedString(answers[a]))) {
continue;
}
TLRPC.TL_pollAnswer answer = new TLRPC.TL_pollAnswer();
answer.text = ChatAttachAlertPollLayout.getFixedString(answers[a]).toString();
answer.option = new byte[1];
answer.option[0] = (byte) (48 + poll.poll.answers.size());
poll.poll.answers.add(answer);
if ((multipleChoise || quizPoll) && answersChecks[a]) {
serializedData.writeByte(answer.option[0]);
}
}
HashMap<String, String> params = new HashMap<>();
params.put("answers", Utilities.bytesToHex(serializedData.toByteArray()));
poll.results = new TLRPC.TL_pollResults();
CharSequence solution = ChatAttachAlertPollLayout.getFixedString(solutionString);
if (solution != null) {
poll.results.solution = solution.toString();
CharSequence[] message = new CharSequence[] { solution };
ArrayList<TLRPC.MessageEntity> entities = getMediaDataController().getEntities(message, true);
if (entities != null && !entities.isEmpty()) {
poll.results.solution_entities = entities;
}
if (!TextUtils.isEmpty(poll.results.solution)) {
poll.results.flags |= 16;
}
}
if (parentFragment.isInScheduleMode()) {
AlertsCreator.createScheduleDatePickerDialog(getParentActivity(), parentFragment.getDialogId(), (notify, scheduleDate) -> {
delegate.sendPoll(poll, params, notify, scheduleDate);
finishFragment();
});
} else {
delegate.sendPoll(poll, params, true, 0);
finishFragment();
}
}
}
});
ActionBarMenu menu = actionBar.createMenu();
doneItem = menu.addItem(done_button, LocaleController.getString("Create", R.string.Create).toUpperCase());
listAdapter = new ListAdapter(context);
fragmentView = new FrameLayout(context);
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
FrameLayout frameLayout = (FrameLayout) fragmentView;
listView = new RecyclerListView(context) {
@Override
protected void requestChildOnScreen(View child, View focused) {
if (!(child instanceof PollEditTextCell)) {
return;
}
super.requestChildOnScreen(child, focused);
}
@Override
public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
rectangle.bottom += AndroidUtilities.dp(60);
return super.requestChildRectangleOnScreen(child, rectangle, immediate);
}
};
listView.setVerticalScrollBarEnabled(false);
((DefaultItemAnimator) listView.getItemAnimator()).setDelayAnimations(false);
listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new TouchHelperCallback());
itemTouchHelper.attachToRecyclerView(listView);
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
listView.setAdapter(listAdapter);
listView.setOnItemClickListener((view, position) -> {
if (position == addAnswerRow) {
addNewField();
} else if (view instanceof TextCheckCell) {
TextCheckCell cell = (TextCheckCell) view;
boolean checked;
boolean wasChecksBefore = quizPoll;
if (position == anonymousRow) {
checked = anonymousPoll = !anonymousPoll;
} else if (position == multipleRow) {
checked = multipleChoise = !multipleChoise;
if (multipleChoise && quizPoll) {
int prevSolutionRow = solutionRow;
quizPoll = false;
updateRows();
RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(quizRow);
if (holder != null) {
((TextCheckCell) holder.itemView).setChecked(false);
} else {
listAdapter.notifyItemChanged(quizRow);
}
listAdapter.notifyItemRangeRemoved(prevSolutionRow, 2);
}
} else {
if (quizOnly != 0) {
return;
}
checked = quizPoll = !quizPoll;
int prevSolutionRow = solutionRow;
updateRows();
if (quizPoll) {
listAdapter.notifyItemRangeInserted(solutionRow, 2);
} else {
listAdapter.notifyItemRangeRemoved(prevSolutionRow, 2);
}
if (quizPoll && multipleChoise) {
multipleChoise = false;
RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(multipleRow);
if (holder != null) {
((TextCheckCell) holder.itemView).setChecked(false);
} else {
listAdapter.notifyItemChanged(multipleRow);
}
}
if (quizPoll) {
boolean was = false;
for (int a = 0; a < answersChecks.length; a++) {
if (was) {
answersChecks[a] = false;
} else if (answersChecks[a]) {
was = true;
}
}
}
}
if (hintShowed && !quizPoll) {
hintView.hide();
}
int count = listView.getChildCount();
for (int a = answerStartRow; a < answerStartRow + answersCount; a++) {
RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(a);
if (holder != null && holder.itemView instanceof PollEditTextCell) {
PollEditTextCell pollEditTextCell = (PollEditTextCell) holder.itemView;
pollEditTextCell.setShowCheckBox(quizPoll, true);
pollEditTextCell.setChecked(answersChecks[a - answerStartRow], wasChecksBefore);
if (pollEditTextCell.getTop() > AndroidUtilities.dp(40) && position == quizRow && !hintShowed) {
hintView.showForView(pollEditTextCell.getCheckBox(), true);
hintShowed = true;
}
}
}
cell.setChecked(checked);
checkDoneButton();
}
});
listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (dy != 0 && hintView != null) {
hintView.hide();
}
}
});
hintView = new HintView(context, 4);
hintView.setText(LocaleController.getString("PollTapToSelect", R.string.PollTapToSelect));
hintView.setAlpha(0.0f);
hintView.setVisibility(View.INVISIBLE);
frameLayout.addView(hintView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 19, 0, 19, 0));
checkDoneButton();
return fragmentView;
}
Aggregations