From e929299468414c12b423e63a3bd0f8515fe27de1 Mon Sep 17 00:00:00 2001 From: liujinwei Date: Fri, 6 Jul 2018 14:44:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E5=A2=9E=E5=88=86=E4=BA=AB=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 回调增加分享类型,改变smaple中单例的实现方式 --- README.md | 10 +++++++--- app/build.gradle | 8 ++++---- .../arvin/socialhelper/sample/MainActivity.java | 2 +- .../sample/TestLoginShareActivity.java | 4 ++-- .../socialhelper/sample/utils/SocialUtil.java | 16 ++++------------ .../sample/wxapi/WXEntryActivity.java | 10 +++++----- .../java/net/arvin/socialhelper/QQHelper.java | 6 +++--- .../java/net/arvin/socialhelper/WBHelper.java | 6 +++--- .../java/net/arvin/socialhelper/WXHelper.java | 6 +++--- .../callback/SocialShareCallback.java | 12 ++++++++++-- .../arvin/socialhelper/entities/ShareEntity.java | 6 +++--- 11 files changed, 45 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 1b7469f..b7a803b 100644 --- a/README.md +++ b/README.md @@ -32,14 +32,14 @@ allprojects { ``` dependencies { ... - compile 'com.github.arvinljw:SocialHelper:v1.0.8' + compile 'com.github.arvinljw:SocialHelper:v1.0.9' } ``` *注:如果在该module中使用了v7包,那么可使用exclude命令移除本库的引用避免重复,gson也是一样,大体方法如下* ``` -compile ('com.github.arvinljw:SocialHelper:v1.0.8'){ +compile ('com.github.arvinljw:SocialHelper:v1.0.9'){ exclude group: 'com.android.support' } ``` @@ -150,7 +150,7 @@ public interface SocialLoginCallback extends SocialCallback{ } public interface SocialShareCallback extends SocialCallback{ - void shareSuccess(); + void shareSuccess(int type); } ``` @@ -226,6 +226,10 @@ protected void onNewIntent(Intent intent) { ### Release Log +**v1.0.9:** + +* 分享回调增加分享类型 + **v1.0.8:** * 优化appId等参数为空是不抛异常,只打印日志,避免使用奔溃 diff --git a/app/build.gradle b/app/build.gradle index 33e1802..a86711f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -21,8 +21,8 @@ dependencies { api fileTree(dir: 'libs', include: ['*.jar']) api 'com.android.support:appcompat-v7:'.concat(projectSupportVersion) implementation 'com.android.support.constraint:constraint-layout:1.1.2' -// compile project(':socialhelper') - api ('com.github.arvinljw:SocialHelper:v1.0.7'){ - exclude group: 'com.android.support' - } + api project(':socialhelper') +// api ('com.github.arvinljw:SocialHelper:v1.0.9'){ +// exclude group: 'com.android.support' +// } } diff --git a/app/src/main/java/net/arvin/socialhelper/sample/MainActivity.java b/app/src/main/java/net/arvin/socialhelper/sample/MainActivity.java index 5ecfd84..428d62d 100644 --- a/app/src/main/java/net/arvin/socialhelper/sample/MainActivity.java +++ b/app/src/main/java/net/arvin/socialhelper/sample/MainActivity.java @@ -16,7 +16,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - socialHelper = SocialUtil.getInstance().socialHelper(); + socialHelper = SocialUtil.INSTANCE.socialHelper; } @Override diff --git a/app/src/main/java/net/arvin/socialhelper/sample/TestLoginShareActivity.java b/app/src/main/java/net/arvin/socialhelper/sample/TestLoginShareActivity.java index 662d68b..5a1771c 100644 --- a/app/src/main/java/net/arvin/socialhelper/sample/TestLoginShareActivity.java +++ b/app/src/main/java/net/arvin/socialhelper/sample/TestLoginShareActivity.java @@ -37,7 +37,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test_login_share); setTitle("测试SocialHelper"); - socialHelper = SocialUtil.getInstance().socialHelper(); + socialHelper = SocialUtil.INSTANCE.socialHelper; initView(); initEvent(); } @@ -168,7 +168,7 @@ public void socialError(String msg) { } @Override - public void shareSuccess() { + public void shareSuccess(int type) { Toast.makeText(this, "分享成功", Toast.LENGTH_SHORT).show(); } diff --git a/app/src/main/java/net/arvin/socialhelper/sample/utils/SocialUtil.java b/app/src/main/java/net/arvin/socialhelper/sample/utils/SocialUtil.java index c72fdaf..8bb120f 100644 --- a/app/src/main/java/net/arvin/socialhelper/sample/utils/SocialUtil.java +++ b/app/src/main/java/net/arvin/socialhelper/sample/utils/SocialUtil.java @@ -7,12 +7,12 @@ * Function: * Desc: */ -public class SocialUtil { - private static SocialUtil sInstance = new SocialUtil(); +public enum SocialUtil { + INSTANCE(); - private SocialHelper socialHelper; + public SocialHelper socialHelper; - private SocialUtil() { + SocialUtil() { socialHelper = new SocialHelper.Builder() .setQqAppId("qqAppId") .setWxAppId("wxAppId") @@ -21,12 +21,4 @@ private SocialUtil() { .setWbRedirectUrl("wbRedirectUrl") .build(); } - - public static SocialUtil getInstance() { - return sInstance; - } - - public SocialHelper socialHelper() { - return socialHelper; - } } diff --git a/app/src/main/java/net/arvin/socialhelper/sample/wxapi/WXEntryActivity.java b/app/src/main/java/net/arvin/socialhelper/sample/wxapi/WXEntryActivity.java index 8c6552c..080d1b8 100644 --- a/app/src/main/java/net/arvin/socialhelper/sample/wxapi/WXEntryActivity.java +++ b/app/src/main/java/net/arvin/socialhelper/sample/wxapi/WXEntryActivity.java @@ -27,7 +27,7 @@ public class WXEntryActivity extends AppCompatActivity implements IWXAPIEventHan protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - String wxAppId = SocialUtil.getInstance().socialHelper().getBuilder().getWxAppId(); + String wxAppId = SocialUtil.INSTANCE.socialHelper.getBuilder().getWxAppId(); api = WXAPIFactory.createWXAPI(this, wxAppId, true); api.registerApp(wxAppId); @@ -52,15 +52,15 @@ public void onResp(BaseResp baseResp) { if (baseResp.getType() == ConstantsAPI.COMMAND_SENDAUTH) { if (baseResp.errCode == BaseResp.ErrCode.ERR_OK) { String code = ((SendAuth.Resp) baseResp).code; - SocialUtil.getInstance().socialHelper().sendAuthBackBroadcast(this, code); + SocialUtil.INSTANCE.socialHelper.sendAuthBackBroadcast(this, code); } else { - SocialUtil.getInstance().socialHelper().sendAuthBackBroadcast(this, null); + SocialUtil.INSTANCE.socialHelper.sendAuthBackBroadcast(this, null); } } else if (baseResp.getType() == ConstantsAPI.COMMAND_SENDMESSAGE_TO_WX) { if (baseResp.errCode == BaseResp.ErrCode.ERR_OK) { - SocialUtil.getInstance().socialHelper().sendShareBackBroadcast(this, true); + SocialUtil.INSTANCE.socialHelper.sendShareBackBroadcast(this, true); } else { - SocialUtil.getInstance().socialHelper().sendShareBackBroadcast(this, false); + SocialUtil.INSTANCE.socialHelper.sendShareBackBroadcast(this, false); } } onBackPressed(); diff --git a/socialhelper/src/main/java/net/arvin/socialhelper/QQHelper.java b/socialhelper/src/main/java/net/arvin/socialhelper/QQHelper.java index 3b731ec..8ab1be2 100644 --- a/socialhelper/src/main/java/net/arvin/socialhelper/QQHelper.java +++ b/socialhelper/src/main/java/net/arvin/socialhelper/QQHelper.java @@ -62,12 +62,12 @@ public void onComplete(Object obj) { }; } - private void initShareListener() { + private void initShareListener(final ShareEntity shareInfo) { shareListener = new NormalUIListener(activity, shareCallback) { @Override public void onComplete(Object o) { if (shareCallback != null) { - shareCallback.shareSuccess(); + shareCallback.shareSuccess(shareInfo.getType()); } } }; @@ -155,7 +155,7 @@ public void share(SocialShareCallback callback, ShareEntity shareInfo) { } return; } - initShareListener(); + initShareListener(shareInfo); if (shareInfo.getType() == ShareEntity.TYPE_QQ) { tencent.shareToQQ(activity, shareInfo.getParams(), shareListener); } else { diff --git a/socialhelper/src/main/java/net/arvin/socialhelper/WBHelper.java b/socialhelper/src/main/java/net/arvin/socialhelper/WBHelper.java index 261c7f3..8a58ace 100644 --- a/socialhelper/src/main/java/net/arvin/socialhelper/WBHelper.java +++ b/socialhelper/src/main/java/net/arvin/socialhelper/WBHelper.java @@ -202,7 +202,7 @@ public void share(SocialShareCallback callback, ShareEntity shareInfo) { } return; } - initShareLister(); + initShareLister(shareInfo); shareHandler = new WbShareHandler(activity); shareHandler.registerApp(); @@ -213,12 +213,12 @@ public void share(SocialShareCallback callback, ShareEntity shareInfo) { shareHandler.shareMessage(weiboMessage, false); } - private void initShareLister() { + private void initShareLister(final ShareEntity shareInfo) { wbShareCallback = new WbShareCallback() { @Override public void onWbShareSuccess() { if (shareCallback != null) { - shareCallback.shareSuccess(); + shareCallback.shareSuccess(shareInfo.getType()); } } diff --git a/socialhelper/src/main/java/net/arvin/socialhelper/WXHelper.java b/socialhelper/src/main/java/net/arvin/socialhelper/WXHelper.java index 4fad835..bf37369 100644 --- a/socialhelper/src/main/java/net/arvin/socialhelper/WXHelper.java +++ b/socialhelper/src/main/java/net/arvin/socialhelper/WXHelper.java @@ -191,7 +191,7 @@ public void share(SocialShareCallback callback, ShareEntity shareInfo) { return; } - initShareReceiver(); + initShareReceiver(shareInfo); SendMessageToWX.Req req = new SendMessageToWX.Req(); req.message = createMessage(req, shareInfo.getParams()); @@ -205,7 +205,7 @@ public void share(SocialShareCallback callback, ShareEntity shareInfo) { /** * 分享回调 */ - private void initShareReceiver() { + private void initShareReceiver(final ShareEntity shareInfo) { if (wxShareReceiver == null) { wxShareReceiver = new BroadcastReceiver() { @Override @@ -213,7 +213,7 @@ public void onReceive(Context activity, Intent intent) { boolean shareSuccess = intent.getBooleanExtra(SocialHelper.KEY_WX_SHARE_CALL_BACK, false); if (shareCallback != null) { if (shareSuccess) { - shareCallback.shareSuccess(); + shareCallback.shareSuccess(shareInfo.getType()); } else { shareCallback.socialError(activity.getString(R.string.social_cancel)); } diff --git a/socialhelper/src/main/java/net/arvin/socialhelper/callback/SocialShareCallback.java b/socialhelper/src/main/java/net/arvin/socialhelper/callback/SocialShareCallback.java index 8f1800b..21d8b7f 100644 --- a/socialhelper/src/main/java/net/arvin/socialhelper/callback/SocialShareCallback.java +++ b/socialhelper/src/main/java/net/arvin/socialhelper/callback/SocialShareCallback.java @@ -5,6 +5,14 @@ * Function: * Desc: */ -public interface SocialShareCallback extends SocialCallback{ - void shareSuccess(); +public interface SocialShareCallback extends SocialCallback { + /** + * @param type 取值有0或1,2,3,4分别对应下边的qq,微信好友,朋友圈和微博 + *

+ * qq==0||qq==1,因为在分享到qq好友时也能选择分享到qq空间,而又没有回调参数去判断 + * 微信==2 + * 朋友圈==3 + * 微博==4 + */ + void shareSuccess(int type); } diff --git a/socialhelper/src/main/java/net/arvin/socialhelper/entities/ShareEntity.java b/socialhelper/src/main/java/net/arvin/socialhelper/entities/ShareEntity.java index d1a2c04..c4b16d1 100644 --- a/socialhelper/src/main/java/net/arvin/socialhelper/entities/ShareEntity.java +++ b/socialhelper/src/main/java/net/arvin/socialhelper/entities/ShareEntity.java @@ -16,9 +16,9 @@ public class ShareEntity { * type 值 * qq==0 * qzone==1 - * 微信==2 - * 朋友圈==3 - * 微博==4 + * 微信==2 + * 朋友圈==3 + * 微博==4 */ public static final int TYPE_QQ = 0; public static final int TYPE_Q_ZONE = 1;