diff --git a/README.md b/README.md index 042e093..1b7469f 100644 --- a/README.md +++ b/README.md @@ -32,14 +32,14 @@ allprojects { ``` dependencies { ... - compile 'com.github.arvinljw:SocialHelper:v1.0.7' + compile 'com.github.arvinljw:SocialHelper:v1.0.8' } ``` *注:如果在该module中使用了v7包,那么可使用exclude命令移除本库的引用避免重复,gson也是一样,大体方法如下* ``` -compile ('com.github.arvinljw:SocialHelper:v1.0.7'){ +compile ('com.github.arvinljw:SocialHelper:v1.0.8'){ exclude group: 'com.android.support' } ``` @@ -226,6 +226,12 @@ protected void onNewIntent(Intent intent) { ### Release Log +**v1.0.8:** + +* 优化appId等参数为空是不抛异常,只打印日志,避免使用奔溃 +* 删除SocialHelper中上个版本Deprecate了的方法 +* 增加使用SocialHelper的[使用例子](https://github.com/arvinljw/SocialHelper/blob/master/app/src/main/java/net/arvin/socialhelper/sample/TestLoginShareActivity.java),但是无法直接使用,因为各种appId不匹配,需要在自己的app中按需使用。 + **v1.0.7:** * 更新微信,qq,微博sdk版本 diff --git a/app/build.gradle b/app/build.gradle index a2bc4e8..33e1802 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,6 +20,7 @@ android { 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' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7774f8e..e821738 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -15,7 +15,7 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> - + diff --git a/app/src/main/java/net/arvin/socialhelper/sample/TestLoginShareActivity.java b/app/src/main/java/net/arvin/socialhelper/sample/TestLoginShareActivity.java new file mode 100644 index 0000000..662d68b --- /dev/null +++ b/app/src/main/java/net/arvin/socialhelper/sample/TestLoginShareActivity.java @@ -0,0 +1,185 @@ +package net.arvin.socialhelper.sample; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.RadioGroup; +import android.widget.TextView; +import android.widget.Toast; + +import net.arvin.socialhelper.SocialHelper; +import net.arvin.socialhelper.callback.SocialLoginCallback; +import net.arvin.socialhelper.callback.SocialShareCallback; +import net.arvin.socialhelper.entities.QQShareEntity; +import net.arvin.socialhelper.entities.ShareEntity; +import net.arvin.socialhelper.entities.ThirdInfoEntity; +import net.arvin.socialhelper.entities.WBShareEntity; +import net.arvin.socialhelper.entities.WXShareEntity; +import net.arvin.socialhelper.sample.utils.SocialUtil; + +import java.util.ArrayList; + +public class TestLoginShareActivity extends AppCompatActivity implements View.OnClickListener, SocialLoginCallback, SocialShareCallback { + private String imgUrl = "https://upload-images.jianshu.io/upload_images/3157525-afe6f0ba902eb523.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240"; + private String localImgUrl = "/storage/emulated/0/DCIM/Camera/IMG_20180422_113944.jpg"; + private String title = "个人博客"; + private String summary = "好好学习"; + private String targetUrl = "https://arvinljw.github.io"; + + private SocialHelper socialHelper; + + private TextView tvLoginInfo; + private RadioGroup rgShareInfo; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_test_login_share); + setTitle("测试SocialHelper"); + socialHelper = SocialUtil.getInstance().socialHelper(); + initView(); + initEvent(); + } + + private void initView() { + tvLoginInfo = findViewById(R.id.tv_login_info); + rgShareInfo = findViewById(R.id.rg_share_info); + } + + private void initEvent() { + findViewById(R.id.img_qq).setOnClickListener(this); + findViewById(R.id.img_wx).setOnClickListener(this); + findViewById(R.id.img_wb).setOnClickListener(this); + findViewById(R.id.img_qq_share).setOnClickListener(this); + findViewById(R.id.img_wx_share).setOnClickListener(this); + findViewById(R.id.img_wb_share).setOnClickListener(this); + } + + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.img_qq: + socialHelper.loginQQ(this, this); + break; + case R.id.img_wx: + socialHelper.loginWX(this, this); + break; + case R.id.img_wb: + socialHelper.loginWB(this, this); + break; + case R.id.img_qq_share: + socialHelper.shareQQ(this, createQQShareEntity(), this); + break; + case R.id.img_wx_share: + socialHelper.shareWX(this, createWXShareEntity(), this); + break; + case R.id.img_wb_share: + socialHelper.shareWB(this, createWBShareEntity(), this); + break; + } + } + + private ShareEntity createQQShareEntity() { + ShareEntity shareEntity = null; + int checkedRadioButtonId = rgShareInfo.getCheckedRadioButtonId(); + switch (checkedRadioButtonId) { + case R.id.rb_img: + shareEntity = QQShareEntity.createImageInfo(localImgUrl, "ni6"); + break; + case R.id.rb_img_text: + shareEntity = QQShareEntity.createImageTextInfo(title, targetUrl, + imgUrl, summary, "ni6"); + break; + case R.id.rb_web: + //分享到qq空间,因为qq图文就包含了targetUrl所以比较常用 + ArrayList imgUrls = new ArrayList<>(); + imgUrls.add(imgUrl); + shareEntity = QQShareEntity.createImageTextInfoToQZone(title, targetUrl, + imgUrls, summary, "ni6"); + break; + } + return shareEntity; + } + + private ShareEntity createWXShareEntity() { + ShareEntity shareEntity = null; + int checkedRadioButtonId = rgShareInfo.getCheckedRadioButtonId(); + switch (checkedRadioButtonId) { + case R.id.rb_img: + shareEntity = WXShareEntity.createImageInfo(false, localImgUrl); + break; + case R.id.rb_img_text: + //微信图文是分开的,但是在分享到朋友圈的web中是可以有混合的 + shareEntity = WXShareEntity.createImageInfo(false, R.mipmap.ic_launcher); + break; + case R.id.rb_web: + shareEntity = WXShareEntity.createWebPageInfo(false, targetUrl, R.mipmap.ic_launcher, + title, summary); + break; + } + return shareEntity; + } + + private ShareEntity createWBShareEntity() { + ShareEntity shareEntity = null; + int checkedRadioButtonId = rgShareInfo.getCheckedRadioButtonId(); + switch (checkedRadioButtonId) { + case R.id.rb_img: + shareEntity = WBShareEntity.createImageTextInfo(localImgUrl, title); + break; + case R.id.rb_img_text: + shareEntity = WBShareEntity.createImageTextInfo(R.mipmap.ic_launcher, title); + break; + case R.id.rb_web: + shareEntity = WBShareEntity.createWebInfo(targetUrl, + title, summary, R.mipmap.ic_launcher, "这是要说的内容"); + break; + } + return shareEntity; + } + + //用处:qq登录和分享回调,以及微博登录回调 + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (data != null && socialHelper != null) {//qq分享如果选择留在qq,通过home键退出,再进入app则不会有回调 + socialHelper.onActivityResult(requestCode, resultCode, data); + } + } + + //用处:微博分享回调 + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + if (socialHelper != null) { + socialHelper.onNewIntent(intent); + } + } + + @Override + public void loginSuccess(ThirdInfoEntity info) { + tvLoginInfo.setText(toString(info)); + } + + @Override + public void socialError(String msg) { + Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); + } + + @Override + public void shareSuccess() { + Toast.makeText(this, "分享成功", Toast.LENGTH_SHORT).show(); + } + + private String toString(ThirdInfoEntity info) { + return "登录信息 = {" + + "unionId='" + info.getUnionId() + '\'' + + ", openId='" + info.getOpenId() + '\'' + + ", nickname='" + info.getNickname() + '\'' + + ", sex='" + info.getSex() + '\'' + + ", avatar='" + info.getAvatar() + '\'' + + ", platform='" + info.getPlatform() + '\'' + + '}'; + } +} diff --git a/app/src/main/res/layout/activity_test_login_share.xml b/app/src/main/res/layout/activity_test_login_share.xml new file mode 100644 index 0000000..784f820 --- /dev/null +++ b/app/src/main/res/layout/activity_test_login_share.xml @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-xxhdpi/img_qq_p.png b/app/src/main/res/mipmap-xxhdpi/img_qq_p.png new file mode 100644 index 0000000..66580a3 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/img_qq_p.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/img_wb_p.png b/app/src/main/res/mipmap-xxhdpi/img_wb_p.png new file mode 100644 index 0000000..21c4c86 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/img_wb_p.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/img_wx_p.png b/app/src/main/res/mipmap-xxhdpi/img_wx_p.png new file mode 100644 index 0000000..614c179 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/img_wx_p.png differ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 3ab3e9c..2008ed1 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -3,4 +3,5 @@ #3F51B5 #303F9F #FF4081 + #000 diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..afbed9b --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,4 @@ + + + 16sp + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 5885930..2d9b8cb 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -8,4 +8,8 @@ @color/colorAccent +