diff --git a/README.md b/README.md index ab84fe0..95a5a5c 100644 --- a/README.md +++ b/README.md @@ -38,14 +38,14 @@ Core library contains `SocialTextView`, `SocialEditText` and helper class applies these behavior into any `TextView`. ```xml - + ``` See [attrs.xml](https://github.com/HendraAnggrian/socialview/blob/master/socialview/res/values/attrs.xml) @@ -57,10 +57,10 @@ Modify its state and set listeners programmatically. textView.setMentionEnabled(false); textView.setHashtagColor(Color.RED); textView.setOnHashtagClickListener(new SocialView.OnClickListener() { - @Override - public void invoke(SocialView socialView, String s) { - // do something - } + @Override + public void invoke(SocialView socialView, String s) { + // do something + } }); ``` @@ -69,13 +69,13 @@ textView.setOnHashtagClickListener(new SocialView.OnClickListener() { Extended library comes with `SocialAutoCompleteTextView`. ```xml - + ``` To display suggestions, it is required to `setHashtagAdapter()` @@ -91,7 +91,8 @@ textView.setHashtagAdapter(hashtagAdapter); ArrayAdapter mentionAdapter = new MentionAdapter(getContext()); mentionAdapter.add(new Mention("dirtyhobo")); mentionAdapter.add(new Mention("hobo", "Regular Hobo", R.mipmap.ic_launcher)); -mentionAdapter.add(new Mention("hendraanggrian", "Hendra Anggrian", "https://avatars0.githubusercontent.com/u/11507430?v=3&s=460")); +mentionAdapter.add(new Mention("hendraanggrian", "Hendra Anggrian", + "https://avatars0.githubusercontent.com/u/11507430?v=3&s=460")); textView.setMentionAdapter(mentionAdapter); ``` @@ -102,34 +103,34 @@ customized `SocialAdapter` or write your own `ArrayAdapter`. ```java public class Person { - public final String name; + public final String name; - public Person(String name) { - this.name = name; - } + public Person(String name) { + this.name = name; + } } // easier public class PersonAdapter extends SocialAdapter { - public PersonAdapter(@NonNull Context context) { - super(context, R.layout.item_person, R.id.textview_person); - } - - @Override - public String convertToString(Person $receiver) { - return $receiver.name; - } - - @Override - public View getView(int position, View convertView, @NonNull ViewGroup parent) { - ... - } + public PersonAdapter(@NonNull Context context) { + super(context, R.layout.item_person, R.id.textview_person); + } + + @Override + public String convertToString(Person $receiver) { + return $receiver.name; + } + + @Override + public View getView(int position, View convertView, @NonNull ViewGroup parent) { + // ... + } } // this works too public class PersonAdapter extends ArrayAdapter { - // your own adapter layout, view holder, data binding - // and of course, filtering logic + // your own adapter layout, view holder, data binding + // and of course, filtering logic } ``` diff --git a/build.gradle.kts b/build.gradle.kts index f9511da..3d1fbe1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,6 @@ plugins { alias(libs.plugins.android.application) apply false alias(libs.plugins.android.library) apply false kotlin("android") version libs.versions.kotlin apply false - kotlin("kapt") version libs.versions.kotlin apply false } allprojects { @@ -26,6 +25,11 @@ subprojects { plugins.withType().configureEach { configure(::configureAndroid) } + plugins.withType { + kotlinExtension.jvmToolchain(libs.versions.jdk.get().toInt()) + (the() as ExtensionAware).extensions.getByType() + .jvmTarget = JavaVersion.toVersion(libs.versions.jdk.get()).toString() + } } fun configureAndroid(extension: BaseExtension) { diff --git a/buildSrc/src/Releases.kt b/buildSrc/src/Releases.kt index e5fb7f8..ce8f01a 100644 --- a/buildSrc/src/Releases.kt +++ b/buildSrc/src/Releases.kt @@ -7,7 +7,7 @@ const val DEVELOPER_URL = "https://github.com/$DEVELOPER_ID/" const val RELEASE_GROUP = "com.hendraanggrian.appcompat" const val RELEASE_ARTIFACT = "socialview" -const val RELEASE_VERSION = "0.1-SNAPSHOT" +const val RELEASE_VERSION = "0.1" const val RELEASE_DESCRIPTION = "Android TextView and EditText with hashtag, mention, and hyperlink support" const val RELEASE_URL = "https://github.com/$DEVELOPER_ID/$RELEASE_ARTIFACT/" diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f768658..2ba83b5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -35,4 +35,7 @@ robolectric = "org.robolectric:robolectric:4.10.3" truth = "com.google.truth:truth:1.1.5" [bundles] -androidx-test = ["androidx-test-core", "androidx-test-runner", "androidx-test-junit", "robolectric", "truth"] +androidx-test = [ + "androidx-test-core", "androidx-test-runner", "androidx-test-junit", + "robolectric", "truth" +] diff --git a/rulebook_checks.xml b/rulebook_checks.xml index 6fca5cd..7d2c38f 100644 --- a/rulebook_checks.xml +++ b/rulebook_checks.xml @@ -4,15 +4,14 @@ "https://checkstyle.org/dtds/configuration_1_3.dtd"> @@ -46,10 +45,10 @@ - + - + diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index f8d0646..a2037e0 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -1,15 +1,13 @@ plugins { alias(libs.plugins.android.application) kotlin("android") version libs.versions.kotlin - kotlin("kapt") version libs.versions.kotlin } android { namespace = "com.example.$RELEASE_ARTIFACT" testNamespace = "$namespace.test" defaultConfig { - minSdk = 23 - applicationId = "com.example.socialview" + applicationId = "com.example.$RELEASE_ARTIFACT" multiDexEnabled = true } lint.abortOnError = false diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 969725d..7d6de12 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -1,22 +1,22 @@ + package="com.example.socialview"> - + - - - - - - - - + + + + + + + + diff --git a/sample/src/main/kotlin/com/example/socialview/ExampleActivity.kt b/sample/src/main/kotlin/com/example/socialview/ExampleActivity.kt index 3e30ea0..1f541e6 100644 --- a/sample/src/main/kotlin/com/example/socialview/ExampleActivity.kt +++ b/sample/src/main/kotlin/com/example/socialview/ExampleActivity.kt @@ -12,12 +12,12 @@ import android.widget.ArrayAdapter import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar -import com.hendraanggrian.appcompat.socialview.Hashtag -import com.hendraanggrian.appcompat.socialview.Mention -import com.hendraanggrian.appcompat.widget.HashtagArrayAdapter -import com.hendraanggrian.appcompat.widget.MentionArrayAdapter -import com.hendraanggrian.appcompat.widget.SocialArrayAdapter -import com.hendraanggrian.appcompat.widget.SocialAutoCompleteTextView +import com.hendraanggrian.appcompat.socialview.autocomplete.Hashtag +import com.hendraanggrian.appcompat.socialview.autocomplete.Mention +import com.hendraanggrian.appcompat.socialview.widget.HashtagArrayAdapter +import com.hendraanggrian.appcompat.socialview.widget.MentionArrayAdapter +import com.hendraanggrian.appcompat.socialview.widget.SocialArrayAdapter +import com.hendraanggrian.appcompat.socialview.widget.SocialAutoCompleteTextView class ExampleActivity : AppCompatActivity() { private companion object { @@ -100,13 +100,11 @@ class ExampleActivity : AppCompatActivity() { textView.hashtagAdapter = customHashtagAdapter textView.mentionAdapter = customMentionAdapter } - else -> { textView.hashtagAdapter = defaultHashtagAdapter textView.mentionAdapter = defaultMentionAdapter } } - R.id.enableHashtagItem -> textView.isHashtagEnabled = item.isChecked R.id.enableMentionItem -> textView.isMentionEnabled = item.isChecked R.id.enableHyperlinkItem -> textView.isHyperlinkEnabled = item.isChecked @@ -128,7 +126,6 @@ class ExampleActivity : AppCompatActivity() { holder = ViewHolder(view!!) view.tag = holder } - else -> holder = view.tag as ViewHolder } getItem(position)?.let { model -> holder.textView.text = model.name } diff --git a/sample/src/main/res/layout/activity_example.xml b/sample/src/main/res/layout/activity_example.xml index 92016e6..9264547 100644 --- a/sample/src/main/res/layout/activity_example.xml +++ b/sample/src/main/res/layout/activity_example.xml @@ -16,7 +16,7 @@ android:layout_height="?actionBarSize"/> - extends ArrayAdapter { private Filter filter; diff --git a/socialview-autocomplete/src/main/java/com/hendraanggrian/appcompat/widget/SocialAutoCompleteTextView.java b/socialview-autocomplete/src/main/java/com/hendraanggrian/appcompat/socialview/widget/SocialAutoCompleteTextView.java similarity index 94% rename from socialview-autocomplete/src/main/java/com/hendraanggrian/appcompat/widget/SocialAutoCompleteTextView.java rename to socialview-autocomplete/src/main/java/com/hendraanggrian/appcompat/socialview/widget/SocialAutoCompleteTextView.java index e3347d1..82b28eb 100644 --- a/socialview-autocomplete/src/main/java/com/hendraanggrian/appcompat/widget/SocialAutoCompleteTextView.java +++ b/socialview-autocomplete/src/main/java/com/hendraanggrian/appcompat/socialview/widget/SocialAutoCompleteTextView.java @@ -1,4 +1,4 @@ -package com.hendraanggrian.appcompat.widget; +package com.hendraanggrian.appcompat.socialview.widget; import android.content.Context; import android.content.res.ColorStateList; @@ -15,8 +15,6 @@ import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatMultiAutoCompleteTextView; import com.hendraanggrian.appcompat.socialview.internal.SocialViewHelper; -import com.hendraanggrian.appcompat.socialview.widget.SocialView; - import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -41,19 +39,20 @@ public void beforeTextChanged(CharSequence s, int start, int count, int after) { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { - if (!TextUtils.isEmpty(s) && start < s.length()) { - switch (s.charAt(start)) { - case '#': - if (getAdapter() != hashtagAdapter) { - setAdapter(hashtagAdapter); - } - break; - case '@': - if (getAdapter() != mentionAdapter) { - setAdapter(mentionAdapter); - } - break; - } + if (TextUtils.isEmpty(s) || start >= s.length()) { + return; + } + switch (s.charAt(start)) { + case '#': + if (getAdapter() != hashtagAdapter) { + setAdapter(hashtagAdapter); + } + break; + case '@': + if (getAdapter() != mentionAdapter) { + setAdapter(mentionAdapter); + } + break; } } diff --git a/socialview-autocomplete/src/main/res/layout/socialview_layout_mention.xml b/socialview-autocomplete/src/main/res/layout/socialview_layout_mention.xml index 436a960..d41b8ed 100644 --- a/socialview-autocomplete/src/main/res/layout/socialview_layout_mention.xml +++ b/socialview-autocomplete/src/main/res/layout/socialview_layout_mention.xml @@ -1,6 +1,6 @@ = Build.VERSION_CODES.LOLLIPOP) { - colorAttr = android.R.attr.colorAccent; - } else { - // get colorAccent defined for AppCompat - colorAttr = context.getResources().getIdentifier("colorAccent", "attr", - context.getPackageName()); - } - TypedValue outValue = new TypedValue(); - context.getTheme().resolveAttribute(colorAttr, outValue, true); - return outValue.data; + private AppCompatActivity activity; + private SocialAutoCompleteTextView view; + + @Before + public void setup() { + activity = Robolectric.buildActivity(TestActivity.class).setup().get(); + view = new SocialAutoCompleteTextView(activity); + } + + @Test + public void hashtagPattern() { + assertEquals("#(\\w+)", view.getHashtagPattern().pattern()); + view.setHashtagPattern(Patterns.PHONE); + assertEquals(Patterns.PHONE, view.getHashtagPattern()); + } + + @Test + public void mentionPattern() { + assertEquals("@(\\w+)", view.getMentionPattern().pattern()); + view.setMentionPattern(Patterns.PHONE); + assertEquals(Patterns.PHONE, view.getMentionPattern()); + } + + @Test + public void hyperlinkPattern() { + assertEquals(PatternsCompat.WEB_URL, view.getHyperlinkPattern()); + view.setHyperlinkPattern(Patterns.PHONE); + assertEquals(Patterns.PHONE, view.getHyperlinkPattern()); + } + + @Test + public void hashtagEnabled() { + assertTrue(view.isHashtagEnabled()); + view.setHashtagEnabled(false); + assertFalse(view.isHashtagEnabled()); + } + + @Test + public void mentionEnabled() { + assertTrue(view.isMentionEnabled()); + view.setMentionEnabled(false); + assertFalse(view.isMentionEnabled()); + } + + @Test + public void hyperlinkEnabled() { + assertTrue(view.isHyperlinkEnabled()); + view.setHyperlinkEnabled(false); + assertFalse(view.isHyperlinkEnabled()); + } + + @Test + public void hashtagColor() { + assertEquals(getThemeAccentColor(view.getContext()), view.getHashtagColor()); + view.setHashtagColor(Color.RED); + assertEquals(Color.RED, view.getHashtagColor()); + view.setHashtagColors(ColorStateList.valueOf(Color.GREEN)); + assertEquals(Color.GREEN, view.getHashtagColor()); + } + + @Test + public void mentionColor() { + assertEquals(getThemeAccentColor(view.getContext()), view.getMentionColor()); + view.setMentionColor(Color.RED); + assertEquals(Color.RED, view.getMentionColor()); + view.setMentionColors(ColorStateList.valueOf(Color.GREEN)); + assertEquals(Color.GREEN, view.getMentionColor()); + } + + @Test + public void hyperlinkColor() { + assertEquals(getThemeAccentColor(view.getContext()), view.getHyperlinkColor()); + view.setHyperlinkColor(Color.RED); + assertEquals(Color.RED, view.getHyperlinkColor()); + view.setHyperlinkColors(ColorStateList.valueOf(Color.GREEN)); + assertEquals(Color.GREEN, view.getHyperlinkColor()); + } + + @Test + public void getHashtags() { + view.setText("Here's a #cool #hashtag"); + assertThat(view.getHashtags()).containsExactly("cool", "hashtag"); + } + + @Test + public void getMentions() { + view.setText("Here's a #cool #hashtag"); + assertThat(view.getHashtags()).containsExactly("cool", "hashtag"); + } + + private static int getThemeAccentColor(Context context) { + int colorAttr; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + colorAttr = android.R.attr.colorAccent; + } else { + // get colorAccent defined for AppCompat + colorAttr = context.getResources().getIdentifier("colorAccent", "attr", + context.getPackageName()); } + TypedValue outValue = new TypedValue(); + context.getTheme().resolveAttribute(colorAttr, outValue, true); + return outValue.data; + } } diff --git a/socialview-autocomplete/src/test/res/layout/test_socialautocompletetextview.xml b/socialview-autocomplete/src/test/res/layout/test_socialautocompletetextview.xml index e4e1ae2..8dfad13 100644 --- a/socialview-autocomplete/src/test/res/layout/test_socialautocompletetextview.xml +++ b/socialview-autocomplete/src/test/res/layout/test_socialautocompletetextview.xml @@ -1,5 +1,5 @@ - 0 && start > 0) { - final char c = s.charAt(start - 1); - switch (c) { - case '#': - hashtagEditing = true; - mentionEditing = false; - break; - case '@': + if (count <= 0 || start <= 0) { + return; + } + final char c = s.charAt(start - 1); + switch (c) { + case '#': + hashtagEditing = true; + mentionEditing = false; + break; + case '@': + hashtagEditing = false; + mentionEditing = true; + break; + default: + if (!Character.isLetterOrDigit(c)) { hashtagEditing = false; - mentionEditing = true; - break; - default: - if (!Character.isLetterOrDigit(c)) { - hashtagEditing = false; - mentionEditing = false; - } else if (hashtagChangedListener != null && hashtagEditing) { - hashtagChangedListener.onChanged( - SocialViewHelper.this, - s.subSequence(indexOfPreviousNonLetterDigit(s, 0, start - 1) + 1, start)); - } else if (mentionChangedListener != null && mentionEditing) { - mentionChangedListener.onChanged( - SocialViewHelper.this, - s.subSequence(indexOfPreviousNonLetterDigit(s, 0, start - 1) + 1, start)); - } - break; - } + mentionEditing = false; + } else if (hashtagChangedListener != null && hashtagEditing) { + hashtagChangedListener.onChanged(SocialViewHelper.this, + s.subSequence(indexOfPreviousNonLetterDigit(s, 0, start - 1) + 1, start)); + } else if (mentionChangedListener != null && mentionEditing) { + mentionChangedListener.onChanged(SocialViewHelper.this, + s.subSequence(indexOfPreviousNonLetterDigit(s, 0, start - 1) + 1, start)); + } + break; } } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { - // triggered when text is added if (s.length() == 0) { return; } @@ -134,12 +143,10 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { hashtagEditing = false; mentionEditing = false; } else if (hashtagChangedListener != null && hashtagEditing) { - hashtagChangedListener.onChanged( - SocialViewHelper.this, + hashtagChangedListener.onChanged(SocialViewHelper.this, s.subSequence(indexOfPreviousNonLetterDigit(s, 0, start) + 1, start + count)); } else if (mentionChangedListener != null && mentionEditing) { - mentionChangedListener.onChanged( - SocialViewHelper.this, + mentionChangedListener.onChanged(SocialViewHelper.this, s.subSequence(indexOfPreviousNonLetterDigit(s, 0, start) + 1, start + count)); } break; @@ -148,7 +155,8 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override - public void afterTextChanged(Editable s) {} + public void afterTextChanged(Editable s) { + } }; private SocialViewHelper(@NonNull TextView view, @Nullable AttributeSet attrs) { @@ -157,16 +165,16 @@ private SocialViewHelper(@NonNull TextView view, @Nullable AttributeSet attrs) { view.addTextChangedListener(textWatcher); view.setText(view.getText(), TextView.BufferType.SPANNABLE); - final TypedArray a = - view.getContext() - .obtainStyledAttributes( - attrs, R.styleable.SocialView, R.attr.socialViewStyle, R.style.Widget_SocialView); - flags = - a.getInteger( - R.styleable.SocialView_socialFlags, FLAG_HASHTAG | FLAG_MENTION | FLAG_HYPERLINK); - hashtagColors = a.getColorStateList(R.styleable.SocialView_hashtagColor); - mentionColors = a.getColorStateList(R.styleable.SocialView_mentionColor); - hyperlinkColors = a.getColorStateList(R.styleable.SocialView_hyperlinkColor); + final TypedArray a = view.getContext().obtainStyledAttributes(attrs, R.styleable.SocialView, + R.attr.socialViewStyle, R.style.Widget_SocialView); + flags = a.getInteger(R.styleable.SocialView_socialFlags, + FLAG_HASHTAG | FLAG_MENTION | FLAG_HYPERLINK); + hashtagColors = Objects.requireNonNull( + a.getColorStateList(R.styleable.SocialView_hashtagColor)); + mentionColors = Objects.requireNonNull( + a.getColorStateList(R.styleable.SocialView_mentionColor)); + hyperlinkColors = Objects.requireNonNull( + a.getColorStateList(R.styleable.SocialView_hyperlinkColor)); a.recycle(); recolorize(); } @@ -387,43 +395,34 @@ private void recolorize() { spannable.removeSpan(span); } if (isHashtagEnabled()) { - spanAll( - spannable, - getHashtagPattern(), - new Supplier() { - @Override - public CharacterStyle get() { - return hashtagClickListener != null - ? new SocialClickableSpan(hashtagClickListener, hashtagColors, false) - : new ForegroundColorSpan(hashtagColors.getDefaultColor()); - } - }); + spanAll(spannable, getHashtagPattern(), new Supplier<>() { + @Override + public CharacterStyle get() { + return hashtagClickListener != null + ? new SocialClickableSpan(hashtagClickListener, hashtagColors, false) + : new ForegroundColorSpan(hashtagColors.getDefaultColor()); + } + }); } if (isMentionEnabled()) { - spanAll( - spannable, - getMentionPattern(), - new Supplier() { - @Override - public CharacterStyle get() { - return mentionClickListener != null - ? new SocialClickableSpan(mentionClickListener, mentionColors, false) - : new ForegroundColorSpan(mentionColors.getDefaultColor()); - } - }); + spanAll(spannable, getMentionPattern(), new Supplier<>() { + @Override + public CharacterStyle get() { + return mentionClickListener != null + ? new SocialClickableSpan(mentionClickListener, mentionColors, false) + : new ForegroundColorSpan(mentionColors.getDefaultColor()); + } + }); } if (isHyperlinkEnabled()) { - spanAll( - spannable, - getHyperlinkPattern(), - new Supplier() { - @Override - public CharacterStyle get() { - return hyperlinkClickListener != null - ? new SocialClickableSpan(hyperlinkClickListener, hyperlinkColors, true) - : new SocialURLSpan(text, hyperlinkColors); - } - }); + spanAll(spannable, getHyperlinkPattern(), new Supplier<>() { + @Override + public CharacterStyle get() { + return hyperlinkClickListener != null + ? new SocialClickableSpan(hyperlinkClickListener, hyperlinkColors, true) + : new SocialUrlSpan(text, hyperlinkColors); + } + }); } } @@ -445,8 +444,8 @@ private static int indexOfPreviousNonLetterDigit(CharSequence text, int start, i return start; } - private static void spanAll( - Spannable spannable, Pattern pattern, Supplier styleSupplier) { + private static void spanAll(Spannable spannable, Pattern pattern, + Supplier styleSupplier) { final Matcher matcher = pattern.matcher(spannable); while (matcher.find()) { final int start = matcher.start(); @@ -479,8 +478,8 @@ private static class SocialClickableSpan extends ClickableSpan { private final boolean isHyperlink; private CharSequence text; - private SocialClickableSpan( - OnClickListener listener, ColorStateList colors, boolean isHyperlink) { + private SocialClickableSpan(OnClickListener listener, ColorStateList colors, + boolean isHyperlink) { this.listener = listener; this.color = colors.getDefaultColor(); this.isHyperlink = isHyperlink; @@ -491,8 +490,8 @@ public void onClick(@NonNull View widget) { if (!(widget instanceof SocialView)) { throw new IllegalStateException("Clicked widget is not an instance of SocialView."); } - listener.onClick( - (SocialView) widget, !isHyperlink ? text.subSequence(1, text.length()) : text); + listener.onClick((SocialView) widget, + !isHyperlink ? text.subSequence(1, text.length()) : text); } @Override @@ -502,11 +501,13 @@ public void updateDrawState(@NonNull TextPaint ds) { } } - /** Default {@link CharacterStyle} for hyperlinks. */ - private static class SocialURLSpan extends URLSpan { + /** + * Default {@link CharacterStyle} for hyperlinks. + */ + private static class SocialUrlSpan extends URLSpan { private final int color; - private SocialURLSpan(CharSequence url, ColorStateList colors) { + private SocialUrlSpan(CharSequence url, ColorStateList colors) { super(url.toString()); this.color = colors.getDefaultColor(); } diff --git a/socialview/src/main/java/com/hendraanggrian/appcompat/socialview/widget/SocialEditText.java b/socialview/src/main/java/com/hendraanggrian/appcompat/socialview/widget/SocialEditText.java index a7d2e65..41b71cb 100644 --- a/socialview/src/main/java/com/hendraanggrian/appcompat/socialview/widget/SocialEditText.java +++ b/socialview/src/main/java/com/hendraanggrian/appcompat/socialview/widget/SocialEditText.java @@ -8,7 +8,6 @@ import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatEditText; import com.hendraanggrian.appcompat.socialview.internal.SocialViewHelper; - import java.util.List; import java.util.regex.Pattern; diff --git a/socialview/src/main/java/com/hendraanggrian/appcompat/socialview/widget/SocialView.java b/socialview/src/main/java/com/hendraanggrian/appcompat/socialview/widget/SocialView.java index 79a36d8..ab39cb7 100644 --- a/socialview/src/main/java/com/hendraanggrian/appcompat/socialview/widget/SocialView.java +++ b/socialview/src/main/java/com/hendraanggrian/appcompat/socialview/widget/SocialView.java @@ -12,28 +12,28 @@ /** * Base interface of all social widgets, which usually derived from {@link android.widget.TextView}. - * Out of the box, there are {@link SocialTextView}, {@link SocialEditText}, and {@code - * SocialAutoCompleteTextView}. It can also be implemented in any {@link android.view.View} using - * {@link SocialViewHelper}. + * Out of the box, there are {@link SocialTextView}, {@link SocialEditText}, + * and {@code SocialAutoCompleteTextView}. It can also be implemented in + * any {@link android.view.View} using {@link SocialViewHelper}. */ public interface SocialView { /** - * Returns regex that are responsible for finding hashtags. By default, the pattern are - * {@code #(\w+)}. + * Returns regex that are responsible for finding hashtags. By default, the pattern + * are {@code #(\w+)}. */ @NonNull Pattern getHashtagPattern(); /** - * Returns regex that are responsible for finding mentions. By default, the pattern are - * {@code @(\w+)}. + * Returns regex that are responsible for finding mentions. By default, the pattern + * are {@code @(\w+)}. */ @NonNull Pattern getMentionPattern(); /** - * Returns regex that are responsible for finding hyperlinks. By default, the pattern are - * {@link PatternsCompat#WEB_URL}. + * Returns regex that are responsible for finding hyperlinks. By default, the pattern + * are {@link PatternsCompat#WEB_URL}. */ @NonNull Pattern getHyperlinkPattern(); diff --git a/socialview/src/main/res/values/attrs.xml b/socialview/src/main/res/values/attrs.xml index 1547ae4..b21cd0c 100644 --- a/socialview/src/main/res/values/attrs.xml +++ b/socialview/src/main/res/values/attrs.xml @@ -5,16 +5,15 @@ - + - diff --git a/socialview/src/test/java/com/hendraanggrian/appcompat/socialview/CustomStyleTest.java b/socialview/src/test/java/com/hendraanggrian/appcompat/socialview/CustomStyleTest.java index 51fdbe1..16fc59b 100644 --- a/socialview/src/test/java/com/hendraanggrian/appcompat/socialview/CustomStyleTest.java +++ b/socialview/src/test/java/com/hendraanggrian/appcompat/socialview/CustomStyleTest.java @@ -1,16 +1,12 @@ package com.hendraanggrian.appcompat.socialview; import static org.junit.Assert.assertEquals; - import android.graphics.Color; import android.os.Build; import android.os.Bundle; - import androidx.appcompat.app.AppCompatActivity; - -import com.hendraanggrian.appcompat.socialview.widget.SocialEditText; import com.hendraanggrian.appcompat.socialview.test.R; - +import com.hendraanggrian.appcompat.socialview.widget.SocialEditText; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -29,7 +25,8 @@ public class CustomStyleTest { @Before public void setup() { activity = Robolectric.buildActivity(StyleTestActivity.class).setup().get(); - view = (SocialEditText) activity.getLayoutInflater().inflate(R.layout.test_socialedittext, null); + view = (SocialEditText) activity.getLayoutInflater() + .inflate(R.layout.test_socialedittext, null); } @Test @@ -43,7 +40,7 @@ private static class StyleTestActivity extends AppCompatActivity { @Override protected void onCreate(Bundle bundle) { super.onCreate(bundle); - setTheme(com.hendraanggrian.appcompat.socialview.test.R.style.MyAppTheme); + setTheme(R.style.MyAppTheme); } } } diff --git a/socialview/src/test/java/com/hendraanggrian/appcompat/socialview/SocialViewTestHelper.java b/socialview/src/test/java/com/hendraanggrian/appcompat/socialview/SocialViewTestHelper.java index da1883f..65711db 100644 --- a/socialview/src/test/java/com/hendraanggrian/appcompat/socialview/SocialViewTestHelper.java +++ b/socialview/src/test/java/com/hendraanggrian/appcompat/socialview/SocialViewTestHelper.java @@ -4,7 +4,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; - import android.content.Context; import android.content.res.ColorStateList; import android.graphics.Color; @@ -12,9 +11,7 @@ import android.util.Patterns; import android.util.TypedValue; import android.widget.TextView; - import androidx.core.util.PatternsCompat; - import com.hendraanggrian.appcompat.socialview.widget.SocialView; public class SocialViewTestHelper { diff --git a/socialview/src/test/java/com/hendraanggrian/appcompat/socialview/TestActivity.java b/socialview/src/test/java/com/hendraanggrian/appcompat/socialview/TestActivity.java index 6ed6196..1aa50f3 100644 --- a/socialview/src/test/java/com/hendraanggrian/appcompat/socialview/TestActivity.java +++ b/socialview/src/test/java/com/hendraanggrian/appcompat/socialview/TestActivity.java @@ -1,7 +1,6 @@ package com.hendraanggrian.appcompat.socialview; import android.os.Bundle; - import androidx.appcompat.app.AppCompatActivity; import com.hendraanggrian.appcompat.socialview.test.R; @@ -9,6 +8,6 @@ public class TestActivity extends AppCompatActivity { @Override protected void onCreate(Bundle bundle) { super.onCreate(bundle); - setTheme(R.style.Theme_MaterialComponents_Light_NoActionBar_Bridge); + setTheme(R.style.Theme_AppCompat_Light_NoActionBar); } } diff --git a/socialview/src/test/java/com/hendraanggrian/appcompat/socialview/widget/SocialEditTextTest.java b/socialview/src/test/java/com/hendraanggrian/appcompat/socialview/widget/SocialEditTextTest.java index 4ad6d81..2fc6493 100644 --- a/socialview/src/test/java/com/hendraanggrian/appcompat/socialview/widget/SocialEditTextTest.java +++ b/socialview/src/test/java/com/hendraanggrian/appcompat/socialview/widget/SocialEditTextTest.java @@ -1,12 +1,9 @@ package com.hendraanggrian.appcompat.socialview.widget; import android.os.Build; - import androidx.appcompat.app.AppCompatActivity; - import com.hendraanggrian.appcompat.socialview.SocialViewTestHelper; import com.hendraanggrian.appcompat.socialview.TestActivity; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/socialview/src/test/java/com/hendraanggrian/appcompat/socialview/widget/SocialTextViewTest.java b/socialview/src/test/java/com/hendraanggrian/appcompat/socialview/widget/SocialTextViewTest.java index 089c3d5..29420fc 100644 --- a/socialview/src/test/java/com/hendraanggrian/appcompat/socialview/widget/SocialTextViewTest.java +++ b/socialview/src/test/java/com/hendraanggrian/appcompat/socialview/widget/SocialTextViewTest.java @@ -1,12 +1,9 @@ package com.hendraanggrian.appcompat.socialview.widget; import android.os.Build; - import androidx.appcompat.app.AppCompatActivity; - import com.hendraanggrian.appcompat.socialview.SocialViewTestHelper; import com.hendraanggrian.appcompat.socialview.TestActivity; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith;