use material buttons in timeline (#1627)

* use material buttons in timeline

* remove wrong switch option
This commit is contained in:
Konrad Pozniak 2020-01-07 19:40:52 +01:00 committed by GitHub
commit e5b78f65cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 96 additions and 107 deletions

View file

@ -28,10 +28,9 @@ import android.text.style.StyleSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ToggleButton;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -332,7 +331,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
}
private static class StatusNotificationViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener, ToggleButton.OnCheckedChangeListener {
implements View.OnClickListener {
private final TextView message;
private final View statusNameBar;
private final TextView displayName;
@ -342,8 +341,8 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
private final ImageView statusAvatar;
private final ImageView notificationAvatar;
private final TextView contentWarningDescriptionTextView;
private final ToggleButton contentWarningButton;
private final ToggleButton contentCollapseButton; // TODO: This code SHOULD be based on StatusBaseViewHolder
private final Button contentWarningButton;
private final Button contentCollapseButton; // TODO: This code SHOULD be based on StatusBaseViewHolder
private StatusDisplayOptions statusDisplayOptions;
private String accountId;
@ -375,7 +374,6 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
itemView.setOnClickListener(this);
message.setOnClickListener(this);
statusContent.setOnClickListener(this);
contentWarningButton.setOnCheckedChangeListener(this);
shortSdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
longSdf = new SimpleDateFormat("MM/dd HH:mm:ss", Locale.getDefault());
}
@ -481,6 +479,14 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
boolean hasSpoiler = !TextUtils.isEmpty(statusViewData.getSpoilerText());
contentWarningDescriptionTextView.setVisibility(hasSpoiler ? View.VISIBLE : View.GONE);
contentWarningButton.setVisibility(hasSpoiler ? View.VISIBLE : View.GONE);
contentWarningButton.setOnClickListener(view -> {
if (getAdapterPosition() != RecyclerView.NO_POSITION) {
notificationActionListener.onExpandedChange(!statusViewData.isExpanded(), getAdapterPosition());
}
statusContent.setVisibility(statusViewData.isExpanded() ? View.GONE : View.VISIBLE);
});
setupContentAndSpoiler(notificationViewData, listener);
}
@ -537,19 +543,19 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
List<Emoji> emojis = statusViewData.getStatusEmojis();
if (statusViewData.isCollapsible() && (notificationViewData.isExpanded() || !hasSpoiler)) {
contentCollapseButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
contentCollapseButton.setOnClickListener(view -> {
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION && notificationActionListener != null) {
notificationActionListener.onNotificationContentCollapsedChange(isChecked, position);
notificationActionListener.onNotificationContentCollapsedChange(statusViewData.isCollapsed(), position);
}
});
contentCollapseButton.setVisibility(View.VISIBLE);
if (statusViewData.isCollapsed()) {
contentCollapseButton.setChecked(true);
contentCollapseButton.setText(R.string.status_content_warning_show_more);
statusContent.setFilters(COLLAPSE_INPUT_FILTER);
} else {
contentCollapseButton.setChecked(false);
contentCollapseButton.setText(R.string.status_content_warning_show_less);
statusContent.setFilters(NO_INPUT_FILTER);
}
} else {
@ -565,12 +571,5 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
contentWarningDescriptionTextView.setText(emojifiedContentWarning);
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (getAdapterPosition() != RecyclerView.NO_POSITION) {
notificationActionListener.onExpandedChange(isChecked, getAdapterPosition());
}
statusContent.setVisibility(isChecked ? View.VISIBLE : View.GONE);
}
}
}

View file

@ -13,7 +13,6 @@ import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
@ -23,6 +22,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.google.android.material.button.MaterialButton;
import com.keylesspalace.tusky.R;
import com.keylesspalace.tusky.entity.Attachment;
import com.keylesspalace.tusky.entity.Attachment.Focus;
@ -73,7 +73,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
private TextView sensitiveMediaWarning;
private View sensitiveMediaShow;
protected TextView[] mediaLabels;
private ToggleButton contentWarningButton;
private MaterialButton contentWarningButton;
private ImageView avatarInset;
public ImageView avatar;
@ -173,7 +173,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
}
public void toggleContentWarning() {
contentWarningButton.toggle();
contentWarningButton.performClick();
}
protected void setSpoilerAndContent(boolean expanded,
@ -193,18 +193,28 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
contentWarningDescription.setText(emojiSpoiler);
contentWarningDescription.setVisibility(View.VISIBLE);
contentWarningButton.setVisibility(View.VISIBLE);
contentWarningButton.setChecked(expanded);
contentWarningButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
setContentWarningButtonText(expanded);
contentWarningButton.setOnClickListener( view -> {
contentWarningDescription.invalidate();
if (getAdapterPosition() != RecyclerView.NO_POSITION) {
listener.onExpandedChange(isChecked, getAdapterPosition());
listener.onExpandedChange(!expanded, getAdapterPosition());
}
this.setTextVisible(isChecked, content, mentions, emojis, poll, statusDisplayOptions, listener);
setContentWarningButtonText(!expanded);
this.setTextVisible(!expanded, content, mentions, emojis, poll, statusDisplayOptions, listener);
});
this.setTextVisible(expanded, content, mentions, emojis, poll, statusDisplayOptions, listener);
}
}
private void setContentWarningButtonText(boolean expanded) {
if(expanded) {
contentWarningButton.setText(R.string.status_content_warning_show_less);
} else {
contentWarningButton.setText(R.string.status_content_warning_show_more);
}
}
private void setTextVisible(boolean expanded,
Spanned content,
Status.Mention[] mentions,

View file

@ -19,8 +19,8 @@ import android.content.Context;
import android.text.InputFilter;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ToggleButton;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
@ -38,7 +38,7 @@ public class StatusViewHolder extends StatusBaseViewHolder {
private static final InputFilter[] NO_INPUT_FILTER = new InputFilter[0];
private TextView statusInfo;
private ToggleButton contentCollapseButton;
private Button contentCollapseButton;
public StatusViewHolder(View itemView) {
super(itemView);
@ -96,18 +96,18 @@ public class StatusViewHolder extends StatusBaseViewHolder {
private void setupCollapsedState(final StatusViewData.Concrete status, final StatusActionListener listener) {
/* input filter for TextViews have to be set before text */
if (status.isCollapsible() && (status.isExpanded() || TextUtils.isEmpty(status.getSpoilerText()))) {
contentCollapseButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
contentCollapseButton.setOnClickListener(view -> {
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION)
listener.onContentCollapsedChange(isChecked, position);
listener.onContentCollapsedChange(!status.isCollapsed(), position);
});
contentCollapseButton.setVisibility(View.VISIBLE);
if (status.isCollapsed()) {
contentCollapseButton.setChecked(true);
contentCollapseButton.setText(R.string.status_content_warning_show_more);
content.setFilters(COLLAPSE_INPUT_FILTER);
} else {
contentCollapseButton.setChecked(false);
contentCollapseButton.setText(R.string.status_content_warning_show_less);
content.setFilters(NO_INPUT_FILTER);
}
} else {

View file

@ -19,9 +19,9 @@ import android.content.Context;
import android.text.InputFilter;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ToggleButton;
import androidx.recyclerview.widget.RecyclerView;
@ -41,7 +41,7 @@ public class ConversationViewHolder extends StatusBaseViewHolder {
private static final InputFilter[] NO_INPUT_FILTER = new InputFilter[0];
private TextView conversationNameTextView;
private ToggleButton contentCollapseButton;
private Button contentCollapseButton;
private ImageView[] avatars;
private StatusDisplayOptions statusDisplayOptions;
@ -145,18 +145,18 @@ public class ConversationViewHolder extends StatusBaseViewHolder {
private void setupCollapsedState(boolean collapsible, boolean collapsed, boolean expanded, String spoilerText, final StatusActionListener listener) {
/* input filter for TextViews have to be set before text */
if (collapsible && (expanded || TextUtils.isEmpty(spoilerText))) {
contentCollapseButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
contentCollapseButton.setOnClickListener(view -> {
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION)
listener.onContentCollapsedChange(isChecked, position);
listener.onContentCollapsedChange(!collapsed, position);
});
contentCollapseButton.setVisibility(View.VISIBLE);
if (collapsed) {
contentCollapseButton.setChecked(true);
contentCollapseButton.setText(R.string.status_content_warning_show_more);
content.setFilters(COLLAPSE_INPUT_FILTER);
} else {
contentCollapseButton.setChecked(false);
contentCollapseButton.setText(R.string.status_content_warning_show_less);
content.setFilters(NO_INPUT_FILTER);
}
} else {

View file

@ -93,12 +93,14 @@ class StatusViewHolder(
itemView.statusContentWarningDescription.text = emojiSpoiler
itemView.statusContentWarningDescription.show()
itemView.statusContentWarningButton.show()
itemView.statusContentWarningButton.isChecked = viewState.isContentShow(status.id, true)
itemView.statusContentWarningButton.setOnCheckedChangeListener { _, isViewChecked ->
setContentWarningButtonText(viewState.isContentShow(status.id, true))
itemView.statusContentWarningButton.setOnClickListener {
status()?.let { status ->
val contentShown = viewState.isContentShow(status.id, true)
itemView.statusContentWarningDescription.invalidate()
viewState.setContentShow(status.id, isViewChecked)
setTextVisible(isViewChecked, status.content, status.mentions, status.emojis, adapterHandler)
viewState.setContentShow(status.id, !contentShown)
setTextVisible(!contentShown, status.content, status.mentions, status.emojis, adapterHandler)
setContentWarningButtonText(!contentShown)
}
}
setTextVisible(viewState.isContentShow(status.id, true), status.content, status.mentions, status.emojis, adapterHandler)
@ -106,6 +108,13 @@ class StatusViewHolder(
}
}
private fun setContentWarningButtonText(contentShown: Boolean) {
if(contentShown) {
itemView.statusContentWarningButton.setText(R.string.status_content_warning_show_less)
} else {
itemView.statusContentWarningButton.setText(R.string.status_content_warning_show_more)
}
}
private fun setTextVisible(expanded: Boolean,
content: Spanned,
@ -144,19 +153,19 @@ class StatusViewHolder(
private fun setupCollapsedState(collapsible: Boolean, collapsed: Boolean, expanded: Boolean, spoilerText: String) {
/* input filter for TextViews have to be set before text */
if (collapsible && (expanded || TextUtils.isEmpty(spoilerText))) {
itemView.buttonToggleContent.setOnCheckedChangeListener { _, isChecked ->
itemView.buttonToggleContent.setOnClickListener{
status()?.let { status ->
viewState.setCollapsed(status.id, isChecked)
viewState.setCollapsed(status.id, !collapsed)
updateTextView()
}
}
itemView.buttonToggleContent.show()
if (collapsed) {
itemView.buttonToggleContent.isChecked = true
itemView.buttonToggleContent.setText(R.string.status_content_show_more)
itemView.statusContent.filters = COLLAPSE_INPUT_FILTER
} else {
itemView.buttonToggleContent.isChecked = false
itemView.buttonToggleContent.setText(R.string.status_content_show_less)
itemView.statusContent.filters = NO_INPUT_FILTER
}
} else {