use of org.telegram.ui.Cells.ThemePreviewMessagesCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ThemeSetUrlActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (creatingNewTheme) {
actionBar.setTitle(LocaleController.getString("NewThemeTitle", R.string.NewThemeTitle));
} else {
actionBar.setTitle(LocaleController.getString("EditThemeTitle", R.string.EditThemeTitle));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
saveTheme();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItem(done_button, LocaleController.getString("Done", R.string.Done).toUpperCase());
fragmentView = new LinearLayout(context);
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
LinearLayout linearLayout = (LinearLayout) fragmentView;
linearLayout.setOrientation(LinearLayout.VERTICAL);
fragmentView.setOnTouchListener((v, event) -> true);
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));
headerCell = new HeaderCell(context, 23);
headerCell.setText(LocaleController.getString("Info", R.string.Info));
linearLayoutTypeContainer.addView(headerCell);
nameField = new EditTextBoldCursor(context);
nameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
nameField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
nameField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
nameField.setMaxLines(1);
nameField.setLines(1);
nameField.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
nameField.setBackgroundDrawable(null);
nameField.setPadding(0, 0, 0, 0);
nameField.setSingleLine(true);
InputFilter[] inputFilters = new InputFilter[1];
inputFilters[0] = new InputFilter.LengthFilter(128);
nameField.setFilters(inputFilters);
nameField.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
nameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
nameField.setHint(LocaleController.getString("ThemeNamePlaceholder", R.string.ThemeNamePlaceholder));
nameField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
nameField.setCursorSize(AndroidUtilities.dp(20));
nameField.setCursorWidth(1.5f);
linearLayoutTypeContainer.addView(nameField, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50, 23, 0, 23, 0));
nameField.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_DONE) {
AndroidUtilities.hideKeyboard(nameField);
return true;
}
return false;
});
divider = new View(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);
}
};
linearLayoutTypeContainer.addView(divider, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));
LinearLayout linkContainer = new LinearLayout(context);
linkContainer.setOrientation(LinearLayout.HORIZONTAL);
linearLayoutTypeContainer.addView(linkContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50, 23, 0, 23, 0));
editText = new EditTextBoldCursor(context);
editText.setText(getMessagesController().linkPrefix + "/addtheme/");
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);
linkContainer.addView(editText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 50));
linkField = new EditTextBoldCursor(context);
linkField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
linkField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
linkField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
linkField.setMaxLines(1);
linkField.setLines(1);
linkField.setBackgroundDrawable(null);
linkField.setPadding(0, 0, 0, 0);
linkField.setSingleLine(true);
linkField.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
linkField.setImeOptions(EditorInfo.IME_ACTION_DONE);
linkField.setHint(LocaleController.getString("SetUrlPlaceholder", R.string.SetUrlPlaceholder));
linkField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
linkField.setCursorSize(AndroidUtilities.dp(20));
linkField.setCursorWidth(1.5f);
linkContainer.addView(linkField, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
linkField.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
doneButton.performClick();
return true;
}
return false;
});
linkField.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 (ignoreCheck) {
return;
}
checkUrl(linkField.getText().toString(), false);
}
@Override
public void afterTextChanged(Editable editable) {
if (creatingNewTheme) {
return;
}
if (linkField.length() > 0) {
String url = "https://" + getMessagesController().linkPrefix + "/addtheme/" + linkField.getText();
String text = LocaleController.formatString("ThemeHelpLink", R.string.ThemeHelpLink, url);
int index = text.indexOf(url);
SpannableStringBuilder textSpan = new SpannableStringBuilder(text);
if (index >= 0) {
textSpan.setSpan(new LinkSpan(url), index, index + url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
helpInfoCell.setText(TextUtils.concat(infoText, "\n\n", textSpan));
} else {
helpInfoCell.setText(infoText);
}
}
});
if (creatingNewTheme) {
linkField.setOnFocusChangeListener((v, hasFocus) -> {
if (hasFocus) {
helpInfoCell.setText(AndroidUtilities.replaceTags(LocaleController.getString("ThemeCreateHelp2", R.string.ThemeCreateHelp2)));
} else {
helpInfoCell.setText(AndroidUtilities.replaceTags(LocaleController.getString("ThemeCreateHelp", R.string.ThemeCreateHelp)));
}
});
}
checkInfoCell = new TextInfoPrivacyCell(context);
checkInfoCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
checkInfoCell.setVisibility(View.GONE);
checkInfoCell.setBottomPadding(0);
linearLayout.addView(checkInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
helpInfoCell = new TextInfoPrivacyCell(context);
helpInfoCell.getTextView().setMovementMethod(new LinkMovementMethodMy());
helpInfoCell.getTextView().setHighlightColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkSelection));
if (creatingNewTheme) {
helpInfoCell.setText(AndroidUtilities.replaceTags(LocaleController.getString("ThemeCreateHelp", R.string.ThemeCreateHelp)));
} else {
helpInfoCell.setText(infoText = AndroidUtilities.replaceTags(LocaleController.getString("ThemeSetUrlHelp", R.string.ThemeSetUrlHelp)));
}
linearLayout.addView(helpInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
if (creatingNewTheme) {
helpInfoCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
messagesCell = new ThemePreviewMessagesCell(context, parentLayout, 1);
linearLayout.addView(messagesCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
createCell = new TextSettingsCell(context);
createCell.setBackgroundDrawable(Theme.getSelectorDrawable(true));
createCell.setText(LocaleController.getString("UseDifferentTheme", R.string.UseDifferentTheme), false);
linearLayout.addView(createCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
createCell.setOnClickListener(v -> {
if (getParentActivity() == null) {
return;
}
BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity(), false);
builder.setApplyBottomPadding(false);
LinearLayout container = new LinearLayout(context);
container.setOrientation(LinearLayout.VERTICAL);
TextView titleView = new TextView(context);
titleView.setText(LocaleController.getString("ChooseTheme", R.string.ChooseTheme));
titleView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
titleView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
container.addView(titleView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 22, 12, 22, 4));
titleView.setOnTouchListener((v2, event) -> true);
builder.setCustomView(container);
ArrayList<Theme.ThemeInfo> themes = new ArrayList<>();
for (int a = 0, N = Theme.themes.size(); a < N; a++) {
Theme.ThemeInfo themeInfo = Theme.themes.get(a);
if (themeInfo.info != null && themeInfo.info.document == null) {
continue;
}
themes.add(themeInfo);
}
ThemesHorizontalListCell cell = new ThemesHorizontalListCell(context, ThemeActivity.THEME_TYPE_OTHER, themes, new ArrayList<>()) {
@Override
protected void updateRows() {
builder.getDismissRunnable().run();
}
};
container.addView(cell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 148, 0, 7, 0, 1));
cell.scrollToCurrentTheme(fragmentView.getMeasuredWidth(), false);
showDialog(builder.create());
});
createInfoCell = new TextInfoPrivacyCell(context);
createInfoCell.setText(AndroidUtilities.replaceTags(LocaleController.getString("UseDifferentThemeInfo", R.string.UseDifferentThemeInfo)));
createInfoCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
linearLayout.addView(createInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
} else {
helpInfoCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
}
if (info != null) {
ignoreCheck = true;
nameField.setText(info.title);
nameField.setSelection(nameField.length());
linkField.setText(info.slug);
linkField.setSelection(linkField.length());
ignoreCheck = false;
}
return fragmentView;
}
use of org.telegram.ui.Cells.ThemePreviewMessagesCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ReactionsDoubleTapManageActivity method createView.
@Override
public View createView(Context context) {
actionBar.setTitle(LocaleController.getString("Reactions", R.string.Reactions));
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();
}
}
});
LinearLayout linaerLayout = new LinearLayout(context);
linaerLayout.setOrientation(LinearLayout.VERTICAL);
listView = new RecyclerListView(context);
listView.setLayoutManager(new LinearLayoutManager(context));
listView.setAdapter(listAdapter = new RecyclerView.Adapter() {
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view;
switch(viewType) {
case 0:
ThemePreviewMessagesCell messagesCell = new ThemePreviewMessagesCell(context, parentLayout, ThemePreviewMessagesCell.TYPE_REACTIONS_DOUBLE_TAP);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
messagesCell.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
}
messagesCell.fragment = ReactionsDoubleTapManageActivity.this;
view = messagesCell;
break;
case 2:
TextInfoPrivacyCell cell = new TextInfoPrivacyCell(context);
cell.setText(LocaleController.getString("DoubleTapPreviewRational", R.string.DoubleTapPreviewRational));
view = cell;
break;
default:
case 1:
{
view = new AvailableReactionCell(context, true);
}
break;
}
return new RecyclerListView.Holder(view);
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
switch(getItemViewType(position)) {
case 1:
AvailableReactionCell reactionCell = (AvailableReactionCell) holder.itemView;
TLRPC.TL_availableReaction react = getAvailableReactions().get(position - reactionsStartRow);
reactionCell.bind(react, react.reaction.contains(MediaDataController.getInstance(currentAccount).getDoubleTapReaction()));
break;
}
}
@Override
public int getItemCount() {
return getAvailableReactions().size();
}
@Override
public int getItemViewType(int position) {
if (position == previewRow) {
return 0;
}
if (position == infoRow) {
return 2;
}
return 1;
}
});
listView.setOnItemClickListener((view, position) -> {
if (view instanceof AvailableReactionCell) {
MediaDataController.getInstance(currentAccount).setDoubleTapReaction(((AvailableReactionCell) view).react.reaction);
AndroidUtilities.updateVisibleRows(listView);
}
});
linaerLayout.addView(listView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
fragmentView = contentView = linaerLayout;
updateColors();
updateRows();
return contentView;
}
Aggregations