From 534215fdbc81b182a708ffdce43e81f0becb2a80 Mon Sep 17 00:00:00 2001 From: Jatin Rao Date: Thu, 1 Mar 2018 15:57:13 +0530 Subject: [PATCH 1/4] Fix for issue #1224 showing complete notification on click --- .../notification/ExpandableTextView.java | 87 +++++++++++++++++++ .../notification/NotificationRenderer.java | 4 +- app/src/main/res/layout/item_notification.xml | 8 +- app/src/main/res/values/attrs.xml | 4 + gradle.properties | 44 ++++++---- 5 files changed, 123 insertions(+), 24 deletions(-) create mode 100644 app/src/main/java/fr/free/nrw/commons/notification/ExpandableTextView.java diff --git a/app/src/main/java/fr/free/nrw/commons/notification/ExpandableTextView.java b/app/src/main/java/fr/free/nrw/commons/notification/ExpandableTextView.java new file mode 100644 index 000000000..473a4ebf1 --- /dev/null +++ b/app/src/main/java/fr/free/nrw/commons/notification/ExpandableTextView.java @@ -0,0 +1,87 @@ +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(text); + bufferType = type; + setText(); + } + + private CharSequence getTrimmedText(CharSequence text) { + 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(originalText); + setText(); + } + + public int getTrimLength() { + return trimLength; + } +} diff --git a/app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java b/app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java index a5aac0508..3e5e470a1 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java +++ b/app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java @@ -17,8 +17,8 @@ import fr.free.nrw.commons.R; */ public class NotificationRenderer extends Renderer { - @BindView(R.id.title) TextView title; - @BindView(R.id.description) TextView description; + @BindView(R.id.title) ExpandableTextView title; + @BindView(R.id.description) ExpandableTextView description; @BindView(R.id.time) TextView time; @BindView(R.id.icon) ImageView icon; private NotificationClicked listener; diff --git a/app/src/main/res/layout/item_notification.xml b/app/src/main/res/layout/item_notification.xml index d8f4dd8d4..593f2ab4f 100644 --- a/app/src/main/res/layout/item_notification.xml +++ b/app/src/main/res/layout/item_notification.xml @@ -34,7 +34,7 @@ tools:text="@string/placeholder_place_distance" /> - - diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 38331d635..0a1df6e2f 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -16,4 +16,8 @@ + + + + \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 10685ea11..0f0385cbb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,21 +1,29 @@ -gradleVersion = 3.0.0 - -SUPPORT_LIB_VERSION = 26.0.2 - -compileSdkVersion = android-26 -buildToolsVersion = 26.0.2 - -minSdkVersion = 15 - -targetSdkVersion = 25 +## Project-wide Gradle settings. +# +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# Default value: -Xmx1024m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +# +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +#Thu Mar 01 15:28:48 IST 2018 +systemProp.http.proxyPort=0 +compileSdkVersion=android-26 android.useDeprecatedNdk=true - -# Library dependencies BUTTERKNIFE_VERSION=8.6.0 -DAGGER_VERSION=2.13 -LEAK_CANARY=1.5.4 org.gradle.jvmargs=-Xmx1536M - -#TODO: Temporary disabled. https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#aapt2 -#Refer to PR: https://github.com/commons-app/apps-android-commons/pull/932 -android.enableAapt2=false \ No newline at end of file +buildToolsVersion=26.0.2 +targetSdkVersion=25 +android.enableAapt2=false +SUPPORT_LIB_VERSION=26.0.2 +minSdkVersion=15 +systemProp.http.proxyHost= +LEAK_CANARY=1.5.4 +DAGGER_VERSION=2.13 +gradleVersion=3.0.0 From 0a861317f4a1f319165d1e87a6b0db33c4e2e243 Mon Sep 17 00:00:00 2001 From: Jatin Rao Date: Thu, 1 Mar 2018 17:14:55 +0530 Subject: [PATCH 2/4] Removed unsused variable from method getTrimmedText --- .../free/nrw/commons/notification/ExpandableTextView.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/notification/ExpandableTextView.java b/app/src/main/java/fr/free/nrw/commons/notification/ExpandableTextView.java index 473a4ebf1..c66d145bd 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/ExpandableTextView.java +++ b/app/src/main/java/fr/free/nrw/commons/notification/ExpandableTextView.java @@ -58,12 +58,12 @@ public class ExpandableTextView extends android.support.v7.widget.AppCompatTextV @Override public void setText(CharSequence text, BufferType type) { originalText = text; - trimmedText = getTrimmedText(text); + trimmedText = getTrimmedText(); bufferType = type; setText(); } - private CharSequence getTrimmedText(CharSequence text) { + private CharSequence getTrimmedText() { if (originalText != null && originalText.length() > trimLength) { return new SpannableStringBuilder(originalText, 0, trimLength + 1).append(ELLIPSIS); } else { @@ -77,7 +77,7 @@ public class ExpandableTextView extends android.support.v7.widget.AppCompatTextV public void setTrimLength(int trimLength) { this.trimLength = trimLength; - trimmedText = getTrimmedText(originalText); + trimmedText = getTrimmedText(); setText(); } From 81147aada129d8ffac154faa957af317166131c4 Mon Sep 17 00:00:00 2001 From: Jatin Rao Date: Sat, 3 Mar 2018 19:55:09 +0530 Subject: [PATCH 3/4] Fixes issue 1224 --- app/build.gradle | 2 + .../notification/ExpandableTextView.java | 87 ------------------- .../notification/NotificationRenderer.java | 5 +- app/src/main/res/layout/item_notification.xml | 15 ++-- app/src/main/res/values/attrs.xml | 4 - 5 files changed, 13 insertions(+), 100 deletions(-) delete mode 100644 app/src/main/java/fr/free/nrw/commons/notification/ExpandableTextView.java diff --git a/app/build.gradle b/app/build.gradle index 6f225dc2f..5ae2e70df 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -94,6 +94,8 @@ dependencies { implementation "com.google.dagger:dagger-android-support:$DAGGER_VERSION" kapt "com.google.dagger:dagger-compiler:$DAGGER_VERSION" kapt "com.google.dagger:dagger-android-processor:$DAGGER_VERSION" + + compile 'com.borjabravo:readmoretextview:2.1.0' } android { diff --git a/app/src/main/java/fr/free/nrw/commons/notification/ExpandableTextView.java b/app/src/main/java/fr/free/nrw/commons/notification/ExpandableTextView.java deleted file mode 100644 index c66d145bd..000000000 --- a/app/src/main/java/fr/free/nrw/commons/notification/ExpandableTextView.java +++ /dev/null @@ -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; - } -} diff --git a/app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java b/app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java index 3e5e470a1..87924d286 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java +++ b/app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java @@ -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 { - @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; diff --git a/app/src/main/res/layout/item_notification.xml b/app/src/main/res/layout/item_notification.xml index 593f2ab4f..bd364c029 100644 --- a/app/src/main/res/layout/item_notification.xml +++ b/app/src/main/res/layout/item_notification.xml @@ -1,11 +1,10 @@ - + android:minHeight="72dp"> - - diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 0a1df6e2f..38331d635 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -16,8 +16,4 @@ - - - - \ No newline at end of file From ff11c9d1f0427b34f0ac533662b01f141c153daa Mon Sep 17 00:00:00 2001 From: Jatin Rao Date: Sun, 4 Mar 2018 22:19:40 +0530 Subject: [PATCH 4/4] Added a white space between text and show less --- .../nrw/commons/notification/NotificationRenderer.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java b/app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java index 87924d286..a02b9eff4 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java +++ b/app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java @@ -1,5 +1,6 @@ package fr.free.nrw.commons.notification; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -47,9 +48,13 @@ public class NotificationRenderer extends Renderer { @Override public void render() { Notification notification = getContent(); - title.setText(notification.notificationText); + StringBuilder str = new StringBuilder(notification.notificationText); + str.append(" " ); + title.setText(str); time.setText(notification.date); - description.setText(notification.description); + StringBuilder desc = new StringBuilder(notification.description); + desc.append(" "); + description.setText(desc); switch (notification.notificationType) { case THANK_YOU_EDIT: icon.setImageResource(R.drawable.ic_edit_black_24dp);