summaryrefslogtreecommitdiffstats
path: root/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java')
-rw-r--r--app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java92
1 files changed, 84 insertions, 8 deletions
diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java
index 9fdeb6207..ea5311c4e 100644
--- a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java
+++ b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java
@@ -71,12 +71,17 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
import com.vanniktech.emoji.EmojiManager;
import com.vanniktech.emoji.EmojiPopup;
import com.vanniktech.emoji.one.EmojiOneProvider;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
import java.lang.ref.WeakReference;
+import java.nio.charset.StandardCharsets;
import java.text.Normalizer;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -86,6 +91,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
+import java.util.Random;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -102,6 +108,7 @@ import app.fedilab.android.client.entities.api.Status;
import app.fedilab.android.client.entities.api.Tag;
import app.fedilab.android.client.entities.app.BaseAccount;
import app.fedilab.android.client.entities.app.Languages;
+import app.fedilab.android.client.entities.app.Quotes;
import app.fedilab.android.client.entities.app.StatusDraft;
import app.fedilab.android.databinding.ComposeAttachmentItemBinding;
import app.fedilab.android.databinding.ComposePollBinding;
@@ -214,8 +221,10 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
promptDraftListener.promptDraft();
}
int finalPosition = position;
- Helper.createAttachmentFromUri(context, uris, attachment -> {
- statusList.get(finalPosition).media_attachments.add(attachment);
+ Helper.createAttachmentFromUri(context, uris, attachments -> {
+ for (Attachment attachment : attachments) {
+ statusList.get(finalPosition).media_attachments.add(attachment);
+ }
notifyItemChanged(finalPosition);
});
}
@@ -545,6 +554,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
public void run() {
String fedilabHugsTrigger = ":fedilab_hugs:";
String fedilabMorseTrigger = ":fedilab_morse:";
+ String fedilabQuoteTrigger = ":fedilab_quote:";
if (s.toString().contains(fedilabHugsTrigger)) {
newContent[0] = s.toString().replaceAll(Pattern.quote(fedilabHugsTrigger), "").trim();
int toFill = 500 - newContent[0].length();
@@ -612,6 +622,57 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
updateCharacterCount(holder);
};
mainHandler.post(myRunnable);
+ } else if (s.toString().contains(fedilabQuoteTrigger)) {
+ newContent[0] = s.toString().replaceAll(fedilabQuoteTrigger, "").trim();
+ List<String> mentions = new ArrayList<>();
+ String mentionPattern = "@[a-z0-9_]+(@[a-z0-9.\\-]+[a-z0-9]+)?";
+ final Pattern mPattern = Pattern.compile(mentionPattern, Pattern.CASE_INSENSITIVE);
+ Matcher matcherMentions = mPattern.matcher(newContent[0]);
+ while (matcherMentions.find()) {
+ mentions.add(matcherMentions.group());
+ }
+ for (String mention : mentions) {
+ newContent[0] = newContent[0].replace(mention, "");
+ }
+
+ InputStream is;
+ newContent[0] = "";
+ if (mentions.size() > 0) {
+ for (String mention : mentions) {
+ newContent[0] += mention + " ";
+ }
+ }
+ try {
+ is = context.getAssets().open("quotes/famous.json");
+ int size;
+ size = is.available();
+ byte[] buffer = new byte[size];
+ //noinspection ResultOfMethodCallIgnored
+ is.read(buffer);
+ is.close();
+ String json = new String(buffer, StandardCharsets.UTF_8);
+ Gson gson = new Gson();
+ List<Quotes.Quote> quotes = gson.fromJson(json, new TypeToken<List<Quotes.Quote>>() {
+ }.getType());
+ if (quotes != null && quotes.size() > 0) {
+ final int random = new Random().nextInt(quotes.size());
+ Quotes.Quote quote = quotes.get(random);
+ newContent[0] += quote.content + "\n- " + quote.author;
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ Handler mainHandler = new Handler(Looper.getMainLooper());
+
+ Runnable myRunnable = () -> {
+ holder.binding.content.setText(newContent[0]);
+ statusList.get(holder.getBindingAdapterPosition()).text = newContent[0];
+ holder.binding.content.setSelection(holder.binding.content.getText().length());
+ autocomplete = false;
+ updateCharacterCount(holder);
+ };
+ mainHandler.post(myRunnable);
}
}
};
@@ -649,6 +710,15 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
autocomplete = true;
return;
}
+
+ String patternQ = "^(.|\\s)*(:fedilab_quote:)";
+ final Pattern qPattern = Pattern.compile(patternQ);
+ Matcher mq = qPattern.matcher((s.toString().substring(currentCursorPosition[0] - searchLength[0], currentCursorPosition[0])));
+ if (mq.matches()) {
+ autocomplete = true;
+ return;
+ }
+
String[] searchInArray = (s.toString().substring(currentCursorPosition[0] - searchLength[0], currentCursorPosition[0])).split("\\s");
if (searchInArray.length < 1) {
updateCharacterCount(holder);
@@ -1030,6 +1100,11 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
public void onLoadCleared(@Nullable Drawable placeholder) {
}
+
+ @Override
+ public void onLoadFailed(@Nullable Drawable errorDrawable) {
+ super.onLoadFailed(errorDrawable);
+ }
});
builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
if (attachment.description != null) {
@@ -1088,15 +1163,15 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
});
composeAttachmentItemBinding.preview.setOnClickListener(v -> displayAttachments(holder, position, finalMediaPosition));
if (attachment.description == null || attachment.description.trim().isEmpty()) {
- composeAttachmentItemBinding.buttonDescription.setIconResource(R.drawable.ic_baseline_warning_24);
+ composeAttachmentItemBinding.buttonDescription.setChipIconResource(R.drawable.ic_baseline_warning_24);
composeAttachmentItemBinding.buttonDescription.setTextColor(ContextCompat.getColor(context, R.color.black));
- composeAttachmentItemBinding.buttonDescription.setIconTintResource(R.color.black);
- composeAttachmentItemBinding.buttonDescription.setBackgroundTintList(ThemeHelper.getNoDescriptionColorStateList(context));
+ composeAttachmentItemBinding.buttonDescription.setChipIconTintResource(R.color.black);
+ composeAttachmentItemBinding.buttonDescription.setChipBackgroundColor(ThemeHelper.getNoDescriptionColorStateList(context));
} else {
- composeAttachmentItemBinding.buttonDescription.setIconResource(R.drawable.ic_baseline_check_circle_24);
+ composeAttachmentItemBinding.buttonDescription.setChipIconResource(R.drawable.ic_baseline_check_circle_24);
composeAttachmentItemBinding.buttonDescription.setTextColor(ContextCompat.getColor(context, R.color.white));
- composeAttachmentItemBinding.buttonDescription.setIconTintResource(R.color.white);
- composeAttachmentItemBinding.buttonDescription.setBackgroundTintList(ThemeHelper.getHavingDescriptionColorStateList(context));
+ composeAttachmentItemBinding.buttonDescription.setChipIconTintResource(R.color.white);
+ composeAttachmentItemBinding.buttonDescription.setChipBackgroundColor(ThemeHelper.getHavingDescriptionColorStateList(context));
}
holder.binding.attachmentsList.addView(composeAttachmentItemBinding.getRoot());
mediaPosition++;
@@ -1296,6 +1371,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
break;
}
+ holder.binding.visibilityPanel.setOnTouchListener((view, motionEvent) -> true);
holder.binding.buttonCloseAttachmentPanel.setOnClickListener(v -> holder.binding.attachmentChoicesPanel.setVisibility(View.GONE));
holder.binding.buttonVisibility.setOnClickListener(v -> {
holder.binding.visibilityPanel.setVisibility(View.VISIBLE);