Skip to content

Commit 534215f

Browse files
committed
Fix for issue commons-app#1224 showing complete notification on click
1 parent 89245a6 commit 534215f

File tree

5 files changed

+123
-24
lines changed

5 files changed

+123
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package fr.free.nrw.commons.notification;
2+
3+
/**
4+
* Created by jatin on 1/3/18.
5+
*/
6+
7+
import android.content.Context;
8+
import android.content.res.TypedArray;
9+
import android.text.SpannableStringBuilder;
10+
import android.util.AttributeSet;
11+
import android.view.View;
12+
13+
import fr.free.nrw.commons.R;
14+
15+
/**
16+
* User: Bazlur Rahman Rokon
17+
* Date: 9/7/13 - 3:33 AM
18+
*/
19+
public class ExpandableTextView extends android.support.v7.widget.AppCompatTextView {
20+
private static final int DEFAULT_TRIM_LENGTH = 40;
21+
private static final String ELLIPSIS = "...More";
22+
23+
private CharSequence originalText;
24+
private CharSequence trimmedText;
25+
private BufferType bufferType;
26+
private boolean trim = true;
27+
private int trimLength;
28+
29+
public ExpandableTextView(Context context) {
30+
this(context, null);
31+
}
32+
33+
public ExpandableTextView(Context context, AttributeSet attrs) {
34+
super(context, attrs);
35+
36+
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ExpandableTextView);
37+
this.trimLength = typedArray.getInt(R.styleable.ExpandableTextView_trimLength, DEFAULT_TRIM_LENGTH);
38+
typedArray.recycle();
39+
40+
setOnClickListener(new OnClickListener() {
41+
@Override
42+
public void onClick(View v) {
43+
trim = !trim;
44+
setText();
45+
requestFocusFromTouch();
46+
}
47+
});
48+
}
49+
50+
private void setText() {
51+
super.setText(getDisplayableText(), bufferType);
52+
}
53+
54+
private CharSequence getDisplayableText() {
55+
return trim ? trimmedText : originalText;
56+
}
57+
58+
@Override
59+
public void setText(CharSequence text, BufferType type) {
60+
originalText = text;
61+
trimmedText = getTrimmedText(text);
62+
bufferType = type;
63+
setText();
64+
}
65+
66+
private CharSequence getTrimmedText(CharSequence text) {
67+
if (originalText != null && originalText.length() > trimLength) {
68+
return new SpannableStringBuilder(originalText, 0, trimLength + 1).append(ELLIPSIS);
69+
} else {
70+
return originalText;
71+
}
72+
}
73+
74+
public CharSequence getOriginalText() {
75+
return originalText;
76+
}
77+
78+
public void setTrimLength(int trimLength) {
79+
this.trimLength = trimLength;
80+
trimmedText = getTrimmedText(originalText);
81+
setText();
82+
}
83+
84+
public int getTrimLength() {
85+
return trimLength;
86+
}
87+
}

app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
*/
1818

1919
public class NotificationRenderer extends Renderer<Notification> {
20-
@BindView(R.id.title) TextView title;
21-
@BindView(R.id.description) TextView description;
20+
@BindView(R.id.title) ExpandableTextView title;
21+
@BindView(R.id.description) ExpandableTextView description;
2222
@BindView(R.id.time) TextView time;
2323
@BindView(R.id.icon) ImageView icon;
2424
private NotificationClicked listener;

app/src/main/res/layout/item_notification.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
tools:text="@string/placeholder_place_distance"
3535
/>
3636

37-
<TextView
37+
<fr.free.nrw.commons.notification.ExpandableTextView
3838
android:id="@+id/title"
3939
android:layout_width="match_parent"
4040
android:layout_height="wrap_content"
@@ -46,12 +46,12 @@
4646
android:layout_toRightOf="@id/icon"
4747
android:layout_toStartOf="@id/time"
4848
android:ellipsize="end"
49-
android:maxLines="2"
49+
5050
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
5151
tools:text="@string/placeholder_place_name"
5252
/>
5353

54-
<TextView
54+
<fr.free.nrw.commons.notification.ExpandableTextView
5555
android:id="@+id/description"
5656
android:layout_width="match_parent"
5757
android:layout_height="wrap_content"
@@ -62,7 +62,7 @@
6262
android:layout_below="@id/title"
6363
android:layout_marginBottom="16dp"
6464
android:ellipsize="end"
65-
android:maxLines="4"
65+
6666
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
6767
tools:text="@string/placeholder_place_description"
6868
/>

app/src/main/res/values/attrs.xml

+4
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@
1616
<attr name="drawableEnd" format="reference"/>
1717
<attr name="drawableBottom" format="reference"/>
1818
</declare-styleable>
19+
20+
<declare-styleable name="ExpandableTextView">
21+
<attr name="trimLength" format="integer"/>
22+
</declare-styleable>
1923
</resources>

gradle.properties

+26-18
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
1-
gradleVersion = 3.0.0
2-
3-
SUPPORT_LIB_VERSION = 26.0.2
4-
5-
compileSdkVersion = android-26
6-
buildToolsVersion = 26.0.2
7-
8-
minSdkVersion = 15
9-
10-
targetSdkVersion = 25
1+
## Project-wide Gradle settings.
2+
#
3+
# For more details on how to configure your build environment visit
4+
# http://www.gradle.org/docs/current/userguide/build_environment.html
5+
#
6+
# Specifies the JVM arguments used for the daemon process.
7+
# The setting is particularly useful for tweaking memory settings.
8+
# Default value: -Xmx1024m -XX:MaxPermSize=256m
9+
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10+
#
11+
# When configured, Gradle will run in incubating parallel mode.
12+
# This option should only be used with decoupled projects. More details, visit
13+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14+
# org.gradle.parallel=true
15+
#Thu Mar 01 15:28:48 IST 2018
16+
systemProp.http.proxyPort=0
17+
compileSdkVersion=android-26
1118
android.useDeprecatedNdk=true
12-
13-
# Library dependencies
1419
BUTTERKNIFE_VERSION=8.6.0
15-
DAGGER_VERSION=2.13
16-
LEAK_CANARY=1.5.4
1720
org.gradle.jvmargs=-Xmx1536M
18-
19-
#TODO: Temporary disabled. https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#aapt2
20-
#Refer to PR: https://github.com/commons-app/apps-android-commons/pull/932
21-
android.enableAapt2=false
21+
buildToolsVersion=26.0.2
22+
targetSdkVersion=25
23+
android.enableAapt2=false
24+
SUPPORT_LIB_VERSION=26.0.2
25+
minSdkVersion=15
26+
systemProp.http.proxyHost=
27+
LEAK_CANARY=1.5.4
28+
DAGGER_VERSION=2.13
29+
gradleVersion=3.0.0

0 commit comments

Comments
 (0)