Skip to content

Commit

Permalink
调增分享成功回调
Browse files Browse the repository at this point in the history
回调增加分享类型,改变smaple中单例的实现方式
  • Loading branch information
liujinwei committed Jul 6, 2018
1 parent 32d42fb commit e929299
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 41 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
```
Expand Down Expand Up @@ -150,7 +150,7 @@ public interface SocialLoginCallback extends SocialCallback{
}
public interface SocialShareCallback extends SocialCallback{
void shareSuccess();
void shareSuccess(int type);
}
```

Expand Down Expand Up @@ -226,6 +226,10 @@ protected void onNewIntent(Intent intent) {

### Release Log

**v1.0.9:**

* 分享回调增加分享类型

**v1.0.8:**

* 优化appId等参数为空是不抛异常,只打印日志,避免使用奔溃
Expand Down
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -21,12 +21,4 @@ private SocialUtil() {
.setWbRedirectUrl("wbRedirectUrl")
.build();
}

public static SocialUtil getInstance() {
return sInstance;
}

public SocialHelper socialHelper() {
return socialHelper;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
};
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void share(SocialShareCallback callback, ShareEntity shareInfo) {
}
return;
}
initShareLister();
initShareLister(shareInfo);
shareHandler = new WbShareHandler(activity);
shareHandler.registerApp();

Expand All @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -205,15 +205,15 @@ public void share(SocialShareCallback callback, ShareEntity shareInfo) {
/**
* 分享回调
*/
private void initShareReceiver() {
private void initShareReceiver(final ShareEntity shareInfo) {
if (wxShareReceiver == null) {
wxShareReceiver = new BroadcastReceiver() {
@Override
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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,微信好友,朋友圈和微博
* <p>
* qq==0||qq==1,因为在分享到qq好友时也能选择分享到qq空间,而又没有回调参数去判断
* 微信==2
* 朋友圈==3
* 微博==4
*/
void shareSuccess(int type);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e929299

Please sign in to comment.