Giter VIP home page Giter VIP logo

socialview's Introduction

logo SocialView

demo

Download

Core

The core module comes with basic SocialTextView and SocialEditText. It also contains SocialView to implement hashtag and mention support to any view extending TextView.

compile 'io.github.hendraanggrian:socialview-core:0.3.0'

Commons

The commons module has all core module components plus SocialSuggestionEditText that displays hashtag and mention suggestions as you type. You can use custom model extending Hashtagable and Mentionable, or even use your adapter extending SuggestionAdapter<Hashtagable> and SuggestionAdapter<Mentionable>.

compile 'io.github.hendraanggrian:socialview-commons:0.3.0'

Core

Comes with SocialTextView and SocialEditText.

<io.github.hendraanggrian.socialview.SocialTextView
    android:id="@+id/socialtextview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="#hashtag and @mention."
    app:hashtagColor="@color/blue" // if not set, color accent of current app theme is used
    app:mentionColor="@color/red"  // if not set, color accent of current app theme is used
    app:hashtagEnabled="true"      // true by default
    app:mentionEnabled="false"     // true by default
    />

You can also change them programatically.

SocialTextView socialTextView = (SocialTextView) findViewById(R.id.socialtextview);
socialTextView.setHashtagColor(ContextCompat.getColor(this, R.color.red));
socialTextView.setMentionColorRes(R.color.blue);
socialTextView.setHashtagEnabled(false);

// set listener
socialTextView.setOnHashtagClickListener(new SocialView.OnSocialClickListener() {
    @Override
    public void(View v, String clicked) {
        // do something
    }
});

Note that SocialTextView and SocialEditText are basically just TextView and EditText that implement SocialViewBase of which overriden methods are passed for SocialView to process inside each of them. With this in mind, SocialView can be attached to any TextView or view extending TextView:

CustomTextView textView = ...;
SocialViewAttacher attacher = SocialViewAttacher.attach(textView);
attacher.setHashtagColorRes(R.color.red);
attacher.setMentionEnabled(false);
attacher.setOnHashtagClickListener((view, clicked) -> {});
// etc.

Commons

Comes with SocialSuggestionEditText and all the interfaces, models, and adapters necessary to use it.

<io.github.hendraanggrian.socialview.SocialSuggestionEditText
    android:id="@+id/socialsuggestionedittext"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="What's on your mind?"
    app:hashtagColor="@color/blue" // if not set, color accent of current app theme is used
    app:mentionColor="@color/red"  // if not set, color accent of current app theme is used
    app:hashtagEnabled="true"      // true by default
    app:mentionEnabled="false"     // true by default
/>

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

SocialSuggestionEditText editText = (SocialSuggestionEditText) view.findViewById(R.id.socialsuggestionedittext);
editText.setHashtagAdapter(new HashtagAdapter(getContext())); // or use custom adapter extending SuggestionAdapter<Hashtagable>
editText.setMentionAdapter(new MentionAdapter(getContext())); // or use custom adapter extending SuggestionAdapter<Mentionable>

// use default item Hashtag
editText.getHashtagAdapter().add(new Hashtag("follow"));
// a hashtag can have count
editText.getHashtagAdapter().add(new Hashtag("followme", 1000));
// or use custom model implementing Hashtagable
editText.getHashtagAdapter().add(new Interest("followmeorillkillyou", 500));

// use default item Mention
editText.getMentionAdapter().add(new Mention("dirtyhobo"));
// a mention can have display name and avatar (can be drawable or string url)
editText.getMentionAdapter().add(new Mention("hobo", "Regular Hobo", R.mipmap.ic_launcher));
// or use custom model implementing Mentionable
editText.getMentionAdapter().add(new User("hendraanggrian", "Hendra Anggrian", "https://avatars0.githubusercontent.com/u/11507430?v=3&s=460"));

socialview's People

Contributors

hendraanggrian avatar

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.