2017-01-23 06:19:30 +01:00
|
|
|
/* Copyright 2017 Andrew Dawson
|
|
|
|
*
|
2017-04-10 02:12:31 +02:00
|
|
|
* This file is a part of Tusky.
|
2017-01-23 06:19:30 +01:00
|
|
|
*
|
2017-04-10 02:12:31 +02:00
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2017-01-23 06:19:30 +01:00
|
|
|
*
|
|
|
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2017-04-10 02:12:31 +02:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
2017-01-23 06:19:30 +01:00
|
|
|
*
|
2017-04-10 02:12:31 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
2017-01-23 06:19:30 +01:00
|
|
|
|
2017-05-05 00:55:34 +02:00
|
|
|
package com.keylesspalace.tusky.adapter;
|
2017-01-23 06:19:30 +01:00
|
|
|
|
|
|
|
import android.content.Context;
|
2019-01-11 20:05:15 +01:00
|
|
|
import android.text.InputFilter;
|
2019-07-27 21:53:28 +02:00
|
|
|
import android.text.TextUtils;
|
2017-01-23 06:19:30 +01:00
|
|
|
import android.view.View;
|
2020-01-07 19:40:52 +01:00
|
|
|
import android.widget.Button;
|
2017-01-23 06:19:30 +01:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2019-12-30 21:37:20 +01:00
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
2017-05-05 00:55:34 +02:00
|
|
|
import com.keylesspalace.tusky.R;
|
2017-07-14 07:06:32 +02:00
|
|
|
import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
2019-01-11 20:05:15 +01:00
|
|
|
import com.keylesspalace.tusky.util.SmartLengthInputFilter;
|
2019-12-30 21:37:20 +01:00
|
|
|
import com.keylesspalace.tusky.util.StatusDisplayOptions;
|
2017-07-12 21:54:52 +02:00
|
|
|
import com.keylesspalace.tusky.viewdata.StatusViewData;
|
2018-07-30 15:36:22 +02:00
|
|
|
|
2018-04-28 22:59:46 +02:00
|
|
|
import at.connyduck.sparkbutton.helpers.Utils;
|
2017-01-23 06:19:30 +01:00
|
|
|
|
2017-08-03 23:26:26 +02:00
|
|
|
public class StatusViewHolder extends StatusBaseViewHolder {
|
2019-01-11 20:05:15 +01:00
|
|
|
private static final InputFilter[] COLLAPSE_INPUT_FILTER = new InputFilter[]{SmartLengthInputFilter.INSTANCE};
|
|
|
|
private static final InputFilter[] NO_INPUT_FILTER = new InputFilter[0];
|
|
|
|
|
2019-05-02 19:44:35 +02:00
|
|
|
private TextView statusInfo;
|
2020-01-07 19:40:52 +01:00
|
|
|
private Button contentCollapseButton;
|
2017-08-03 06:29:31 +02:00
|
|
|
|
2019-12-30 21:37:20 +01:00
|
|
|
public StatusViewHolder(View itemView) {
|
|
|
|
super(itemView);
|
2019-05-02 19:44:35 +02:00
|
|
|
statusInfo = itemView.findViewById(R.id.status_info);
|
2019-01-11 20:05:15 +01:00
|
|
|
contentCollapseButton = itemView.findViewById(R.id.button_toggle_content);
|
2017-01-23 06:19:30 +01:00
|
|
|
}
|
|
|
|
|
2017-11-30 20:12:09 +01:00
|
|
|
@Override
|
|
|
|
protected int getMediaPreviewHeight(Context context) {
|
|
|
|
return context.getResources().getDimensionPixelSize(R.dimen.status_media_preview_height);
|
|
|
|
}
|
|
|
|
|
2017-08-03 23:26:26 +02:00
|
|
|
@Override
|
2019-12-30 21:37:20 +01:00
|
|
|
protected void setupWithStatus(StatusViewData.Concrete status,
|
|
|
|
final StatusActionListener listener,
|
|
|
|
StatusDisplayOptions statusDisplayOptions,
|
2019-05-26 08:46:08 +02:00
|
|
|
@Nullable Object payloads) {
|
2019-07-27 21:53:28 +02:00
|
|
|
if (payloads == null) {
|
|
|
|
|
|
|
|
setupCollapsedState(status, listener);
|
2019-03-16 14:38:29 +01:00
|
|
|
|
2019-07-27 21:53:28 +02:00
|
|
|
String rebloggedByDisplayName = status.getRebloggedByUsername();
|
|
|
|
if (rebloggedByDisplayName == null) {
|
|
|
|
hideStatusInfo();
|
|
|
|
} else {
|
|
|
|
setRebloggedByDisplayName(rebloggedByDisplayName);
|
|
|
|
statusInfo.setOnClickListener(v -> listener.onOpenReblog(getAdapterPosition()));
|
2019-05-02 19:44:35 +02:00
|
|
|
}
|
2019-07-27 21:53:28 +02:00
|
|
|
|
2018-03-01 21:10:10 +01:00
|
|
|
}
|
2019-12-30 21:37:20 +01:00
|
|
|
super.setupWithStatus(status, listener, statusDisplayOptions, payloads);
|
2019-07-27 21:53:28 +02:00
|
|
|
|
2017-01-23 06:19:30 +01:00
|
|
|
}
|
|
|
|
|
2019-01-11 20:05:15 +01:00
|
|
|
private void setRebloggedByDisplayName(final String name) {
|
2019-05-02 19:44:35 +02:00
|
|
|
Context context = statusInfo.getContext();
|
2018-09-28 17:15:01 +02:00
|
|
|
String boostedText = context.getString(R.string.status_boosted_format, name);
|
2019-05-02 19:44:35 +02:00
|
|
|
statusInfo.setText(boostedText);
|
|
|
|
statusInfo.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// don't use this on the same ViewHolder as setRebloggedByDisplayName, will cause recycling issues as paddings are changed
|
|
|
|
void setPollInfo(final boolean ownPoll) {
|
|
|
|
statusInfo.setText(ownPoll ? R.string.poll_ended_created : R.string.poll_ended_voted);
|
|
|
|
statusInfo.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ic_poll_24dp, 0, 0, 0);
|
|
|
|
statusInfo.setCompoundDrawablePadding(Utils.dpToPx(statusInfo.getContext(), 10));
|
|
|
|
statusInfo.setPaddingRelative(Utils.dpToPx(statusInfo.getContext(), 28), 0, 0, 0);
|
|
|
|
statusInfo.setVisibility(View.VISIBLE);
|
2017-01-23 06:19:30 +01:00
|
|
|
}
|
|
|
|
|
2019-05-02 19:44:35 +02:00
|
|
|
void hideStatusInfo() {
|
|
|
|
statusInfo.setVisibility(View.GONE);
|
2017-01-23 06:19:30 +01:00
|
|
|
}
|
2019-01-11 20:05:15 +01:00
|
|
|
|
|
|
|
private void setupCollapsedState(final StatusViewData.Concrete status, final StatusActionListener listener) {
|
|
|
|
/* input filter for TextViews have to be set before text */
|
2019-07-27 21:53:28 +02:00
|
|
|
if (status.isCollapsible() && (status.isExpanded() || TextUtils.isEmpty(status.getSpoilerText()))) {
|
2020-01-07 19:40:52 +01:00
|
|
|
contentCollapseButton.setOnClickListener(view -> {
|
2019-01-11 20:05:15 +01:00
|
|
|
int position = getAdapterPosition();
|
|
|
|
if (position != RecyclerView.NO_POSITION)
|
2020-01-07 19:40:52 +01:00
|
|
|
listener.onContentCollapsedChange(!status.isCollapsed(), position);
|
2019-01-11 20:05:15 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
contentCollapseButton.setVisibility(View.VISIBLE);
|
|
|
|
if (status.isCollapsed()) {
|
2020-01-07 19:40:52 +01:00
|
|
|
contentCollapseButton.setText(R.string.status_content_warning_show_more);
|
2019-01-11 20:05:15 +01:00
|
|
|
content.setFilters(COLLAPSE_INPUT_FILTER);
|
|
|
|
} else {
|
2020-01-07 19:40:52 +01:00
|
|
|
contentCollapseButton.setText(R.string.status_content_warning_show_less);
|
2019-01-11 20:05:15 +01:00
|
|
|
content.setFilters(NO_INPUT_FILTER);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
contentCollapseButton.setVisibility(View.GONE);
|
|
|
|
content.setFilters(NO_INPUT_FILTER);
|
|
|
|
}
|
|
|
|
}
|
2019-03-04 19:24:27 +01:00
|
|
|
}
|