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

@ -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,