Fixes issue #450 - Crashes with selection
This commit is contained in:
parent
301a8a161f
commit
3195a15b50
|
@ -70,6 +70,7 @@ import fr.gouv.etalab.mastodon.client.Entities.Attachment;
|
|||
import fr.gouv.etalab.mastodon.client.Entities.Emojis;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.helper.CrossActions;
|
||||
import fr.gouv.etalab.mastodon.helper.CustomTextView;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnPostNotificationsActionInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveEmojiInterface;
|
||||
|
@ -1048,10 +1049,10 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
|
|||
class ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
FrameLayout card_status_container;
|
||||
TextView notification_status_content;
|
||||
CustomTextView notification_status_content;
|
||||
TextView notification_type;
|
||||
LinearLayout status_spoiler_container;
|
||||
TextView status_spoiler;
|
||||
CustomTextView status_spoiler;
|
||||
Button status_spoiler_button;
|
||||
TextView notification_account_username;
|
||||
ImageView notification_account_profile;
|
||||
|
|
|
@ -105,6 +105,7 @@ import fr.gouv.etalab.mastodon.client.Entities.Error;
|
|||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment;
|
||||
import fr.gouv.etalab.mastodon.helper.CrossActions;
|
||||
import fr.gouv.etalab.mastodon.helper.CustomTextView;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveCardInterface;
|
||||
|
@ -240,9 +241,9 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
class ViewHolder extends RecyclerView.ViewHolder{
|
||||
LinearLayout status_content_container;
|
||||
LinearLayout status_spoiler_container;
|
||||
TextView status_spoiler;
|
||||
CustomTextView status_spoiler;
|
||||
Button status_spoiler_button;
|
||||
TextView status_content;
|
||||
CustomTextView status_content;
|
||||
TextView status_content_translated;
|
||||
LinearLayout status_content_translated_container;
|
||||
TextView status_account_username;
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
package fr.gouv.etalab.mastodon.helper;
|
||||
|
||||
/* 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 android.content.Context;
|
||||
import android.text.Selection;
|
||||
import android.text.Spannable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 12/05/2018.
|
||||
* Allows to fix crashes with selection see: https://stackoverflow.com/a/36740247
|
||||
*/
|
||||
|
||||
public class CustomTextView extends android.support.v7.widget.AppCompatTextView {
|
||||
|
||||
|
||||
public CustomTextView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public CustomTextView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public CustomTextView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
|
@ -91,7 +91,7 @@
|
|||
android:orientation="vertical"
|
||||
android:visibility="gone"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
<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">
|
||||
<TextView
|
||||
<fr.gouv.etalab.mastodon.helper.CustomTextView
|
||||
android:id="@+id/notification_status_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:textIsSelectable="true"
|
||||
|
|
|
@ -144,7 +144,7 @@
|
|||
android:orientation="vertical"
|
||||
android:visibility="gone"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
<fr.gouv.etalab.mastodon.helper.CustomTextView
|
||||
android:id="@+id/status_spoiler"
|
||||
android:layout_marginTop="10dp"
|
||||
android:textIsSelectable="true"
|
||||
|
@ -174,7 +174,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
<fr.gouv.etalab.mastodon.helper.CustomTextView
|
||||
android:id="@+id/status_content"
|
||||
android:textIsSelectable="true"
|
||||
android:layout_marginTop="10dp"
|
||||
|
|
|
@ -118,7 +118,7 @@
|
|||
android:orientation="vertical"
|
||||
android:visibility="gone"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
<fr.gouv.etalab.mastodon.helper.CustomTextView
|
||||
android:id="@+id/status_spoiler"
|
||||
android:layout_marginTop="10dp"
|
||||
android:textIsSelectable="true"
|
||||
|
@ -148,7 +148,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
<fr.gouv.etalab.mastodon.helper.CustomTextView
|
||||
android:id="@+id/status_content"
|
||||
android:textIsSelectable="true"
|
||||
android:layout_marginLeft="10dp"
|
||||
|
|
|
@ -117,7 +117,7 @@
|
|||
android:orientation="vertical"
|
||||
android:visibility="gone"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
<fr.gouv.etalab.mastodon.helper.CustomTextView
|
||||
android:id="@+id/status_spoiler"
|
||||
android:layout_marginTop="10dp"
|
||||
android:textIsSelectable="true"
|
||||
|
@ -147,7 +147,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
<fr.gouv.etalab.mastodon.helper.CustomTextView
|
||||
android:id="@+id/status_content"
|
||||
android:textIsSelectable="true"
|
||||
android:layout_marginLeft="10dp"
|
||||
|
|
Loading…
Reference in New Issue