From e1e9268ef5051a96375f810372560f2da9516ad5 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Tue, 7 Jan 2020 19:40:52 +0100 Subject: [PATCH] use material buttons in timeline (#1627) * use material buttons in timeline * remove wrong switch option --- .../tusky/adapter/NotificationsAdapter.java | 33 +++++++++---------- .../tusky/adapter/StatusBaseViewHolder.java | 24 ++++++++++---- .../tusky/adapter/StatusViewHolder.java | 12 +++---- .../conversation/ConversationViewHolder.java | 12 +++---- .../report/adapter/StatusViewHolder.kt | 25 +++++++++----- app/src/main/res/drawable/toggle_small.xml | 6 ---- .../main/res/drawable/toggle_small_light.xml | 6 ---- app/src/main/res/layout/item_conversation.xml | 21 +++++------- .../main/res/layout/item_report_status.xml | 14 ++++---- app/src/main/res/layout/item_status.xml | 17 +++++----- .../main/res/layout/item_status_detailed.xml | 15 ++++----- .../res/layout/item_status_notification.xml | 15 ++++----- app/src/main/res/values-night/styles.xml | 1 - app/src/main/res/values/attrs.xml | 1 - app/src/main/res/values/styles.xml | 1 - 15 files changed, 96 insertions(+), 107 deletions(-) delete mode 100644 app/src/main/res/drawable/toggle_small.xml delete mode 100644 app/src/main/res/drawable/toggle_small_light.xml diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java b/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java index 433676f0..35a5526a 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java @@ -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 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); - } } } diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java index fe63c9ae..b22ebd07 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java @@ -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, diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java index 40800fa9..56cef6ee 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java @@ -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 { diff --git a/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationViewHolder.java index c0e1a3d2..36557599 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationViewHolder.java @@ -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 { diff --git a/app/src/main/java/com/keylesspalace/tusky/components/report/adapter/StatusViewHolder.kt b/app/src/main/java/com/keylesspalace/tusky/components/report/adapter/StatusViewHolder.kt index 2007c2ac..b4120ca8 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/report/adapter/StatusViewHolder.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/report/adapter/StatusViewHolder.kt @@ -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 { diff --git a/app/src/main/res/drawable/toggle_small.xml b/app/src/main/res/drawable/toggle_small.xml deleted file mode 100644 index bf55fff0..00000000 --- a/app/src/main/res/drawable/toggle_small.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable/toggle_small_light.xml b/app/src/main/res/drawable/toggle_small_light.xml deleted file mode 100644 index 5f27f87a..00000000 --- a/app/src/main/res/drawable/toggle_small_light.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/item_conversation.xml b/app/src/main/res/layout/item_conversation.xml index 49fcd65e..df82c654 100644 --- a/app/src/main/res/layout/item_conversation.xml +++ b/app/src/main/res/layout/item_conversation.xml @@ -136,13 +136,13 @@ tools:text="content warning which is very long and it doesn't fit" tools:visibility="visible" /> - - - - - - - - - - - - - + app:layout_constraintTop_toBottomOf="@+id/status_content_warning_description" + tools:text="@string/status_content_warning_show_more" /> - - - - - - diff --git a/app/src/main/res/values-night/styles.xml b/app/src/main/res/values-night/styles.xml index c53c519d..e9164b53 100644 --- a/app/src/main/res/values-night/styles.xml +++ b/app/src/main/res/values-night/styles.xml @@ -35,7 +35,6 @@ @drawable/reblog_direct_dark @drawable/favourite_active_dark @drawable/favourite_inactive_dark - @drawable/toggle_small #80000000 @drawable/media_preview_unloaded_dark @drawable/status_divider_dark diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 2be80485..b3750663 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -20,7 +20,6 @@ - diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 8a73ad68..a13eed14 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -87,7 +87,6 @@ @drawable/reblog_direct_light @drawable/favourite_active_light @drawable/favourite_inactive_light - @drawable/toggle_small_light #80B0B0B0 @drawable/media_preview_unloaded_light @drawable/status_divider_light