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;
|
2017-01-23 16:19:30 +11:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.TextView;
|
2019-01-12 06:05:15 +11:00
|
|
|
import android.widget.ToggleButton;
|
2017-01-23 16:19:30 +11:00
|
|
|
|
2019-04-17 05:39:12 +10:00
|
|
|
import com.bumptech.glide.Glide;
|
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;
|
2019-01-12 06:05:15 +11:00
|
|
|
import com.keylesspalace.tusky.util.SmartLengthInputFilter;
|
2017-07-13 05:54:52 +10:00
|
|
|
import com.keylesspalace.tusky.viewdata.StatusViewData;
|
2018-07-30 23:36:22 +10:00
|
|
|
|
2019-03-05 05:24:27 +11:00
|
|
|
import androidx.annotation.Nullable;
|
2019-01-12 06:05:15 +11:00
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
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];
|
|
|
|
|
2017-12-01 06:12:09 +11:00
|
|
|
private TextView rebloggedBar;
|
2019-01-12 06:05:15 +11:00
|
|
|
private ToggleButton contentCollapseButton;
|
2017-08-03 14:29:31 +10:00
|
|
|
|
2018-08-17 12:53:38 +10:00
|
|
|
StatusViewHolder(View itemView, boolean useAbsoluteTime) {
|
|
|
|
super(itemView, useAbsoluteTime);
|
2017-12-01 06:12:09 +11:00
|
|
|
rebloggedBar = itemView.findViewById(R.id.status_reblogged);
|
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-08-04 07:26:26 +10:00
|
|
|
@Override
|
2019-04-10 04:13:25 +10:00
|
|
|
protected void setAvatar(String url, @Nullable String rebloggedUrl, boolean isBot) {
|
|
|
|
super.setAvatar(url, rebloggedUrl, isBot);
|
2017-07-14 15:06:32 +10:00
|
|
|
Context context = avatar.getContext();
|
|
|
|
|
2019-04-19 23:23:30 +10:00
|
|
|
boolean hasReblog = rebloggedUrl != null && !rebloggedUrl.isEmpty();
|
|
|
|
int padding = hasReblog ? Utils.dpToPx(context, 12) : 0;
|
|
|
|
|
|
|
|
avatar.setPaddingRelative(0, 0, padding, padding);
|
|
|
|
|
|
|
|
if (hasReblog) {
|
2019-04-10 04:13:25 +10:00
|
|
|
avatarInset.setVisibility(View.VISIBLE);
|
2019-04-17 05:39:12 +10:00
|
|
|
Glide.with(context)
|
2017-08-04 07:26:26 +10:00
|
|
|
.load(rebloggedUrl)
|
2018-03-31 04:46:36 +11:00
|
|
|
.placeholder(R.drawable.avatar_default)
|
2019-04-10 04:13:25 +10:00
|
|
|
.into(avatarInset);
|
2017-01-31 15:51:02 +11:00
|
|
|
}
|
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-02-13 05:22:37 +11:00
|
|
|
protected void setupWithStatus(StatusViewData.Concrete status, final StatusActionListener listener,
|
2019-03-17 00:38:29 +11:00
|
|
|
boolean mediaPreviewEnabled, @Nullable Object payloads) {
|
|
|
|
if (status == null || payloads==null) {
|
|
|
|
if (status == null) {
|
|
|
|
showContent(false);
|
2018-03-02 07:10:10 +11:00
|
|
|
} else {
|
2019-03-17 00:38:29 +11:00
|
|
|
showContent(true);
|
|
|
|
setupCollapsedState(status, listener);
|
|
|
|
super.setupWithStatus(status, listener, mediaPreviewEnabled, null);
|
|
|
|
|
|
|
|
String rebloggedByDisplayName = status.getRebloggedByUsername();
|
|
|
|
if (rebloggedByDisplayName == null) {
|
|
|
|
hideRebloggedByDisplayName();
|
|
|
|
} else {
|
|
|
|
setRebloggedByDisplayName(rebloggedByDisplayName);
|
|
|
|
}
|
|
|
|
|
|
|
|
rebloggedBar.setOnClickListener(v -> listener.onOpenReblog(getAdapterPosition()));}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
super.setupWithStatus(status, listener, mediaPreviewEnabled, payloads);
|
2018-03-02 07:10:10 +11:00
|
|
|
}
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
|
|
|
|
2019-01-12 06:05:15 +11:00
|
|
|
private void setRebloggedByDisplayName(final String name) {
|
2017-12-01 06:12:09 +11:00
|
|
|
Context context = rebloggedBar.getContext();
|
2018-09-29 01:15:01 +10:00
|
|
|
String boostedText = context.getString(R.string.status_boosted_format, name);
|
2017-12-01 06:12:09 +11:00
|
|
|
rebloggedBar.setText(boostedText);
|
2017-02-13 16:18:17 +11:00
|
|
|
rebloggedBar.setVisibility(View.VISIBLE);
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
|
|
|
|
2017-02-23 06:13:51 +11:00
|
|
|
private void hideRebloggedByDisplayName() {
|
2017-08-03 14:29:31 +10:00
|
|
|
if (rebloggedBar == null) {
|
|
|
|
return;
|
|
|
|
}
|
2017-02-13 16:18:17 +11:00
|
|
|
rebloggedBar.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 */
|
|
|
|
if (status.isCollapsible() && (status.isExpanded() || status.getSpoilerText() == null || status.getSpoilerText().isEmpty())) {
|
|
|
|
contentCollapseButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
|
|
|
int position = getAdapterPosition();
|
|
|
|
if (position != RecyclerView.NO_POSITION)
|
|
|
|
listener.onContentCollapsedChange(isChecked, position);
|
|
|
|
});
|
|
|
|
|
|
|
|
contentCollapseButton.setVisibility(View.VISIBLE);
|
|
|
|
if (status.isCollapsed()) {
|
|
|
|
contentCollapseButton.setChecked(true);
|
|
|
|
content.setFilters(COLLAPSE_INPUT_FILTER);
|
|
|
|
} else {
|
|
|
|
contentCollapseButton.setChecked(false);
|
|
|
|
content.setFilters(NO_INPUT_FILTER);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
contentCollapseButton.setVisibility(View.GONE);
|
|
|
|
content.setFilters(NO_INPUT_FILTER);
|
|
|
|
}
|
|
|
|
}
|
2019-03-05 05:24:27 +11:00
|
|
|
}
|