Fix issue #527 - Disable custom Emoji

This commit is contained in:
stom79 2018-10-28 11:32:23 +01:00
parent a721b11305
commit 0bf843d00a
18 changed files with 147 additions and 79 deletions

View File

@ -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"

View File

@ -19,5 +19,4 @@ public class BaseActivity extends AppCompatActivity {
Helper.installProvider();
EmojiManager.install(new EmojiOneProvider());
}
}

View File

@ -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);
}

View File

@ -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 <http://www.gnu.org/licenses>. */
import java.util.List;
/**
* Created by Thomas on 26/10/2018.
* Manage conversation
*/
public class Conversation {
private String id;
private List<Account> 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<Account> getAccounts() {
return accounts;
}
public void setAccounts(List<Account> accounts) {
this.accounts = accounts;
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -16,19 +16,16 @@ package fr.gouv.etalab.mastodon.helper;
* see <http://www.gnu.org/licenses>. */
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);
}*/
}

View File

@ -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;

View File

@ -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

View File

@ -161,7 +161,11 @@
android:text="@string/set_automatically_split_toot"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/set_display_emoji"
android:layout_width="wrap_content"
android:text="@string/set_display_emoji"
android:layout_height="wrap_content" />
<!-- Resize pictures -->
<LinearLayout
android:layout_marginTop="10dp"

View File

@ -91,7 +91,7 @@
android:orientation="vertical"
android:visibility="gone"
android:layout_height="wrap_content">
<com.vanniktech.emoji.EmojiTextView
<fr.gouv.etalab.mastodon.helper.CustomTextView
android:id="@+id/status_spoiler"
android:layout_marginTop="10dp"
android:textIsSelectable="true"
@ -122,7 +122,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.vanniktech.emoji.EmojiTextView
<fr.gouv.etalab.mastodon.helper.CustomTextView
android:id="@+id/notification_status_content"
android:layout_marginTop="10dp"
android:textIsSelectable="true"

View File

@ -147,7 +147,7 @@
android:orientation="vertical"
android:visibility="gone"
android:layout_height="wrap_content">
<com.vanniktech.emoji.EmojiTextView
<fr.gouv.etalab.mastodon.helper.CustomTextView
android:id="@+id/status_spoiler"
android:layout_marginTop="10dp"
android:textIsSelectable="true"
@ -177,7 +177,7 @@
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<com.vanniktech.emoji.EmojiTextView
<fr.gouv.etalab.mastodon.helper.CustomTextView
android:id="@+id/status_content"
android:textIsSelectable="true"
android:layout_marginTop="10dp"

View File

@ -119,7 +119,7 @@
android:orientation="vertical"
android:visibility="gone"
android:layout_height="wrap_content">
<com.vanniktech.emoji.EmojiTextView
<fr.gouv.etalab.mastodon.helper.CustomTextView
android:id="@+id/status_spoiler"
android:layout_marginTop="10dp"
android:textIsSelectable="true"
@ -150,7 +150,7 @@
android:layout_marginBottom="5dp"
android:orientation="vertical"
android:layout_height="wrap_content">
<com.vanniktech.emoji.EmojiTextView
<fr.gouv.etalab.mastodon.helper.CustomTextView
android:id="@+id/status_content"
android:textIsSelectable="true"
android:layout_marginLeft="10dp"

View File

@ -108,7 +108,7 @@
android:orientation="vertical"
android:visibility="gone"
android:layout_height="wrap_content">
<com.vanniktech.emoji.EmojiTextView
<fr.gouv.etalab.mastodon.helper.CustomTextView
android:id="@+id/status_spoiler"
android:layout_marginTop="10dp"
android:textIsSelectable="true"
@ -138,7 +138,7 @@
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<com.vanniktech.emoji.EmojiTextView
<fr.gouv.etalab.mastodon.helper.CustomTextView
android:id="@+id/status_content"
android:textIsSelectable="true"
android:layout_marginLeft="10dp"

View File

@ -161,8 +161,12 @@
android:text="@string/set_automatically_split_toot"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/set_display_emoji"
android:layout_width="wrap_content"
android:text="@string/set_display_emoji"
android:layout_height="wrap_content" />
<!-- Resize pictures -->
<LinearLayout

View File

@ -653,6 +653,7 @@
<string name="no_lists">No lists</string>
<string name="videos">Videos</string>
<string name="channels">Channels</string>
<string name="set_display_emoji">Use Emoji One</string>
<string-array name="filter_expire">
<item>Never</item>