2017-01-23 16:19:30 +11:00
|
|
|
/* Copyright 2017 Andrew Dawson
|
|
|
|
*
|
2017-04-10 10:12:31 +10:00
|
|
|
* This file is a part of Tusky.
|
2017-01-23 16:19:30 +11:00
|
|
|
*
|
2017-04-10 10:12:31 +10: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 16:19:30 +11:00
|
|
|
*
|
|
|
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2017-04-10 10:12:31 +10:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
2017-01-23 16:19:30 +11:00
|
|
|
*
|
2017-04-10 10:12:31 +10: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 16:19:30 +11:00
|
|
|
|
2017-05-05 08:55:34 +10:00
|
|
|
package com.keylesspalace.tusky.adapter;
|
2017-01-23 16:19:30 +11:00
|
|
|
|
|
|
|
import android.content.Context;
|
2019-01-12 06:05:15 +11:00
|
|
|
import android.text.InputFilter;
|
2019-07-28 05:53:28 +10:00
|
|
|
import android.text.TextUtils;
|
2017-01-23 16:19:30 +11:00
|
|
|
import android.view.View;
|
2020-01-08 05:40:52 +11:00
|
|
|
import android.widget.Button;
|
2017-01-23 16:19:30 +11:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2019-12-31 07:37:20 +11:00
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
2017-05-05 08:55:34 +10:00
|
|
|
import com.keylesspalace.tusky.R;
|
2017-07-14 15:06:32 +10:00
|
|
|
import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
2021-01-16 07:16:32 +11:00
|
|
|
import com.keylesspalace.tusky.util.CustomEmojiHelper;
|
2019-01-12 06:05:15 +11:00
|
|
|
import com.keylesspalace.tusky.util.SmartLengthInputFilter;
|
2019-12-31 07:37:20 +11:00
|
|
|
import com.keylesspalace.tusky.util.StatusDisplayOptions;
|
2021-01-16 07:16:32 +11:00
|
|
|
import com.keylesspalace.tusky.util.StringUtils;
|
2017-07-13 05:54:52 +10:00
|
|
|
import com.keylesspalace.tusky.viewdata.StatusViewData;
|
2018-07-30 23:36:22 +10:00
|
|
|
|
2018-04-29 06:59:46 +10:00
|
|
|
import at.connyduck.sparkbutton.helpers.Utils;
|
2017-01-23 16:19:30 +11:00
|
|
|
|
2017-08-04 07:26:26 +10:00
|
|
|
public class StatusViewHolder extends StatusBaseViewHolder {
|
2019-01-12 06:05:15 +11:00
|
|
|
private static final InputFilter[] COLLAPSE_INPUT_FILTER = new InputFilter[]{SmartLengthInputFilter.INSTANCE};
|
|
|
|
private static final InputFilter[] NO_INPUT_FILTER = new InputFilter[0];
|
|
|
|
|
2019-05-03 03:44:35 +10:00
|
|
|
private TextView statusInfo;
|
2020-01-08 05:40:52 +11:00
|
|
|
private Button contentCollapseButton;
|
2017-08-03 14:29:31 +10:00
|
|
|
|
2019-12-31 07:37:20 +11:00
|
|
|
public StatusViewHolder(View itemView) {
|
|
|
|
super(itemView);
|
2019-05-03 03:44:35 +10:00
|
|
|
statusInfo = itemView.findViewById(R.id.status_info);
|
2019-01-12 06:05:15 +11:00
|
|
|
contentCollapseButton = itemView.findViewById(R.id.button_toggle_content);
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
|
|
|
|
2017-12-01 06:12:09 +11:00
|
|
|
@Override
|
|
|
|
protected int getMediaPreviewHeight(Context context) {
|
|
|
|
return context.getResources().getDimensionPixelSize(R.dimen.status_media_preview_height);
|
|
|
|
}
|
|
|
|
|
2017-08-04 07:26:26 +10:00
|
|
|
@Override
|
2019-12-31 07:37:20 +11:00
|
|
|
protected void setupWithStatus(StatusViewData.Concrete status,
|
|
|
|
final StatusActionListener listener,
|
|
|
|
StatusDisplayOptions statusDisplayOptions,
|
2019-05-26 16:46:08 +10:00
|
|
|
@Nullable Object payloads) {
|
2019-07-28 05:53:28 +10:00
|
|
|
if (payloads == null) {
|
|
|
|
|
|
|
|
setupCollapsedState(status, listener);
|
2019-03-17 00:38:29 +11:00
|
|
|
|
2019-07-28 05:53:28 +10:00
|
|
|
String rebloggedByDisplayName = status.getRebloggedByUsername();
|
|
|
|
if (rebloggedByDisplayName == null) {
|
|
|
|
hideStatusInfo();
|
|
|
|
} else {
|
2021-01-16 07:16:32 +11:00
|
|
|
setRebloggedByDisplayName(rebloggedByDisplayName, status);
|
2019-07-28 05:53:28 +10:00
|
|
|
statusInfo.setOnClickListener(v -> listener.onOpenReblog(getAdapterPosition()));
|
2019-05-03 03:44:35 +10:00
|
|
|
}
|
2019-07-28 05:53:28 +10:00
|
|
|
|
2018-03-02 07:10:10 +11:00
|
|
|
}
|
2019-12-31 07:37:20 +11:00
|
|
|
super.setupWithStatus(status, listener, statusDisplayOptions, payloads);
|
2019-07-28 05:53:28 +10:00
|
|
|
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
|
|
|
|
2021-01-16 07:16:32 +11:00
|
|
|
private void setRebloggedByDisplayName(final CharSequence name, final StatusViewData.Concrete status) {
|
2019-05-03 03:44:35 +10:00
|
|
|
Context context = statusInfo.getContext();
|
2021-01-16 07:16:32 +11:00
|
|
|
CharSequence wrappedName = StringUtils.unicodeWrap(name);
|
|
|
|
CharSequence boostedText = context.getString(R.string.status_boosted_format, wrappedName);
|
|
|
|
CharSequence emojifiedText = CustomEmojiHelper.emojify(boostedText, status.getRebloggedByAccountEmojis(), statusInfo);
|
|
|
|
statusInfo.setText(emojifiedText);
|
2019-05-03 03:44:35 +10:00
|
|
|
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 16:19:30 +11:00
|
|
|
}
|
|
|
|
|
2019-05-03 03:44:35 +10:00
|
|
|
void hideStatusInfo() {
|
|
|
|
statusInfo.setVisibility(View.GONE);
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
2019-01-12 06:05:15 +11:00
|
|
|
|
|
|
|
private void setupCollapsedState(final StatusViewData.Concrete status, final StatusActionListener listener) {
|
|
|
|
/* input filter for TextViews have to be set before text */
|
2019-07-28 05:53:28 +10:00
|
|
|
if (status.isCollapsible() && (status.isExpanded() || TextUtils.isEmpty(status.getSpoilerText()))) {
|
2020-01-08 05:40:52 +11:00
|
|
|
contentCollapseButton.setOnClickListener(view -> {
|
2019-01-12 06:05:15 +11:00
|
|
|
int position = getAdapterPosition();
|
|
|
|
if (position != RecyclerView.NO_POSITION)
|
2020-01-08 05:40:52 +11:00
|
|
|
listener.onContentCollapsedChange(!status.isCollapsed(), position);
|
2019-01-12 06:05:15 +11:00
|
|
|
});
|
|
|
|
|
|
|
|
contentCollapseButton.setVisibility(View.VISIBLE);
|
|
|
|
if (status.isCollapsed()) {
|
2020-01-08 05:40:52 +11:00
|
|
|
contentCollapseButton.setText(R.string.status_content_warning_show_more);
|
2019-01-12 06:05:15 +11:00
|
|
|
content.setFilters(COLLAPSE_INPUT_FILTER);
|
|
|
|
} else {
|
2020-01-08 05:40:52 +11:00
|
|
|
contentCollapseButton.setText(R.string.status_content_warning_show_less);
|
2019-01-12 06:05:15 +11:00
|
|
|
content.setFilters(NO_INPUT_FILTER);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
contentCollapseButton.setVisibility(View.GONE);
|
|
|
|
content.setFilters(NO_INPUT_FILTER);
|
|
|
|
}
|
|
|
|
}
|
2019-03-05 05:24:27 +11:00
|
|
|
}
|