Giter Club home page Giter Club logo

socialview's Introduction

Travis CI Codecov Maven Central Nexus Snapshot Android SDK

SocialView

Hashtag preview. Mention preview.

TextView and EditText with hashtag, mention, and hyperlink support.

  • Pre-loaded with default views, but also installable to any custom view.
  • Display hashtag and mention suggestions as you type.

Download

repositories {
    mavenCentral()
    google()
}
dependencies {
    // base widgets
    implementation "com.hendraanggrian.appcompat:socialview:$version"

    // auto-complete widgets
    implementation "com.hendraanggrian.appcompat:socialview-autocomplete:$version"
}

Usage

Core

Core library contains SocialTextView, SocialEditText and helper class applies these behavior into any TextView.

<com.hendraanggrian.appcompat.socialview.widget.SocialTextView
  android:id="@+id/textView"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:text="#hashtag and @mention."
  app:socialFlags="hashtag|mention"
  app:hashtagColor="@color/blue"
  app:mentionColor="@color/red"/>

See attrs.xml for full list of available attributes.

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
  }
});

Auto-complete

Extended library comes with SocialAutoCompleteTextView.

<com.hendraanggrian.appcompat.socialview.widget.SocialAutoCompleteTextView
  android:id="@+id/textView"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:hint="What's on your mind?"
  app:socialFlags="hyperlink"
  app:hyperlinkColor="@color/green"/>

To display suggestions, it is required to setHashtagAdapter() and setMentionAdapter().

ArrayAdapter<Hashtag> hashtagAdapter = new HashtagAdapter(getContext());
hashtagAdapter.add(new Hashtag("follow"));
hashtagAdapter.add(new Hashtag("followme", 1000));
hashtagAdapter.add(new Hashtag("followmeorillkillyou", 500));
textView.setHashtagAdapter(hashtagAdapter);

ArrayAdapter<Mention> 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"));
textView.setMentionAdapter(mentionAdapter);

To customize hashtag or mention adapter, create a custom adapter using customized SocialAdapter or write your own ArrayAdapter.

Custom adapters are experimental, see sample for example.

public class Person {
  public final String name;

  public Person(String name) {
    this.name = name;
  }
}

// easier
public class PersonAdapter extends SocialAdapter<Person> {
  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<Person> {
  // your own adapter layout, view holder, data binding
  // and of course, filtering logic
}

Then, use the custom adapter.

ArrayAdapter<Person> adapter = new PersonAdapter(getContext());
adapter.add(personA);
adapter.add(personB);
textView.setMentionAdapter(adapter);

socialview's People

Contributors

hanggrian avatar stanbar avatar uzaysan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

socialview's Issues

delete mentionned person

i have created custom adapter for mentioned users
if i try to delete some characters of the mentioned person this one still in customautocomplete.getMentions()
how can i handle that and remove this one from customautocomplete.getMentions()??

Failed to resolve

The library is hosted in jcenter?

I'm include jcenter in repositories in the gradle, but the library is Failed to resolve.

What is the problem

Error:Could not find com.android.support:appcompat-v7:26.0.0.
Required by:
xxxandroid:app:unspecified
xxxandroid:app:unspecified > com.hendraanggrian:socialview-core:0.16.0

Please install the Android Support Repository from the Android SDK Manager.
Open Android SDK Manager

Mentions with different languages

Hello, my friend. Thanks for your work. I have some problems, with mentions on other languages. For example I need to click on @Андрей mention, but on text view it looks like simple text, so I cant click on it. Can you fix it?

Help

First of all Thank you for creating such a awesome library.
can you please tell me how to get mention id onclick on Mention and I want to allow spaces for mention.
Can you guide me how can I achieve it?
I have tried a lot but didn't get any solution....

How to apply custom adapter?

Hi hendraanggrian, I'm using your library to make mentions like Facebook or Instagram.
I've faced problem that I cannot apply my own custom adapter with custom model class.
When I apply my custom adapter class, It doesn't show any items.

The Below is my custom adapter code.

` public class PhotoPersonAdaper extends SocialAdapter {

private Context context;
private ArrayList<UserModel> commentTable;

public PhotoPersonAdaper(Context context, int resource, int textViewResourceId, ArrayList<UserModel> commentTable) {
    super(context, resource, textViewResourceId);
    this.context = context;
    this.commentTable = commentTable;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = LayoutInflater.from(context).inflate(R.layout.comment_item, null, false);
    CircleImageView image_comment_mention = (CircleImageView) view.findViewById(R.id.image_comment_mention);
    TextView tv = (TextView) view.findViewById(R.id.tv_comment_username);

    Glide.with(context)
            .load(commentTable.get(position).getProfileUrl())
            .into(image_comment_mention);

    tv.setText(commentTable.get(position).getDogName());
    return view;
}

@NotNull
@Override
public String convertToString(UserModel photoCommentTable) {
    return photoCommentTable.getDogName();
}

}`

filtering is not happen.

first of all this is great library , so thanks for this.
so the prob is in hashtag list there is no "#" is shown and if i get module from your library to change manually then some files are not downloaded from github so that i m not able to import your module, and second prob is that if i want only than hashtag and mention person which starting letter and ending letter is that(like example "k") so that is not happen it search all data which contain that letter. so if you help me in that it will appreciated .

App crash when deleting

Hi there,
First of all, amazing library!!
But wanted to know what can i do with a crash i am handling right now with the EditText (SocialAutoCompleteTextView)?
When i mention someone at the beginning and going to the middle of the word and start deleting it crashes with this error:

java.lang.IndexOutOfBoundsException: charAt: -1 < 0 at android.text.SpannableStringBuilder.charAt(SpannableStringBuilder.java:121) at com.hendraanggrian.socialview.SociableViewImpl.onTextChanged(SociableViewImpl.java:291) at android.widget.TextView.sendOnTextChanged(TextView.java:9332) at android.widget.TextView.handleTextChanged(TextView.java:9419) at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:11875) at android.text.SpannableStringBuilder.sendTextChanged(SpannableStringBuilder.java:1252) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:573) at android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:229) at android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:227) at android.text.method.BaseKeyListener.backspaceOrForwardDelete(BaseKeyListener.java:370) at android.text.method.BaseKeyListener.backspace(BaseKeyListener.java:71) at android.text.method.BaseKeyListener.onKeyDown(BaseKeyListener.java:479) at android.text.method.QwertyKeyListener.onKeyDown(QwertyKeyListener.java:362) at android.text.method.TextKeyListener.onKeyDown(TextKeyListener.java:141) at android.widget.TextView.doKeyDown(TextView.java:7302) at android.widget.TextView.onKeyDown(TextView.java:7079) at android.widget.AutoCompleteTextView.onKeyDown(AutoCompleteTextView.java:831) at android.view.KeyEvent.dispatch(KeyEvent.java:2688) at android.view.View.dispatchKeyEvent(View.java:11465) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1797) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1797) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1797) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1797) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1797) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1797) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1797) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1797) at com.android.internal.policy.DecorView.superDispatchKeyEvent(DecorView.java:415) at com.android.internal.policy.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1811) at android.app.Activity.dispatchKeyEvent(Activity.java:3251) at android.support.v7.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:535) at android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:58) at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:316) at com.android.internal.policy.DecorView.dispatchKeyEvent(DecorView.java:329) at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4703) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4575) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4117) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4170) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4136) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4263) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4144) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4320) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4117) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4170) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4136) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4144) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4117) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4170) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4136) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4296) at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4457) at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2435) at an

Thanks in advance :)

SocialView.OnSocialClickListener() doesn't exist anymore?

In the description you mentioned SocialView.OnSocialClickListener() to know when you click a mention or a hashtag. But it seems it doesn't exist anymore? I need something like this so I know what the user selected from the list. Any solutions?

results continue to filter even after

I am using own adapter and filtering logic

So once I type @ or # it will popup results, however once I select an item and continue to type regular caption, it still is trying to filter results

Text remove setMentionTextChangedListener not work proper

textView.setMentionTextChangedListener(new Function2<SocialView, CharSequence, Unit>() {
@OverRide
public Unit invoke(SocialView socialView, CharSequence s) {
data = socialView.getMentions();
Timber.i("===========USERID %s",data.size());
Timber.i("===================STATUSUTIL %s",socialView.getMentions());
return null;
}
});

Mentions working only once

Hello, my friend. Thanks for your lib, it is very usefull, but when i tyiping text and use mention, I cant see the list of mentions when I write @ for second time

Social Suggestion Box UI Shadow

hi.. Can you please help with the UI of social mention suggestion Box . I need to remove the shadow and elevation in the suggestion box. Can it be done ? Pls help

Add Support for RichTextFormatting

Hello, nice library here. I wanted to ask if it's possible to add support for rich text formatting like on WhatsApp and Slack such that when a user types any group of words between here it becomes bold and here becomes italic...

Hashtag Pattern UTF (Feature)

Thanks you very much for this project.

I was taking a look into your implementation and i think that you could update the Hashtag regular expression to accept non english words etc..

Example:
#(\w+) fails with #Mañana

Solution:
([##]+)([0-9A-Z_]*[A-Z_]+[a-z0-9_üÀ-ÖØ-öø-ÿ]*)

Hope to help you work on it soon.
Jeff.

Handle mentions with spaces

How do i be able to handle mentions with spaces

Input: @moh
Suggestions: "mohsin abbas", "mohsin naqvi", "syed mohsin"
after selection it breaks at space.

If I use the displayName and userName prop, Firstly it shows in view which is not cool

All I want is it somehow after selection it shows as one mention including space.

Thanks

Android

Is it available for android using java.

Failing to add library

I have added following lines to my app build.gradle

implementation "com.hendraanggrian.appcompat:socialview:0.1"
implementation "com.hendraanggrian.appcompat:socialview-commons:0.1"

Now its throwing following error when I perform Gradle Sync

AGPBI: {"kind":"error","text":"error: resource android:attr/dialogCornerRadius not found.","sources":[{"file":"C:\Users\User\.gradle\caches\transforms-1\files-1.1\appcompat-1.0.0-beta01.aar\ce72d4b1fec626ed0410db1106f23caf\res\values-v28\values-v28.xml","position":{"startLine":8,"startColumn":4,"startOffset":447,"endLine":11,"endColumn":12,"endOffset":684}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: resource android:attr/dialogCornerRadius not found.","sources":[{"file":"C:\Users\User\Documents\GIT\thestarinme-app-android-intrepo\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml","position":{"startLine":10}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: resource android:attr/fontVariationSettings not found.","sources":[{"file":"C:\Users\User\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\f2c84627ffa3757e7034ce359df8c894\res\values\values.xml","position":{"startLine":250,"startColumn":4,"startOffset":27058,"endColumn":68,"endOffset":27122}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: resource android:attr/ttcIndex not found.","sources":[{"file":"C:\Users\User\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\f2c84627ffa3757e7034ce359df8c894\res\values\values.xml","position":{"startLine":250,"startColumn":4,"startOffset":27058,"endColumn":68,"endOffset":27122}}],"original":"","tool":"AAPT"}

Target SDK version is API 27
Android Studio version 3.1.3

Please help me with the correct implementation to include the library in my project.

Needs better logic on SocialTextWatcher.

SocialTextWatcher is a text change listener that monitors whether user is currently typing a hashtag or mention. This is particularly useful for SocialAutoCompleteTextView in event that whether you want to clear the adapter or add new items according to user input.

Unfortunately, my logic in TextWatcher is not at its best and would really appreciate it if a better one is provided.

Bug on Text Matcher

When I have text "[email protected]", it will have 2 listener:

  • @gmail for mention type
  • gmail.com for hyperlink type

I think your regex to matching the text must be refine with whitespace prefix. For example:

  • hello @username => it will be found as mention
  • hello@username => it won't
  • check it on google.com => found as hyperlink
  • email me at [email protected] => not found as hyperlink

colors change

1)- How to prevent HashTag text color and mention text color from changed until i found that mention in the DataBase

SocialAutoCompleteTextView don't show cursor

Hello Friend,

Is happening to me the following situation, when opening the screen with a SocialAutoCompleteTextView the cursor does not appear in the field, even with the focus on it.

When typing some text the cursor appears normally, even erasing everything it remains there.

That is, it happens when entering the screen and field being empty, only with a hint.

Class is missed

Hello, SociableView.class from import com.hendraanggrian.socialview.SociableView is missed.
So I can`t do onMentionClickListener, because I need this class.

text.setOnMentionClickListener(new Function2<SociableView, CharSequence, Unit>() {
                    @Override
                    public Unit invoke(SociableView sociableView, CharSequence charSequence) {
                        //my click
                    }
                });

URL

Hello, can you add url property ?

AutoComplete cant inflate view

android.view.InflateException: Binary XML file line #9: Error inflating class TextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at io.github.hendraanggrian.socialview.commons.HashtagAdapter.getView(HashtagAdapter.java:27)
at android.widget.AbsListView.obtainView(AbsListView.java:2263)
at android.widget.ListPopupWindow$DropDownListView.obtainView(ListPopupWindow.java:1585)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
at android.widget.ListPopupWindow.buildDropDown(ListPopupWindow.java:1167)
at android.widget.ListPopupWindow.show(ListPopupWindow.java:554)
at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1096)
at android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:971)
at android.widget.AutoCompleteTextView.onFilterComplete(AutoCompleteTextView.java:953)
at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:285)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5045)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
at android.content.res.TypedArray.getColor(TypedArray.java:327)
at android.widget.TextView.(TextView.java:677)
at android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:60)
at android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:56)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:1008)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1067)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
at io.github.hendraanggrian.socialview.commons.HashtagAdapter.getView(HashtagAdapter.java:27) 
at android.widget.AbsListView.obtainView(AbsListView.java:2263) 
at android.widget.ListPopupWindow$DropDownListView.obtainView(ListPopupWindow.java:1585) 
at android.widget.ListView.measureHeightOfChildren(ListView.java:1263) 
at android.widget.ListPopupWindow.buildDropDown(ListPopupWindow.java:1167) 
at android.widget.ListPopupWindow.show(ListPopupWindow.java:554) 
at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1096) 
at android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:971) 
at android.widget.AutoCompleteTextView.onFilterComplete(AutoCompleteTextView.java:953) 
at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:285) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5045) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
at dalvik.system.NativeStart.main(Native Method) 

Crash on color set

Hi there,
Since your latest update i get a crash on setting mention/hashtag/hyperlink colors, For example:
commercialContentTextView.setMentionColor(Color.BLACK);
also on this:
commercialContentTextView.setMentionColor(Color.parseColor("#000000"));

the error i'm getting is:
android.content.res.Resources$NotFoundException: Resource ID #0xff000000 at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:195) at android.content.res.Resources.getColor(Resources.java:949) at android.content.Context.getColor(Context.java:588) at android.support.v4.content.ContextCompat.getColor(ContextCompat.java:409) at com.hendraanggrian.socialview.SocialView$DefaultImpls.setMentionColor(SocialView.kt:129) at com.hendraanggrian.widget.SocialTextView.setMentionColor(SocialTextView.kt:12)

Would be happy to get your attention as always :)

Hyperlink click listener

Hi there @HendraAnggrian,
Is there any way i can listen to hyperlink clicks and get the URL of it?
Thanks.

displayname not show on MentionArrayAdapter

as title, please help

doAsync {
            val users = AppDatabase.getInstance().userDao().all()
            val adapter = MentionArrayAdapter<Mention>(context!!)
            uiThread {
                users?.forEach { that ->
                    dLog("User ${that.getEmail()} ${that.name}")
                    adapter.add(Mention(that.getEmail(), "${that.name}", that.profile_image_url_large))
                }
                et_text.mentionAdapter = adapter
            }
}

15574

BTW, thanks for this awesome library 👍

Only colorize valid mentions

Some mentions can be invalid. For example, Telegram only highlights mentions that are in fact valid and existing users.

A simple solution for that would be to have an option to disable auto-coloring, so that I can check for mention validity in a text-watcher and only call colorize() if that mention is in fact valid

Crash when long click on hashtag or mention.

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.widget.Editor$SelectionModifierCursorController.getMinTouchOffset()' on a null object reference
at android.widget.Editor.touchPositionIsInSelection(Editor.java:1084)
at android.widget.Editor.performLongClick(Editor.java:1205)
at android.widget.TextView.performLongClick(TextView.java:10891)
at android.view.View.performLongClick(View.java:6322)
at android.view.View$CheckForLongPress.run(View.java:24695)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6665)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:781)

hashtag and mention filter logic.

thank you so much for sharing such a excellent library it really helped me alot but i need your support to filter hashtag and mentions in such a way that enter text should matched from the beginning and not from anywhere in the text also please help me to understand that how can i display the list of hashtags with a # character assign to it at the beginning .and if you have Java version of this library then please share with me it really helped me . Thank you so much

onBackPress event

when on back press, if possible hide keyboard instead of remove suggestion; how to do this?

a

Crash when writing mention/tag

Hi there friend,
Been using a lot your awesome library, but i came across an issue that never occurred to me before.
I made an custom adapter for the mentions and assigned it to the SocialAutoCompleteTextView.
When i enter a mention or even a hashtag and check if there are mentions or hashtags i get a crash (after pressing a 'post' button that checks if there are mentions/hashtags).

My custom adapter:

public class MentionsCustomAdapter extends SocialAdapter<Mention> {
    private Filter filter = new SocialFilter() {
        @Override
        public CharSequence convertResultToString(Object resultValue) {
            return ((Mention) resultValue).getUsername();
        }
    };

    public MentionsCustomAdapter(@NonNull Context context) {
        super(context, R.layout.item_mentions, R.id.textview_mention_username);
    }

    @NonNull
    @Override
    public View getView(int position, View convertView, @NonNull ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_mentions, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Mention item = getItem(position);
        if (item != null) {
            if (item.getAvatar() != null) {
                Glide.with(getContext()).load(item.getAvatar()).dontAnimate().into(holder.imageView);
            }

            holder.textViewUsername.setText(item.getUsername());
            if (ViewsKt.setVisibleBy(holder.textViewDisplayName, !TextUtils.isEmpty(item.getDisplayname())))
                holder.textViewDisplayName.setText(item.getDisplayname());
        }
        return convertView;
    }

    @NonNull
    @Override
    public Filter getFilter() {
        return filter;
    }

    private static class ViewHolder {
        @NonNull
        private final CircularImageView imageView;
        @NonNull
        private final TextView textViewUsername;
        @NonNull
        private final TextView textViewDisplayName;

        private ViewHolder(@NonNull View view) {
            imageView = view.findViewById(R.id.imageview_mention_username);
            textViewUsername = view.findViewById(R.id.textview_mention_username);
            textViewDisplayName = view.findViewById(R.id.textview_mention_displayname);
        }
    }
}

Adapter assignment:

        mentionArrayAdapter = new MentionsCustomAdapter(this);
        hashtagArrayAdapter = new HashtagAdapter(this);

        postContent.setMentionAdapter(mentionArrayAdapter);
        postContent.setHashtagAdapter(hashtagArrayAdapter);

My checks:

                String mentionsToString = "";
                if (postContent.getMentions().size() > 0) {
                    StringBuilder builder = new StringBuilder();
                    for (String s : postContent.getMentions()) {
                        for (TagsModel model : originalTagsModels) {
                            if (s.equals(model.getTagName().replace(" ", ""))) {
                                builder.append(model.getTagId()).append(",");
                                content = content.replace(s.replace(" ", ""), String.valueOf(model.getTagId()));
                            }
                        }
                    }
                    mentionsToString = builder.toString();
                }

                String tagsToString = "";
                if (postContent.getHashtags().size() > 0) {
                    StringBuilder builder2 = new StringBuilder();
                    for (String s : postContent.getHashtags()) {
                        builder2.append(s).append(",");
                    }
                    tagsToString = builder2.toString();
                }

This is the line where it crashes: if (postContent.getHashtags().size() > 0) { With the following error:

07-28 10:48:45.180 5694-5694/app.example.com E/AndroidRuntime: FATAL EXCEPTION: main
                                                                  Process: app.example.com, PID: 5694
                                                                  java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
                                                                      at java.util.regex.Matcher.group(Matcher.java:370)
                                                                      at com.hendraanggrian.socialview.SocialView$DefaultImpls.newList(SocialView.kt:111)
                                                                      at com.hendraanggrian.socialview.SocialView$DefaultImpls.getHashtags(SocialView.kt:104)
                                                                      at com.hendraanggrian.widget.SocialAutoCompleteTextView.getHashtags(SocialAutoCompleteTextView.kt:15)
                                                                      at app.example.com.posts.NewPostActivity$9.onClick(NewPostActivity.java:408)
                                                                      at android.view.View.performClick(View.java:6256)
                                                                      at android.view.View$PerformClick.run(View.java:24697)
                                                                      at android.os.Handler.handleCallback(Handler.java:789)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:98)
                                                                      at android.os.Looper.loop(Looper.java:164)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

BTW, i'm using the latest library version 0.15.2
Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.