mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Fixes issue 1224
This commit is contained in:
parent
0a861317f4
commit
81147aada1
5 changed files with 13 additions and 100 deletions
|
|
@ -1,87 +0,0 @@
|
|||
package fr.free.nrw.commons.notification;
|
||||
|
||||
/**
|
||||
* Created by jatin on 1/3/18.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import fr.free.nrw.commons.R;
|
||||
|
||||
/**
|
||||
* User: Bazlur Rahman Rokon
|
||||
* Date: 9/7/13 - 3:33 AM
|
||||
*/
|
||||
public class ExpandableTextView extends android.support.v7.widget.AppCompatTextView {
|
||||
private static final int DEFAULT_TRIM_LENGTH = 40;
|
||||
private static final String ELLIPSIS = "...More";
|
||||
|
||||
private CharSequence originalText;
|
||||
private CharSequence trimmedText;
|
||||
private BufferType bufferType;
|
||||
private boolean trim = true;
|
||||
private int trimLength;
|
||||
|
||||
public ExpandableTextView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public ExpandableTextView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ExpandableTextView);
|
||||
this.trimLength = typedArray.getInt(R.styleable.ExpandableTextView_trimLength, DEFAULT_TRIM_LENGTH);
|
||||
typedArray.recycle();
|
||||
|
||||
setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
trim = !trim;
|
||||
setText();
|
||||
requestFocusFromTouch();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setText() {
|
||||
super.setText(getDisplayableText(), bufferType);
|
||||
}
|
||||
|
||||
private CharSequence getDisplayableText() {
|
||||
return trim ? trimmedText : originalText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(CharSequence text, BufferType type) {
|
||||
originalText = text;
|
||||
trimmedText = getTrimmedText();
|
||||
bufferType = type;
|
||||
setText();
|
||||
}
|
||||
|
||||
private CharSequence getTrimmedText() {
|
||||
if (originalText != null && originalText.length() > trimLength) {
|
||||
return new SpannableStringBuilder(originalText, 0, trimLength + 1).append(ELLIPSIS);
|
||||
} else {
|
||||
return originalText;
|
||||
}
|
||||
}
|
||||
|
||||
public CharSequence getOriginalText() {
|
||||
return originalText;
|
||||
}
|
||||
|
||||
public void setTrimLength(int trimLength) {
|
||||
this.trimLength = trimLength;
|
||||
trimmedText = getTrimmedText();
|
||||
setText();
|
||||
}
|
||||
|
||||
public int getTrimLength() {
|
||||
return trimLength;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ import android.view.ViewGroup;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.borjabravo.readmoretextview.ReadMoreTextView;
|
||||
import com.pedrogomez.renderers.Renderer;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
|
@ -17,8 +18,8 @@ import fr.free.nrw.commons.R;
|
|||
*/
|
||||
|
||||
public class NotificationRenderer extends Renderer<Notification> {
|
||||
@BindView(R.id.title) ExpandableTextView title;
|
||||
@BindView(R.id.description) ExpandableTextView description;
|
||||
@BindView(R.id.title) ReadMoreTextView title;
|
||||
@BindView(R.id.description) ReadMoreTextView description;
|
||||
@BindView(R.id.time) TextView time;
|
||||
@BindView(R.id.icon) ImageView icon;
|
||||
private NotificationClicked listener;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:foreground="?selectableItemBackground"
|
||||
android:minHeight="72dp"
|
||||
>
|
||||
android:minHeight="72dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
|
|
@ -34,7 +33,7 @@
|
|||
tools:text="@string/placeholder_place_distance"
|
||||
/>
|
||||
|
||||
<fr.free.nrw.commons.notification.ExpandableTextView
|
||||
<com.borjabravo.readmoretextview.ReadMoreTextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
@ -46,12 +45,13 @@
|
|||
android:layout_toRightOf="@id/icon"
|
||||
android:layout_toStartOf="@id/time"
|
||||
android:ellipsize="end"
|
||||
|
||||
app:trimLines="2"
|
||||
app:colorClickableText="#969494"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
|
||||
tools:text="@string/placeholder_place_name"
|
||||
/>
|
||||
|
||||
<fr.free.nrw.commons.notification.ExpandableTextView
|
||||
<com.borjabravo.readmoretextview.ReadMoreTextView
|
||||
android:id="@+id/description"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
@ -62,7 +62,8 @@
|
|||
android:layout_below="@id/title"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:ellipsize="end"
|
||||
|
||||
app:trimLines="2"
|
||||
app:colorClickableText="#969494"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||
tools:text="@string/placeholder_place_description"
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -16,8 +16,4 @@
|
|||
<attr name="drawableEnd" format="reference"/>
|
||||
<attr name="drawableBottom" format="reference"/>
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="ExpandableTextView">
|
||||
<attr name="trimLength" format="integer"/>
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
Loading…
Add table
Add a link
Reference in a new issue