From 0bf843d00a1b8a9347e1ca0ff30bb8f4bdc31e23 Mon Sep 17 00:00:00 2001 From: stom79 Date: Sun, 28 Oct 2018 11:32:23 +0100 Subject: [PATCH] Fix issue #527 - Disable custom Emoji --- app/build.gradle | 1 + .../mastodon/activities/BaseActivity.java | 1 - .../mastodon/activities/TootActivity.java | 19 +++-- .../client/Entities/Conversation.java | 64 +++++++++++++++ .../mastodon/client/Entities/Status.java | 1 - .../drawers/NotificationsListAdapter.java | 4 +- .../mastodon/drawers/StatusListAdapter.java | 5 +- .../mastodon/fragments/SettingsFragment.java | 13 +++ .../mastodon/helper/CustomTextView.java | 79 ++++++------------- .../gouv/etalab/mastodon/helper/Helper.java | 1 + .../helper/MastalabAutoCompleteTextView.java | 9 ++- .../res/layout-sw600dp/fragment_settings.xml | 6 +- .../main/res/layout/drawer_notification.xml | 4 +- app/src/main/res/layout/drawer_status.xml | 4 +- .../main/res/layout/drawer_status_compact.xml | 4 +- .../main/res/layout/drawer_status_focused.xml | 4 +- app/src/main/res/layout/fragment_settings.xml | 6 +- app/src/main/res/values/strings.xml | 1 + 18 files changed, 147 insertions(+), 79 deletions(-) create mode 100644 app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Conversation.java diff --git a/app/build.gradle b/app/build.gradle index 233b41788..d011d2ee0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -75,6 +75,7 @@ dependencies { implementation "com.koushikdutta.async:androidasync:2.+" implementation 'com.vanniktech:emoji-one:0.6.0-SNAPSHOT' implementation 'com.vanniktech:emoji-twitter:0.6.0-SNAPSHOT' + implementation 'com.vanniktech:emoji:0.6.0-SNAPSHOT' playstoreImplementation "io.github.kobakei:ratethisapp:$ratethisappLibraryVersion" diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseActivity.java index 309ea660b..897a49dfc 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseActivity.java @@ -19,5 +19,4 @@ public class BaseActivity extends AppCompatActivity { Helper.installProvider(); EmojiManager.install(new EmojiOneProvider()); } - } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java index fb99aaa94..a0baf7b8f 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java @@ -56,6 +56,7 @@ import android.view.ViewTreeObserver; import android.view.inputmethod.InputMethodManager; import android.widget.AdapterView; import android.widget.ArrayAdapter; +import android.widget.AutoCompleteTextView; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; @@ -265,15 +266,19 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount toot_sensitive = findViewById(R.id.toot_sensitive); drawer_layout = findViewById(R.id.drawer_layout); toot_emoji = findViewById(R.id.toot_emoji); - final EmojiPopup emojiPopup = EmojiPopup.Builder.fromRootView(drawer_layout).build(toot_content); - toot_emoji.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - emojiPopup.toggle(); // Toggles visibility of the Popup. - } - }); + if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_EMOJI, true)) { + final EmojiPopup emojiPopup = EmojiPopup.Builder.fromRootView(drawer_layout).build(toot_content); + toot_emoji.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + emojiPopup.toggle(); // Toggles visibility of the Popup. + } + }); + }else { + toot_emoji.setVisibility(View.GONE); + } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Conversation.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Conversation.java new file mode 100644 index 000000000..1d4d6bf4c --- /dev/null +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Conversation.java @@ -0,0 +1,64 @@ +package fr.gouv.etalab.mastodon.client.Entities; +/* Copyright 2018 Thomas Schneider + * + * This file is a part of Mastalab + * + * 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. + * + * Mastalab 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 Mastalab; if not, + * see . */ + + +import java.util.List; + +/** + * Created by Thomas on 26/10/2018. + * Manage conversation + */ + +public class Conversation { + + private String id; + private List accounts; + private Status last_status; + private boolean unread; + + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Status getLast_status() { + return last_status; + } + + public void setLast_status(Status last_status) { + this.last_status = last_status; + } + + public boolean isUnread() { + return unread; + } + + public void setUnread(boolean unread) { + this.unread = unread; + } + + public List getAccounts() { + return accounts; + } + + public void setAccounts(List accounts) { + this.accounts = accounts; + } +} diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java index cb7893386..1d9b6a4bd 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java @@ -60,7 +60,6 @@ import fr.gouv.etalab.mastodon.activities.HashTagActivity; import fr.gouv.etalab.mastodon.activities.MainActivity; import fr.gouv.etalab.mastodon.activities.PeertubeActivity; import fr.gouv.etalab.mastodon.activities.ShowAccountActivity; -import fr.gouv.etalab.mastodon.activities.WebviewActivity; import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask; import fr.gouv.etalab.mastodon.helper.CrossActions; import fr.gouv.etalab.mastodon.helper.Helper; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java index 74e3a0052..ba8e7b5c4 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java @@ -1076,10 +1076,10 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On class ViewHolder extends RecyclerView.ViewHolder { FrameLayout card_status_container; - EmojiTextView notification_status_content; + CustomTextView notification_status_content; TextView notification_type; LinearLayout status_spoiler_container; - EmojiTextView status_spoiler; + CustomTextView status_spoiler; Button status_spoiler_button; TextView notification_account_username; ImageView notification_account_profile; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java index 33ef5835f..5f28cb1ae 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java @@ -116,7 +116,6 @@ import fr.gouv.etalab.mastodon.sqlite.TempMuteDAO; import static fr.gouv.etalab.mastodon.activities.MainActivity.currentLocale; import static fr.gouv.etalab.mastodon.helper.Helper.THEME_BLACK; import static fr.gouv.etalab.mastodon.helper.Helper.THEME_DARK; -import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT; import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor; import static fr.gouv.etalab.mastodon.helper.Helper.getLiveInstance; @@ -228,9 +227,9 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct class ViewHolder extends RecyclerView.ViewHolder{ LinearLayout status_content_container; LinearLayout status_spoiler_container; - EmojiTextView status_spoiler; + CustomTextView status_spoiler; Button status_spoiler_button; - EmojiTextView status_content; + CustomTextView status_content; TextView status_content_translated; LinearLayout status_content_translated_container; TextView status_account_username; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java index 269b2c6d8..64e9cb508 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java @@ -190,6 +190,19 @@ public class SettingsFragment extends Fragment { } }); + boolean display_emoji = sharedpreferences.getBoolean(Helper.SET_DISPLAY_EMOJI, true); + final CheckBox set_display_emoji = rootView.findViewById(R.id.set_display_emoji); + set_display_emoji.setChecked(display_emoji); + + set_display_emoji.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putBoolean(Helper.SET_DISPLAY_EMOJI, set_display_emoji.isChecked()); + editor.apply(); + } + }); + boolean expand_media = sharedpreferences.getBoolean(Helper.SET_EXPAND_MEDIA, false); final CheckBox set_expand_media = rootView.findViewById(R.id.set_expand_image); set_expand_media.setChecked(expand_media); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/CustomTextView.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/CustomTextView.java index 5a7a3703c..2def0f090 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/CustomTextView.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/CustomTextView.java @@ -16,19 +16,16 @@ package fr.gouv.etalab.mastodon.helper; * see . */ import android.annotation.SuppressLint; import android.content.Context; +import android.content.SharedPreferences; import android.content.res.TypedArray; import android.graphics.Paint; -import android.support.annotation.CallSuper; import android.support.annotation.DimenRes; import android.support.annotation.Px; -import android.text.Selection; -import android.text.Spannable; +import android.support.v7.widget.AppCompatTextView; +import android.text.SpannableStringBuilder; import android.util.AttributeSet; -import android.view.KeyEvent; -import android.view.MotionEvent; -import com.vanniktech.emoji.EmojiEditTextInterface; -import com.vanniktech.emoji.emoji.Emoji; +import com.vanniktech.emoji.EmojiManager; import fr.gouv.etalab.mastodon.R; @@ -38,64 +35,57 @@ import fr.gouv.etalab.mastodon.R; * Allows to fix crashes with selection see: https://stackoverflow.com/a/36740247 */ -public class CustomTextView extends android.support.v7.widget.AppCompatTextView implements EmojiEditTextInterface { +public class CustomTextView extends AppCompatTextView { private float emojiSize; + private boolean emoji; public CustomTextView(Context context) { super(context); } public CustomTextView(Context context, AttributeSet attrs) { super(context, attrs); + final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); + emoji = sharedpreferences.getBoolean(Helper.SET_DISPLAY_EMOJI, true); + final Paint.FontMetrics fontMetrics = getPaint().getFontMetrics(); final float defaultEmojiSize = fontMetrics.descent - fontMetrics.ascent; if (attrs == null) { emojiSize = defaultEmojiSize; } else { - @SuppressLint("CustomViewStyleable") final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.EmojiMultiAutoCompleteTextView); + @SuppressLint("CustomViewStyleable") final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.EmojiTextView); try { - emojiSize = a.getDimension(R.styleable.EmojiMultiAutoCompleteTextView_emojiSize, defaultEmojiSize); + emojiSize = a.getDimension(R.styleable.EmojiTextView_emojiSize, defaultEmojiSize); } finally { a.recycle(); } } - setText(getText()); } - public CustomTextView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - @Override - public void backspace() { - final KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL); - dispatchKeyEvent(event); - } - - @Override - public float getEmojiSize() { - return emojiSize; - } - - @Override @CallSuper - public void input(final Emoji emoji) { - if (emoji != null) { - final int start = getSelectionStart(); - final int end = getSelectionEnd(); - - append(emoji.getUnicode()); + public void setText(final CharSequence rawText, final BufferType type) { + if( emoji) { + final CharSequence text = rawText == null ? "" : rawText; + final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text); + final Paint.FontMetrics fontMetrics = getPaint().getFontMetrics(); + final float defaultEmojiSize = fontMetrics.descent - fontMetrics.ascent; + EmojiManager.getInstance().replaceWithImages(getContext(), spannableStringBuilder, emojiSize, defaultEmojiSize); + super.setText(spannableStringBuilder, type); + }else { + super.setText(rawText, type); } + } - @Override + /** sets the emoji size in pixels and automatically invalidates the text and renders it with the new size */ public final void setEmojiSize(@Px final int pixels) { setEmojiSize(pixels, true); } - @Override + /** sets the emoji size in pixels and automatically invalidates the text and renders it with the new size when {@code shouldInvalidate} is true */ public final void setEmojiSize(@Px final int pixels, final boolean shouldInvalidate) { emojiSize = pixels; @@ -104,31 +94,14 @@ public class CustomTextView extends android.support.v7.widget.AppCompatTextView } } - @Override + /** sets the emoji size in pixels with the provided resource and automatically invalidates the text and renders it with the new size */ public final void setEmojiSizeRes(@DimenRes final int res) { setEmojiSizeRes(res, true); } - @Override + /** sets the emoji size in pixels with the provided resource and invalidates the text and renders it with the new size when {@code shouldInvalidate} is true */ public final void setEmojiSizeRes(@DimenRes final int res, final boolean shouldInvalidate) { setEmojiSize(getResources().getDimensionPixelSize(res), shouldInvalidate); } - //TODO: sounds no longer needed, commented but might be removed in a next release - /*@Override - public boolean dispatchTouchEvent(final MotionEvent event) { - // FIXME simple workaround to https://code.google.com/p/android/issues/detail?id=191430 - int startSelection = getSelectionStart(); - int endSelection = getSelectionEnd(); - if (startSelection < 0 || endSelection < 0){ - Selection.setSelection((Spannable) getText(), getText().length()); - } else if (startSelection != endSelection) { - if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { - final CharSequence text = getText(); - setText(null); - setText(text); - } - } - return super.dispatchTouchEvent(event); - }*/ } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index 5dda8822d..0c2f3a770 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -270,6 +270,7 @@ public class Helper { public static final String SET_NOTIF_SOUND = "set_notif_sound"; public static final String SET_ENABLE_TIME_SLOT = "set_enable_time_slot"; public static final String SET_KEEP_BACKGROUND_PROCESS = "set_keep_background_process"; + public static final String SET_DISPLAY_EMOJI = "set_display_emoji"; public static final int S_512KO = 1; public static final int S_1MO = 2; public static final int S_2MO = 3; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/MastalabAutoCompleteTextView.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/MastalabAutoCompleteTextView.java index 3cbceff74..6eb2179c2 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/MastalabAutoCompleteTextView.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/MastalabAutoCompleteTextView.java @@ -2,6 +2,7 @@ package fr.gouv.etalab.mastodon.helper; import android.annotation.SuppressLint; import android.content.Context; +import android.content.SharedPreferences; import android.content.res.TypedArray; import android.graphics.Paint; import android.support.annotation.CallSuper; @@ -19,6 +20,7 @@ import fr.gouv.etalab.mastodon.R; public class MastalabAutoCompleteTextView extends android.support.v7.widget.AppCompatAutoCompleteTextView implements EmojiEditTextInterface { private float emojiSize; + private boolean emoji; public MastalabAutoCompleteTextView(Context context) { super(context); @@ -29,7 +31,8 @@ public class MastalabAutoCompleteTextView extends android.support.v7.widget.AppC final Paint.FontMetrics fontMetrics = getPaint().getFontMetrics(); final float defaultEmojiSize = fontMetrics.descent - fontMetrics.ascent; - + final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); + emoji = sharedpreferences.getBoolean(Helper.SET_DISPLAY_EMOJI, true); if (attrs == null) { emojiSize = defaultEmojiSize; } else { @@ -54,7 +57,9 @@ public class MastalabAutoCompleteTextView extends android.support.v7.widget.AppC protected void onTextChanged(final CharSequence text, final int start, final int lengthBefore, final int lengthAfter) { final Paint.FontMetrics fontMetrics = getPaint().getFontMetrics(); final float defaultEmojiSize = fontMetrics.descent - fontMetrics.ascent; - EmojiManager.getInstance().replaceWithImages(getContext(), getText(), emojiSize, defaultEmojiSize); + if( emoji) { + EmojiManager.getInstance().replaceWithImages(getContext(), getText(), emojiSize, defaultEmojiSize); + } } @Override diff --git a/app/src/main/res/layout-sw600dp/fragment_settings.xml b/app/src/main/res/layout-sw600dp/fragment_settings.xml index 0b2fe5d5b..cbca6b6a8 100644 --- a/app/src/main/res/layout-sw600dp/fragment_settings.xml +++ b/app/src/main/res/layout-sw600dp/fragment_settings.xml @@ -161,7 +161,11 @@ android:text="@string/set_automatically_split_toot" android:layout_height="wrap_content" /> - + - - - - - - - - - + No lists Videos Channels + Use Emoji One Never