What is the EasyShare

It is an Android social sharing scaffolding, integrated with wechat, QQ, Weibo sharing. Project address: github.com/xiong-it/Ea… If you feel helpful, you can give a star. If you have opinions or suggestions, you can make an issue or initiate PR

What is EasyShare for

Abstract factory, factory method, bridge mode and Java generic package are used as a simple and extensible sharing component, which cannot replace ShareSDK and other commercial SDK. It is only for development exchange and discussion, and is not recommended to be used directly for online projects. It can be used for developers’ reference and extension.

Architecture class diagram

  • IShareContent: Defines a shared content interface with a share behavior that is delivered to the ISharePlatform in bridge mode
  • ISharePlatform: A target platform for sharing content and an object interface for actual sharing behaviors
  • IShareModel: Encapsulate attributes of shared content, such as title, image address, link, etc
  • IShareDataFactory: According to IShareModel production to share the data required by ISharePlatform platform, its implementation class abstract factory AbsShareDataFactory defines the data functions required by the production of wechat, Moments of friends, QQ, weibo four product families

structure

  • Callback – Callback interface definition
  • Factory-factory class, the top-level abstract factory defines the shared data function for all platforms produced, splitting dimensions: sharing sub-platform as product family, sharing content type as product line.
  • Model – Model class. The top-level interface is IShareModel. The data model required for sharing data is added here.
  • Platform – Sharing target platform. ISharePlatform is the target platform interface. All derivative platforms need to implement this interface.
  • Type – Encapsulation of shared data types, entry to sharing, top-level interface IShareContent, and Share behavior.
  • Ui-interface related classes, such as isharedialog.java, share interface classes for selecting popovers that need to be implemented in the popovers used in the project.
  • Wxapi – The package name must be the project package name. This is for demonstration purposes only.

The integration steps

  1. Clone the warehouse
  2. Reference DemoActivity

Sharing code Examples

Take bitmap sharing as an example (scenario: QR code image sharing)

IShareModel = newBitmapShareModel() {
    @Override
    public Bitmap shareBitmap() {
            returngetShareBitmap(); }}; / / 2. Instantiate share data type IShareContent bitmapShare = ShareContentFactory. NewShareContent (platform, model); Bitmapshare.share (this.activity, new); // 3OnShareResultCallback() {
    @Override
    public void onShareCancel(ISharePlatform platform, IShareContent type} @override public void onShareFailed(ISharePlatform platform, IShareContent)type, int errCode, String errMsg) {// Share failed} @override public void onShareSuccess(ISharePlatform platform, IShareContent)type) {// Share success}});Copy the code

When you need to add a share type

  1. Extend IShareModel interface and add implementation classes
  2. Extend IShareContent interface, add implementation class
  3. Extend AbsShareDataFactory abstract factory product line, add subclass production corresponding data to share

When you need to add a sharing platform

  1. Introduce corresponding platform to rely on LIBS
  2. Extend the ISharePlatform interface and add an implementation class
  3. Extend the AbsShareDataFactory abstract class product family (add abstract functions) and its subclass implementation
  4. Modify IShareDialog subclass implementation, add click event