Ilhasoft/socialview


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

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.Ilhasoft:socialview:0.1.0'
	}
	dependencies {
		implementation("com.github.Ilhasoft:socialview:0.1.0")
	}
	<dependency>
	    <groupId>com.github.Ilhasoft</groupId>
	    <artifactId>socialview</artifactId>
	    <version>0.1.0</version>
	</dependency>

                            
    libraryDependencies += "com.github.Ilhasoft" % "socialview" % "0.1.0"
        
        

                            
    :dependencies [[com.github.Ilhasoft/socialview "0.1.0"]]
        
        

Readme


socialview

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

demo

Core

Lightweight library that comes with SocialTextView and SocialViewImpl to attach any TextView.

<com.hendraanggrian.widget.SocialTextView
    android:id="@+id/socialtextview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="#hashtag and @mention."/>

SocialTextView

Modify its state and set listeners in java.

SocialTextView textView = (SocialTextView) findViewById(R.id.socialtextview);
textView.setMentionEnabled(false);
textView.setHashtagColor(ContextCompat.getColor(this, R.color.red));
textView.setOnHashtagClickListener(new SocialView.OnSocialClickListener() {
    @Override
    public void(View v, String text) {
        // TODO: do something
    }
});

Any TextView or subclasses of TextView can be attached.

CustomTextView tv = ...;
SocialView socialView = SocialViewImpl.attach(tv);

Attributes

| Attributes | Description | Default value/behavior | |------------------|----------------------------------|-------------------------------| | typeEnabled | flags to enable span coloring | hashtag\|mention\|hyperlink | | hashtagColor   | color of hashtag items           | current theme's accent color | | mentionColor | color of mention items | current theme's accent color | | hyperlinkColor | color of hyperlink items | current theme's accent color |

Commons

Extended core library with SocialEditText and SocialAutoCompleteTextView to display suggestions as you type.

<com.hendraanggrian.widget.SocialAutoCompleteTextView
    android:id="@+id/socialsuggestionedittext"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="What's on your mind?"/>

SocialEditText SocialAutoCompleteTextView hashtag suggestions SocialAutoCompleteTextView mention suggestions

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

SocialAutoCompleteTextView<Hashtag, Mention> textView = (SocialAutoCompleteTextView) findViewById(R.id.socialsuggestionedittext);
textView.setHashtagAdapter(new HashtagAdapter(getContext())); // or use custom adapter
textView.setMentionAdapter(new MentionAdapter(getContext())); // or use custom adapter

textView.getHashtagAdapter().add(new Hashtag("follow"));
textView.getHashtagAdapter().add(new Hashtag("followme", 1000));
textView.getHashtagAdapter().add(new Interest("followmeorillkillyou", 500));

textView.getMentionAdapter().add(new Mention("dirtyhobo"));
textView.getMentionAdapter().add(new Mention("hobo", "Regular Hobo", R.mipmap.ic_launcher));
textView.getMentionAdapter().add(new Mention("hendraanggrian", "Hendra Anggrian", "https://avatars0.githubusercontent.com/u/11507430?v=3&s=460"));

Download

repositories {
    jcenter()
}

dependencies {
    // core only
    compile 'com.hendraanggrian:socialview-core:0.11.1'
    // core and commons
    compile 'com.hendraanggrian:socialview-commons:0.11.1'
}

License

Copyright 2016 Hendra Anggrian

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.