Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements: ChatActionBar #718

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion .gitignore
null-nick marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ obj
/captures
/local.properties

libc++_shared.so
libc++_shared.so
signing.properties
null-nick marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.thunderdog.challegram.component.chat;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
Expand All @@ -24,6 +25,7 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;

import org.thunderdog.challegram.R;
import org.thunderdog.challegram.core.Lang;
Expand All @@ -38,55 +40,69 @@

public class TopBarView extends FrameLayoutFix {
private final ImageView topDismissButton;
private final LinearLayout actionsList;
private final LinearLayout actionsContainer;
private final TextView additionalTextView;
private LinearLayout actionsList;

private boolean canDismiss;

public interface DismissListener {
void onDismissRequest (TopBarView barView);
void onDismissRequest(TopBarView barView);
null-nick marked this conversation as resolved.
Show resolved Hide resolved
}

public static class Item {
final int id;
final int stringRes;
final int iconResId;
final View.OnClickListener onClickListener;

boolean isNegative;
boolean noDismiss;

public Item (int id, int stringRes, View.OnClickListener onClickListener) {
public Item(int id, int stringRes, int iconResId, View.OnClickListener onClickListener) {
null-nick marked this conversation as resolved.
Show resolved Hide resolved
this.id = id;
this.stringRes = stringRes;
this.iconResId = iconResId;
this.onClickListener = onClickListener;
}

public Item setIsNegative () {
public Item(int id, int stringRes, View.OnClickListener onClickListener) {
null-nick marked this conversation as resolved.
Show resolved Hide resolved
this(id, stringRes, 0, onClickListener);
}

public Item setIsNegative() {
this.isNegative = true;
return this;
}

public Item setNoDismiss () {
public Item setNoDismiss() {
null-nick marked this conversation as resolved.
Show resolved Hide resolved
this.noDismiss = true;
return this;
}
}

private DismissListener dismissListener;

public TopBarView (@NonNull Context context) {
public TopBarView(@NonNull Context context) {
null-nick marked this conversation as resolved.
Show resolved Hide resolved
super(context);

setLayoutParams(FrameLayoutFix.newParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(36f)));
ViewSupport.setThemedBackground(this, ColorId.filling, null);

actionsContainer = new LinearLayout(context);
actionsContainer.setOrientation(LinearLayout.VERTICAL);
actionsContainer.setLayoutParams(FrameLayoutFix.newParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(40f), Lang.gravity() | Gravity.TOP));
addView(actionsContainer);

actionsList = new LinearLayout(context);
actionsList.setOrientation(LinearLayout.HORIZONTAL);
actionsList.setLayoutParams(FrameLayoutFix.newParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, Lang.gravity() | Gravity.TOP));
addView(actionsList);
actionsContainer.addView(actionsList);

topDismissButton = new ImageView(context) {
topDismissButton = new AppCompatImageView(context) {
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent (MotionEvent event) {
public boolean onTouchEvent(MotionEvent event) {
null-nick marked this conversation as resolved.
Show resolved Hide resolved
return Views.isValid(this) && super.onTouchEvent(event);
}
};
Expand All @@ -98,35 +114,43 @@ public boolean onTouchEvent (MotionEvent event) {
topDismissButton.setScaleType(ImageView.ScaleType.CENTER);
topDismissButton.setColorFilter(Theme.iconColor());
topDismissButton.setImageResource(R.drawable.baseline_close_18);
topDismissButton.setLayoutParams(FrameLayoutFix.newParams(Screen.dp(40f), ViewGroup.LayoutParams.MATCH_PARENT, Lang.gravity() | Gravity.TOP));
topDismissButton.setLayoutParams(FrameLayoutFix.newParams(Screen.dp(40f), ViewGroup.LayoutParams.MATCH_PARENT, Gravity.END | Gravity.TOP));
topDismissButton.setBackgroundResource(R.drawable.bg_btn_header);
Views.setClickable(topDismissButton);
topDismissButton.setVisibility(View.INVISIBLE);
addView(topDismissButton);

additionalTextView = new TextView(context);
additionalTextView.setVisibility(View.GONE);
additionalTextView.setGravity(Gravity.CENTER);
additionalTextView.setTextColor(Theme.getColor(ColorId.textNeutral));
additionalTextView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
actionsContainer.addView(additionalTextView);
}

public void setDismissListener (DismissListener dismissListener) {
public void setDismissListener(DismissListener dismissListener) {
null-nick marked this conversation as resolved.
Show resolved Hide resolved
this.dismissListener = dismissListener;
}

private @Nullable ViewController<?> themeProvider;

public void addThemeListeners (@Nullable ViewController<?> themeProvider) {
public void addThemeListeners(@Nullable ViewController<?> themeProvider) {
null-nick marked this conversation as resolved.
Show resolved Hide resolved
this.themeProvider = themeProvider;
if (themeProvider != null) {
themeProvider.addThemeFilterListener(topDismissButton, ColorId.icon);
themeProvider.addThemeInvalidateListener(this);
}
}

public void setCanDismiss (boolean canDismiss) {
public void setCanDismiss(boolean canDismiss) {
null-nick marked this conversation as resolved.
Show resolved Hide resolved
if (this.canDismiss != canDismiss) {
this.canDismiss = canDismiss;
topDismissButton.setVisibility(canDismiss ? View.VISIBLE : View.GONE);
}
}

public void setItems (Item... items) {
public void setItems(Item... items) {
null-nick marked this conversation as resolved.
Show resolved Hide resolved
actionsList = (LinearLayout) actionsContainer.getChildAt(0);
for (int i = 0; i < actionsList.getChildCount(); i++) {
View view = actionsList.getChildAt(i);
if (view != null && themeProvider != null) {
Expand All @@ -145,25 +169,46 @@ public void setItems (Item... items) {
canDismiss = true;
}
int textColorId = item.isNegative ? ColorId.textNegative : ColorId.textNeutral;
TextView button = Views.newTextView(getContext(), 15f, Theme.getColor(textColorId), Gravity.CENTER, Views.TEXT_FLAG_BOLD | Views.TEXT_FLAG_HORIZONTAL_PADDING);
button.setId(item.id);

LinearLayout buttonLayout = new LinearLayout(getContext());
buttonLayout.setOrientation(LinearLayout.HORIZONTAL);
buttonLayout.setGravity(Gravity.CENTER);
buttonLayout.setBackgroundResource(R.drawable.bg_btn_header);
buttonLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, 2f));
Views.setClickable(buttonLayout);

if (item.iconResId != 0) {
ImageView iconView = new ImageView(getContext());
iconView.setImageResource(item.iconResId);
iconView.setColorFilter(Theme.getColor(textColorId));
iconView.setLayoutParams(new LinearLayout.LayoutParams(Screen.dp(24f), Screen.dp(24f))); // Increased icon size
buttonLayout.addView(iconView);
}

TextView buttonText = Views.newTextView(getContext(), 15f, Theme.getColor(textColorId), Gravity.CENTER, Views.TEXT_FLAG_BOLD | Views.TEXT_FLAG_HORIZONTAL_PADDING); // Increased text size
buttonText.setId(item.id);
if (themeProvider != null) {
themeProvider.addThemeTextColorListener(button, textColorId);
themeProvider.addThemeTextColorListener(buttonText, textColorId);
}
button.setEllipsize(TextUtils.TruncateAt.END);
button.setSingleLine(true);
button.setBackgroundResource(R.drawable.bg_btn_header);
button.setOnClickListener(item.onClickListener);
Views.setMediumText(button, Lang.getString(item.stringRes).toUpperCase());
Views.setClickable(button);
button.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, 2f));
actionsList.addView(button);
buttonText.setEllipsize(TextUtils.TruncateAt.END);
buttonText.setSingleLine(true);
buttonText.setText(Lang.getString(item.stringRes).toUpperCase());
buttonText.setOnClickListener(item.onClickListener);

buttonLayout.addView(buttonText);
actionsList.addView(buttonLayout);
}
if (items.length > 1) {
View offsetView = new View(getContext());
offsetView.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, .75f));
actionsList.addView(offsetView);
}
setCanDismiss(canDismiss);
additionalTextView.setVisibility(items.length == 0 && !TextUtils.isEmpty(additionalTextView.getText()) ? View.VISIBLE : View.GONE);
}

public void setAdditionalText(String text) {
additionalTextView.setText(text);
additionalTextView.setVisibility(TextUtils.isEmpty(text) ? View.GONE : View.VISIBLE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8040,13 +8040,13 @@ private boolean needActionBar () {
}

private TopBarView.Item newAddContactItem (long chatId) {
return new TopBarView.Item(R.id.btn_addContact, R.string.AddContact, v -> {
return new TopBarView.Item(R.id.btn_addContact, R.string.AddContact, R.drawable.baseline_person_add_24, v -> {
tdlib.ui().addContact(this, tdlib.chatUser(chatId));
});
}

private TopBarView.Item newUnarchiveItem (long chatId) {
return new TopBarView.Item(R.id.btn_unarchiveChat, R.string.UnarchiveUnmute, v -> {
return new TopBarView.Item(R.id.btn_unarchiveChat, R.string.UnarchiveUnmute, R.drawable.baseline_unarchive_24, v -> {
tdlib.client().send(new TdApi.AddChatToList(chatId, new TdApi.ChatListMain()), tdlib.okHandler());
TdApi.ChatNotificationSettings settings = tdlib.chatSettings(chatId);
if (settings != null) {
Expand All @@ -8066,7 +8066,7 @@ private TopBarView.Item newUnarchiveItem (long chatId) {
}

private TopBarView.Item newReportItem (long chatId, boolean isBlock) {
return new TopBarView.Item(R.id.btn_reportChat, isBlock ? R.string.BlockContact : R.string.ReportSpam, v -> {
return new TopBarView.Item(R.id.btn_reportChat, isBlock ? R.string.BlockContact : R.string.ReportSpam, isBlock ? R.drawable.baseline_block_24 : R.drawable.baseline_report_24, v -> {
showSettings(new SettingsWrapBuilder(R.id.btn_reportSpam)
.setHeaderItem(new ListItem(ListItem.TYPE_INFO, 0, 0, Lang.getStringBold(R.string.ReportChatSpam, chat.title), false))
.setRawItems(getChatUserId() != 0 ? new ListItem[] {
Expand Down