forked from mirrors/Fedilab
Allow to get a quote
This commit is contained in:
parent
a63f1a9300
commit
625f15fb32
16 changed files with 8308 additions and 223 deletions
8206
app/src/main/assets/quotes/famous.json
Normal file
8206
app/src/main/assets/quotes/famous.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,15 +0,0 @@
|
|||
base_theme,1
|
||||
author,acn128
|
||||
name,ACN
|
||||
theme_boost_header_color,-727060
|
||||
theme_text_header_1_line,-10865760
|
||||
theme_text_header_2_line,-11719543
|
||||
theme_statuses_color,-197380
|
||||
theme_link_color,-13681272
|
||||
theme_icons_color,-15395562
|
||||
pref_color_background,-1
|
||||
pref_color_navigation_bar,true
|
||||
pref_color_status_bar,true
|
||||
theme_accent,-14059009
|
||||
theme_text_color,-13027015
|
||||
theme_primary,-1
|
|
|
@ -1,13 +0,0 @@
|
|||
base_theme,2
|
||||
author,Fedilab
|
||||
name,Breeze Dark - Yellow
|
||||
theme_boost_header_color,-14012878
|
||||
theme_statuses_color,-14473687
|
||||
theme_link_color,-12734743
|
||||
theme_icons_color,-4340793
|
||||
pref_color_background,-15658735
|
||||
pref_color_navigation_bar,true
|
||||
pref_color_status_bar,true
|
||||
theme_accent,-148405
|
||||
theme_text_color,-1052431
|
||||
theme_primary,-13552069
|
|
|
@ -1,15 +0,0 @@
|
|||
base_theme,2
|
||||
author,Roboron
|
||||
name,Cyberpunk Neon
|
||||
theme_boost_header_color,-16776697,
|
||||
theme_text_header_1_line,-1441575,
|
||||
theme_text_header_2_line,-5242717,
|
||||
theme_statuses_color,-16181197,
|
||||
theme_link_color,-1441575,
|
||||
theme_icons_color,-16138810,
|
||||
pref_color_background,-16774370,
|
||||
pref_color_navigation_bar,true,
|
||||
pref_color_status_bar,true,
|
||||
theme_accent,-1441575,
|
||||
theme_text_color,-16138810,
|
||||
theme_primary,-16774370,
|
|
|
@ -1,15 +0,0 @@
|
|||
base_theme,0
|
||||
author,S1m
|
||||
name,Dark Elephant
|
||||
theme_boost_header_color,-13552317
|
||||
theme_text_header_1_line,-3479297
|
||||
theme_text_header_2_line,-7287815
|
||||
theme_statuses_color,-13552317
|
||||
theme_link_color,-11098143
|
||||
theme_icons_color,-789517
|
||||
pref_color_background,-14144456
|
||||
pref_color_navigation_bar,true
|
||||
pref_color_status_bar,true
|
||||
theme_accent,-13922086
|
||||
theme_text_color,-789517
|
||||
theme_primary,-14144456
|
|
|
@ -1,15 +0,0 @@
|
|||
base_theme,2
|
||||
author,Jøta Seth
|
||||
name,Grey Orange
|
||||
theme_boost_header_color,-14869219
|
||||
theme_text_header_1_line,-1
|
||||
theme_text_header_2_line,-1
|
||||
theme_statuses_color,-14145496
|
||||
theme_link_color,-26624
|
||||
theme_icons_color,-26624
|
||||
pref_color_background,-13092808
|
||||
pref_color_navigation_bar,true
|
||||
pref_color_status_bar,true
|
||||
theme_accent,-26624
|
||||
theme_text_color,-1
|
||||
theme_primary,-14408668
|
|
|
@ -1,15 +0,0 @@
|
|||
base_theme,2
|
||||
author,@AntoineD@h.kher.nl
|
||||
name,Gruvbox OLED
|
||||
theme_boost_header_color,-16777216
|
||||
theme_text_header_1_line,-265785
|
||||
theme_text_header_2_line,-6777062
|
||||
theme_statuses_color,-16777216
|
||||
theme_link_color,-2647775
|
||||
theme_icons_color,-7175308
|
||||
pref_color_background,-16777216
|
||||
pref_color_navigation_bar,true
|
||||
pref_color_status_bar,true
|
||||
theme_accent,-9921174
|
||||
theme_text_color,-265785
|
||||
theme_primary,-16777216
|
|
|
@ -1,15 +0,0 @@
|
|||
base_theme,2
|
||||
author,AngryTux
|
||||
name,Less Angry Orange
|
||||
theme_boost_header_color,-15855063
|
||||
theme_text_header_1_line,-2128640
|
||||
theme_text_header_2_line,-5329234
|
||||
theme_statuses_color,-1
|
||||
theme_link_color,-12146699
|
||||
theme_icons_color,-2128640
|
||||
pref_color_background,-15987700
|
||||
pref_color_navigation_bar,true
|
||||
pref_color_status_bar,true
|
||||
theme_accent,-3968000
|
||||
theme_text_color,-197380
|
||||
theme_primary,-14408668
|
|
|
@ -1,15 +0,0 @@
|
|||
base_theme,2
|
||||
author,Mondstern
|
||||
name,Mondstern Fedilab
|
||||
theme_boost_header_color,-1,
|
||||
theme_text_header_1_line,-13855804,
|
||||
theme_text_header_2_line,-16227945,
|
||||
theme_statuses_color,-14935012,
|
||||
theme_link_color,-15542685,
|
||||
theme_icons_color,-10723999,
|
||||
pref_color_background,-15921907,
|
||||
pref_color_navigation_bar,false,
|
||||
pref_color_status_bar,false,
|
||||
theme_accent,-15542685,
|
||||
theme_text_color,-1,
|
||||
theme_primary,-14474461,
|
|
|
@ -1,13 +0,0 @@
|
|||
base_theme,2
|
||||
author,Fedilab
|
||||
name,Nocturnal
|
||||
theme_boost_header_color,-12895429
|
||||
theme_statuses_color,-13553359
|
||||
theme_link_color,-16747570
|
||||
theme_icons_color,-10158118
|
||||
pref_color_background,-14606047
|
||||
pref_color_navigation_bar,true
|
||||
pref_color_status_bar,true
|
||||
theme_accent,-13136013
|
||||
theme_text_color,-2236963
|
||||
theme_primary,-14013910
|
|
|
@ -1,15 +0,0 @@
|
|||
base_theme,2
|
||||
author,Jøta Seth
|
||||
name,Photon Dark
|
||||
theme_boost_header_color,-14145496
|
||||
theme_text_header_1_line,-1
|
||||
theme_text_header_2_line,-1
|
||||
theme_statuses_color,-14935012
|
||||
theme_link_color,-14059009
|
||||
theme_icons_color,-9474193
|
||||
pref_color_background,-15921907
|
||||
pref_color_navigation_bar,true
|
||||
pref_color_status_bar,true
|
||||
theme_accent,-14059009
|
||||
theme_text_color,-1
|
||||
theme_primary,-14474461
|
|
|
@ -1,15 +0,0 @@
|
|||
base_theme,1
|
||||
author,Animaly
|
||||
name,Solarized - Cyan Accent
|
||||
theme_boost_header_color,-69167
|
||||
theme_text_header_1_line,-4880128
|
||||
theme_text_header_2_line,-7102047
|
||||
theme_statuses_color,-133405
|
||||
theme_link_color,-14251054
|
||||
theme_icons_color,-10106727
|
||||
pref_color_background,-1120043
|
||||
pref_color_navigation_bar,true
|
||||
pref_color_status_bar,true
|
||||
theme_accent,-8021760
|
||||
theme_text_color,-16766154
|
||||
theme_primary,-1120043
|
|
|
@ -1,15 +0,0 @@
|
|||
base_theme,2
|
||||
author,Fedilab
|
||||
name,Solarized Dark - Purple
|
||||
theme_boost_header_color,-16506327
|
||||
theme_text_header_1_line,-1120043
|
||||
theme_text_header_2_line,-1120043
|
||||
theme_statuses_color,-16304574
|
||||
theme_link_color,-14251054
|
||||
theme_icons_color,-7102047
|
||||
pref_color_background,-16766154
|
||||
pref_color_navigation_bar,true
|
||||
pref_color_status_bar,true
|
||||
theme_accent,-9670204
|
||||
theme_text_color,-133405
|
||||
theme_primary,-16304574
|
|
|
@ -1,47 +0,0 @@
|
|||
[
|
||||
{
|
||||
"theme_name": "Dark",
|
||||
"base_theme": "DARK",
|
||||
"primary": "#FF272727",
|
||||
"primary_dark": "#FF272727",
|
||||
"primary_light": "#FFd9e1e8",
|
||||
"accent": "#FF2b90d9",
|
||||
"accent_dark": "#FF1b80c9",
|
||||
"accent_light": "#FF772b90d9",
|
||||
"background": "#FF272727",
|
||||
"background_dark": "#FF282c37",
|
||||
"background_light": "#FF282c37",
|
||||
"should_tint_statusbar": true,
|
||||
"should_tint_navbar": true
|
||||
},
|
||||
{
|
||||
"theme_name": "Light",
|
||||
"base_theme": "LIGHT",
|
||||
"primary": "#FFFFFF",
|
||||
"primary_dark": "#FFFFFFFF",
|
||||
"primary_light": "#FFd9e1e8",
|
||||
"accent": "#FF2b90d9",
|
||||
"accent_dark": "#FF1b80c9",
|
||||
"accent_light": "#FF772b90d9",
|
||||
"background": "#FFFFFFFF",
|
||||
"background_dark": "#FFFFFFFF",
|
||||
"background_light": "#FFFFFFFF",
|
||||
"should_tint_statusbar": true,
|
||||
"should_tint_navbar": true
|
||||
},
|
||||
{
|
||||
"theme_name": "Black",
|
||||
"base_theme": "DARK",
|
||||
"primary": "#FF000000",
|
||||
"primary_dark": "#FF000000",
|
||||
"primary_light": "#FF000000",
|
||||
"accent": "#FF606984",
|
||||
"accent_dark": "#FF606984",
|
||||
"accent_light": "#FF606984",
|
||||
"background": "#FF000000",
|
||||
"background_dark": "#FF000000",
|
||||
"background_light": "#FF000000",
|
||||
"should_tint_statusbar": true,
|
||||
"should_tint_navbar": true
|
||||
}
|
||||
]
|
|
@ -0,0 +1,34 @@
|
|||
package app.fedilab.android.client.entities.app;
|
||||
/* Copyright 2022 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Fedilab
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class Quotes implements Serializable {
|
||||
|
||||
@SerializedName("quotes")
|
||||
public List<Quote> quotes;
|
||||
|
||||
public static class Quote implements Serializable {
|
||||
@SerializedName("author")
|
||||
public String author;
|
||||
@SerializedName("content")
|
||||
public String content;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
@ -545,6 +552,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();
|
||||
|
@ -604,6 +612,57 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
|||
newContent[0] = newContent[0].replaceAll("null", "");
|
||||
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);
|
||||
} 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];
|
||||
|
@ -649,6 +708,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);
|
||||
|
|
Loading…
Reference in a new issue