Giter Club home page Giter Club logo

sociallinkify's Introduction

SocialLinkify

An Android library for linking @ mentions & Hashtags to their corresponding social network

Motivation

For most of our projects we handle multiple social network types, which results in us needing to handle multiple link destinations for @ mentions and Hashtags. For example, if the @Buffer mention is used then this library will allow you to make that a clickable span pointing to either the Buffer Twitter profile, Facebook Page or Instagram profile. The same can be done for Hashtags. Rather than duplicate code across our projects we decided to create a small helper library to separate this from our projects.

How to use

There is only one function to call from SocialLinkify, that is socialLinkifyText(). This will return you an instance of a Spannable which you can then use to set your textview content to. This function takes four parameters:

  • color - An Int representing the color you wish to use for linked elements

  • text - The String that you wish to apply linking to

  • socialNetwork - The SocialNetwork which you want the elements to be linked to. This can be either TWITTER, FACEBOOK or INSTAGRAM.

  • patternTypes - A varargs parameter for the PatternType patterns that you want to be recognised, this can be any collection of HASHTAG, MENTION and URL.

For example, if I want to create linked spans for Twitter @ mentions, Hashtags & URLs:

text_message.text = SocialLinkify.socialLinkifyText(
        ContextCompat.getColor(context, R.color.some_color), message.text,
        SocialNetwork.TWITTER, PatternType.HASHTAG, PatternType.MENTION, PatternType.URL)

or if I want to create linked spans for Instagram @ mentions only:

text_message.text = SocialLinkify.socialLinkifyText(
        ContextCompat.getColor(context, R.color.some_color), message.text,
        SocialNetwork.INSTAGRAM, PatternType.MENTION)

or if I just want to create linked spans for Facebook hashtags:

text_message.text = SocialLinkify.socialLinkifyText(
        ContextCompat.getColor(context, R.color.some_color), message.text,
        SocialNetwork.FACEBOOK, PatternType.HASHTAG)

The SocialNetwork class also has a handy fromString() function to allow you to retrieve a SocialNetwork instance from some string that may be used in your app such as "twitter".

sociallinkify's People

Contributors

hitherejoe avatar pavlospt avatar vgonda avatar christxph avatar johnjohndoe avatar

Watchers

James Cloos 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.