comment #702 - Support quotes

This commit is contained in:
Thomas 2022-12-29 19:02:15 +01:00
parent cfcab79cf8
commit 23cd690f33
11 changed files with 128 additions and 8 deletions

View file

@ -104,7 +104,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
public static final int TAKE_PHOTO = 5600;
private final Timer timer = new Timer();
private List<Status> statusList;
private Status statusReply, statusMention;
private Status statusReply, statusMention, statusQuoted;
private StatusDraft statusDraft;
private ComposeAdapter composeAdapter;
private boolean promptSaveDraft;
@ -465,6 +465,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
Bundle b = getIntent().getExtras();
if (b != null) {
statusReply = (Status) b.getSerializable(Helper.ARG_STATUS_REPLY);
statusQuoted = (Status) b.getSerializable(Helper.ARG_QUOTED_MESSAGE);
statusDraft = (StatusDraft) b.getSerializable(Helper.ARG_STATUS_DRAFT);
scheduledStatus = (ScheduledStatus) b.getSerializable(Helper.ARG_STATUS_SCHEDULED);
statusReplyId = b.getString(Helper.ARG_STATUS_REPLY_ID);
@ -557,6 +558,9 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
List<Status> statusDraftList = new ArrayList<>();
Status status = new Status();
status.id = Helper.generateIdString();
if (statusQuoted != null) {
status.quote_id = statusQuoted.id;
}
statusDraftList.add(status);
if (statusReplyId != null && statusDraft != null) {//Delete and redraft
@ -647,6 +651,18 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
binding.recyclerView.setAdapter(composeAdapter);
statusesVM.getContext(currentInstance, BaseMainActivity.currentToken, statusReply.id)
.observe(ComposeActivity.this, this::initializeContextView);
} else if (statusQuoted != null) {
statusList.add(statusQuoted);
int statusCount = statusList.size();
statusDraftList.get(0).quote_id = statusQuoted.id;
//StatusDraftList at this point should only have one element
statusList.addAll(statusDraftList);
composeAdapter = new ComposeAdapter(statusList, statusCount, account, accountMention, visibility, editMessageId);
composeAdapter.manageDrafts = this;
composeAdapter.promptDraftListener = this;
LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this);
binding.recyclerView.setLayoutManager(mLayoutManager);
binding.recyclerView.setAdapter(composeAdapter);
} else {
//Compose without replying
statusList.addAll(statusDraftList);

View file

@ -59,7 +59,8 @@ public interface MastodonStatusesService {
@Field("sensitive") Boolean sensitive,
@Field("spoiler_text") String spoiler_text,
@Field("visibility") String visibility,
@Field("language") String language
@Field("language") String language,
@Field("quote_id") String quote_id
);
@GET("statuses/{id}/source")

View file

@ -48,6 +48,8 @@ public class Status implements Serializable, Cloneable {
public String spoiler_text;
@SerializedName("text")
public String text;
@SerializedName("quote_id")
public String quote_id;
@SerializedName("visibility")
public String visibility;
@SerializedName("language")
@ -76,6 +78,8 @@ public class Status implements Serializable, Cloneable {
public String content;
@SerializedName("reblog")
public Status reblog;
@SerializedName("quote")
public Status quote;
@SerializedName("application")
public App application;
@SerializedName("account")

View file

@ -226,6 +226,7 @@ public class Helper {
public static final String ARG_STATUS_DRAFT_ID = "ARG_STATUS_DRAFT_ID";
public static final String ARG_STATUS_REPLY = "ARG_STATUS_REPLY";
public static final String ARG_MENTION_BOOSTER = "ARG_MENTION_BOOSTER";
public static final String ARG_QUOTED_MESSAGE = "ARG_QUOTED_MESSAGE";
public static final String ARG_STATUS_REPLY_ID = "ARG_STATUS_REPLY_ID";
public static final String ARG_ACCOUNT = "ARG_ACCOUNT";
public static final String ARG_ACCOUNT_ID = "ARG_ACCOUNT_ID";

View file

@ -221,7 +221,7 @@ public class ComposeWorker extends Worker {
if (dataPost.scheduledDate == null) {
if (dataPost.statusEditId == null) {
statusCall = mastodonStatusesService.createStatus(null, dataPost.token, statuses.get(i).text, attachmentIds, poll_options, poll_expire_in,
poll_multiple, poll_hide_totals, in_reply_to_status, statuses.get(i).sensitive, statuses.get(i).spoilerChecked ? statuses.get(i).spoiler_text : null, statuses.get(i).visibility.toLowerCase(), language);
poll_multiple, poll_hide_totals, in_reply_to_status, statuses.get(i).sensitive, statuses.get(i).spoilerChecked ? statuses.get(i).spoiler_text : null, statuses.get(i).visibility.toLowerCase(), language, statuses.get(i).quote_id);
} else { //Status is edited
statusCall = mastodonStatusesService.updateStatus(null, dataPost.token, dataPost.statusEditId, statuses.get(i).text, attachmentIds, poll_options, poll_expire_in,
poll_multiple, poll_hide_totals, in_reply_to_status, statuses.get(i).sensitive, statuses.get(i).spoilerChecked ? statuses.get(i).spoiler_text : null, statuses.get(i).visibility.toLowerCase(), language);

View file

@ -396,6 +396,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
boolean displayTranslate = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_TRANSLATE), false);
boolean displayCounters = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_COUNTER_FAV_BOOST), false);
boolean removeLeftMargin = sharedpreferences.getBoolean(context.getString(R.string.SET_REMOVE_LEFT_MARGIN), false);
boolean extraFeatures = sharedpreferences.getBoolean(context.getString(R.string.SET_EXTAND_EXTRA_FEATURES), false);
if (removeLeftMargin) {
LinearLayoutCompat.MarginLayoutParams p = (LinearLayoutCompat.MarginLayoutParams) holder.binding.spoiler.getLayoutParams();
@ -438,6 +439,44 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
String loadMediaType = sharedpreferences.getString(context.getString(R.string.SET_LOAD_MEDIA_TYPE), "ALWAYS");
if (statusToDeal.quote != null) {
holder.binding.quotedMessage.cardviewContainer.setCardElevation(5);
holder.binding.quotedMessage.dividerCard.setVisibility(View.GONE);
holder.binding.quotedMessage.cardviewContainer.setStrokeWidth(1);
holder.binding.quotedMessage.cardviewContainer.setOnClickListener(v -> {
Intent intent = new Intent(context, ContextActivity.class);
intent.putExtra(Helper.ARG_STATUS, statusToDeal.quote);
context.startActivity(intent);
});
holder.binding.quotedMessage.cardviewContainer.setStrokeColor(ThemeHelper.getAttColor(context, R.attr.colorPrimary));
holder.binding.quotedMessage.statusContent.setText(
statusToDeal.quote.getSpanContent(context,
new WeakReference<>(holder.binding.quotedMessage.statusContent), null),
TextView.BufferType.SPANNABLE);
MastodonHelper.loadPPMastodon(holder.binding.quotedMessage.avatar, statusToDeal.quote.account);
if (statusToDeal.quote.account != null) {
holder.binding.quotedMessage.displayName.setText(
statusToDeal.quote.account.getSpanDisplayName(context,
new WeakReference<>(holder.binding.quotedMessage.displayName)),
TextView.BufferType.SPANNABLE);
holder.binding.quotedMessage.username.setText(String.format("@%s", statusToDeal.quote.account.acct));
}
if (statusToDeal.quote.spoiler_text != null && !statusToDeal.quote.spoiler_text.trim().isEmpty()) {
holder.binding.quotedMessage.spoiler.setVisibility(View.VISIBLE);
holder.binding.quotedMessage.spoiler.setText(
statusToDeal.quote.getSpanSpoiler(context,
new WeakReference<>(holder.binding.quotedMessage.spoiler), null),
TextView.BufferType.SPANNABLE);
} else {
holder.binding.quotedMessage.spoiler.setVisibility(View.GONE);
holder.binding.quotedMessage.spoiler.setText(null);
}
holder.binding.quotedMessage.cardviewContainer.setVisibility(View.VISIBLE);
} else {
holder.binding.quotedMessage.cardviewContainer.setVisibility(View.GONE);
}
if (currentAccount != null && currentAccount.api == Account.API.PLEROMA) {
if (status.pleroma != null && status.pleroma.emoji_reactions != null && status.pleroma.emoji_reactions.size() > 0) {
holder.binding.layoutReactions.getRoot().setVisibility(View.VISIBLE);
@ -553,9 +592,10 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
int truncate_toots_size = sharedpreferences.getInt(context.getString(R.string.SET_TRUNCATE_TOOTS_SIZE), 0);
if (currentAccount != null && currentAccount.api == Account.API.PLEROMA) {
if (extraFeatures) {
holder.binding.statusAddCustomEmoji.setVisibility(View.VISIBLE);
holder.binding.statusEmoji.setVisibility(View.VISIBLE);
holder.binding.actionButtonQuote.setVisibility(View.VISIBLE);
}
holder.binding.actionButtonFavorite.pressOnTouch(false);
@ -951,6 +991,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.statusAddCustomEmoji.getLayoutParams().width = (int) (normalSize * scaleIcon);
holder.binding.statusAddCustomEmoji.getLayoutParams().height = (int) (normalSize * scaleIcon);
holder.binding.statusAddCustomEmoji.requestLayout();
holder.binding.actionButtonQuote.getLayoutParams().width = (int) (normalSize * scaleIcon);
holder.binding.actionButtonQuote.getLayoutParams().height = (int) (normalSize * scaleIcon);
holder.binding.actionButtonQuote.requestLayout();
holder.binding.statusEmoji.getLayoutParams().width = (int) (normalSize * scaleIcon);
holder.binding.statusEmoji.getLayoutParams().height = (int) (normalSize * scaleIcon);
holder.binding.actionButtonMore.getLayoutParams().width = (int) (normalSize * scaleIcon);
@ -1903,6 +1948,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
CrossActionHelper.doCrossAction(context, CrossActionHelper.TypeOfCrossAction.REPLY_ACTION, null, statusToDeal);
return true;
});
holder.binding.actionButtonQuote.setOnClickListener(v -> {
Intent intent = new Intent(context, ComposeActivity.class);
intent.putExtra(Helper.ARG_QUOTED_MESSAGE, statusToDeal);
context.startActivity(intent);
});
holder.binding.actionButtonReply.setOnClickListener(v -> {
if (remote) {
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
@ -2286,6 +2336,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
if (theme_icons_color != -1) {
Helper.changeDrawableColor(context, holder.binding.actionButtonReply, theme_icons_color);
Helper.changeDrawableColor(context, holder.binding.statusAddCustomEmoji, theme_icons_color);
Helper.changeDrawableColor(context, holder.binding.actionButtonQuote, theme_icons_color);
Helper.changeDrawableColor(context, holder.binding.statusEmoji, theme_icons_color);
Helper.changeDrawableColor(context, holder.binding.actionButtonMore, theme_icons_color);
Helper.changeDrawableColor(context, R.drawable.ic_round_star_24, theme_icons_color);

View file

@ -186,12 +186,13 @@ public class StatusesVM extends AndroidViewModel {
Boolean sensitive,
String spoiler_text,
String visibility,
String language) {
String language,
String quote_id) {
MastodonStatusesService mastodonStatusesService = init(instance);
statusMutableLiveData = new MutableLiveData<>();
new Thread(() -> {
Call<Status> statusCall = mastodonStatusesService.createStatus(idempotency_Key, token, text, media_ids, poll_options, poll_expire_in,
poll_multiple, poll_hide_totals, in_reply_to_id, sensitive, spoiler_text, visibility, language);
poll_multiple, poll_hide_totals, in_reply_to_id, sensitive, spoiler_text, visibility, language, quote_id);
Status status = null;
if (statusCall != null) {
try {

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?attr/colorControlNormal"
android:pathData="M6,17h3l2,-4L11,7L5,7v6h3zM14,17h3l2,-4L19,7h-6v6h3z" />
</vector>

View file

@ -394,6 +394,12 @@
</com.google.android.material.card.MaterialCardView>
<include
android:id="@+id/quoted_message"
layout="@layout/drawer_status_simple"
android:visibility="gone"
tools:visibility="visible" />
<com.google.android.material.button.MaterialButton
android:id="@+id/display_media"
android:layout_width="wrap_content"
@ -628,7 +634,7 @@
<com.varunest.sparkbutton.SparkButton
android:id="@+id/action_button_boost"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/action_button_favorite"
app:layout_constraintEnd_toStartOf="@+id/action_button_quote"
app:layout_constraintStart_toEndOf="@+id/action_button_reply_container"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="48dp"
@ -642,11 +648,29 @@
app:sparkbutton_primaryColor="@color/boost_icon"
app:sparkbutton_secondaryColor="@color/boost_icon" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/action_button_quote"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:background="@color/transparent"
android:clickable="true"
android:contentDescription="@string/translate"
android:focusable="true"
android:src="@drawable/ic_baseline_format_quote_24"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/action_button_favorite"
app:layout_constraintStart_toEndOf="@+id/action_button_boost"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />
<com.varunest.sparkbutton.SparkButton
android:id="@+id/action_button_favorite"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/action_button_bookmark"
app:layout_constraintStart_toEndOf="@+id/action_button_boost"
app:layout_constraintStart_toEndOf="@+id/action_button_quote"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="48dp"
android:layout_height="48dp"

View file

@ -1429,6 +1429,7 @@
<string name="SET_NOTIF_VALIDATION_FAV" translatable="false">SET_NOTIF_VALIDATION_FAV</string>
<string name="SET_DISPLAY_COUNTER_FAV_BOOST" translatable="false">SET_DISPLAY_COUNTER_FAV_BOOST</string>
<string name="SET_REMOVE_LEFT_MARGIN" translatable="false">SET_REMOVE_LEFT_MARGIN</string>
<string name="SET_EXTAND_EXTRA_FEATURES" translatable="false">SET_EXTAND_EXTRA_FEATURES</string>
<string name="SET_INNER_MARKER" translatable="false">SET_INNER_MARKER</string>
<string name="SET_NOTIF_SILENT" translatable="false">SET_NOTIF_SILENT</string>
@ -2147,4 +2148,6 @@
<string name="api_key">Translator API key</string>
<string name="version">Version</string>
<string name="set_translator_version">Translator version</string>
<string name="set_extand_extra_features_title">Extra features</string>
<string name="set_extand_extra_features">By enabling that option the app will display extra features. This feature is done for social softwares like Pleroma, Akkoma or Glitch Social</string>
</resources>

View file

@ -28,6 +28,15 @@
app:summary="@string/set_remove_left_margin"
app:title="@string/set_remove_left_margin_title" />
<SwitchPreferenceCompat
app:defaultValue="false"
app:iconSpaceReserved="false"
app:key="@string/SET_EXTAND_EXTRA_FEATURES"
app:singleLineTitle="false"
app:summary="@string/set_extand_extra_features"
app:title="@string/set_extand_extra_features_title" />
<SwitchPreferenceCompat
app:defaultValue="true"
app:iconSpaceReserved="false"