Commit 1c7d10188a6facb4ebd34e5e5260d21e28526baa

Authored by YangShuai
2 parents a3a3b4f5 184007b8

Merge branch 'master' of bj.gitlab.cnlive.com:cnlive-team/newModuleStrike

# Conflicts:
#	app/strike/src/main/java/com/cnlive/strike/MyActivity.java
#	settings.gradle
Showing 38 changed files with 4576 additions and 31 deletions

Too many changes to show.

To preserve performance only 38 of 112 files are displayed.

app/strike/src/main/java/com/cnlive/strike/MyActivity.java
1 1 package com.cnlive.strike;
2 2  
3 3  
4   -import android.os.Handler;
5   -import android.os.Message;
  4 +import android.content.Intent;
6 5 import android.text.TextUtils;
7   -
8   -import androidx.annotation.NonNull;
  6 +import android.view.View;
9 7  
10 8 import com.alibaba.android.arouter.facade.annotation.Route;
11 9 import com.cnlive.core.libs.base.frame.activity.BaseActivity;
12   -import com.cnlive.core.libs.base.util.QMUITipDialogUtil;
  10 +import com.cnlive.core.libs.base.util.NetworkUtil;
  11 +import com.cnlive.moudle.collectionTrace.commonInfo.CollCommonInfo;
  12 +import com.cnlive.moudle.collectionTrace.ui.activity.RaceListActivity;
13 13 import com.cnlive.moudle.pedometer.commonInfo.CommonInfo;
  14 +import com.cnlive.moudle.pedometer.ui.activity.RunLineActivity;
  15 +import com.cnlive.moudle.pedometer.ui.fragment.RunLineFragment;
14 16 import com.cnlive.strike.databinding.ActivityMyBinding;
15 17 import com.cnlive.strike.user.auth.UserService;
16 18 import com.cnlive.strike.xiaojiaspeaker.commonInfo.XiaoJIaCommInfo;
... ... @@ -18,7 +20,7 @@ import com.cnlive.strike.xiaojiaspeaker.commonInfo.XiaoJIaCommInfo;
18 20 @Route(path = "/strick/MyActivity")
19 21 public class MyActivity extends BaseActivity {
20 22 public ActivityMyBinding binding;
21   - private Handler testHandler;
  23 +
22 24 // @Override
23 25 // protected int getBindLayoutId() {
24 26 // return R.layout.activity_my;
... ... @@ -32,17 +34,9 @@ public class MyActivity extends BaseActivity {
32 34  
33 35 @Override
34 36 protected void initView() {
35   - testHandler = getMyActHandler();
36   - testHandler.sendEmptyMessageAtTime(0, 0);
37   -// testHandler.postDelayed(new Runnable() {
38   -// @Override
39   -// public void run() {
40   -// QMUITipDialogUtil.successDialog(MyActivity.this, "测试", 5);
41   -// }
42   -// },5000);
43 37 // loadRootFragment(new EmptyFragment());
44   -// initXiaoJiaSoundBoxData();
45   -// startActivity(new Intent(MyActivity.this, RunLineActivity.class));
  38 + initXiaoJiaSoundBoxData();
  39 + startActivity(new Intent(MyActivity.this, RunLineActivity.class));
46 40 // RaceListActivity.newInstance(me, UserService.getUid(me),
47 41 // UserService.getInstance(me).getAppAccount().getNickName(),
48 42 // UserService.getInstance(me).getAppAccount().getFaceUrl());
... ... @@ -94,12 +88,6 @@ public class MyActivity extends BaseActivity {
94 88 }
95 89  
96 90 @Override
97   - public void onReceiveActHandleMessage(@NonNull Message msg) {
98   - super.onReceiveActHandleMessage(msg);
99   - QMUITipDialogUtil.successDialog(MyActivity.this, "测试", 5);
100   - }
101   -
102   - @Override
103 91 protected void initData() {
104 92 }
105 93  
... ...
app/strike/src/main/java/com/cnlive/strike/imgutil/ImgActivity.java
... ... @@ -197,7 +197,6 @@ public class ImgActivity extends AppCompatActivity {
197 197  
198 198 @Override
199 199 public void onDownLoadSuccess(Bitmap bitmap) {
200   - Log.e("sssssss", "onDownLoadSuccess: " );
201 200 //网络请求
202 201 bitmaps = bitmap;
203 202 Message msg = new Message();
... ...
build.gradle
... ... @@ -8,6 +8,8 @@ static void imput(String type, Project project, Object dependencyNotation) {
8 8  
9 9 buildscript {
10 10 repositories {
  11 + //关联微博
  12 + maven { url "https://dl.bintray.com/thelasterstar/maven/" }
11 13 google()
12 14 jcenter()
13 15  
... ... @@ -22,14 +24,6 @@ buildscript {
22 24 }
23 25  
24 26 allprojects {
25   - repositories {
26   - google()
27   - jcenter()
28   -
29   - }
30   -}
31   -
32   -allprojects {
33 27 // configurations.all {
34 28 ////// resolutionStrategy.force 'androidx.appcompat:appcompat:1.1.0'
35 29 // }
... ... @@ -130,11 +124,15 @@ allprojects {
130 124 repositories {
131 125 google()
132 126 jcenter()
  127 +
133 128 maven {
134 129 url maven.mixedUrl
135 130 credentials { username = nexusId; password = nexusPw }
136 131 }
137 132 //------------------ 资源库配置 END------------------
  133 +
  134 + //关联微博
  135 + maven { url "https://dl.bintray.com/thelasterstar/maven/" }
138 136 maven {
139 137 url 'https://dl.bintray.com/granzon/cnlive'
140 138 }
... ...
cloud/share/.gitignore 0 → 100644
  1 +/build
... ...
cloud/share/build.gradle 0 → 100644
  1 +apply plugin: 'com.android.library'
  2 +
  3 +android {
  4 +// compileSdkVersion rootProject.ext.compileSdkVersion
  5 +// buildToolsVersion rootProject.ext.buildToolsVersion
  6 +//
  7 +// defaultConfig {
  8 +// minSdkVersion rootProject.ext.minSdkVersion
  9 +// targetSdkVersion rootProject.ext.targetSdkVersion
  10 +// versionCode rootProject.ext.versionCode
  11 +// versionName rootProject.ext.versionName
  12 +// javaCompileOptions {
  13 +// annotationProcessorOptions {
  14 +// arguments = [AROUTER_MODULE_NAME: project.getName(), AROUTER_GENERATE_DOC: "enable"]
  15 +// }
  16 +// }
  17 +// }
  18 + compileOptions {
  19 + sourceCompatibility JavaVersion.VERSION_1_8
  20 + targetCompatibility JavaVersion.VERSION_1_8
  21 + }
  22 +
  23 + dataBinding {
  24 + enabled true
  25 + }
  26 + dexOptions {
  27 + javaMaxHeapSize '4g'
  28 + }
  29 +
  30 + buildTypes {
  31 +
  32 + debug {
  33 + zipAlignEnabled true
  34 + buildConfigField("String", "QQ_SHARE", stringValue("1106866745"))
  35 + buildConfigField("String", "WECHAT_SHARE", stringValue("wx9b7f9443a8ccf15a"))
  36 + buildConfigField("String", "WECHAT_KEY", stringValue("8d9970bf2901411d8dd2bffb344f147e"))
  37 + buildConfigField("String", "SEND_AUTH_REQ_STATE", stringValue("com_cnlive_strike_debug"))
  38 + manifestPlaceholders = [
  39 + QQ_APPKEY: "tencent1106866745"
  40 + ]
  41 + }
  42 + release {
  43 + zipAlignEnabled true
  44 + buildConfigField("String", "QQ_SHARE", stringValue("1106691520"))
  45 + buildConfigField("String", "WECHAT_SHARE", stringValue("wxed528fc749b7ee88"))
  46 + buildConfigField("String", "WECHAT_KEY", stringValue("729c3d3055fe336bcdef7020c2548e89"))
  47 + buildConfigField("String", "SEND_AUTH_REQ_STATE", stringValue("com_cnlive_strike"))
  48 + manifestPlaceholders = [
  49 + QQ_APPKEY: "tencent1106691520"
  50 + ]
  51 + }
  52 + }
  53 +
  54 +}
  55 +
  56 +static def stringValue(def value) {
  57 + return "\"${value}\""
  58 +}
  59 +
  60 +dependencies {
  61 + implementation fileTree(include: ['*.jar'], dir: 'libs')
  62 + //CNLive Encipher
  63 + implementation "com.cnlive.libs:analytics:1.1.2"
  64 + implementation 'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:5.3.1'
  65 + implementation files('libs/open_sdk_r6008_lite.jar')
  66 + //微博
  67 + implementation 'com.sina.weibo.sdk:core:4.4.1:openDefaultRelease@aar'
  68 +
  69 + implementation project(':core:network')
  70 + implementation project(':core:base')
  71 + implementation project (':cloud:user')
  72 +}
... ...
cloud/share/libs/open_sdk_r6008_lite.jar 0 → 100644
No preview for this file type
cloud/share/proguard-rules.pro 0 → 100644
  1 +# Add project specific ProGuard rules here.
  2 +# You can control the set of applied configuration files using the
  3 +# proguardFiles setting in build.gradle.
  4 +#
  5 +# For more details, see
  6 +# http://developer.android.com/guide/developing/tools/proguard.html
  7 +
  8 +# If your project uses WebView with JS, uncomment the following
  9 +# and specify the fully qualified class name to the JavaScript interface
  10 +# class:
  11 +#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
  12 +# public *;
  13 +#}
  14 +
  15 +# Uncomment this to preserve the line number information for
  16 +# debugging stack traces.
  17 +#-keepattributes SourceFile,LineNumberTable
  18 +
  19 +# If you keep the line number information, uncomment this to
  20 +# hide the original source file name.
  21 +#-renamesourcefileattribute SourceFile
... ...
cloud/share/src/debug/AndroidManifest.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<manifest xmlns:android="http://schemas.android.com/apk/res/android" >
  3 +
  4 + <application>
  5 +
  6 +
  7 + <activity
  8 + android:name="com.cnlive.strike.debug.wxapi.WXEntryActivity"
  9 + android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
  10 + android:label="@string/app_name"
  11 + android:exported="true"
  12 + android:launchMode="singleTop">
  13 + </activity>
  14 +
  15 + </application>
  16 +
  17 +</manifest>
0 18 \ No newline at end of file
... ...
cloud/share/src/debug/java/com/cnlive/strike/debug/wxapi/WXEntryActivity.java 0 → 100644
  1 +package com.cnlive.strike.debug.wxapi;
  2 +
  3 +import android.app.Activity;
  4 +import android.content.ComponentName;
  5 +import android.content.Intent;
  6 +import android.content.SharedPreferences;
  7 +import android.os.Bundle;
  8 +import android.os.Handler;
  9 +import android.os.Message;
  10 +import android.text.TextUtils;
  11 +import android.util.Log;
  12 +import android.widget.Toast;
  13 +
  14 +import com.cnlive.core.libs.base.application.AppConfig;
  15 +import com.cnlive.core.libs.base.util.AlertUtil;
  16 +import com.cnlive.share.BuildConfig;
  17 +import com.cnlive.share.arouter.ARouterUtil;
  18 +import com.cnlive.share.data.ShareIntegralTypeInfo;
  19 +import com.cnlive.share.data.WeChatInfo;
  20 +import com.cnlive.share.observable.WechatLoginObservable;
  21 +import com.cnlive.share.observable.WechatShareObservable;
  22 +import com.cnlive.share.util.DateTimeUtil;
  23 +import com.cnlive.share.util.OkHttpUtils;
  24 +import com.cnlive.strike.user.auth.UserService;
  25 +import com.google.gson.Gson;
  26 +import com.tencent.mm.opensdk.constants.ConstantsAPI;
  27 +import com.tencent.mm.opensdk.modelbase.BaseReq;
  28 +import com.tencent.mm.opensdk.modelbase.BaseResp;
  29 +import com.tencent.mm.opensdk.modelmsg.SendAuth;
  30 +import com.tencent.mm.opensdk.openapi.IWXAPI;
  31 +import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
  32 +import com.tencent.mm.opensdk.openapi.WXAPIFactory;
  33 +
  34 +import org.json.JSONException;
  35 +import org.json.JSONObject;
  36 +
  37 +import java.lang.ref.WeakReference;
  38 +
  39 +/**
  40 + * 作者: 吴奎庆
  41 + * <p>
  42 + * 时间: 2018/8/23
  43 + * <p>
  44 + * 简介:
  45 + */
  46 +
  47 +public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
  48 +
  49 + private IWXAPI api;
  50 +
  51 + @Override
  52 + public void onCreate(Bundle savedInstanceState) {
  53 + super.onCreate(savedInstanceState);
  54 +
  55 + api = WXAPIFactory.createWXAPI(this, BuildConfig.WECHAT_SHARE,false);
  56 + api.handleIntent(getIntent(), this);
  57 + }
  58 +
  59 + @Override
  60 + protected void onNewIntent(Intent intent) {
  61 + super.onNewIntent(intent);
  62 + setIntent(intent);
  63 + api.handleIntent(intent, this);
  64 + }
  65 +
  66 + @Override
  67 + public void onReq(BaseReq baseReq) {
  68 + }
  69 +
  70 +
  71 + private SendAuth.Resp resp;
  72 +
  73 + @Override
  74 + public void onResp(BaseResp baseResp) {
  75 +
  76 + //微信登录为getType为1,分享为0
  77 + if (baseResp.getType() == 1) {
  78 + //登录回调
  79 + resp = (SendAuth.Resp) baseResp;
  80 + switch (resp.errCode) {
  81 + case BaseResp.ErrCode.ERR_OK:
  82 + String code = String.valueOf(resp.code);
  83 + //获取用户信息
  84 + getAccessToken(code);
  85 + break;
  86 + case BaseResp.ErrCode.ERR_AUTH_DENIED://用户拒绝授权
  87 + AlertUtil.showDeftToast(this, "用户拒绝授权");
  88 + this.finish();
  89 + break;
  90 + case BaseResp.ErrCode.ERR_USER_CANCEL://用户取消
  91 + AlertUtil.showDeftToast(this, "用户取消登录");
  92 + this.finish();
  93 + break;
  94 + default:
  95 + this.finish();
  96 + break;
  97 + }
  98 + } else {
  99 + String result = "";
  100 + switch (baseResp.errCode) {
  101 + case BaseResp.ErrCode.ERR_OK:
  102 + result = "分享成功";
  103 + WechatShareObservable.getInstance().update(1);
  104 + break;
  105 + case BaseResp.ErrCode.ERR_USER_CANCEL:
  106 + result = "分享取消";
  107 + WechatShareObservable.getInstance().update(2);
  108 + break;
  109 + case BaseResp.ErrCode.ERR_AUTH_DENIED:
  110 + result = "分享失败";
  111 + WechatShareObservable.getInstance().update(3);
  112 + break;
  113 + default:
  114 + result = "分享失败";
  115 + break;
  116 + }
  117 +
  118 +
  119 + AlertUtil.showDeftToast(this, result);
  120 + this.finish();
  121 + processShareType(baseResp);
  122 + }
  123 +
  124 +
  125 + }
  126 +
  127 + private void getAccessToken(String code) {
  128 + String getTokenUrl = String.format("https://api.weixin.qq.com/sns/oauth2/access_token?" +
  129 + "appid=%s&secret=%s&code=%s&grant_type=authorization_code", AppConfig.getWechatAppid(),
  130 + BuildConfig.WECHAT_KEY, code);
  131 + OkHttpUtils.ResultCallback<String> resultCallback = new OkHttpUtils.ResultCallback<String>() {
  132 + @Override
  133 + public void onSuccess(String response) {
  134 + String access = null;
  135 + String openId = null;
  136 + try {
  137 + JSONObject jsonObject = new JSONObject(response);
  138 + access = jsonObject.getString("access_token");
  139 + openId = jsonObject.getString("openid");
  140 + } catch (JSONException e) {
  141 + e.printStackTrace();
  142 + }
  143 + //获取个人信息
  144 + String getUserInfo = "https://api.weixin.qq.com/sns/userinfo?access_token=" + access + "&openid=" + openId + "";
  145 + OkHttpUtils.ResultCallback<WeChatInfo> resultCallback = new OkHttpUtils.ResultCallback<WeChatInfo>() {
  146 + @Override
  147 + public void onSuccess(WeChatInfo response) {
  148 + response.setErrCode(resp.errCode);
  149 + if (response != null) WechatLoginObservable.getInstance().update(response);
  150 + finish();
  151 + }
  152 +
  153 + @Override
  154 + public void onFailure(Exception e) {
  155 + Toast.makeText(WXEntryActivity.this, "登录失败", Toast.LENGTH_SHORT).show();
  156 + }
  157 + };
  158 + OkHttpUtils.get(getUserInfo, resultCallback);
  159 + }
  160 +
  161 + @Override
  162 + public void onFailure(Exception e) {
  163 + Toast.makeText(WXEntryActivity.this, "登录失败", Toast.LENGTH_SHORT).show();
  164 + }
  165 + };
  166 + OkHttpUtils.get(getTokenUrl, resultCallback);
  167 +
  168 + }
  169 +
  170 +
  171 + /**
  172 + * 更具不同的分享类型处理不同的 分享逻辑
  173 + *
  174 + * @param baseResp
  175 + */
  176 + private void processShareType(BaseResp baseResp) {
  177 + String shareType = baseResp.transaction;
  178 + if (TextUtils.isEmpty(shareType)) return;
  179 + try {
  180 + Gson gson = new Gson();
  181 + ShareIntegralTypeInfo integralTypeInfo = gson.fromJson(shareType, ShareIntegralTypeInfo.class);
  182 +
  183 + if ("witnessVideo".equals(integralTypeInfo.getShareType())) {
  184 + SharedPreferences preferences = this.getSharedPreferences("sharevideo", MODE_PRIVATE);
  185 + boolean status = preferences.getBoolean(UserService.getUid(this), false);
  186 + String newTime = DateTimeUtil.getCurrentTime();
  187 + String oldtime = preferences.getString(UserService.getUid(this) + "time", "2019-04-10");
  188 + boolean sameDay = DateTimeUtil.isSameDay(newTime, oldtime);
  189 + if (!status) {
  190 + ARouterUtil.addIntegrationPic(this, "share_video", integralTypeInfo.getContentId(), "sharevideo");
  191 + }
  192 + if (status && !sameDay) {
  193 + ARouterUtil.addIntegrationPic(this, "share_video", integralTypeInfo.getContentId(), "sharevideo");
  194 + }
  195 +
  196 + } else if (integralTypeInfo.getShareType() != null) {
  197 + SharedPreferences preferences = this.getSharedPreferences("sharearticle", MODE_PRIVATE);
  198 + boolean status = preferences.getBoolean(UserService.getUid(this), false);
  199 + String newTime = DateTimeUtil.getCurrentTime();
  200 + String oldtime = preferences.getString(UserService.getUid(this) + "time", "2019-04-10");
  201 + boolean sameDay = DateTimeUtil.isSameDay(newTime, oldtime);
  202 + if (!status) {
  203 + ARouterUtil.addIntegrationPic(this, "share_article", integralTypeInfo.getContentId(), "sharearticle");
  204 + }
  205 + if (status && !sameDay) {
  206 + ARouterUtil.addIntegrationPic(this, "share_article", integralTypeInfo.getContentId(), "sharearticle");
  207 + }
  208 + }
  209 +
  210 + } catch (Exception e) {
  211 + return;
  212 + }
  213 + }
  214 +
  215 +}
... ...
cloud/share/src/main/AndroidManifest.xml 0 → 100644
  1 +<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  2 +
  3 + package="com.cnlive.share">
  4 +
  5 + <!-- 添加必要的权限 -->
  6 + <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  7 + <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  8 + <uses-permission android:name="android.permission.GET_TASKS" />
  9 + <uses-permission android:name="android.permission.INTERNET" />
  10 + <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  11 + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  12 + <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
  13 + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  14 + <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  15 +
  16 + <application android:largeHeap="true">
  17 +
  18 + <meta-data
  19 + android:name="WEIBO_APPKEY"
  20 + android:value="3884700821" />
  21 + <meta-data
  22 + android:name="WEIBO_CHANNEL"
  23 + android:value="weibo" />
  24 +
  25 + <activity android:name=".ui.ShareImgActivity"
  26 + android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
  27 + android:launchMode="singleTop"
  28 + android:theme="@style/ShareActivityTheme"
  29 + />
  30 + <activity
  31 + android:name="com.tencent.connect.common.AssistActivity"
  32 + android:configChanges="orientation|keyboardHidden|screenSize"
  33 + android:theme="@android:style/Theme.Translucent.NoTitleBar" />
  34 + <activity
  35 + android:name="com.tencent.tauth.AuthActivity"
  36 + android:launchMode="singleTop"
  37 + android:noHistory="true">
  38 + <intent-filter>
  39 + <action android:name="android.intent.action.VIEW" />
  40 +
  41 + <category android:name="android.intent.category.DEFAULT" />
  42 + <category android:name="android.intent.category.BROWSABLE" />
  43 +
  44 + <data android:scheme="${QQ_APPKEY}" />
  45 + </intent-filter>
  46 + </activity>
  47 + <activity
  48 + android:name=".ui.ShareActivity"
  49 + android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
  50 + android:launchMode="singleTop"
  51 + android:theme="@style/ShareActivityTheme" />
  52 + <activity
  53 + android:name="com.cnlive.share.ui.WechatAppletActivity"
  54 + android:exported="true"
  55 + android:label="@string/app_name"
  56 + android:launchMode="singleTop"
  57 + android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
  58 + </application>
  59 +
  60 +</manifest>
0 61 \ No newline at end of file
... ...
cloud/share/src/main/java/com/cnlive/share/QQListener.java 0 → 100644
  1 +package com.cnlive.share;
  2 +
  3 +import android.util.Log;
  4 +
  5 +import com.tencent.tauth.IUiListener;
  6 +import com.tencent.tauth.UiError;
  7 +
  8 +/**
  9 + * 作者: 吴奎庆
  10 + * <p>
  11 + * 时间: 2018/8/23
  12 + * <p>
  13 + * 简介:
  14 + */
  15 +
  16 +public class QQListener implements IUiListener {
  17 + @Override
  18 + public void onComplete(Object o) {
  19 + Log.e("","");
  20 + }
  21 +
  22 + @Override
  23 + public void onError(UiError uiError) {
  24 + Log.e("","");
  25 + }
  26 +
  27 + @Override
  28 + public void onCancel() {
  29 + Log.e("","");
  30 + }
  31 +}
... ...
cloud/share/src/main/java/com/cnlive/share/adapter/DataBindingAdapter.java 0 → 100644
  1 +package com.cnlive.share.adapter;
  2 +
  3 +import android.content.Context;
  4 +import android.view.LayoutInflater;
  5 +import android.view.View;
  6 +import android.view.ViewGroup;
  7 +
  8 +import com.cnlive.core.libs.base.frame.adapter.BaseRecyclerAdapter;
  9 +import com.cnlive.core.libs.base.frame.adapter.holder.DataBindingViewHolder;
  10 +
  11 +import androidx.annotation.NonNull;
  12 +import androidx.databinding.DataBindingUtil;
  13 +import androidx.databinding.ViewDataBinding;
  14 +import androidx.recyclerview.widget.RecyclerView;
  15 +
  16 +import com.cnlive.share.BR;
  17 +
  18 +/**
  19 + * Created by gujun on 2017/5/23.
  20 + */
  21 +
  22 +public class DataBindingAdapter<T> extends BaseRecyclerAdapter<T> {
  23 + private int layoutId;
  24 + protected int itemBRId;
  25 +
  26 + protected OnAdapterViewClickListener<T> l;
  27 + protected OnAdapterViewLoadMoreListener loadMoreListener;
  28 +
  29 + public DataBindingAdapter(Context context) {
  30 + super(context);
  31 + }
  32 +
  33 + public DataBindingAdapter(Context context, int layoutId, int itemBRId) {
  34 + super(context);
  35 + this.layoutId = layoutId;
  36 + this.itemBRId = itemBRId;
  37 + }
  38 +
  39 + public void setOnViewClickListener(OnAdapterViewClickListener listener) {
  40 + l = listener;
  41 + }
  42 +
  43 + public void setOnLoadMoreListener(OnAdapterViewLoadMoreListener listener) {
  44 + loadMoreListener = listener;
  45 + }
  46 +
  47 + @NonNull
  48 + @Override
  49 + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
  50 + ViewDataBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), layoutId, parent, false);
  51 + DataBindingViewHolder viewHolder = new DataBindingViewHolder(binding.getRoot());
  52 + viewHolder.setBinding(binding);
  53 + return viewHolder;
  54 + }
  55 +
  56 + @Override
  57 + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
  58 + DataBindingViewHolder videoListViewHolder = (DataBindingViewHolder) holder;
  59 + videoListViewHolder.getBinding().setVariable(itemBRId, getItem(position));
  60 + if (l != null)
  61 + videoListViewHolder.getBinding().setVariable(BR.viewClickListener, l);
  62 + videoListViewHolder.getBinding().executePendingBindings();
  63 + if (loadMoreListener != null && position == getList().size() - 1) {
  64 + loadMoreListener.onLoadMore();
  65 + }
  66 + }
  67 +
  68 +
  69 + public interface OnAdapterViewClickListener<T> {
  70 + void onViewClick(View v, T program);
  71 + }
  72 +
  73 + public interface OnAdapterViewLoadMoreListener {
  74 + void onLoadMore();
  75 + }
  76 +
  77 +}
... ...
cloud/share/src/main/java/com/cnlive/share/api/ApiShareService.java 0 → 100644
  1 +package com.cnlive.share.api;
  2 +
  3 +import com.cnlive.core.network.model.BaseResult;
  4 +import com.cnlive.share.model.ShortLinkInfo;
  5 +
  6 +import java.util.Map;
  7 +
  8 +import io.reactivex.Observable;
  9 +import retrofit2.http.POST;
  10 +import retrofit2.http.QueryMap;
  11 +
  12 +/**
  13 + * created by hanyayun
  14 + * on 2019/12/3
  15 + */
  16 +public interface ApiShareService {
  17 +
  18 + /**
  19 + * 预约
  20 + *
  21 + * @param maps
  22 + * @return
  23 + */
  24 + @POST("Daren/announcementCheck/genShortLinks.action")
  25 + Observable<BaseResult<ShortLinkInfo>> genShortLinks(@QueryMap() Map<String, String> maps);
  26 +
  27 +}
... ...
cloud/share/src/main/java/com/cnlive/share/arouter/ARouterUtil.java 0 → 100644
  1 +package com.cnlive.share.arouter;
  2 +
  3 +import android.content.Context;
  4 +
  5 +import com.alibaba.android.arouter.launcher.ARouter;
  6 +import com.cnlive.core.libs.base.util.SharedPreferencesHelper;
  7 +import com.cnlive.core.network.action.CoinRainAction;
  8 +import com.cnlive.strike.user.auth.UserService;
  9 +
  10 +public class ARouterUtil {
  11 + /**
  12 + * 分享完成 增加积分
  13 + */
  14 + public static void addIntegrationPic(Context context, String taskId, String contentId, String addtype) {
  15 + Boolean app_is_show_integral = SharedPreferencesHelper.getInstance(context).getBoolValue("APP_IS_SHOW_INTEGRAL");
  16 + if (app_is_show_integral) {
  17 + CoinRainAction.code(context, UserService.getUid(context), taskId, contentId, addtype,false);
  18 + }
  19 + }
  20 +
  21 + /**
  22 + * 打开举报的h5页面
  23 + *
  24 + * @param context
  25 + * @param url
  26 + */
  27 + public static void startReportActivity(Context context, String url) {
  28 + ARouter.getInstance().build("/web/WebViewActivity")
  29 + .withString("rUrl", url)
  30 + .navigation(context);
  31 + }
  32 +
  33 +
  34 +}
... ...
cloud/share/src/main/java/com/cnlive/share/data/FullVideoShareItemData.java 0 → 100644
  1 +package com.cnlive.share.data;
  2 +
  3 +public class FullVideoShareItemData {
  4 +
  5 + public static final int TYPE_WEIXIN = 0X1001;
  6 + public static final int TYPE_PENG_YOU_QUAN = 0X1002;
  7 + public static final int TYPE_WJJ = 0X1003;
  8 + public static final int TYPE_WJJ_QUAN = 0X1004;
  9 + public static final int TYPE_QQ = 0X1005;
  10 + public static final int TYPE_BROWSER = 0X1006;
  11 + public static final int TYPE_WEIBO = 0X1007;
  12 +
  13 + private int iconId;
  14 + private String title;
  15 + private int type;
  16 +
  17 + public FullVideoShareItemData(int iconId, String title, int type) {
  18 + this.iconId = iconId;
  19 + this.title = title;
  20 + this.type = type;
  21 + }
  22 +
  23 + public int getIconId() {
  24 + return iconId;
  25 + }
  26 +
  27 + public void setIconId(int iconId) {
  28 + this.iconId = iconId;
  29 + }
  30 +
  31 + public String getTitle() {
  32 + return title;
  33 + }
  34 +
  35 + public void setTitle(String title) {
  36 + this.title = title;
  37 + }
  38 +
  39 + public int getType() {
  40 + return type;
  41 + }
  42 +
  43 + public void setType(int type) {
  44 + this.type = type;
  45 + }
  46 +}
... ...
cloud/share/src/main/java/com/cnlive/share/data/IconInfo.java 0 → 100644
  1 +package com.cnlive.share.data;
  2 +
  3 +/**
  4 + * Created by Lynn on 2018/8/23.
  5 + */
  6 +
  7 +public class IconInfo {
  8 + public static final String WJJ_FRIEND = "wjj_friend";//网家家好友
  9 + public static final String WJJ_CIRCLE = "wjj_circle";//网家家生活圈
  10 + public static final String WECHAT_FRIEND = "weChat_friend";//微信好友
  11 + public static final String WECHAT_CIRCLE = "weChat_circle";//微信朋友圈
  12 + public static final String QQ = "qq";//qq
  13 + public static final String WEBO = "webo";//微博
  14 + public static final String BROWSER = "browser";//浏览器打开
  15 + public static final String REPORT = "report"; //举报
  16 + public static final String DOWNLOAD_ALBUM_IMG = "down_album_img";
  17 + private String id;
  18 + private String title;
  19 + private int icon;
  20 +
  21 + public IconInfo(String id, String title, int icon) {
  22 + this.id = id;
  23 + this.title = title;
  24 + this.icon = icon;
  25 + }
  26 +
  27 + public String getId() {
  28 + return id;
  29 + }
  30 +
  31 + public void setId(String id) {
  32 + this.id = id;
  33 + }
  34 +
  35 + public String getTitle() {
  36 + return title;
  37 + }
  38 +
  39 + public void setTitle(String title) {
  40 + this.title = title;
  41 + }
  42 +
  43 + public int getIcon() {
  44 + return icon;
  45 + }
  46 +
  47 + public void setIcon(int icon) {
  48 + this.icon = icon;
  49 + }
  50 +}
... ...
cloud/share/src/main/java/com/cnlive/share/data/ShareInfo.java 0 → 100644
  1 +package com.cnlive.share.data;
  2 +
  3 +/**
  4 + * 创建:wukuiqing
  5 + * <p>
  6 + * 时间:2017/11/13
  7 + * <p>
  8 + * 描述:分享的 数据类型
  9 + */
  10 +
  11 +public class ShareInfo {
  12 + //分享的标题
  13 + private String title;
  14 + //分享的简介
  15 + private String content;
  16 + //分享的图片
  17 + private String imgurl;
  18 + private String siteUrl;
  19 + //分享的Url
  20 + private String url;
  21 + //分享的类型 (默认: share_article 积分用)
  22 + private String shareType;
  23 + //分享的内容id
  24 + private String contentId;
  25 + //兼容低版本的网页链接
  26 + private String webpageUrl;
  27 + //小程序原始id 示例(gh_d43f693ca31f);
  28 + private String userName;
  29 + //小程序页面路径 示例 ("/pages/media")
  30 + private String path;
  31 + //(int类型) 正式版:0,测试版:1,体验版:2
  32 + private int miniprogramType;
  33 + // 1:目击者 2:生活圈 3:H5 4:点播 5:直播
  34 +
  35 + //举报类型
  36 + private String reportType;
  37 + //是否展示投诉的页面
  38 + public boolean isReport;
  39 +
  40 + //是否是网家家生活圈内容的分享
  41 + private boolean isProcessWjjShare;
  42 +
  43 + //网家家分享区分外部内部时 内部用的url
  44 + private String wjjShareUrl;
  45 +
  46 +
  47 + public boolean isProcessWjjShare() {
  48 + return isProcessWjjShare;
  49 + }
  50 +
  51 + public void setProcessWjjShare(boolean processWjjShare) {
  52 + isProcessWjjShare = processWjjShare;
  53 + }
  54 +
  55 + public String getWjjShareUrl() {
  56 + return wjjShareUrl;
  57 + }
  58 +
  59 + public void setWjjShareUrl(String wjjShareUrl) {
  60 + this.wjjShareUrl = wjjShareUrl;
  61 + }
  62 +
  63 +
  64 +
  65 + public String getReportType() {
  66 + return reportType;
  67 + }
  68 +
  69 + public void setReportType(String reportType) {
  70 + this.reportType = reportType;
  71 + }
  72 +
  73 +
  74 + public String getWebpageUrl() {
  75 + return webpageUrl;
  76 + }
  77 +
  78 + public void setWebpageUrl(String webpageUrl) {
  79 + this.webpageUrl = webpageUrl;
  80 + }
  81 +
  82 + public String getUserName() {
  83 + return userName;
  84 + }
  85 +
  86 + public void setUserName(String userName) {
  87 + this.userName = userName;
  88 + }
  89 +
  90 + public String getPath() {
  91 + return path;
  92 + }
  93 +
  94 + public void setPath(String path) {
  95 + this.path = path;
  96 + }
  97 +
  98 + public int getMiniprogramType() {
  99 + return miniprogramType;
  100 + }
  101 +
  102 + public void setMiniprogramType(int miniprogramType) {
  103 + this.miniprogramType = miniprogramType;
  104 + }
  105 +
  106 +
  107 + public String getShareType() {
  108 + return shareType;
  109 + }
  110 +
  111 + public void setShareType(String shareType) {
  112 + if (shareType == null) {
  113 + shareType = "share_article";
  114 + }
  115 + this.shareType = shareType;
  116 + }
  117 +
  118 + public String getContentId() {
  119 + return contentId;
  120 + }
  121 +
  122 + public void setContentId(String contentId) {
  123 + if (contentId == null) {
  124 + contentId = "";
  125 + }
  126 + this.contentId = contentId;
  127 + }
  128 +
  129 + public String getTitle() {
  130 + return title;
  131 + }
  132 +
  133 + public void setTitle(String title) {
  134 + if (title != null && title.length() >= 200)
  135 + title = title.substring(0, 200);
  136 +
  137 + this.title = title;
  138 + }
  139 +
  140 + public String getContent() {
  141 + return content;
  142 + }
  143 +
  144 + public void setContent(String content) {
  145 + if (content != null && content.length() >= 200)
  146 + content = content.substring(0, 200);
  147 +
  148 + this.content = content;
  149 + }
  150 +
  151 + public String getImgurl() {
  152 + return imgurl;
  153 + }
  154 +
  155 + public void setImgurl(String imgurl) {
  156 + this.imgurl = imgurl;
  157 + }
  158 +
  159 + public String getSiteUrl() {
  160 + return siteUrl;
  161 + }
  162 +
  163 + public void setSiteUrl(String siteUrl) {
  164 + this.siteUrl = siteUrl;
  165 + }
  166 +
  167 + public String getUrl() {
  168 + return url;
  169 + }
  170 +
  171 + public void setUrl(String url) {
  172 + this.url = url;
  173 + }
  174 +}
... ...
cloud/share/src/main/java/com/cnlive/share/data/ShareIntegralTypeInfo.java 0 → 100644
  1 +package com.cnlive.share.data;
  2 +
  3 +/**
  4 + * 作者: 吴奎庆
  5 + * <p>
  6 + * 时间: 2019/3/9
  7 + * <p>
  8 + * 简介: 分享
  9 + */
  10 +public class ShareIntegralTypeInfo {
  11 + public String getShareType() {
  12 + return shareType;
  13 + }
  14 +
  15 + public void setShareType(String shareType) {
  16 + this.shareType = shareType;
  17 + }
  18 +
  19 + public String getContentId() {
  20 + return contentId;
  21 + }
  22 +
  23 + public void setContentId(String contentId) {
  24 + this.contentId = contentId;
  25 + }
  26 +
  27 + private String shareType;
  28 + private String contentId;
  29 +}
... ...
cloud/share/src/main/java/com/cnlive/share/data/WeChatInfo.java 0 → 100644
  1 +package com.cnlive.share.data;
  2 +
  3 +/**
  4 + * 作者: 吴奎庆
  5 + * <p>
  6 + * 时间: 2019/8/30
  7 + * <p>
  8 + * 简介:
  9 + */
  10 +
  11 +public class WeChatInfo {
  12 + private int errCode;
  13 +
  14 + private String openid;
  15 +
  16 + //普通用户性别,1为男性,2为女性
  17 + private int sex;
  18 +
  19 + private String nickname;
  20 +
  21 + private String headimgurl;
  22 +
  23 + private String province;
  24 +
  25 + private String language;
  26 +
  27 + private String country;
  28 +
  29 + private String unionid;
  30 +
  31 + public String getOpenid() {
  32 + return openid;
  33 + }
  34 +
  35 + public void setOpenid(String openid) {
  36 + this.openid = openid;
  37 + }
  38 +
  39 + public String getNickname() {
  40 + return nickname;
  41 + }
  42 +
  43 + public void setNickname(String nickname) {
  44 + this.nickname = nickname;
  45 + }
  46 +
  47 + public String getHeadimgurl() {
  48 + return headimgurl;
  49 + }
  50 +
  51 + public void setHeadimgurl(String headimgurl) {
  52 + this.headimgurl = headimgurl;
  53 + }
  54 +
  55 + public String getSex() {
  56 + return "" + sex;
  57 + }
  58 +
  59 + public String getProvince() {
  60 + return province;
  61 + }
  62 +
  63 + public void setProvince(String province) {
  64 + this.province = province;
  65 + }
  66 +
  67 + public String getLanguage() {
  68 + return language;
  69 + }
  70 +
  71 + public void setLanguage(String language) {
  72 + this.language = language;
  73 + }
  74 +
  75 + public String getCountry() {
  76 + return country;
  77 + }
  78 +
  79 + public void setCountry(String country) {
  80 + this.country = country;
  81 + }
  82 +
  83 + public String getUnionid() {
  84 + return unionid;
  85 + }
  86 +
  87 + public void setUnionid(String unionid) {
  88 + this.unionid = unionid;
  89 + }
  90 +
  91 + public void setSex(int sex) {
  92 + this.sex = sex;
  93 + }
  94 +
  95 + public int getErrCode() {
  96 + return errCode;
  97 + }
  98 +
  99 + public void setErrCode(int errCode) {
  100 + this.errCode = errCode;
  101 + }
  102 +
  103 + @Override
  104 + public String toString() {
  105 + return "WeChatInfo{" +
  106 + "errCode='" + errCode + '\'' +
  107 + ", openid='" + openid + '\'' +
  108 + ", sex=" + sex +
  109 + ", nickname='" + nickname + '\'' +
  110 + ", headimgurl='" + headimgurl + '\'' +
  111 + ", province='" + province + '\'' +
  112 + ", language='" + language + '\'' +
  113 + ", country='" + country + '\'' +
  114 + ", unionid='" + unionid + '\'' +
  115 + '}';
  116 + }
  117 +}
... ...
cloud/share/src/main/java/com/cnlive/share/model/ShareReleaseInfoUtil.java 0 → 100644
  1 +package com.cnlive.share.model;
  2 +
  3 +import android.content.Context;
  4 +import android.content.Intent;
  5 +import android.net.Uri;
  6 +
  7 +
  8 +import com.cnlive.core.libs.base.application.AppConfig;
  9 +
  10 +import java.io.Serializable;
  11 +
  12 +public class ShareReleaseInfoUtil {
  13 +
  14 + public static final String SHARE_TYPE = "strike.intent.extra.TYPE";
  15 + public static final String SHARE_IMAGE = "strike.intent.extra.IMAGE";
  16 +
  17 + public static final String ACTION_SHARE_SEND = "netpp.intent.action.SHARE_SEND";
  18 + public static final String ACTION_SHARE_RELEASE = "netpp.intent.action.SHARE_RELEASE";
  19 +
  20 + //分享类型
  21 + public static final String TYPE_HTML = "strike.intent.type.HTML";
  22 +
  23 + private ShareConfig config;
  24 +
  25 + public static final class ShareConfig implements Serializable {
  26 +
  27 + public static ShareConfig newInstance() {
  28 + return new ShareConfig();
  29 + }
  30 +
  31 + public static ShareConfig parse(Intent intent) {
  32 + if (intent == null) return new ShareConfig();
  33 +
  34 + String title = intent.getStringExtra(Intent.EXTRA_TITLE);
  35 + String subTitle = intent.getStringExtra(Intent.EXTRA_TEXT);
  36 + String url = intent.getStringExtra(Intent.EXTRA_SUBJECT);
  37 + String type = intent.getStringExtra(ShareReleaseInfoUtil.SHARE_TYPE);
  38 + String image = intent.getStringExtra(ShareReleaseInfoUtil.SHARE_IMAGE);
  39 +
  40 + return new ShareConfig(title, subTitle, image, url, type);
  41 + }
  42 +
  43 + private ShareConfig() {
  44 +
  45 + }
  46 +
  47 + private ShareConfig(String title, String subTitle, String image, String url, String type) {
  48 + this.title = title;
  49 + this.subTitle = subTitle;
  50 + this.image = image;
  51 + this.url = url;
  52 + this.type = type;
  53 + }
  54 +
  55 + //分享标题
  56 + private String title = "";
  57 + //分享副标题
  58 + private String subTitle = "";
  59 + //分享图标
  60 + private String image = "";
  61 + //分享URL地址
  62 + private String url = "";
  63 + //分享类型
  64 + private String type = "";
  65 + //分享文件地址(通过输入流读取)
  66 + private Uri uri;
  67 +
  68 + public ShareReleaseInfoUtil build() {
  69 + return new ShareReleaseInfoUtil(this);
  70 + }
  71 +
  72 + public void shareSend(Context context) {
  73 + new ShareReleaseInfoUtil(this).share(context, ACTION_SHARE_SEND);
  74 + }
  75 +
  76 + public void shareRelease(Context context) {
  77 + new ShareReleaseInfoUtil(this).share(context, ACTION_SHARE_RELEASE);
  78 + }
  79 +
  80 + public String getTitle() {
  81 + return title;
  82 + }
  83 +
  84 + public ShareConfig setTitle(String title) {
  85 + this.title = title;
  86 + return this;
  87 + }
  88 +
  89 + public String getSubTitle() {
  90 + return subTitle;
  91 + }
  92 +
  93 + public ShareConfig setSubTitle(String subTitle) {
  94 + this.subTitle = subTitle;
  95 + return this;
  96 + }
  97 +
  98 + public String getImage() {
  99 + return image;
  100 + }
  101 +
  102 + public ShareConfig setImage(String image) {
  103 + this.image = image;
  104 + return this;
  105 + }
  106 +
  107 + public String getUrl() {
  108 + return url;
  109 + }
  110 +
  111 + public ShareConfig setUrl(String url) {
  112 + this.url = url;
  113 + return this;
  114 + }
  115 +
  116 + public String getType() {
  117 + return type;
  118 + }
  119 +
  120 + public ShareConfig setType(String type) {
  121 + this.type = type;
  122 + return this;
  123 + }
  124 +
  125 + public Uri getUri() {
  126 + return uri;
  127 + }
  128 +
  129 + public void setUri(Uri uri) {
  130 + this.uri = uri;
  131 + }
  132 + }
  133 +
  134 + private ShareReleaseInfoUtil(ShareConfig config) {
  135 + this.config = config;
  136 + }
  137 +
  138 + public void shareSend(Context context) {
  139 + share(context, ACTION_SHARE_SEND);
  140 + }
  141 +
  142 + public void shareRelease(Context context) {
  143 + share(context, ACTION_SHARE_RELEASE);
  144 + }
  145 +
  146 + public void share(Context context, String action) {
  147 + Intent intent = new Intent(action);
  148 + intent.setPackage(AppConfig.getAppPackeg());
  149 + intent.setType("text/plain");
  150 + intent.putExtra(Intent.EXTRA_TITLE, config.title);
  151 + intent.putExtra(Intent.EXTRA_TEXT, config.subTitle);
  152 + intent.putExtra(Intent.EXTRA_SUBJECT, config.url);
  153 + intent.putExtra(ShareReleaseInfoUtil.SHARE_TYPE, config.type);
  154 + intent.putExtra(ShareReleaseInfoUtil.SHARE_IMAGE, config.image);
  155 + context.startActivity(intent);
  156 + }
  157 +}
... ...
cloud/share/src/main/java/com/cnlive/share/model/ShareStateInfo.java 0 → 100644
  1 +package com.cnlive.share.model;
  2 +
  3 +/**
  4 + * 作者: 吴奎庆
  5 + * <p>
  6 + * 时间: 2019/10/23
  7 + * <p>
  8 + * 简介:
  9 + */
  10 +public class ShareStateInfo {
  11 +
  12 + // 1 网家家好友 2 网家家生活圈 3 微信好友 4 微信朋友圈 5 qq 6 微博 7 外部 8 举报 9 其他
  13 + String type;
  14 + //商城的分享的类型
  15 + String shopShareType;
  16 + //是否分享成功
  17 + boolean isShareSuccess;
  18 +
  19 + public String getType() {
  20 + return type;
  21 + }
  22 +
  23 + public void setType(String type) {
  24 + this.type = type;
  25 + }
  26 +
  27 + public String getShopShareType() {
  28 + return shopShareType;
  29 + }
  30 +
  31 + public void setShopShareType(String shopShareType) {
  32 + this.shopShareType = shopShareType;
  33 + }
  34 +
  35 + public boolean isShareSuccess() {
  36 + return isShareSuccess;
  37 + }
  38 +
  39 + public void setShareSuccess(boolean shareSuccess) {
  40 + isShareSuccess = shareSuccess;
  41 + }
  42 +
  43 +
  44 +
  45 +}
... ...
cloud/share/src/main/java/com/cnlive/share/model/ShortLinkInfo.java 0 → 100644
  1 +package com.cnlive.share.model;
  2 +
  3 +/**
  4 + * 作者: 吴奎庆
  5 + * <p>
  6 + * 时间: 2019/1/15
  7 + * <p>
  8 + * 简介: 长短链接切换的bena
  9 + */
  10 +public class ShortLinkInfo {
  11 + public String getShortUrl() {
  12 + return shortUrl;
  13 + }
  14 +
  15 + public void setShortUrl(String shortUrl) {
  16 + this.shortUrl = shortUrl;
  17 + }
  18 +
  19 + String shortUrl;
  20 +
  21 +}
... ...
cloud/share/src/main/java/com/cnlive/share/observable/ShareClickObservable.java 0 → 100644
  1 +package com.cnlive.share.observable;
  2 +
  3 +import java.util.Observable;
  4 +
  5 +/**
  6 + * 作者: 吴奎庆
  7 + * <p>
  8 + * 时间: 2019/9/25
  9 + * <p>
  10 + * 简介: 分享点击的观察者
  11 + */
  12 +public class ShareClickObservable extends Observable {
  13 +
  14 + private static ShareClickObservable instance;
  15 +
  16 + public static ShareClickObservable getInstance() {
  17 +
  18 + synchronized (ShareClickObservable.class) {
  19 + if (instance == null) {
  20 + instance = new ShareClickObservable();
  21 + }
  22 + }
  23 + return instance;
  24 + }
  25 +
  26 + /**
  27 + * @param type 1 网家家好友 2 网家家生活圈 3 微信好友 4 微信朋友圈 5 qq 6 微博 7 外部 8 举报
  28 + */
  29 + public void update(int type) {
  30 + setChanged();
  31 + notifyObservers(type);
  32 + }
  33 +
  34 +}
... ...
cloud/share/src/main/java/com/cnlive/share/observable/ShareStateObservable.java 0 → 100644
  1 +package com.cnlive.share.observable;
  2 +
  3 +import com.cnlive.share.model.ShareStateInfo;
  4 +
  5 +import java.util.Observable;
  6 +
  7 +/**
  8 + * 作者: 吴奎庆
  9 + * <p>
  10 + * 时间: 2019/10/23
  11 + * <p>
  12 + * 简介: 三方分享的状态回调
  13 + */
  14 +public class ShareStateObservable extends Observable {
  15 +
  16 + static ShareStateObservable instance;
  17 +
  18 + public static ShareStateObservable newInstance() {
  19 +
  20 + synchronized (ShareStateObservable.class) {
  21 + if (instance == null) {
  22 + instance = new ShareStateObservable();
  23 + }
  24 + }
  25 + return instance;
  26 + }
  27 +
  28 + /**
  29 + * 更新分享的状态
  30 + * @param info
  31 + */
  32 + public void update(ShareStateInfo info) {
  33 + setChanged();
  34 + notifyObservers(info);
  35 +
  36 + }
  37 +
  38 +
  39 +
  40 +}
... ...
cloud/share/src/main/java/com/cnlive/share/observable/ShareWjjStateObservable.java 0 → 100644
  1 +package com.cnlive.share.observable;
  2 +
  3 +import java.util.Observable;
  4 +
  5 +/**
  6 + * 作者: 吴奎庆
  7 + * <p>
  8 + * 时间: 2019/10/23
  9 + * <p>
  10 + * 简介: 网++分享成功的状态
  11 + */
  12 +public class ShareWjjStateObservable extends Observable {
  13 +
  14 + static ShareWjjStateObservable instance;
  15 +
  16 + public static ShareWjjStateObservable newInstance() {
  17 +
  18 + synchronized (ShareWjjStateObservable.class) {
  19 + if (instance == null) {
  20 + instance = new ShareWjjStateObservable();
  21 + }
  22 + return instance;
  23 + }
  24 + }
  25 +
  26 + public void update(boolean isSuccessed){
  27 + setChanged();
  28 + notifyObservers(isSuccessed);
  29 + }
  30 +}
... ...
cloud/share/src/main/java/com/cnlive/share/observable/WechatLoginObservable.java 0 → 100644
  1 +package com.cnlive.share.observable;
  2 +
  3 +import com.cnlive.share.data.WeChatInfo;
  4 +
  5 +import java.util.Observable;
  6 +
  7 +/**
  8 + * 作者: 吴奎庆
  9 + * <p>
  10 + * 时间: 2019/9/10
  11 + * <p>
  12 + * 简介: 微信三方登陆的观察者
  13 + *
  14 + */
  15 +public class WechatLoginObservable extends Observable {
  16 + static WechatLoginObservable wechatLoginObservable;
  17 +
  18 + public static WechatLoginObservable getInstance() {
  19 + if (wechatLoginObservable == null)
  20 + synchronized (WechatLoginObservable.class) {
  21 + if (wechatLoginObservable == null)
  22 + wechatLoginObservable = new WechatLoginObservable();
  23 + }
  24 + return wechatLoginObservable;
  25 + }
  26 +
  27 +
  28 + public void update(WeChatInfo wechatInfo) {
  29 + setChanged();
  30 + notifyObservers(wechatInfo);
  31 + }
  32 +
  33 +}
... ...
cloud/share/src/main/java/com/cnlive/share/observable/WechatShareObservable.java 0 → 100644
  1 +package com.cnlive.share.observable;
  2 +
  3 +import java.util.Observable;
  4 +
  5 +/**
  6 + * 作者: 吴奎庆
  7 + * <p>
  8 + * 时间: 2019/9/18
  9 + * <p>
  10 + * 简介: 微信分享完成
  11 + */
  12 +public class WechatShareObservable extends Observable {
  13 +
  14 + static WechatShareObservable wechatLoginObservable;
  15 +
  16 + public static WechatShareObservable getInstance() {
  17 + if (wechatLoginObservable == null)
  18 + synchronized (WechatLoginObservable.class) {
  19 + if (wechatLoginObservable == null)
  20 + wechatLoginObservable = new WechatShareObservable();
  21 + }
  22 + return wechatLoginObservable;
  23 + }
  24 +
  25 + /**
  26 + * 1 分享完成 2 取消 3 失败
  27 + * @param state
  28 + */
  29 + public void update(int state) {
  30 + setChanged();
  31 + notifyObservers(state);
  32 + }
  33 +
  34 +}
... ...
cloud/share/src/main/java/com/cnlive/share/ui/FullVideoShareView.java 0 → 100644
  1 +package com.cnlive.share.ui;
  2 +
  3 +import android.app.Activity;
  4 +import android.content.Context;
  5 +import android.text.TextUtils;
  6 +import android.util.AttributeSet;
  7 +import android.view.LayoutInflater;
  8 +import android.view.View;
  9 +import android.widget.RelativeLayout;
  10 +
  11 +import com.cnlive.core.libs.base.application.AppConfig;
  12 +import com.cnlive.share.R;
  13 +import com.cnlive.share.BR;
  14 +import com.cnlive.share.adapter.DataBindingAdapter;
  15 +import com.cnlive.share.data.FullVideoShareItemData;
  16 +import com.cnlive.share.data.ShareInfo;
  17 +import com.cnlive.share.databinding.LayoutFullVideoShareBinding;
  18 +import com.cnlive.share.model.ShareReleaseInfoUtil;
  19 +import com.cnlive.share.observable.ShareClickObservable;
  20 +import com.cnlive.share.util.ShareUtils;
  21 +import com.cnlive.share.util.Util;
  22 +
  23 +import java.util.ArrayList;
  24 +import java.util.List;
  25 +
  26 +import androidx.databinding.DataBindingUtil;
  27 +import androidx.recyclerview.widget.GridLayoutManager;
  28 +
  29 +/**
  30 + * 视频横屏状态下的分享视图
  31 + */
  32 +
  33 +public class FullVideoShareView extends RelativeLayout implements DataBindingAdapter.OnAdapterViewClickListener<FullVideoShareItemData> {
  34 + private LayoutFullVideoShareBinding binding;
  35 + private DataBindingAdapter<FullVideoShareItemData> adapter;
  36 + private FullVideoShareListener listener;
  37 + private ShareInfo shareInfo;
  38 + private ShareReleaseInfoUtil.ShareConfig config;
  39 + public static final String SHARE_TITLE = "快来加入中国网家家,优享美好生活!";
  40 + public static final String SHARE_CONTENT = "中国网家家 让生活更美好!";
  41 + public static final String SHARE_END = "";
  42 +
  43 + Context mContext;
  44 +
  45 + public FullVideoShareView(Context context) {
  46 + this(context, null);
  47 + }
  48 +
  49 + public FullVideoShareView(Context context, AttributeSet attrs) {
  50 + this(context, attrs, 0);
  51 + }
  52 +
  53 + public FullVideoShareView(Context context, AttributeSet attrs, int defStyleAttr) {
  54 + super(context, attrs, defStyleAttr);
  55 + init(context);
  56 + mContext = context;
  57 + }
  58 +
  59 + public void setListener(FullVideoShareListener listener) {
  60 + this.listener = listener;
  61 + }
  62 +
  63 + public void setData(String title, String des, String imageUrl, String shareUrl, String shareType, String contentId) {
  64 + shareInfo = new ShareInfo();
  65 +
  66 + shareUrl = TextUtils.isEmpty(shareUrl) ? AppConfig.getShareDownload() : shareUrl;
  67 + shareInfo.setUrl(shareUrl);
  68 +
  69 + title = TextUtils.isEmpty(title) ? SHARE_TITLE : title;
  70 + shareInfo.setTitle(title);
  71 +
  72 + des = TextUtils.isEmpty(des) ? SHARE_CONTENT : des;
  73 + shareInfo.setContent(des);
  74 +
  75 + imageUrl = TextUtils.isEmpty(imageUrl) ? AppConfig.getShareIcon() : imageUrl;
  76 + shareInfo.setImgurl(imageUrl);
  77 +
  78 + shareInfo.setContentId(contentId);
  79 + shareInfo.setShareType(shareType);
  80 + }
  81 +
  82 + public void updateShareUrl(String shareUrl) {
  83 + shareUrl = TextUtils.isEmpty(shareUrl) ? AppConfig.getShareDownload() : shareUrl;
  84 + shareInfo.setUrl(shareUrl);
  85 + }
  86 +
  87 + public void setPaddingRight(int paddingRight) {
  88 + binding.setPaddingRight(paddingRight);
  89 + }
  90 +
  91 + private void init(Context context) {
  92 + binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.layout_full_video_share, this, true);
  93 + binding.shareRecyclerView.setLayoutManager(new GridLayoutManager(context, 4));
  94 + binding.shareOutClickView.setOnClickListener(new OnClickListener() {
  95 + @Override
  96 + public void onClick(View v) {
  97 + setVisibility(GONE);
  98 + if (listener != null)
  99 + listener.onFullVideoShareDismiss();
  100 + }
  101 + });
  102 + binding.shareRightLayout.setOnClickListener(new OnClickListener() {
  103 + @Override
  104 + public void onClick(View v) {
  105 +
  106 + }
  107 + });
  108 +
  109 + List<FullVideoShareItemData> list = new ArrayList<>();
  110 + list.add(new FullVideoShareItemData(R.drawable.wjjhaoyou, "网家家好友", FullVideoShareItemData.TYPE_WJJ));
  111 + list.add(new FullVideoShareItemData(R.drawable.shenghuoquan, "生活圈", FullVideoShareItemData.TYPE_WJJ_QUAN));
  112 + list.add(new FullVideoShareItemData(R.drawable.pengyouquan, "朋友圈", FullVideoShareItemData.TYPE_PENG_YOU_QUAN));
  113 + list.add(new FullVideoShareItemData(R.drawable.wechat, "微信", FullVideoShareItemData.TYPE_WEIXIN));
  114 + list.add(new FullVideoShareItemData(R.drawable.qq, "QQ", FullVideoShareItemData.TYPE_QQ));
  115 + list.add(new FullVideoShareItemData(R.drawable.weibo, "微博", FullVideoShareItemData.TYPE_WEIBO));
  116 + list.add(new FullVideoShareItemData(R.drawable.browser, "浏览器", FullVideoShareItemData.TYPE_BROWSER));
  117 +
  118 + adapter = new DataBindingAdapter(context, R.layout.list_item_full_video_share, BR.data);
  119 + adapter.setOnViewClickListener(this);
  120 + adapter.updateItems(list);
  121 + binding.shareRecyclerView.setAdapter(adapter);
  122 +
  123 + }
  124 +
  125 + @Override
  126 + public void onViewClick(View v, FullVideoShareItemData program) {
  127 + if (shareInfo == null) return;
  128 + if (listener != null)
  129 + listener.onFullVideoShareDismiss();
  130 + setVisibility(GONE);
  131 + if (shareInfo.getUrl()==null || !Util.isNetUrl(shareInfo.getUrl())){
  132 + shareInfo.setUrl(AppConfig.getShareDownload());
  133 + }
  134 + switch (program.getType()) {
  135 + case FullVideoShareItemData.TYPE_BROWSER:
  136 + ShareUtils.startBrowser(getContext(), shareInfo.getUrl());
  137 + ShareClickObservable.getInstance().update(7);
  138 + break;
  139 + case FullVideoShareItemData.TYPE_QQ:
  140 + ShareUtils.shareQQ(shareInfo, (Activity) getContext());
  141 + ShareClickObservable.getInstance().update(1);
  142 + break;
  143 + case FullVideoShareItemData.TYPE_WEIXIN:
  144 + ShareUtils.shareWechat(shareInfo, getContext());
  145 + ShareClickObservable.getInstance().update(3);
  146 + break;
  147 + case FullVideoShareItemData.TYPE_PENG_YOU_QUAN:
  148 + ShareUtils.shareWCE(shareInfo, getContext());
  149 + ShareClickObservable.getInstance().update(4);
  150 + break;
  151 + case FullVideoShareItemData.TYPE_WJJ_QUAN:
  152 + ShareUtils.shareAppMoment(shareInfo, mContext);
  153 + ShareClickObservable.getInstance().update(2);
  154 + break;
  155 + case FullVideoShareItemData.TYPE_WJJ:
  156 + ShareUtils.shareAppIM(shareInfo, mContext);
  157 + ShareClickObservable.getInstance().update(1);
  158 + break;
  159 + case FullVideoShareItemData.TYPE_WEIBO:
  160 + ShareUtils.shareWeiBo((Activity) mContext,shareInfo);
  161 + ShareClickObservable.getInstance().update(6);
  162 + break;
  163 + }
  164 +
  165 + }
  166 +
  167 + public interface FullVideoShareListener {
  168 + void onFullVideoShareDismiss();
  169 + }
  170 +}
... ...
cloud/share/src/main/java/com/cnlive/share/ui/ShareActivity.java 0 → 100644
  1 +package com.cnlive.share.ui;
  2 +
  3 +import android.content.Intent;
  4 +import android.os.Bundle;
  5 +import android.text.TextUtils;
  6 +import android.view.View;
  7 +import android.view.ViewGroup;
  8 +import android.widget.LinearLayout;
  9 +
  10 +import com.alibaba.android.arouter.facade.annotation.Route;
  11 +import com.cnlive.core.libs.base.application.AppConfig;
  12 +import com.cnlive.core.libs.base.util.AlertUtil;
  13 +import com.cnlive.core.libs.base.util.DoublePressed;
  14 +import com.cnlive.core.libs.base.util.SharedPreferencesHelper;
  15 +import com.cnlive.share.R;
  16 +import com.cnlive.share.data.IconInfo;
  17 +import com.cnlive.share.data.ShareInfo;
  18 +import com.cnlive.share.observable.ShareClickObservable;
  19 +import com.cnlive.share.model.ShareStateInfo;
  20 +import com.cnlive.share.observable.ShareStateObservable;
  21 +import com.cnlive.share.observable.ShareWjjStateObservable;
  22 +import com.cnlive.share.observable.WechatShareObservable;
  23 +import com.cnlive.share.util.ShareOtherUtil;
  24 +import com.cnlive.share.util.ShareUtils;
  25 +import com.cnlive.share.util.Util;
  26 +import com.sina.weibo.sdk.share.WbShareCallback;
  27 +import com.sina.weibo.sdk.share.WbShareHandler;
  28 +import com.tencent.connect.common.Constants;
  29 +import com.tencent.tauth.IUiListener;
  30 +import com.tencent.tauth.Tencent;
  31 +import com.cnlive.share.BuildConfig;
  32 +import com.tencent.tauth.UiError;
  33 +
  34 +import java.util.ArrayList;
  35 +import java.util.List;
  36 +import java.util.Observer;
  37 +
  38 +import androidx.annotation.Nullable;
  39 +import androidx.appcompat.app.AppCompatActivity;
  40 +import androidx.recyclerview.widget.LinearLayoutManager;
  41 +import androidx.recyclerview.widget.RecyclerView;
  42 +
  43 +/**
  44 + * 作者: 吴奎庆
  45 + * <p>
  46 + * 时间: 2018/11/30
  47 + * <p>
  48 + * 简介:
  49 + */
  50 +
  51 +@Route(path = "/share/ShareActivity")
  52 +public class ShareActivity extends AppCompatActivity implements View.OnClickListener, ShareDialogListAdapter.ItemClick, IUiListener, WbShareCallback, Observer {
  53 + public static final String SHARE_TITLE = "快来加入中国网家家,优享美好生活!";
  54 + public static final String SHARE_CONTENT = "中国网家家 让生活更美好!";
  55 + private LinearLayout ll_cancle;
  56 + private ShareInfo info;
  57 + private RecyclerView shareRv;
  58 + private RecyclerView shareOther;
  59 + private ShareDialogListAdapter adapter;
  60 +
  61 +
  62 + private boolean isShowWjjLife;
  63 + private boolean isShowWjjFriend;
  64 + private boolean isShowOther;
  65 + private boolean isShowReport;
  66 + //是否打开eventbus 三方分享得通知
  67 + private boolean isOpenShareCallBackEentBus;
  68 +
  69 + private boolean showThirdPlatShare = true;
  70 + private WbShareHandler shareHandler;
  71 + private String shopShareType;
  72 +
  73 + @Override
  74 + protected void onCreate(@Nullable Bundle savedInstanceState) {
  75 + super.onCreate(savedInstanceState);
  76 + setContentView(R.layout.activity_share_dialog);
  77 + WechatShareObservable.getInstance().addObserver(this);
  78 + ShareWjjStateObservable.newInstance().addObserver(this);
  79 + getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
  80 + showThirdPlatShare = SharedPreferencesHelper.getInstance(this).getBoolean("SHOW_THIRD_PLAT_SHARE", true);
  81 + initView();
  82 + initData(getIntent());
  83 +
  84 + }
  85 +
  86 + private void initData(Intent intent) {
  87 + if (intent == null) {
  88 + AlertUtil.showDeftToast(this, "数据异常");
  89 + finish();
  90 + }
  91 + String title = getIntent().getStringExtra("title");
  92 + if (TextUtils.isEmpty(title)) title = SHARE_TITLE;
  93 + String subTitle = getIntent().getStringExtra("subTitle");
  94 + if (TextUtils.isEmpty(subTitle)) subTitle = SHARE_CONTENT;
  95 +
  96 + String shareUrl = getIntent().getStringExtra("shareUrl");
  97 + isOpenShareCallBackEentBus = getIntent().getBooleanExtra("isOpenEventBusCallBack", false);
  98 + if (TextUtils.isEmpty(shareUrl)) shareUrl = AppConfig.getShareDownload();
  99 + //拼接电商商品分享的相关参数
  100 + //// 商品分享类型 1:商品
  101 + shopShareType = getIntent().getStringExtra("shopShareType");
  102 +
  103 + String shareUrlImg = getIntent().getStringExtra("shareUrlImg");
  104 + if (TextUtils.isEmpty(shareUrlImg)) shareUrlImg = AppConfig.getShareIcon();
  105 +
  106 + String webpageUrl = getIntent().getStringExtra("webpageUrl");
  107 + String userName = getIntent().getStringExtra("userName");
  108 + String path = getIntent().getStringExtra("path");
  109 + int miniprogramType = getIntent().getIntExtra("miniprogramType", -1);
  110 +
  111 + String type = getIntent().getStringExtra("shareType");
  112 + String contentId = getIntent().getStringExtra("contentId");
  113 + String reportType = getIntent().getStringExtra("reportType");
  114 + //网家家分享区分外部内部时 内部用的url
  115 + String wjjShareUrl = getIntent().getStringExtra("wjjShareUrl");
  116 +
  117 + isShowWjjLife = getIntent().getBooleanExtra("isShowWjjLife", false);
  118 + isShowWjjFriend = getIntent().getBooleanExtra("isShowWjjFriend", false);
  119 + isShowOther = getIntent().getBooleanExtra("isShowOther", false);
  120 + isShowReport = getIntent().getBooleanExtra("isShowReport", false);
  121 +
  122 +
  123 + info = new ShareInfo();
  124 + info.setUrl(shareUrl);
  125 + info.setTitle(title);
  126 + info.setContent(subTitle);
  127 + info.setImgurl(shareUrlImg);
  128 + info.setShareType(type);
  129 + info.setContentId(contentId);
  130 +
  131 + if (!TextUtils.isEmpty(wjjShareUrl)) {
  132 + info.setProcessWjjShare(true);
  133 + info.setWjjShareUrl(wjjShareUrl);
  134 + }
  135 +
  136 + if (TextUtils.isEmpty(reportType)) reportType = "3";
  137 + info.setReportType(reportType);
  138 +
  139 + //小程序用的参数
  140 + info.setMiniprogramType(miniprogramType);
  141 + info.setPath(path);
  142 + info.setUserName(userName);
  143 + info.setWebpageUrl(webpageUrl);
  144 +
  145 + init();
  146 + }
  147 +
  148 + private void initView() {
  149 + shareRv = findViewById(R.id.share_rv);
  150 + shareOther = findViewById(R.id.share_other);
  151 + ll_cancle = findViewById(R.id.ll_cancle);
  152 + ll_cancle.setOnClickListener(this);
  153 + }
  154 +
  155 + private List<IconInfo> initList() {
  156 + //注册微博
  157 + if (Util.isWeiboInstallAndInit(this)) {
  158 + shareHandler = new WbShareHandler(this);
  159 + shareHandler.registerApp();
  160 + }
  161 + Tencent tencent = Tencent.createInstance(BuildConfig.QQ_SHARE, this.getApplicationContext());
  162 + List<IconInfo> list = new ArrayList<>();
  163 + if (isShowWjjFriend)
  164 + list.add(new IconInfo(IconInfo.WJJ_FRIEND, "网家家好友", R.drawable.wjjhaoyou));
  165 + if (isShowWjjLife)
  166 + list.add(new IconInfo(IconInfo.WJJ_CIRCLE, "网家家生活圈", R.drawable.shenghuoquan));
  167 +
  168 + if ((AppConfig.getShareDownload().equals(info.getUrl()))
  169 + || (info.getUrl().contains("wjjh5.cnlive.com") || info.getUrl().contains("wjjh5test.cnlive.com"))
  170 + || (!info.getUrl().contains("wjjh5.cnlive.com") && !info.getUrl().contains("wjjh5test.cnlive.com") && showThirdPlatShare)) {
  171 + list.add(new IconInfo(IconInfo.WECHAT_FRIEND, "微信好友", R.drawable.wechat));
  172 + list.add(new IconInfo(IconInfo.WECHAT_CIRCLE, "微信朋友圈", R.drawable.pengyouquan));
  173 + list.add(new IconInfo(IconInfo.QQ, "QQ好友", R.drawable.qq));
  174 + list.add(new IconInfo(IconInfo.WEBO, "微博", R.drawable.weibo));
  175 + }
  176 + if (isShowOther) list.add(new IconInfo(IconInfo.BROWSER, "在浏览器打开", R.drawable.browser));
  177 + return list;
  178 + }
  179 +
  180 + private List<IconInfo> initListOther() {
  181 + List<IconInfo> list = new ArrayList<>();
  182 + if (info != null && isShowReport)
  183 + list.add(new IconInfo(IconInfo.REPORT, "投诉", R.drawable.report_icon));
  184 + return list;
  185 + }
  186 +
  187 + private void init() {
  188 + adapter = new ShareDialogListAdapter(this, initList());
  189 + adapter.setItemClick(this);
  190 + LinearLayoutManager manager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
  191 + shareRv.setLayoutManager(manager);
  192 + shareRv.setAdapter(adapter);
  193 +
  194 + if (info != null && isShowReport) {
  195 + shareOther.setVisibility(View.VISIBLE);
  196 + findViewById(R.id.line).setVisibility(View.VISIBLE);
  197 + ShareDialogListAdapter adapterOther = new ShareDialogListAdapter(this, initListOther());
  198 + adapterOther.setItemClick(this);
  199 + LinearLayoutManager layoutManagerOther = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
  200 + shareOther.setLayoutManager(layoutManagerOther);
  201 + shareOther.setAdapter(adapterOther);
  202 + }
  203 +
  204 + }
  205 +
  206 + @Override
  207 + public void onClick(View v) {
  208 + int i = v.getId();
  209 + if (i == R.id.ll_cancle) {
  210 + finish();
  211 + }
  212 + }
  213 +
  214 + @Override
  215 + protected void onRestart() {
  216 + super.onRestart();
  217 + }
  218 +
  219 + @Override
  220 + public void onItemClick(int position, String type) {
  221 + if (info.getUrl() == null || !Util.isNetUrl(info.getUrl())) {
  222 + info.setUrl(AppConfig.getShareDownload());
  223 + }
  224 + if (DoublePressed.onDoublePressed(false, 1000L)) return;
  225 + switch (type) {
  226 + case IconInfo.WJJ_FRIEND:
  227 + ShareUtils.shareAppIM(info, this);
  228 + ShareClickObservable.getInstance().update(1);
  229 +// finish();
  230 + break;
  231 + case IconInfo.WJJ_CIRCLE:
  232 + ShareUtils.shareAppMoment(info, this);
  233 + ShareClickObservable.getInstance().update(2);
  234 +// finish();
  235 + break;
  236 + case IconInfo.WECHAT_FRIEND:
  237 + if (!TextUtils.isEmpty(info.getPath()) && !TextUtils.isEmpty(info.getUserName()) && !TextUtils.isEmpty(info.getWebpageUrl()) && info.getMiniprogramType() != -1) {
  238 + ShareUtils.shareWechatApplet(this, info);
  239 + ShareClickObservable.getInstance().update(3);
  240 + } else {
  241 + ShareUtils.shareWechat(info, this);
  242 + }
  243 +
  244 + break;
  245 + case IconInfo.WECHAT_CIRCLE:
  246 + ShareUtils.shareWCE(info, this);
  247 + ShareClickObservable.getInstance().update(3);
  248 + break;
  249 + case IconInfo.QQ:
  250 + ShareUtils.shareQQActivity(info, this, this);
  251 + ShareClickObservable.getInstance().update(5);
  252 + break;
  253 + case IconInfo.WEBO:
  254 + ShareUtils.shareWeiBo(this, info);
  255 + ShareClickObservable.getInstance().update(6);
  256 + break;
  257 + case IconInfo.BROWSER:
  258 + ShareUtils.startBrowser(this, info.getUrl());
  259 + ShareClickObservable.getInstance().update(7);
  260 + finish();
  261 + break;
  262 + case IconInfo.REPORT:
  263 + if (info != null && !TextUtils.isEmpty(info.getContentId())) {
  264 + ShareOtherUtil.report(this, info.getContentId(), info.getReportType());
  265 + ShareClickObservable.getInstance().update(8);
  266 + } else {
  267 + AlertUtil.showDeftToast(this, "数据异常");
  268 + }
  269 + finish();
  270 + break;
  271 + }
  272 + }
  273 +
  274 + @Override
  275 + public void finish() {
  276 + super.finish();
  277 + overridePendingTransition(R.anim.share_activity_in, R.anim.share_activity_out);
  278 + }
  279 +
  280 + @Override
  281 + protected void onDestroy() {
  282 + super.onDestroy();
  283 + WechatShareObservable.getInstance().deleteObserver(this);
  284 + ShareWjjStateObservable.newInstance().deleteObserver(this);
  285 + }
  286 +
  287 + public void showMessage(String msg) {
  288 + AlertUtil.showDeftToast(this, msg);
  289 + }
  290 +
  291 + @Override
  292 + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
  293 + super.onActivityResult(requestCode, resultCode, data);
  294 + if (shareHandler != null) shareHandler.doResultIntent(data, this);
  295 + // 官方文档没这句代码, 但是很很很重要, 不然不会回调!
  296 + Tencent.onActivityResultData(requestCode, resultCode, data, this);
  297 + if (requestCode == Constants.REQUEST_API) {
  298 + if (resultCode == Constants.REQUEST_QQ_SHARE ||
  299 + resultCode == Constants.REQUEST_QZONE_SHARE ||
  300 + resultCode == Constants.REQUEST_OLD_SHARE) {
  301 + Tencent.handleResultData(data, this);
  302 + }
  303 + }
  304 + }
  305 +
  306 + @Override
  307 + public void onComplete(Object o) {
  308 + if (isOpenShareCallBackEentBus) {
  309 + shopCallback("5", true);
  310 + } else {
  311 + ShareUtils.processQQCallBack(this, info.getShareType(), info.getContentId());
  312 + showMessage("分享成功");
  313 + }
  314 + finish();
  315 + }
  316 +
  317 + @Override
  318 + public void onError(UiError uiError) {
  319 + if (isOpenShareCallBackEentBus) {
  320 + shopCallback("5", false);
  321 + } else {
  322 + showMessage("分享失败");
  323 + }
  324 + finish();
  325 + }
  326 +
  327 + @Override
  328 + public void onCancel() {
  329 + if (isOpenShareCallBackEentBus) {
  330 + shopCallback("5", false);
  331 + } else {
  332 + showMessage("分享取消");
  333 + }
  334 + finish();
  335 + }
  336 +
  337 + @Override
  338 + public void onWbShareSuccess() {
  339 + if (isOpenShareCallBackEentBus) {
  340 + shopCallback("6", true);
  341 + } else {
  342 + showMessage("分享成功");
  343 + }
  344 + finish();
  345 + }
  346 +
  347 + @Override
  348 + public void onWbShareCancel() {
  349 + if (isOpenShareCallBackEentBus) {
  350 + shopCallback("6", false);
  351 + } else {
  352 + showMessage("分享取消");
  353 + }
  354 + finish();
  355 + }
  356 +
  357 + @Override
  358 + public void onWbShareFail() {
  359 + if (isOpenShareCallBackEentBus) {
  360 + shopCallback("6", false);
  361 + } else {
  362 + showMessage("分享失败");
  363 + }
  364 + finish();
  365 + }
  366 +
  367 + private void shopCallback(String type, boolean isSuccess) {
  368 + if (isOpenShareCallBackEentBus) {
  369 + Intent intent = new Intent();
  370 + intent.putExtra("shopShareType", shopShareType);
  371 + intent.putExtra("isShareSuccess", isSuccess);
  372 + setResult(10010, intent);
  373 +
  374 + ShareStateInfo info = new ShareStateInfo();
  375 + info.setShareSuccess(isSuccess);
  376 + info.setShopShareType(shopShareType);
  377 + info.setType(type);
  378 + ShareStateObservable.newInstance().update(info);
  379 + }
  380 +
  381 + }
  382 +
  383 + @Override
  384 + public void update(java.util.Observable observable, Object o) {
  385 + if (observable instanceof WechatShareObservable && o != null) {
  386 + int state = (int) o;
  387 + if (1 == state) {
  388 + //成功
  389 + shopCallback("3", true);
  390 + } else if (2 == state) {
  391 + //取消
  392 + if (isOpenShareCallBackEentBus) {
  393 + shopCallback("3", false);
  394 + }
  395 + } else if (3 == state) {
  396 + //失败
  397 + shopCallback("3", false);
  398 + } else {
  399 + //其他
  400 + shopCallback("3", false);
  401 + }
  402 + finish();
  403 + } else if (observable instanceof ShareWjjStateObservable && o != null) {
  404 + boolean isSuccess= (boolean) o;
  405 + if (isSuccess){
  406 + shopCallback("1", true);
  407 + }else {
  408 + shopCallback("1", false);
  409 + }
  410 + finish();
  411 + }
  412 + }
  413 +}
... ...
cloud/share/src/main/java/com/cnlive/share/ui/ShareDialogListAdapter.java 0 → 100644
  1 +package com.cnlive.share.ui;
  2 +
  3 +import android.content.Context;
  4 +import android.view.LayoutInflater;
  5 +import android.view.View;
  6 +import android.view.ViewGroup;
  7 +import android.widget.ImageView;
  8 +import android.widget.TextView;
  9 +
  10 +import com.cnlive.share.R;
  11 +import com.cnlive.share.data.IconInfo;
  12 +
  13 +import java.util.List;
  14 +
  15 +import androidx.annotation.NonNull;
  16 +import androidx.recyclerview.widget.RecyclerView;
  17 +
  18 +/**
  19 + * Created by Lynn on 2018/8/23.
  20 + */
  21 +
  22 +public class ShareDialogListAdapter extends RecyclerView.Adapter<ShareDialogListAdapter.ShareDialogViewHolder> {
  23 + private Context context;
  24 + private List<IconInfo> data;
  25 + private ItemClick itemClick;
  26 +
  27 + public ShareDialogListAdapter(Context context, List<IconInfo> data) {
  28 + this.data = data;
  29 + this.context = context;
  30 + }
  31 +
  32 + public void setItemClick(ItemClick itemClick) {
  33 + this.itemClick = itemClick;
  34 + }
  35 +
  36 + @NonNull
  37 + @Override
  38 + public ShareDialogListAdapter.ShareDialogViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
  39 + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.share_dialog_item, parent, false);
  40 + ShareDialogViewHolder holder = new ShareDialogViewHolder(view);
  41 + return holder;
  42 + }
  43 +
  44 + @Override
  45 + public void onBindViewHolder(@NonNull ShareDialogListAdapter.ShareDialogViewHolder holder, final int position) {
  46 + holder.name.setText(data.get(position).getTitle());
  47 + holder.icon.setImageResource(data.get(position).getIcon());
  48 + holder.itemView.setOnClickListener(new View.OnClickListener() {
  49 + @Override
  50 + public void onClick(View v) {
  51 + if (itemClick != null) {
  52 + itemClick.onItemClick(position, data.get(position).getId());
  53 + }
  54 + }
  55 + });
  56 + }
  57 +
  58 + @Override
  59 + public int getItemCount() {
  60 + return data.size();
  61 + }
  62 +
  63 + public void updateItems(List<IconInfo> newData) {
  64 + if (data != null) {
  65 + data.clear();
  66 + data.addAll(newData);
  67 + notifyDataSetChanged();
  68 + }
  69 + }
  70 +
  71 + class ShareDialogViewHolder extends RecyclerView.ViewHolder {
  72 + public TextView name;
  73 + public ImageView icon;
  74 +
  75 + public ShareDialogViewHolder(View itemView) {
  76 + super(itemView);
  77 + name = itemView.findViewById(R.id.name);
  78 + icon = itemView.findViewById(R.id.icon);
  79 + }
  80 + }
  81 +
  82 + public interface ItemClick {
  83 + void onItemClick(int position, String type);
  84 + }
  85 +}
... ...
cloud/share/src/main/java/com/cnlive/share/ui/ShareImgActivity.java 0 → 100644
  1 +package com.cnlive.share.ui;
  2 +
  3 +
  4 +import android.content.Context;
  5 +import android.content.Intent;
  6 +import android.content.SharedPreferences;
  7 +import android.graphics.Bitmap;
  8 +import android.graphics.BitmapFactory;
  9 +import android.net.Uri;
  10 +import android.os.Build;
  11 +import android.os.Bundle;
  12 +import android.os.Environment;
  13 +import android.util.Base64;
  14 +import android.view.ViewGroup;
  15 +import android.widget.LinearLayout;
  16 +
  17 +import com.alibaba.android.arouter.facade.annotation.Route;
  18 +import com.cnlive.core.libs.base.util.AlertUtil;
  19 +import com.cnlive.core.libs.base.util.DoublePressed;
  20 +import com.cnlive.share.BuildConfig;
  21 +import com.cnlive.share.R;
  22 +import com.cnlive.share.data.IconInfo;
  23 +import com.cnlive.share.observable.ShareClickObservable;
  24 +import com.cnlive.share.util.ShareUtils;
  25 +import com.cnlive.share.util.Util;
  26 +import com.cnlive.strike.user.auth.UserService;
  27 +import com.sina.weibo.sdk.share.WbShareCallback;
  28 +import com.sina.weibo.sdk.share.WbShareHandler;
  29 +import com.tencent.connect.common.Constants;
  30 +import com.tencent.tauth.IUiListener;
  31 +import com.tencent.tauth.Tencent;
  32 +import com.tencent.tauth.UiError;
  33 +
  34 +import java.io.File;
  35 +import java.io.FileOutputStream;
  36 +import java.io.IOException;
  37 +import java.text.SimpleDateFormat;
  38 +import java.util.ArrayList;
  39 +import java.util.Date;
  40 +import java.util.List;
  41 +
  42 +import androidx.annotation.Nullable;
  43 +import androidx.appcompat.app.AppCompatActivity;
  44 +import androidx.recyclerview.widget.LinearLayoutManager;
  45 +import androidx.recyclerview.widget.RecyclerView;
  46 +
  47 +/**
  48 + * Created by hanyayun 019/06/18.
  49 + */
  50 +@Route(path = "/share/ShareImgActivity")
  51 +public class ShareImgActivity extends AppCompatActivity implements ShareDialogListAdapter.ItemClick, IUiListener, WbShareCallback {
  52 + private RecyclerView shareRv;
  53 + private LinearLayout cancle;
  54 + private ShareDialogListAdapter adapter;
  55 + private Bitmap bitmap;
  56 + private File file;
  57 + private String fileName;
  58 + private boolean isShowWjjLife;
  59 + private boolean isShowWjjFriend;
  60 + private boolean isShowOther;
  61 + private boolean isShowReport;
  62 + private boolean isShowQQ;
  63 + private boolean isShowWB;
  64 + private boolean isShowWC;
  65 + private boolean isShowSave;
  66 + private WbShareHandler shareHandler;
  67 +
  68 + @Override
  69 + protected void onCreate(Bundle savedInstanceState) {
  70 + super.onCreate(savedInstanceState);
  71 + setContentView(R.layout.activity_share_img);
  72 + getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
  73 + isShowWjjLife = getIntent().getBooleanExtra("isShowWjjLife", true);
  74 + isShowWjjFriend = getIntent().getBooleanExtra("isShowWjjFriend", true);
  75 + isShowOther = getIntent().getBooleanExtra("isShowOther", true);
  76 + isShowReport = getIntent().getBooleanExtra("isShowReport", true);
  77 + isShowQQ = getIntent().getBooleanExtra("isShowReport", true);
  78 + isShowWB = getIntent().getBooleanExtra("isShowReport", true);
  79 + isShowWC = getIntent().getBooleanExtra("isShowReport", true);
  80 + isShowSave = getIntent().getBooleanExtra("isShowReport", true);
  81 + initView();
  82 + initList();
  83 + }
  84 +
  85 + private void initView() {
  86 + shareRv = findViewById(R.id.share_img_rv);
  87 + cancle = findViewById(R.id.ll_img_cancle);
  88 + findViewById(R.id.ry_share).setOnClickListener(v -> finish());
  89 + cancle.setOnClickListener(v -> finish());
  90 + }
  91 +
  92 + private void initList() {
  93 + if (getIntent().getStringExtra("fileName") != null)
  94 + fileName = UserService.getUid(this) + getIntent().getStringExtra("fileName");
  95 + SharedPreferences sp = this.getSharedPreferences("sp", Context.MODE_PRIVATE);
  96 + String bt = sp.getString("share_img_string", "");
  97 + bitmap = convertStringToIcon(bt);
  98 + List<IconInfo> list = new ArrayList<>();
  99 + if (isShowWjjFriend)
  100 + list.add(new IconInfo(IconInfo.WJJ_FRIEND, "网家家好友", R.drawable.wjjhaoyou));
  101 + if (isShowWjjLife)
  102 + list.add(new IconInfo(IconInfo.WJJ_CIRCLE, "生活圈", R.drawable.shenghuoquan));
  103 + if (isShowWC) {
  104 + list.add(new IconInfo(IconInfo.WECHAT_FRIEND, "微信好友", R.drawable.wechat));
  105 + list.add(new IconInfo(IconInfo.WECHAT_CIRCLE, "微信朋友圈", R.drawable.pengyouquan));
  106 + }
  107 + if (isShowWB) {
  108 + //注册微博
  109 + if (Util.isWeiboInstallAndInit(this)) {
  110 + shareHandler = new WbShareHandler(this);
  111 + shareHandler.registerApp();
  112 + }
  113 + list.add(new IconInfo(IconInfo.WEBO, "微博", R.drawable.weibo));
  114 + }
  115 + if (isShowQQ) {
  116 + Tencent tencent = Tencent.createInstance(BuildConfig.QQ_SHARE, this.getApplicationContext());
  117 + list.add(new IconInfo(IconInfo.QQ, "QQ好友", R.drawable.qq));
  118 + }
  119 + if (isShowSave)
  120 + list.add(new IconInfo(IconInfo.DOWNLOAD_ALBUM_IMG, "保存到相册", R.drawable.download_album));
  121 +
  122 +
  123 + adapter = new ShareDialogListAdapter(this, list);
  124 + adapter.setItemClick(this);
  125 + LinearLayoutManager manager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
  126 + shareRv.setLayoutManager(manager);
  127 + shareRv.setAdapter(adapter);
  128 + }
  129 +
  130 +
  131 + /**
  132 + * string转成bitmap
  133 + *
  134 + * @param str
  135 + */
  136 + public static Bitmap convertStringToIcon(String str) {
  137 + Bitmap bitmap = null;
  138 + try {
  139 + byte[] bitmapArray;
  140 + bitmapArray = Base64.decode(str, Base64.DEFAULT);
  141 + bitmap =
  142 + BitmapFactory.decodeByteArray(bitmapArray, 0,
  143 + bitmapArray.length);
  144 + return bitmap;
  145 + } catch (Exception e) {
  146 + return null;
  147 + }
  148 + }
  149 +
  150 +
  151 + @Override
  152 + public void onItemClick(int position, String type) {
  153 + if (DoublePressed.onDoublePressed(false, 1000L)) return;
  154 + switch (type) {
  155 + case IconInfo.WJJ_FRIEND:
  156 + if (saveImageToGallery(bitmap, file, "friends") == null)
  157 + AlertUtil.showDeftToast(this, "图片异常");
  158 + break;
  159 + case IconInfo.WJJ_CIRCLE:
  160 + if (saveImageToGallery(bitmap, file, "life") == null)
  161 + AlertUtil.showDeftToast(this, "图片异常");
  162 + break;
  163 + case IconInfo.WECHAT_FRIEND:
  164 + ShareUtils.shareWechatPic(this, bitmap, true);
  165 + finish();
  166 + break;
  167 +
  168 +
  169 + case IconInfo.QQ:
  170 + File shareFile;
  171 + if(file != null){
  172 + shareFile = file;
  173 + }else {
  174 + shareFile = saveImageToGallery(bitmap, null, "");
  175 + if(shareFile == null) {
  176 + AlertUtil.showDeftToast(this, "图片异常");
  177 + return;
  178 + }
  179 + }
  180 + //图片地址 根据文件去getPath或者其余方法进行分享
  181 + if (shareFile.exists()){
  182 + if (shareFile.length()<=5*1024*1024){
  183 + ShareUtils.showQQPic(shareFile, this);
  184 + ShareClickObservable.getInstance().update(5);
  185 + }else {
  186 + showMessage("图片超过");
  187 + }
  188 + }else {
  189 + showMessage("图片异常");
  190 + }
  191 + break;
  192 + case IconInfo.WEBO:
  193 + if (bitmap!=null){
  194 + ShareUtils.shareWbPic(this, bitmap);
  195 + ShareClickObservable.getInstance().update(6);
  196 + }else {
  197 + showMessage("图片异常");
  198 + }
  199 + break;
  200 +
  201 +
  202 + case IconInfo.WECHAT_CIRCLE:
  203 + ShareUtils.shareWechatPic(this, bitmap, false);
  204 + finish();
  205 + break;
  206 + case IconInfo.DOWNLOAD_ALBUM_IMG:
  207 + if (saveImageToGallery(bitmap, file, "send") == null) {
  208 + AlertUtil.showDeftToast(this, "保存失败,请重新点击下载");
  209 + } else {
  210 + AlertUtil.showDeftToast(this, "保存成功");
  211 + finish();
  212 + }
  213 + break;
  214 + }
  215 + }
  216 +
  217 +
  218 + public File saveImageToGallery(Bitmap bmp, File file, String type) {
  219 + //生成路径
  220 + if (file != null) {
  221 + if (type.equals("friends")) {
  222 + ShareUtils.getForwardingImgPath(ShareImgActivity.this, type, file.getPath());
  223 + } else if (type.equals("life")) {
  224 + ShareUtils.getForwardingImgPath(ShareImgActivity.this, type, file.getPath());
  225 + } else {
  226 + sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(file.getPath()))));
  227 + }
  228 + return file;
  229 + }
  230 + String root = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q ? getExternalFilesDir(Environment.DIRECTORY_PICTURES)+"" :Environment.getExternalStorageDirectory().getAbsolutePath();
  231 + String dirName = "erweimaWjj";
  232 + File appDir = new File(root, dirName);
  233 + if (!appDir.exists()) {
  234 + appDir.mkdirs();
  235 + }
  236 +
  237 + //文件名
  238 + String fileNames = "";
  239 + if (fileName != null) {
  240 + fileNames = fileName + ".jpg";
  241 + if (new File(appDir, fileNames).exists()) new File(appDir, fileNames).delete();
  242 + } else {
  243 + long timeStamp = System.currentTimeMillis();
  244 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  245 + String sd = sdf.format(new Date(timeStamp));
  246 + fileNames = sd + ".jpg";
  247 + }
  248 + //获取文件
  249 + file = new File(appDir, fileNames);
  250 + FileOutputStream fos = null;
  251 + try {
  252 + fos = new FileOutputStream(file);
  253 + bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos);
  254 + fos.flush();
  255 + //通知系统相册刷新
  256 + if (type.equals("friends")) {
  257 + ShareUtils.getForwardingImgPath(ShareImgActivity.this, type, file.getPath());
  258 + } else if (type.equals("life")) {
  259 + ShareUtils.getForwardingImgPath(ShareImgActivity.this, type, file.getPath());
  260 + } else {
  261 + sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(file.getPath()))));
  262 + }
  263 + return file;
  264 + } catch (Exception e) {
  265 + e.printStackTrace();
  266 + }finally {
  267 + try {
  268 + if (fos != null) {
  269 + fos.close();
  270 + }
  271 + } catch (IOException e) {
  272 + e.printStackTrace();
  273 + }
  274 + }
  275 + return null;
  276 + }
  277 +
  278 + @Override
  279 + protected void onRestart() {
  280 + super.onRestart();
  281 + }
  282 +
  283 + @Override
  284 + public void finish() {
  285 + super.finish();
  286 + overridePendingTransition(R.anim.share_activity_in, R.anim.share_activity_out);
  287 + }
  288 +
  289 + @Override
  290 + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
  291 + super.onActivityResult(requestCode, resultCode, data);
  292 + if (shareHandler != null) shareHandler.doResultIntent(data, this);
  293 + // 官方文档没这句代码, 但是很很很重要, 不然不会回调!
  294 + Tencent.onActivityResultData(requestCode, resultCode, data, this);
  295 + if (requestCode == Constants.REQUEST_QQ_SHARE) {
  296 + Tencent.handleResultData(data, this);
  297 + }
  298 + }
  299 +
  300 + public void showMessage(String msg) {
  301 + AlertUtil.showDeftToast(this, msg);
  302 + }
  303 +
  304 + @Override
  305 + public void onComplete(Object o) {
  306 + showMessage("分享成功");
  307 + finish();
  308 + }
  309 +
  310 + @Override
  311 + public void onError(UiError uiError) {
  312 + showMessage("分享失败");
  313 + }
  314 +
  315 + @Override
  316 + public void onCancel() {
  317 + showMessage("分享取消");
  318 + }
  319 +
  320 + @Override
  321 + public void onWbShareSuccess() {
  322 + showMessage("分享成功");
  323 + finish();
  324 + }
  325 +
  326 + @Override
  327 + public void onWbShareCancel() {
  328 + showMessage("分享取消");
  329 + }
  330 +
  331 + @Override
  332 + public void onWbShareFail() {
  333 + showMessage("分享失败");
  334 + }
  335 +}
... ...
cloud/share/src/main/java/com/cnlive/share/ui/WechatAppletActivity.java 0 → 100644
  1 +package com.cnlive.share.ui;
  2 +
  3 +import android.app.Activity;
  4 +import android.content.res.Resources;
  5 +import android.graphics.Bitmap;
  6 +import android.graphics.BitmapFactory;
  7 +import android.os.Bundle;
  8 +import android.text.TextUtils;
  9 +
  10 +import com.alibaba.android.arouter.facade.annotation.Route;
  11 +import com.bumptech.glide.Glide;
  12 +import com.bumptech.glide.request.RequestOptions;
  13 +import com.cnlive.core.libs.base.application.AppConfig;
  14 +import com.cnlive.share.BuildConfig;
  15 +import com.cnlive.share.R;
  16 +import com.cnlive.share.util.Util;
  17 +import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
  18 +import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
  19 +import com.tencent.mm.opensdk.modelmsg.WXMiniProgramObject;
  20 +import com.tencent.mm.opensdk.openapi.IWXAPI;
  21 +import com.tencent.mm.opensdk.openapi.WXAPIFactory;
  22 +
  23 +import java.util.concurrent.TimeUnit;
  24 +
  25 +
  26 +/**
  27 + * 作者: 吴奎庆
  28 + * <p>
  29 + * 时间: 2019/3/20
  30 + * <p>
  31 + * 简介:
  32 + */
  33 +@Route(path = "/share/WechatAppletActivity")
  34 +public class WechatAppletActivity extends Activity {
  35 +
  36 + private String webpageUrl;
  37 + private int miniprogramType;
  38 + private String userName;
  39 + private String path;
  40 + private String title;
  41 + private String description;
  42 +
  43 + @Override
  44 + protected void onCreate(Bundle savedInstanceState) {
  45 + super.onCreate(savedInstanceState);
  46 + webpageUrl = getIntent().getStringExtra("webpageUrl");
  47 + miniprogramType = getIntent().getIntExtra("miniprogramType", -1);
  48 + userName = getIntent().getStringExtra("userName");
  49 + path = getIntent().getStringExtra("path");
  50 + title = getIntent().getStringExtra("title");
  51 + description = getIntent().getStringExtra("description");
  52 + String shareImgUrl = getIntent().getStringExtra("shareImgUrl");
  53 +
  54 + if (TextUtils.isEmpty(shareImgUrl)) shareImgUrl = AppConfig.getShareIcon();
  55 + processImgUrlData(shareImgUrl);
  56 + }
  57 +
  58 + private void processImgUrlData(String imgUrl) {
  59 + new Thread(new Runnable() {
  60 + @Override
  61 + public void run() {
  62 + try {
  63 + Bitmap bitmap = Glide.with(WechatAppletActivity.this)
  64 + .setDefaultRequestOptions(new RequestOptions().centerCrop())
  65 + .asBitmap()
  66 + .load(imgUrl)
  67 + .into(120, 120)
  68 + .get(2, TimeUnit.SECONDS);
  69 + if (bitmap == null) {
  70 + Resources res = getResources();
  71 + Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.share_logo_share_module);
  72 + Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 120, 120, true);
  73 + shareWechatApplet(thumbBmp);
  74 + return;
  75 + }
  76 + shareWechatApplet(bitmap);
  77 + } catch (Exception e) {
  78 + Resources res = getResources();
  79 + Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.share_logo_share_module);
  80 + Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 120, 120, true);
  81 + shareWechatApplet(thumbBmp);
  82 + }
  83 +
  84 + }
  85 + }).start();
  86 + }
  87 +
  88 + private void shareWechatApplet(Bitmap thumbBmp) {
  89 + IWXAPI api = WXAPIFactory.createWXAPI(this, BuildConfig.WECHAT_SHARE);
  90 + WXMiniProgramObject miniProgramObj = new WXMiniProgramObject();
  91 + miniProgramObj.webpageUrl = webpageUrl; // 兼容低版本的网页链接
  92 + miniProgramObj.miniprogramType = miniprogramType;// 正式版:0,测试版:1,体验版:2
  93 + miniProgramObj.userName = userName; // 小程序原始id
  94 + miniProgramObj.path = path; //小程序页面路径
  95 + WXMediaMessage msg = new WXMediaMessage(miniProgramObj);
  96 + msg.title = title; // 小程序消息title
  97 + msg.description = description; // 小程序消息desc
  98 + msg.thumbData = Util.bmpToByteArray(thumbBmp, true); // 小程序消息封面图片,小于128k
  99 +
  100 + SendMessageToWX.Req req = new SendMessageToWX.Req();
  101 + req.transaction = Util.buildTransaction("miniProgram");
  102 + req.message = msg;
  103 + req.scene = SendMessageToWX.Req.WXSceneSession; // 目前只支持会话
  104 + api.sendReq(req);
  105 + finish();
  106 + }
  107 +}
... ...
cloud/share/src/main/java/com/cnlive/share/ui/dialog/ShareDialog.java 0 → 100644
  1 +package com.cnlive.share.ui.dialog;
  2 +
  3 +
  4 +import android.app.Activity;
  5 +import android.app.Dialog;
  6 +import android.os.Bundle;
  7 +import android.text.TextUtils;
  8 +import android.util.DisplayMetrics;
  9 +import android.view.View;
  10 +import android.view.ViewGroup;
  11 +import android.view.Window;
  12 +import android.view.WindowManager;
  13 +import android.widget.LinearLayout;
  14 +
  15 +import com.cnlive.core.libs.base.application.AppConfig;
  16 +import com.cnlive.core.libs.base.util.AlertUtil;
  17 +import com.cnlive.core.libs.base.util.SharedPreferencesHelper;
  18 +import com.cnlive.share.R;
  19 +import com.cnlive.share.data.IconInfo;
  20 +import com.cnlive.share.data.ShareInfo;
  21 +import com.cnlive.share.model.ShareReleaseInfoUtil;
  22 +import com.cnlive.share.observable.ShareClickObservable;
  23 +import com.cnlive.share.ui.ShareDialogListAdapter;
  24 +import com.cnlive.share.util.ShareOtherUtil;
  25 +import com.cnlive.share.util.ShareUtils;
  26 +import com.cnlive.share.util.Util;
  27 +
  28 +import java.util.ArrayList;
  29 +import java.util.List;
  30 +
  31 +import androidx.annotation.NonNull;
  32 +import androidx.recyclerview.widget.LinearLayoutManager;
  33 +import androidx.recyclerview.widget.RecyclerView;
  34 +
  35 +/**
  36 + * 创建:wukuiqing
  37 + * <p>
  38 + * 时间:2017/10/11A
  39 + * <p>
  40 + * 描述:分享的dialog
  41 + */
  42 +
  43 +public class ShareDialog extends Dialog implements View.OnClickListener, ShareDialogListAdapter.ItemClick {
  44 +
  45 + private Activity mContext;
  46 + private LinearLayout ll_cancle;
  47 + private ShareInfo info;
  48 + private RecyclerView shareRv;
  49 + private RecyclerView shareOther;
  50 +
  51 + private ShareDialogListAdapter adapter;
  52 + private boolean showOther;
  53 + private boolean showWjj;
  54 +
  55 + private ShareReleaseInfoUtil.ShareConfig config;
  56 +
  57 + public static final String SHARE_TITLE = "快来加入中国网家家,优享美好生活!";
  58 + public static final String SHARE_MOMENT = "生活圈内容";
  59 + public static final String SHARE_CONTENT = "中国网家家 让生活更美好!";
  60 + public static final String SHARE_END = "";
  61 + private ShareDialogListAdapter adapterOther;
  62 + private boolean showThirdPlatShare = true;
  63 +
  64 +
  65 + public static boolean checkEndTag(String str) {
  66 + return !TextUtils.isEmpty(str) && !TextUtils.isEmpty(SHARE_END) && str.endsWith(SHARE_END);
  67 + }
  68 +
  69 + public ShareDialog(@NonNull Activity context) {
  70 + this(context, true, true);
  71 + }
  72 +
  73 + public ShareDialog(@NonNull Activity context, boolean showOther, boolean showWjj) {
  74 + super(context, R.style.ShareDialogStyle);
  75 + mContext = context;
  76 + info = new ShareInfo();
  77 + info.setUrl(AppConfig.getShareDownload());
  78 + info.setTitle(SHARE_TITLE);
  79 + info.setContent(SHARE_CONTENT);
  80 + info.setImgurl(AppConfig.getShareIcon());
  81 +
  82 + this.showOther = showOther;
  83 + this.showWjj = showWjj;
  84 +
  85 + config = ShareReleaseInfoUtil.ShareConfig.newInstance();
  86 + }
  87 +
  88 +
  89 + @Override
  90 + protected void onCreate(Bundle savedInstanceState) {
  91 + super.onCreate(savedInstanceState);
  92 + setContentView(R.layout.layout_share_dialog);
  93 + Window window = getWindow();
  94 + window.setWindowAnimations(R.style.Animation_Bottom_Rising);
  95 +
  96 + showThirdPlatShare = SharedPreferencesHelper.getInstance(mContext).getBoolean("SHOW_THIRD_PLAT_SHARE", true);
  97 +
  98 + shareRv = findViewById(R.id.share_rv);
  99 + shareOther = findViewById(R.id.share_other);
  100 +
  101 + ll_cancle = findViewById(R.id.ll_cancle);
  102 + ll_cancle.setOnClickListener(this);
  103 + setViewLocation();
  104 + setCanceledOnTouchOutside(true);//外部点击取消
  105 +
  106 + init();
  107 +
  108 + }
  109 +
  110 + private List<IconInfo> initList() {
  111 +
  112 +
  113 + List<IconInfo> list = new ArrayList<>();
  114 + if (showWjj) {
  115 + list.add(new IconInfo(IconInfo.WJJ_FRIEND, "网家家好友", R.drawable.wjjhaoyou));
  116 + list.add(new IconInfo(IconInfo.WJJ_CIRCLE, "网家家生活圈", R.drawable.shenghuoquan));
  117 +
  118 +
  119 + }
  120 + if ((AppConfig.getShareDownload().equals(info.getUrl()))
  121 + || (info.getUrl().contains("wjjh5.cnlive.com") || info.getUrl().contains("wjjh5test.cnlive.com"))
  122 + || (!info.getUrl().contains("wjjh5.cnlive.com") && !info.getUrl().contains("wjjh5test.cnlive.com") && showThirdPlatShare)) {
  123 + list.add(new IconInfo(IconInfo.WECHAT_FRIEND, "微信好友", R.drawable.wechat));
  124 + list.add(new IconInfo(IconInfo.WECHAT_CIRCLE, "微信朋友圈", R.drawable.pengyouquan));
  125 + list.add(new IconInfo(IconInfo.QQ, "QQ好友", R.drawable.qq));
  126 + list.add(new IconInfo(IconInfo.WEBO, "微博", R.drawable.weibo));
  127 + }
  128 +// list.add(new IconInfo(IconInfo.WEBO, "微博", R.drawable.weibo));
  129 + if (showOther)
  130 + list.add(new IconInfo(IconInfo.BROWSER, "在浏览器打开", R.drawable.browser));
  131 + return list;
  132 + }
  133 +
  134 + private List<IconInfo> initListOther() {
  135 + List<IconInfo> list = new ArrayList<>();
  136 + if (info != null && info.isReport)
  137 + list.add(new IconInfo(IconInfo.REPORT, "投诉", R.drawable.report_icon));
  138 + return list;
  139 + }
  140 +
  141 + private void init() {
  142 + adapter = new ShareDialogListAdapter(mContext, initList());
  143 + adapter.setItemClick(this);
  144 + LinearLayoutManager layoutManager1 = new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false);
  145 +
  146 + shareRv.setLayoutManager(layoutManager1);
  147 + shareRv.setAdapter(adapter);
  148 +
  149 + if (info != null && info.isReport) {
  150 + shareOther.setVisibility(View.VISIBLE);
  151 + findViewById(R.id.line).setVisibility(View.VISIBLE);
  152 + adapterOther = new ShareDialogListAdapter(mContext, initListOther());
  153 + adapterOther.setItemClick(this);
  154 + LinearLayoutManager layoutManagerOther = new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false);
  155 + shareOther.setLayoutManager(layoutManagerOther);
  156 + shareOther.setAdapter(adapterOther);
  157 +
  158 + }
  159 + }
  160 +
  161 +
  162 + @Override
  163 + public void onClick(View v) {
  164 + int i = v.getId();
  165 + if (i == R.id.ll_cancle) {
  166 + cancel();
  167 + }
  168 + }
  169 +
  170 + /**
  171 + * 设置dialog位于屏幕底部
  172 + */
  173 + private void setViewLocation() {
  174 + DisplayMetrics dm = new DisplayMetrics();
  175 + mContext.getWindowManager().getDefaultDisplay().getMetrics(dm);
  176 + int height = dm.heightPixels;
  177 + Window window = this.getWindow();
  178 + WindowManager.LayoutParams lp = window.getAttributes();
  179 + lp.x = 0;
  180 + lp.y = height;
  181 + lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
  182 + lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
  183 + // 设置显示位置
  184 + onWindowAttributesChanged(lp);
  185 + }
  186 +
  187 + public void setUrl(String url) {
  188 + if (info != null)
  189 + info.setUrl(TextUtils.isEmpty(url) ? AppConfig.getShareDownload() : url);
  190 + if (adapter != null)
  191 + adapter.updateItems(initList());
  192 + }
  193 +
  194 + public void setReport(boolean isReport) {
  195 + if (info != null) info.isReport = isReport;
  196 + }
  197 +
  198 + public void setTitle(String content) {
  199 + if (info != null) {
  200 + String title = TextUtils.isEmpty(content) ? SHARE_TITLE : content;
  201 + if (!title.contains("中国 网++") && !TextUtils.isEmpty(SHARE_END))
  202 + title = title.concat(SHARE_END);
  203 + if (!title.contains("中国 网家家") && !TextUtils.isEmpty(SHARE_END))
  204 + title = title.concat(SHARE_END);
  205 + info.setTitle(title);
  206 + }
  207 + }
  208 +
  209 + public void setDes(String des) {
  210 + if (info != null) {
  211 + String subTitle = TextUtils.isEmpty(des) ? SHARE_CONTENT : des;
  212 + info.setContent(subTitle);
  213 + }
  214 + }
  215 +
  216 + //设置网家家分享的url 网家家好友 生活圈 和微信qq区分开分享
  217 + public void setWjjShareUrl(String wjjLifeCircleContentUrl) {
  218 + if (info != null && !TextUtils.isEmpty(wjjLifeCircleContentUrl)) {
  219 + info.setWjjShareUrl(wjjLifeCircleContentUrl);
  220 + info.setProcessWjjShare(true);
  221 + }
  222 + }
  223 +
  224 + public void setImgurl(String image) {
  225 + if (info != null)
  226 + info.setImgurl(TextUtils.isEmpty(image) ? AppConfig.getShareIcon() : image);
  227 + }
  228 +
  229 + public void setContentId(String id) {
  230 + if (info != null)
  231 + info.setContentId(TextUtils.isEmpty(id) ? "" : id);
  232 + }
  233 +
  234 + public void setReportType(String type) {
  235 + if (info != null)
  236 + info.setReportType(TextUtils.isEmpty(type) ? "3" : type);
  237 + }
  238 +
  239 + public void setShareType(String type) {
  240 + if (info != null)
  241 + info.setShareType(TextUtils.isEmpty(type) ? "" : type);
  242 + }
  243 +
  244 + @Override
  245 + public void onItemClick(int position, String type) {
  246 + if (info.getUrl() == null || !Util.isNetUrl(info.getUrl())) {
  247 + info.setUrl(AppConfig.getShareDownload());
  248 + }
  249 + switch (type) {
  250 + case IconInfo.WJJ_FRIEND:
  251 + ShareUtils.shareAppIM(info, mContext);
  252 + ShareClickObservable.getInstance().update(1);
  253 + dismiss();
  254 + break;
  255 + case IconInfo.WJJ_CIRCLE:
  256 + ShareUtils.shareAppMoment(info, mContext);
  257 + ShareClickObservable.getInstance().update(2);
  258 + dismiss();
  259 + break;
  260 + case IconInfo.WECHAT_FRIEND:
  261 + ShareUtils.shareWechat(info, mContext);
  262 + ShareClickObservable.getInstance().update(3);
  263 + dismiss();
  264 + break;
  265 + case IconInfo.WECHAT_CIRCLE:
  266 + ShareUtils.shareWCE(info, mContext);
  267 + ShareClickObservable.getInstance().update(4);
  268 + dismiss();
  269 + break;
  270 + case IconInfo.QQ:
  271 + ShareUtils.shareQQ(info, mContext);
  272 + ShareClickObservable.getInstance().update(5);
  273 + dismiss();
  274 + break;
  275 + case IconInfo.WEBO:
  276 + ShareUtils.shareWeiBo(mContext, info);
  277 + ShareClickObservable.getInstance().update(6);
  278 + dismiss();
  279 + break;
  280 + case IconInfo.BROWSER:
  281 + ShareUtils.startBrowser(mContext, info.getUrl());
  282 + ShareClickObservable.getInstance().update(7);
  283 + dismiss();
  284 + break;
  285 + case IconInfo.REPORT:
  286 + if (info != null && !TextUtils.isEmpty(info.getContentId())) {
  287 + ShareOtherUtil.report(mContext, info.getContentId(), info.getReportType());
  288 + ShareClickObservable.getInstance().update(8);
  289 + dismiss();
  290 + } else {
  291 + AlertUtil.showDeftToast(mContext, "数据异常");
  292 + }
  293 + break;
  294 +
  295 + }
  296 + }
  297 +}
0 298 \ No newline at end of file
... ...
cloud/share/src/main/java/com/cnlive/share/util/BindingAdapterUtil.java 0 → 100644
  1 +package com.cnlive.share.util;
  2 +
  3 +import android.widget.ImageView;
  4 +
  5 +import androidx.databinding.BindingAdapter;
  6 +
  7 +/**
  8 + * Created by gujun on 2017/5/24.
  9 + * 工具
  10 + */
  11 +
  12 +public class BindingAdapterUtil {
  13 +
  14 + /**
  15 + * 加载本地资源文件
  16 + *
  17 + * @param view
  18 + * @param res
  19 + */
  20 + @BindingAdapter({"imageSYS"})
  21 + public static void loadSYSIMage(ImageView view, int res) {
  22 + view.setImageResource(res);
  23 + }
  24 +
  25 +}
... ...
cloud/share/src/main/java/com/cnlive/share/util/DateTimeUtil.java 0 → 100644
  1 +package com.cnlive.share.util;
  2 +
  3 +import android.annotation.SuppressLint;
  4 +import android.util.Log;
  5 +
  6 +import java.text.DateFormat;
  7 +import java.text.ParseException;
  8 +import java.text.ParsePosition;
  9 +import java.text.SimpleDateFormat;
  10 +import java.util.Calendar;
  11 +import java.util.Date;
  12 +
  13 +/**
  14 + * 时间、日期工具类
  15 + * Created by fanji on 2017/7/19.
  16 + */
  17 +
  18 +public class DateTimeUtil {
  19 +
  20 + static SimpleDateFormat format;
  21 +
  22 + /**
  23 + * 日期格式:yyyy-MM-dd HH:mm:ss
  24 + **/
  25 + public static final String DF_YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
  26 +
  27 + /**
  28 + * 日期格式:yyyy-MM-dd HH:mm
  29 + **/
  30 + public static final String DF_YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm";
  31 + // yyyy-MM-dd-HH-mm
  32 +
  33 + /**
  34 + * 日期格式:yyyy-MM-dd
  35 + **/
  36 + public static final String DF_YYYY_MM_DD = "yyyy-MM-dd";
  37 +
  38 + /**
  39 + * 日期格式:HH:mm:ss
  40 + **/
  41 + public static final String DF_HH_MM_SS = "HH:mm:ss";
  42 +
  43 + /**
  44 + * 日期格式:HH:mm
  45 + **/
  46 + public static final String DF_HH_MM = "HH:mm";
  47 +
  48 + private final static long minute = 60 * 1000;// 1分钟
  49 + private final static long hour = 60 * minute;// 1小时
  50 + private final static long day = 24 * hour;// 1天
  51 + private final static long month = 31 * day;// 月
  52 + private final static long year = 12 * month;// 年
  53 +
  54 +
  55 + public DateTimeUtil() {
  56 +
  57 + }
  58 +
  59 + /**
  60 + * 将日期格式化成友好的字符串:几分钟前、几小时前、几天前、几月前、几年前、刚刚
  61 + *
  62 + * @param date
  63 + * @return
  64 + */
  65 + public static String formatFriendly(Date date) {
  66 + if (date == null) {
  67 + return null;
  68 + }
  69 + long diff = new Date().getTime() - date.getTime();
  70 + long r = 0;
  71 + if (diff > year) {
  72 + r = (diff / year);
  73 + return r + "年前";
  74 + }
  75 + if (diff > month) {
  76 + r = (diff / month);
  77 + return r + "个月前";
  78 + }
  79 + if (diff > day) {
  80 + r = (diff / day);
  81 + return r + "天前";
  82 + }
  83 + if (diff > hour) {
  84 + r = (diff / hour);
  85 + return r + "个小时前";
  86 + }
  87 + if (diff > minute) {
  88 + r = (diff / minute);
  89 + return r + "分钟前";
  90 + }
  91 + return "刚刚";
  92 + }
  93 +
  94 + /**
  95 + * 生活圈模仿微信时间展示样式
  96 + *
  97 + * @param date
  98 + * @return
  99 + */
  100 + public static String formatNewFriendly(Date date) {
  101 + if (date == null) {
  102 + return null;
  103 + }
  104 + long diff = new Date().getTime() - date.getTime();
  105 + long r = 0;
  106 + if (diff > day) {
  107 + r = (diff / day);
  108 + if (r==1){
  109 + return"昨天";
  110 + }else {
  111 + return r + "天前";
  112 + }
  113 + }
  114 + if (diff > hour) {
  115 + r = (diff / hour);
  116 + return r + "小时前";
  117 + }
  118 + if (diff > minute) {
  119 + r = (diff / minute);
  120 + return r + "分钟前";
  121 + }
  122 + return "1分钟前";
  123 + }
  124 +
  125 + /**
  126 + * 将日期以yyyy-MM-dd HH:mm:ss格式化
  127 + *
  128 + * @param dateL 日期
  129 + * @return
  130 + */
  131 + @SuppressLint("SimpleDateFormat")
  132 + public static String formatDateTime(long dateL) {
  133 + SimpleDateFormat sdf = new SimpleDateFormat(DF_YYYY_MM_DD_HH_MM_SS);
  134 + Date date = new Date(dateL);
  135 + return sdf.format(date);
  136 + }
  137 +
  138 + /**
  139 + * 将日期以yyyy-MM-dd HH:mm:ss格式化
  140 + *
  141 + * @param dateL 日期
  142 + * @return
  143 + */
  144 + @SuppressLint("SimpleDateFormat")
  145 + public static String formatDateTime(long dateL, String pattern) {
  146 + SimpleDateFormat sdf = new SimpleDateFormat(pattern);
  147 + Date date = new Date(dateL);
  148 + return sdf.format(date);
  149 + }
  150 +
  151 +
  152 + /**
  153 + * 将日期以yyyy-MM-dd HH:mm:ss格式化
  154 + *
  155 + * @param date 日期
  156 + * @param formater
  157 + * @return
  158 + */
  159 + @SuppressLint("SimpleDateFormat")
  160 + public static String formatDateTime(Date date, String formater) {
  161 + SimpleDateFormat sdf = new SimpleDateFormat(formater);
  162 + return sdf.format(date);
  163 + }
  164 +
  165 + /**
  166 + * 将日期字符串转成日期
  167 + *
  168 + * @param strDate 字符串日期
  169 + * @return java.util.date日期类型
  170 + */
  171 + @SuppressLint("SimpleDateFormat")
  172 + public static Date parseDate(String strDate) {
  173 + DateFormat dateFormat = new SimpleDateFormat(DF_YYYY_MM_DD_HH_MM_SS);
  174 + Date returnDate = null;
  175 + try {
  176 + returnDate = dateFormat.parse(strDate);
  177 + } catch (ParseException e) {
  178 +
  179 + }
  180 + return returnDate;
  181 +
  182 + }
  183 +
  184 + /**
  185 + * 获取系统当前日期
  186 + *
  187 + * @return
  188 + */
  189 + public static Date gainCurrentDate() {
  190 + return new Date();
  191 + }
  192 +
  193 + /**
  194 + * 验证日期是否比当前日期早
  195 + *
  196 + * @param target1 比较时间1
  197 + * @param target2 比较时间2
  198 + * @return true 则代表target1比target2晚或等于target2,否则比target2早
  199 + */
  200 + public static boolean compareDate(Date target1, Date target2) {
  201 + boolean flag = false;
  202 + try {
  203 + String target1DateTime = formatDateTime(target1, DF_YYYY_MM_DD_HH_MM_SS);
  204 + String target2DateTime = formatDateTime(target2, DF_YYYY_MM_DD_HH_MM_SS);
  205 + if (target1DateTime.compareTo(target2DateTime) <= 0) {
  206 + flag = true;
  207 + }
  208 + } catch (Exception e) {
  209 + System.out.println("比较失败,原因:" + e.getMessage());
  210 + }
  211 + return flag;
  212 + }
  213 +
  214 + /**
  215 + * 对日期进行增加操作
  216 + *
  217 + * @param target 需要进行运算的日期
  218 + * @param hour 小时
  219 + * @return
  220 + */
  221 + public static Date addDateTime(Date target, double hour) {
  222 + if (null == target || hour < 0) {
  223 + return target;
  224 + }
  225 +
  226 + return new Date(target.getTime() + (long) (hour * 60 * 60 * 1000));
  227 + }
  228 +
  229 + /**
  230 + * 对日期进行相减操作
  231 + *
  232 + * @param target 需要进行运算的日期
  233 + * @param hour 小时
  234 + * @return
  235 + */
  236 + public static Date subDateTime(Date target, double hour) {
  237 + if (null == target || hour < 0) {
  238 + return target;
  239 + }
  240 +
  241 + return new Date(target.getTime() - (long) (hour * 60 * 60 * 1000));
  242 + }
  243 +
  244 + /**
  245 + * 获取系统时间的方法:月/日 时:分:秒
  246 + */
  247 + public static String getFormateDate() {
  248 + Calendar calendar = Calendar.getInstance();
  249 + int month = (calendar.get(Calendar.MONTH) + 1);
  250 + int day = calendar.get(Calendar.DAY_OF_MONTH);
  251 + int hour = calendar.get(Calendar.HOUR_OF_DAY);
  252 + int minute = calendar.get(Calendar.MINUTE);
  253 + int second = calendar.get(Calendar.SECOND);
  254 +
  255 + String systemTime = (month < 10 ? "0" + month : month) + "/" + (day < 10 ? "0" + day : day) + " " + (hour < 10 ? "0" + hour : hour) + ":" + (minute < 10 ? "0" + minute : minute) + ":" + (second < 10 ? "0" + second : second);
  256 + return systemTime;
  257 + }
  258 +
  259 + /**
  260 + * 获取系统时间的方法:时:分:秒
  261 + */
  262 + public static String getHourAndMinute() {
  263 + Calendar calendar = Calendar.getInstance();
  264 + int hour = calendar.get(Calendar.HOUR_OF_DAY);
  265 + int minute = calendar.get(Calendar.MINUTE);
  266 + return (hour < 10 ? "0" + hour : hour) + ":" + (minute < 10 ? "0" + minute : minute);
  267 + }
  268 +
  269 + /**
  270 + * 获取分钟
  271 + */
  272 + public static int getMinute() {
  273 + Calendar calendar = Calendar.getInstance();
  274 + int hour = calendar.get(Calendar.HOUR_OF_DAY);
  275 + int minute = calendar.get(Calendar.MINUTE);
  276 + return minute;
  277 + }
  278 +
  279 + /**
  280 + * 获取系统时间的方法:时
  281 + */
  282 + public static String getHour() {
  283 + Calendar calendar = Calendar.getInstance();
  284 + int hour = calendar.get(Calendar.HOUR_OF_DAY);
  285 + return ((hour < 10 ? "0" + hour : hour) + "");
  286 + }
  287 +
  288 + /**
  289 + * 将2017-07-10 00:00:00 换2017-07-10
  290 + *
  291 + * @param strDate
  292 + * @return
  293 + */
  294 + public static String strFormatStr(String strDate) {
  295 + if (strDate.equals("")) {
  296 + return "";
  297 + }
  298 + return dateToStr(strToDate(strDate));
  299 + }
  300 +
  301 + /**
  302 + * 2015-01-07 15:05:34
  303 + *
  304 + * @param strDate
  305 + * @return
  306 + */
  307 + @SuppressLint("SimpleDateFormat")
  308 + public static Date strToDateHHMMSS(String strDate) {
  309 + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  310 + ParsePosition pos = new ParsePosition(0);
  311 + Date strtodate = formatter.parse(strDate, pos);
  312 + return strtodate;
  313 + }
  314 +
  315 + /**
  316 + * 2015-01-07 15:05
  317 + *
  318 + * @param strDate
  319 + * @return
  320 + */
  321 + @SuppressLint("SimpleDateFormat")
  322 + public static Date strToDateHHMM(String strDate) {
  323 + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
  324 + ParsePosition pos = new ParsePosition(0);
  325 + Date strtodate = formatter.parse(strDate, pos);
  326 + return strtodate;
  327 + }
  328 +
  329 + /**
  330 + * 2015-01-07
  331 + *
  332 + * @param strDate
  333 + * @return
  334 + */
  335 + @SuppressLint("SimpleDateFormat")
  336 + public static Date strToDate(String strDate) {
  337 + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
  338 + ParsePosition pos = new ParsePosition(0);
  339 + Date strtodate = formatter.parse(strDate, pos);
  340 + return strtodate;
  341 + }
  342 +
  343 + /**
  344 + * 2015.01.07
  345 + *
  346 + * @param strDate
  347 + * @return
  348 + */
  349 + @SuppressLint("SimpleDateFormat")
  350 + public static Date strToDateDorp(String strDate) {
  351 + SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd");
  352 + ParsePosition pos = new ParsePosition(0);
  353 + Date strtodate = formatter.parse(strDate, pos);
  354 + return strtodate;
  355 + }
  356 +
  357 + @SuppressLint("SimpleDateFormat")
  358 + public static String dateToStr(Date dateDate) {
  359 + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
  360 + String dateString = formatter.format(dateDate);
  361 + return dateString;
  362 + }
  363 +
  364 + /**
  365 + * 传入一个String转化为long
  366 + */
  367 + @SuppressLint("SimpleDateFormat")
  368 + public static Long stringParserLong(String param) throws ParseException {
  369 + format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  370 + return format.parse(param).getTime();
  371 + }
  372 +
  373 + /**
  374 + * 传入一个String转化为long
  375 + */
  376 + @SuppressLint("SimpleDateFormat")
  377 + public static Long stringParserLong1(String param) throws ParseException {
  378 + format = new SimpleDateFormat("yyyyMMddHHmmss");
  379 + return format.parse(param).getTime();
  380 + }
  381 +
  382 + /**
  383 + * 当前时间转换为long
  384 + */
  385 + @SuppressLint("SimpleDateFormat")
  386 + public static Long currentDateParserLong() throws ParseException {
  387 + format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  388 + return format.parse(format.format(Calendar.getInstance().getTime())).getTime();
  389 + }
  390 +
  391 + /**
  392 + * 当前时间 如: 2013-04-22 10:37:00
  393 + */
  394 + @SuppressLint("SimpleDateFormat")
  395 + public static String getCurrentDate() {
  396 + format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
  397 + return format.format(Calendar.getInstance().getTime());
  398 + }
  399 +
  400 + /**
  401 + * 当前时间 如: 10:37
  402 + */
  403 + @SuppressLint("SimpleDateFormat")
  404 + public static String getCurrentDateHHMM() {
  405 + format = new SimpleDateFormat("HH:mm");
  406 + return format.format(Calendar.getInstance().getTime());
  407 + }
  408 +
  409 + /**
  410 + * 当前时间 如: 10:37
  411 + *
  412 + * @throws ParseException
  413 + */
  414 + @SuppressLint("SimpleDateFormat")
  415 + public static String getCurrentDateHHMMSS() {
  416 + format = new SimpleDateFormat("HH:mm:ss");
  417 + return format.format(Calendar.getInstance().getTime());
  418 + }
  419 +
  420 + /**
  421 + * 当前时间 如: 20130422
  422 + */
  423 + @SuppressLint("SimpleDateFormat")
  424 + public static String getCurrentDateString() {
  425 + format = new SimpleDateFormat("yyyyMMddHHmm");
  426 + return format.format(Calendar.getInstance().getTime());
  427 + }
  428 +
  429 + /**
  430 + * 当前时间 如: 2013-04-22
  431 + */
  432 + @SuppressLint("SimpleDateFormat")
  433 + public static String getCurrentTime() {
  434 + format = new SimpleDateFormat("yyyy-MM-dd");
  435 + return format.format(Calendar.getInstance().getTime());
  436 + }
  437 +
  438 + @SuppressLint("SimpleDateFormat")
  439 + public static String getSWAHDate() {
  440 + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  441 + return format.format(Calendar.getInstance().getTime());
  442 + }
  443 +
  444 + @SuppressLint("SimpleDateFormat")
  445 + public static Long stringToLongD(String param) throws ParseException {
  446 + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  447 + return format.parse(param.substring(0, param.length() - 4)).getTime();
  448 + }
  449 +
  450 + @SuppressLint("SimpleDateFormat")
  451 + public static Long stringToLong(String param) throws ParseException {
  452 + SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmm");
  453 + return format.parse(param).getTime();
  454 + }
  455 +
  456 + /**
  457 + * 获取两个日期之间的间隔天数
  458 + *
  459 + * @return
  460 + */
  461 + @SuppressLint("SimpleDateFormat")
  462 + public static int getGapCount(Date startDate, Date endDate) {
  463 + Calendar fromCalendar = Calendar.getInstance();
  464 + fromCalendar.setTime(startDate);
  465 + fromCalendar.set(Calendar.HOUR_OF_DAY, 0);
  466 + fromCalendar.set(Calendar.MINUTE, 0);
  467 + fromCalendar.set(Calendar.SECOND, 0);
  468 + fromCalendar.set(Calendar.MILLISECOND, 0);
  469 +
  470 + Calendar toCalendar = Calendar.getInstance();
  471 + toCalendar.setTime(endDate);
  472 + toCalendar.set(Calendar.HOUR_OF_DAY, 0);
  473 + toCalendar.set(Calendar.MINUTE, 0);
  474 + toCalendar.set(Calendar.SECOND, 0);
  475 + toCalendar.set(Calendar.MILLISECOND, 0);
  476 +
  477 + return (int) ((toCalendar.getTime().getTime() - fromCalendar.getTime().getTime()) / (1000 * 60 * 60 * 24));
  478 + }
  479 +
  480 + /**
  481 + * 日期转换成Java字符串
  482 + *
  483 + * @param date
  484 + * @return str
  485 + */
  486 + @SuppressLint("SimpleDateFormat")
  487 + public static String DateToStr(Date date) {
  488 +
  489 + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  490 + String str = format.format(date);
  491 + return str;
  492 + }
  493 +
  494 + /**
  495 + * 字符串转换成日期
  496 + *
  497 + * @param str
  498 + * @return date
  499 + */
  500 + @SuppressLint("SimpleDateFormat")
  501 + public static Date StrToDate(String str) {
  502 +
  503 + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  504 + Date date = null;
  505 + try {
  506 + date = format.parse(str);
  507 + } catch (ParseException e) {
  508 + e.printStackTrace();
  509 + }
  510 + return date;
  511 + }
  512 +
  513 + /**
  514 + * 字符串转换成日期
  515 + *
  516 + * @param str
  517 + * @return date
  518 + */
  519 + @SuppressLint("SimpleDateFormat")
  520 + public static Date StrToDateDrop(String str) {
  521 +
  522 + SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
  523 + Date date = null;
  524 + try {
  525 + date = format.parse(str);
  526 + } catch (ParseException e) {
  527 + e.printStackTrace();
  528 + }
  529 + return date;
  530 + }
  531 +
  532 + /**
  533 + * @param time
  534 + * @return
  535 + */
  536 + @SuppressLint("SimpleDateFormat")
  537 + public static long getLongTime(String time) {
  538 + long ct = 0;
  539 + try {
  540 + format = new SimpleDateFormat("HH:mm:ss");
  541 + ct = format.parse(time).getTime();
  542 + } catch (Exception e) {
  543 + e.printStackTrace();
  544 + }
  545 + return ct;
  546 + }
  547 +
  548 + /**
  549 + * 判断两日期是否同一天
  550 + *
  551 + * @param str1
  552 + * @param str2
  553 + * @return
  554 + */
  555 + @SuppressLint("SimpleDateFormat")
  556 + public static boolean isSameDay(String str1, String str2) {
  557 +
  558 + Date day1 = null, day2 = null;
  559 + day1 = DateTimeUtil.strToDate(str1);
  560 + day2 = DateTimeUtil.strToDate(str2);
  561 +
  562 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  563 +
  564 + String ds1 = sdf.format(day1);
  565 +
  566 + String ds2 = sdf.format(day2);
  567 +
  568 + if (ds1.equals(ds2)) {
  569 + return true;
  570 + } else {
  571 + return false;
  572 + }
  573 +
  574 + }
  575 +
  576 + /**
  577 + * 获取两个日期的时间差
  578 + */
  579 + @SuppressLint("SimpleDateFormat")
  580 + public static int getTimeInterval(String date) {
  581 + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  582 + int interval = 0;
  583 + try {
  584 + Date currentTime = new Date();// 获取现在的时间
  585 + Date beginTime = dateFormat.parse(date);
  586 + interval = (int) ((beginTime.getTime() - currentTime.getTime()) / (1000));// 时间差
  587 + // 单位秒
  588 + } catch (ParseException e) {
  589 + e.printStackTrace();
  590 + }
  591 + return interval;
  592 + }
  593 +
  594 + /**
  595 + * 获取两个日期的时间差 yyyy.MM.dd HH.mm.ss
  596 + */
  597 + @SuppressLint("SimpleDateFormat")
  598 + public static int getInterval(String bDate, String eDate) {
  599 + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd");
  600 + int interval = 0;
  601 + try {
  602 + Date currentTime = dateFormat.parse(eDate);// 获取现在的时间
  603 + Date beginTime = dateFormat.parse(bDate);
  604 + interval = (int) ((beginTime.getTime() - currentTime.getTime()));// 时间差
  605 + // 单位秒
  606 + } catch (ParseException e) {
  607 + e.printStackTrace();
  608 + }
  609 + return interval;
  610 + }
  611 +
  612 + /**
  613 + * 两个时间之差 求出一个long Time
  614 + *
  615 + * @param date
  616 + * @return
  617 + */
  618 + @SuppressLint("SimpleDateFormat")
  619 + public static long getTime(String date) {
  620 +
  621 + DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  622 + long diff = 0;
  623 + try {
  624 + Date currentTime = new Date();// 获取现在的时间
  625 + Date getdate = df.parse(date);
  626 + diff = getdate.getTime() - currentTime.getTime();
  627 +
  628 + } catch (Exception e) {
  629 + }
  630 + return diff;
  631 + }
  632 +
  633 +
  634 + /**
  635 + * 日期转换成Java字符串
  636 + *
  637 + * @param DATE1
  638 + * @param DATE2
  639 + * @return
  640 + */
  641 + @SuppressLint("SimpleDateFormat")
  642 + public static int compare_date(String DATE1, String DATE2) {
  643 + DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
  644 + try {
  645 + Date dt1 = df.parse(DATE1);
  646 + Date dt2 = df.parse(DATE2);
  647 + if (dt1.getTime() >= dt2.getTime()) {
  648 + return 1;
  649 + } else if (dt1.getTime() < dt2.getTime()) {
  650 + return -1;
  651 + } else {
  652 + return 0;
  653 + }
  654 + } catch (Exception exception) {
  655 + exception.printStackTrace();
  656 + }
  657 + return 0;
  658 + }
  659 +
  660 + /**
  661 + * 传入时间 算出星期几
  662 + *
  663 + * @param str 2014年1月3日
  664 + * @param days 1:2014年1月4日 类推
  665 + * @return
  666 + */
  667 + @SuppressLint("SimpleDateFormat")
  668 + public static String formatDate(String str, int days) {
  669 +
  670 + String dateStr = "";
  671 + try {
  672 + DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
  673 + Date date = df.parse(str);
  674 + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  675 + Calendar c = Calendar.getInstance();
  676 + Date d = dateFormat.parse(dateFormat.format(date));
  677 + c.setTime(d);
  678 + c.add(Calendar.DAY_OF_MONTH, days);
  679 + switch (c.get(Calendar.DAY_OF_WEEK) - 1) {
  680 + case 0:
  681 + dateStr = "周日";
  682 + break;
  683 + case 1:
  684 + dateStr = "周一";
  685 + break;
  686 + case 2:
  687 + dateStr = "周二";
  688 + break;
  689 + case 3:
  690 + dateStr = "周三";
  691 + break;
  692 + case 4:
  693 + dateStr = "周四";
  694 + break;
  695 + case 5:
  696 + dateStr = "周五";
  697 + break;
  698 + case 6:
  699 + dateStr = "周六";
  700 + break;
  701 + default:
  702 + break;
  703 + }
  704 + } catch (Exception e) {
  705 + e.printStackTrace();
  706 + }
  707 +
  708 + return dateStr;
  709 + }
  710 +
  711 + /**
  712 + * 根据提供的年月日获取该月份的第一天
  713 + */
  714 + public static String getSupportBeginDayofMonth(int year, int monthOfYear) {
  715 + Calendar cal = Calendar.getInstance();
  716 + cal.set(Calendar.YEAR, year);
  717 + cal.set(Calendar.MONTH, monthOfYear - 1);
  718 + cal.set(Calendar.DAY_OF_MONTH, 1);
  719 + cal.set(Calendar.HOUR_OF_DAY, 0);
  720 + cal.set(Calendar.MINUTE, 0);
  721 + cal.set(Calendar.SECOND, 0);
  722 +
  723 + cal.set(Calendar.DAY_OF_MONTH, 1);
  724 + return cal.getTimeInMillis() + "";
  725 + }
  726 +
  727 + /**
  728 + * 根据提供的年月获取该月份的最后一天
  729 + *
  730 + * @return
  731 + */
  732 + public static String getSupportEndDayofMonth(int year, int monthOfYear) {
  733 + Calendar cal = Calendar.getInstance();
  734 + cal.set(Calendar.YEAR, year);
  735 + cal.set(Calendar.MONTH, monthOfYear);
  736 + cal.set(Calendar.DAY_OF_MONTH, 1);
  737 + cal.set(Calendar.HOUR_OF_DAY, 23);
  738 + cal.set(Calendar.MINUTE, 59);
  739 + cal.set(Calendar.SECOND, 59);
  740 +
  741 + cal.add(Calendar.DAY_OF_MONTH, -1);
  742 + return cal.getTimeInMillis() + "";
  743 + }
  744 +
  745 + public static String getYear(long millseconds) {
  746 +
  747 + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
  748 + Date date = new Date(millseconds);
  749 + return sdf.format(date).substring(0, 4);
  750 + }
  751 +
  752 + public static String getMonth(long millseconds) {
  753 +
  754 + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
  755 + Date date = new Date(millseconds);
  756 + return sdf.format(date).substring(4, 6);
  757 + }
  758 +
  759 + public static String formatFriendly(String timeStr) {
  760 + String time = "";
  761 + try {
  762 + time = DateTimeUtil.formatFriendly(new Date(Long.valueOf(timeStr) * 1000L));
  763 + } catch (Exception e) {
  764 + Log.e("FriendCircleMessage", "Time format exception.", e);
  765 + }
  766 + return time;
  767 + }
  768 +
  769 +}
... ...
cloud/share/src/main/java/com/cnlive/share/util/OkHttpUtils.java 0 → 100644
  1 +package com.cnlive.share.util;
  2 +
  3 +
  4 +
  5 +import android.os.Handler;
  6 +import android.os.Looper;
  7 +
  8 +import com.google.gson.Gson;
  9 +import com.google.gson.internal.$Gson$Types;
  10 +
  11 +import java.io.IOException;
  12 +import java.lang.reflect.ParameterizedType;
  13 +import java.lang.reflect.Type;
  14 +import java.util.List;
  15 +import java.util.concurrent.TimeUnit;
  16 +
  17 +import okhttp3.Call;
  18 +import okhttp3.Callback;
  19 +import okhttp3.FormBody;
  20 +import okhttp3.OkHttpClient;
  21 +import okhttp3.Request;
  22 +import okhttp3.RequestBody;
  23 +import okhttp3.Response;
  24 +
  25 +/**
  26 + *
  27 + */
  28 +public class OkHttpUtils {
  29 +
  30 + private static final String TAG = "OkHttpUtils";
  31 +
  32 + private static OkHttpUtils mInstance;
  33 + private OkHttpClient mOkHttpClient;
  34 + private Handler mDelivery;
  35 + private Gson mGson;
  36 +
  37 + private OkHttpUtils() {
  38 + mOkHttpClient = new OkHttpClient.Builder()
  39 + .connectTimeout(10, TimeUnit.SECONDS)
  40 + .writeTimeout(10, TimeUnit.SECONDS)
  41 + .readTimeout(30, TimeUnit.SECONDS)
  42 + .build();
  43 + mGson = new Gson();
  44 + mDelivery = new Handler(Looper.getMainLooper());
  45 + }
  46 +
  47 + private synchronized static OkHttpUtils getmInstance() {
  48 + if (mInstance == null) {
  49 + mInstance = new OkHttpUtils();
  50 + }
  51 + return mInstance;
  52 + }
  53 +
  54 + private void getRequest(String url, final ResultCallback callback) {
  55 + final Request request = new Request.Builder().url(url).build();
  56 + deliveryResult(callback, request);
  57 + }
  58 +
  59 + private void postRequest(String url, final ResultCallback callback, List<Param> params) {
  60 + Request request = buildPostRequest(url, params);
  61 + deliveryResult(callback, request);
  62 + }
  63 +
  64 + /**
  65 + * 处理结果
  66 + * @param callback
  67 + * @param request
  68 + */
  69 + private void deliveryResult(final ResultCallback callback, Request request) {
  70 +
  71 + mOkHttpClient.newCall(request).enqueue(new Callback() {
  72 + @Override
  73 + public void onFailure(Call call, IOException e) {
  74 + sendFailCallback(callback, e);
  75 + }
  76 +
  77 + @Override
  78 + public void onResponse(Call call, Response response) throws IOException {
  79 + try {
  80 + String str = response.body().string();
  81 + if (callback.mType == String.class) {
  82 + /**
  83 + * 返回字符串
  84 + */
  85 + sendSuccessCallBack(callback, str);
  86 + } else {
  87 + /**
  88 + * 这里处理解析返回对象
  89 + */
  90 + Object object = mGson.fromJson(str, callback.mType);
  91 + sendSuccessCallBack(callback, object);
  92 +
  93 + }
  94 + } catch (final Exception e) {
  95 +// LogUtils.e(TAG, "convert json failure", e);
  96 + sendFailCallback(callback, e);
  97 + }
  98 + }
  99 + });
  100 + }
  101 +
  102 + private void sendFailCallback(final ResultCallback callback, final Exception e) {
  103 + mDelivery.post(new Runnable() {
  104 + @Override
  105 + public void run() {
  106 + if (callback != null) {
  107 + callback.onFailure(e);
  108 + }
  109 + }
  110 + });
  111 + }
  112 +
  113 + private void sendSuccessCallBack(final ResultCallback callback, final Object obj) {
  114 + mDelivery.post(new Runnable() {
  115 + @Override
  116 + public void run() {
  117 + if (callback != null) {
  118 + callback.onSuccess(obj);
  119 + }
  120 + }
  121 + });
  122 + }
  123 +
  124 + private Request buildPostRequest(String url, List<Param> params) {
  125 + FormBody.Builder builder= new FormBody.Builder();
  126 + for (Param param : params) {
  127 + builder.add(param.key, param.value);
  128 + }
  129 + RequestBody requestBody = builder.build();
  130 + return new Request.Builder().url(url).post(requestBody).build();
  131 + }
  132 +
  133 +
  134 + /**********************对外接口************************/
  135 +
  136 + /**
  137 + * get请求
  138 + * @param url 请求url
  139 + * @param callback 请求回调
  140 + */
  141 + public static void get(String url, ResultCallback callback) {
  142 + getmInstance().getRequest(url, callback);
  143 + }
  144 +
  145 + /**
  146 + * post请求
  147 + * @param url 请求url
  148 + * @param callback 请求回调
  149 + * @param params 请求参数
  150 + */
  151 + public static void post(String url, final ResultCallback callback, List<Param> params) {
  152 + getmInstance().postRequest(url, callback, params);
  153 + }
  154 +
  155 + /**
  156 + * http请求回调类,回调方法在UI线程中执行
  157 + * @param <T>
  158 + */
  159 + public static abstract class ResultCallback<T> {
  160 +
  161 + Type mType;
  162 +
  163 + public ResultCallback(){
  164 + mType = getSuperclassTypeParameter(getClass());
  165 + }
  166 +
  167 + static Type getSuperclassTypeParameter(Class<?> subclass) {
  168 + Type superclass = subclass.getGenericSuperclass();
  169 + if (superclass instanceof Class) {
  170 + throw new RuntimeException("Missing type parameter.");
  171 + }
  172 + ParameterizedType parameterized = (ParameterizedType) superclass;
  173 + return $Gson$Types.canonicalize(parameterized.getActualTypeArguments()[0]);
  174 + }
  175 +
  176 + /**
  177 + * 请求成功回调
  178 + * @param response
  179 + */
  180 + public abstract void onSuccess(T response);
  181 +
  182 + /**
  183 + * 请求失败回调
  184 + * @param e
  185 + */
  186 + public abstract void onFailure(Exception e);
  187 + }
  188 +
  189 + /**
  190 + * post请求参数类 这里可以根据项目抽取成泛型
  191 + */
  192 + public static class Param {
  193 +
  194 + String key;
  195 + String value;
  196 +
  197 + public Param() {
  198 + }
  199 +
  200 + public Param(String key, String value) {
  201 + this.key = key;
  202 + this.value = value;
  203 + }
  204 +
  205 + }
  206 +
  207 +
  208 +}
0 209 \ No newline at end of file
... ...
cloud/share/src/main/java/com/cnlive/share/util/ShareOtherUtil.java 0 → 100644
  1 +package com.cnlive.share.util;
  2 +
  3 +import android.content.Context;
  4 +import android.net.Uri;
  5 +import android.text.TextUtils;
  6 +
  7 +import com.cnlive.core.libs.base.application.AppConfig;
  8 +import com.cnlive.core.libs.base.util.AlertUtil;
  9 +import com.cnlive.share.arouter.ARouterUtil;
  10 +
  11 +
  12 +/**
  13 + * 作者: 吴奎庆
  14 + * <p>
  15 + * 时间: 2019/4/25
  16 + * <p>
  17 + * 简介: 分享框的其他页面的工具类
  18 + */
  19 +public class ShareOtherUtil {
  20 + /**
  21 + * 举报的的功能处理
  22 + *
  23 + * @param context
  24 + * @param contentId
  25 + */
  26 + public static void report(Context context, String contentId) {
  27 + String url = AppConfig.getReportUrl();
  28 +// contentId(内容id)、sid(举报者sid)、toSid(被举报者sid)、rtType(1-内容投诉 2-用户投诉)、rtSource(来源 1-目击者 2-生活圈 3-H5)
  29 + if (!TextUtils.isEmpty(url)) {
  30 + url = url.concat("contentId=" + contentId).concat("&rtType=1").concat("&rtSource=3");
  31 + ARouterUtil.startReportActivity(context, url);
  32 + }
  33 + }
  34 +
  35 + /**
  36 + * 举报的的功能处理
  37 + *
  38 + * @param context
  39 + * @param contentId
  40 + */
  41 + public static void report(Context context, String contentId, String type) {
  42 + String url = AppConfig.getReportUrl();
  43 +// contentId(内容id)、sid(举报者sid)、toSid(被举报者sid)、rtType(1-内容投诉 2-用户投诉)、rtSource(来源 1-目击者 2-生活圈 3-H5 4:点播 5:直播)
  44 + if (TextUtils.isEmpty(contentId) || TextUtils.isEmpty(type)) {
  45 + AlertUtil.showDeftToast(context, "数据异常");
  46 + return;
  47 + }
  48 + if (!TextUtils.isEmpty(url)) {
  49 + if (contentId == null) contentId = "";
  50 + contentId = Uri.encode(contentId);
  51 + url = url.concat("contentId=" + contentId).concat("&rtType=1").concat("&rtSource=").concat(type);
  52 + ARouterUtil.startReportActivity(context, url);
  53 + }
  54 + }
  55 +
  56 +}
... ...
cloud/share/src/main/java/com/cnlive/share/util/ShareUtils.java 0 → 100644
  1 +package com.cnlive.share.util;
  2 +
  3 +import android.app.Activity;
  4 +import android.content.Context;
  5 +import android.content.Intent;
  6 +import android.content.SharedPreferences;
  7 +import android.content.res.Resources;
  8 +import android.graphics.Bitmap;
  9 +import android.graphics.BitmapFactory;
  10 +import android.net.Uri;
  11 +import android.os.Bundle;
  12 +import android.text.TextUtils;
  13 +import android.util.Log;
  14 +
  15 +import com.alibaba.android.arouter.launcher.ARouter;
  16 +import com.bumptech.glide.Glide;
  17 +import com.bumptech.glide.request.RequestOptions;
  18 +import com.cnlive.core.libs.base.application.AppConfig;
  19 +import com.cnlive.core.libs.base.util.AlertUtil;
  20 +import com.cnlive.core.libs.base.util.FileUtils;
  21 +import com.cnlive.core.libs.base.util.NetworkUtil;
  22 +import com.cnlive.core.network.HttpConn;
  23 +import com.cnlive.core.network.NetCallBack;
  24 +import com.cnlive.core.network.model.BaseResult;
  25 +import com.cnlive.core.network.request.BaseRequest;
  26 +import com.cnlive.libs.base.analytics.AppProbeUtil;
  27 +import com.cnlive.share.BuildConfig;
  28 +import com.cnlive.share.QQListener;
  29 +import com.cnlive.share.R;
  30 +import com.cnlive.share.api.ApiShareService;
  31 +import com.cnlive.share.arouter.ARouterUtil;
  32 +import com.cnlive.share.data.ShareInfo;
  33 +import com.cnlive.share.data.ShareIntegralTypeInfo;
  34 +import com.cnlive.share.model.ShareReleaseInfoUtil;
  35 +import com.cnlive.share.model.ShortLinkInfo;
  36 +import com.cnlive.strike.user.auth.UserService;
  37 +import com.google.gson.Gson;
  38 +import com.sina.weibo.sdk.api.ImageObject;
  39 +import com.sina.weibo.sdk.api.TextObject;
  40 +import com.sina.weibo.sdk.api.WeiboMultiMessage;
  41 +import com.sina.weibo.sdk.share.WbShareHandler;
  42 +import com.tencent.connect.share.QQShare;
  43 +import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
  44 +import com.tencent.mm.opensdk.modelmsg.WXImageObject;
  45 +import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
  46 +import com.tencent.mm.opensdk.modelmsg.WXMiniProgramObject;
  47 +import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;
  48 +import com.tencent.mm.opensdk.openapi.IWXAPI;
  49 +import com.tencent.mm.opensdk.openapi.WXAPIFactory;
  50 +import com.tencent.tauth.IUiListener;
  51 +import com.tencent.tauth.Tencent;
  52 +import com.tencent.tauth.UiError;
  53 +
  54 +import java.io.File;
  55 +import java.util.HashMap;
  56 +import java.util.Map;
  57 +import java.util.concurrent.TimeUnit;
  58 +
  59 +import io.reactivex.Observable;
  60 +import io.reactivex.ObservableOnSubscribe;
  61 +import io.reactivex.Observer;
  62 +import io.reactivex.android.schedulers.AndroidSchedulers;
  63 +import io.reactivex.disposables.Disposable;
  64 +import io.reactivex.schedulers.Schedulers;
  65 +import retrofit2.adapter.rxjava2.Result;
  66 +
  67 +import static android.content.Context.MODE_PRIVATE;
  68 +import static com.cnlive.share.util.Util.buildTransaction;
  69 +
  70 +/**
  71 + * 创建:wukuiqing
  72 + * <p>
  73 + * 时间:2017/10/17
  74 + * <p>
  75 + * 描述: 分享的工具类
  76 + */
  77 +
  78 +public class ShareUtils {
  79 + private static ShareReleaseInfoUtil.ShareConfig config;
  80 + public static final String SHARE_TITLE = "快来加入中国网家家,优享美好生活!";
  81 +
  82 + /**
  83 + * 分享到微信
  84 + */
  85 + public static void shareWechat(final ShareInfo shareInfo, final Context mContext) {
  86 + AppProbeUtil.Probe_ShareTimes_To(mContext, AppProbeUtil.TYPE_WX_FRIEND);
  87 + if (!NetworkUtil.isConnectInternet(mContext)) {
  88 + AlertUtil.showDeftToast(mContext, "网络异常,请检查您的网络");
  89 + return;
  90 + }
  91 + if (Util.isWeixinAvilible(mContext) || Util.isWXAppInstalledAndSupported(mContext)) {
  92 + new Thread(new Runnable() {
  93 + @Override
  94 + public void run() {
  95 + try {
  96 + Bitmap bitmap = Glide.with(mContext)
  97 + .setDefaultRequestOptions(new RequestOptions().centerCrop())
  98 + .asBitmap()
  99 + .load(shareInfo.getImgurl())
  100 + .into(120, 120)
  101 + .get(2, TimeUnit.SECONDS);
  102 + if (bitmap == null) {
  103 + Resources res = mContext.getResources();
  104 + Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.share_logo_share_module);
  105 + Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 120, 120, true);
  106 + shareWx(thumbBmp, shareInfo, mContext, true);
  107 + return;
  108 + }
  109 + shareWx(bitmap, shareInfo, mContext, true);
  110 + } catch (Exception e) {
  111 + Resources res = mContext.getResources();
  112 + Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.share_logo_share_module);
  113 + Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 120, 120, true);
  114 + shareWx(thumbBmp, shareInfo, mContext, true);
  115 + }
  116 +
  117 + }
  118 + }).start();
  119 + } else {
  120 + AlertUtil.showDeftToast(mContext, "您未安装该第三方应用,无法分享信息到该应用中!");
  121 + }
  122 +
  123 + }
  124 +
  125 + private static void shareWx(Bitmap thumbBmp, ShareInfo shareInfo, Context mContext, boolean isWechat) {
  126 + if (!NetworkUtil.isConnectInternet(mContext)) {
  127 + AlertUtil.showDeftToast(mContext, "网络异常,请检查您的网络");
  128 + }
  129 + String url = Util.processUrlData(shareInfo.getUrl(), mContext, false);
  130 + WXWebpageObject webpage = new WXWebpageObject();
  131 + IWXAPI api = WXAPIFactory.createWXAPI(mContext, AppConfig.getWechatAppid());
  132 + webpage.webpageUrl = url;
  133 + WXMediaMessage msg = new WXMediaMessage(webpage);
  134 + msg.title = shareInfo.getTitle();
  135 + msg.description = shareInfo.getContent();
  136 + msg.thumbData = Util.bmpToByteArray(thumbBmp, true);
  137 + SendMessageToWX.Req req = new SendMessageToWX.Req();
  138 + if (TextUtils.isEmpty(shareInfo.getShareType())) {
  139 + req.transaction = buildTransaction("webpage");
  140 + } else {
  141 + //封装的微信分享的gson数据
  142 + ShareIntegralTypeInfo integralTypeInfo = new ShareIntegralTypeInfo();
  143 + integralTypeInfo.setContentId(shareInfo.getContentId());
  144 + integralTypeInfo.setShareType(shareInfo.getShareType());
  145 + Gson gson = new Gson();
  146 + String shareType = gson.toJson(integralTypeInfo);
  147 + req.transaction = shareType;
  148 + }
  149 + req.message = msg;
  150 + req.scene = isWechat ? SendMessageToWX.Req.WXSceneSession : SendMessageToWX.Req.WXSceneTimeline;
  151 + api.sendReq(req);//发送到微信
  152 + if (thumbBmp != null)
  153 + thumbBmp.recycle();
  154 +
  155 + }
  156 +
  157 +
  158 + /**
  159 + * 分享qq
  160 + *
  161 + * @param shareInfo
  162 + * @param mContext
  163 + */
  164 + public static void shareQQ(ShareInfo shareInfo, Activity mContext) {
  165 + if (mContext == null) return;
  166 + if (!NetworkUtil.isConnectInternet(mContext)) {
  167 + AlertUtil.showDeftToast(mContext, "网络异常,请检查您的网络");
  168 + return;
  169 + }
  170 + if (shareInfo == null || TextUtils.isEmpty(shareInfo.getUrl())) {
  171 + AlertUtil.showDeftToast(mContext, "数据异常");
  172 + }
  173 + AppProbeUtil.Probe_ShareTimes_To(mContext, AppProbeUtil.TYPE_QQ_FRIEND);
  174 + String url = Util.processUrlData(shareInfo.getUrl(), mContext, false);
  175 + if (!TextUtils.isEmpty(url) && url.length() >= 512) {
  176 + Map<String, String> requestMap = new HashMap<>();
  177 + requestMap.put("longUrl", url);
  178 + HttpConn.action(BaseRequest.init().service(ApiShareService.class)
  179 + .genShortLinks(requestMap), new NetCallBack<BaseResult<ShortLinkInfo>>() {
  180 + @Override
  181 + public void onRequestState(int state) {
  182 +
  183 + }
  184 +
  185 + @Override
  186 + public void onSuccess(BaseResult<ShortLinkInfo> data) {
  187 + if (!TextUtils.isEmpty(data.getData().getShortUrl())) {
  188 + showQQ(shareInfo, mContext, data.getData().getShortUrl());
  189 + } else {
  190 + AlertUtil.showDeftToast(mContext, "数据异常");
  191 + }
  192 + }
  193 +
  194 + @Override
  195 + public void onFailure(String errCode, String errMsg) {
  196 + AlertUtil.showDeftToast(mContext, errMsg);
  197 + }
  198 + });
  199 + } else {
  200 + showQQ(shareInfo, mContext, url);
  201 + }
  202 +
  203 + }
  204 +
  205 + private static void showQQ(ShareInfo shareInfo, Activity mContext, String url) {
  206 + Tencent mTencent = Tencent.createInstance(BuildConfig.QQ_SHARE, mContext);
  207 + String imgUrl;
  208 + if (!TextUtils.isEmpty(shareInfo.getImgurl()) && shareInfo.getImgurl().contains("http")) {
  209 + imgUrl = shareInfo.getImgurl();
  210 + } else {
  211 + imgUrl = AppConfig.getShareIcon();
  212 + }
  213 + if (Util.checkQQ(mContext) || Util.isQQClientAvailable(mContext) || mTencent.isQQInstalled(mContext)) {
  214 + Bundle params = new Bundle();
  215 + params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
  216 + params.putString(QQShare.SHARE_TO_QQ_TITLE, shareInfo.getTitle());// 标题
  217 + params.putString(QQShare.SHARE_TO_QQ_SUMMARY, shareInfo.getContent());// 摘要
  218 + params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, url);// 内容地址
  219 + params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL, imgUrl);// 网络图片地址
  220 + params.putString(QQShare.SHARE_TO_QQ_APP_NAME, "网家家");// 应用名称
  221 + // 分享操作要在主线程中完成
  222 + mTencent.shareToQQ(mContext, params, new QQListener() {
  223 + @Override
  224 + public void onComplete(Object o) {
  225 + processQQCallBack(mContext, shareInfo.getShareType(), shareInfo.getContentId());
  226 + AlertUtil.showDeftToast(mContext, "分享成功");
  227 +
  228 + }
  229 +
  230 + @Override
  231 + public void onError(UiError uiError) {
  232 + AlertUtil.showDeftToast(mContext, "分享失败");
  233 + }
  234 +
  235 + @Override
  236 + public void onCancel() {
  237 + AlertUtil.showDeftToast(mContext, "取消分享");
  238 + }
  239 + });
  240 + } else {
  241 + AlertUtil.showDeftToast(mContext, "您未安装该第三方应用,无法分享信息到该应用中!");
  242 + }
  243 + }
  244 +
  245 + //分享纯图片到qq
  246 +
  247 + public static void showQQPic(File file, Activity mContext) {
  248 + Tencent mTencent = Tencent.createInstance(BuildConfig.QQ_SHARE, mContext);
  249 + if (Util.checkQQ(mContext) || Util.isQQClientAvailable(mContext) || mTencent.isQQInstalled(mContext)) {
  250 +
  251 + Bundle params = new Bundle();
  252 + params.putString(QQShare.SHARE_TO_QQ_IMAGE_LOCAL_URL, file.getAbsolutePath());
  253 + params.putString(QQShare.SHARE_TO_QQ_APP_NAME, "");
  254 + params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_IMAGE);
  255 + mTencent.shareToQQ(mContext, params, new IUiListener() {
  256 + @Override
  257 + public void onComplete(Object o) {
  258 +
  259 + }
  260 +
  261 + @Override
  262 + public void onError(UiError uiError) {
  263 +
  264 + }
  265 +
  266 + @Override
  267 + public void onCancel() {
  268 +
  269 + }
  270 + });
  271 +
  272 + } else {
  273 + AlertUtil.showDeftToast(mContext, "您未安装该第三方应用,无法分享信息到该应用中!");
  274 + }
  275 + }
  276 +
  277 +
  278 + /**
  279 + * 处理qq成功回调的数据
  280 + *
  281 + * @param mContext
  282 + * @param shareType 分享的类型
  283 + * @param contentId 用与统计的内容ID
  284 + */
  285 + public static void processQQCallBack(Activity mContext, String shareType, String contentId) {
  286 + if (TextUtils.isEmpty(shareType)) return;
  287 + switch (shareType) {
  288 + case "witnessVideo":
  289 + SharedPreferences preferences = mContext.getSharedPreferences("sharevideo", MODE_PRIVATE);
  290 + boolean status = preferences.getBoolean(UserService.getUid(mContext), false);
  291 + String newTime = DateTimeUtil.getCurrentTime();
  292 + String oldtime = preferences.getString(UserService.getUid(mContext) + "time", "2019-04-10");
  293 + boolean sameDay = DateTimeUtil.isSameDay(newTime, oldtime);
  294 + if (!status) {
  295 + ARouterUtil.addIntegrationPic(mContext, "share_video", contentId, "sharevideo");
  296 + }
  297 + if (status && !sameDay) {
  298 + ARouterUtil.addIntegrationPic(mContext, "share_video", contentId, "sharevideo");
  299 + }
  300 + break;
  301 + default:
  302 + SharedPreferences preferences1 = mContext.getSharedPreferences("sharearticle", MODE_PRIVATE);
  303 + boolean status1 = preferences1.getBoolean(UserService.getUid(mContext), false);
  304 + String newTime1 = DateTimeUtil.getCurrentTime();
  305 + String oldtime1 = preferences1.getString(UserService.getUid(mContext) + "time", "2019-04-10");
  306 + boolean sameDay1 = DateTimeUtil.isSameDay(newTime1, oldtime1);
  307 + if (!status1) {
  308 + ARouterUtil.addIntegrationPic(mContext, "share_article", contentId, "sharearticle");
  309 + }
  310 + if (status1 && !sameDay1) {
  311 + ARouterUtil.addIntegrationPic(mContext, "share_article", contentId, "sharearticle");
  312 + }
  313 + break;
  314 + }
  315 + }
  316 +
  317 + /**
  318 + * 分享到朋友圈
  319 + */
  320 + public static void shareWCE(final ShareInfo shareInfo, final Context mContext) {
  321 + AppProbeUtil.Probe_ShareTimes_To(mContext, AppProbeUtil.TYPE_WX_MOMENT);
  322 + if (!NetworkUtil.isConnectInternet(mContext)) {
  323 + AlertUtil.showDeftToast(mContext, "网络异常,请检查您的网络");
  324 + return;
  325 + }
  326 + if (Util.checkWechat(mContext)) {
  327 +
  328 + new Thread(new Runnable() {
  329 + @Override
  330 + public void run() {
  331 + try {
  332 + Bitmap bitmap = Glide.with(mContext)
  333 + .setDefaultRequestOptions(new RequestOptions().centerCrop())
  334 + .asBitmap()
  335 + .load(shareInfo.getImgurl())
  336 + .into(120, 120)
  337 + .get(2, TimeUnit.SECONDS);
  338 + if (bitmap == null) {
  339 + Resources res = mContext.getResources();
  340 + Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.share_logo_share_module);
  341 + Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 120, 120, true);
  342 + shareWx(thumbBmp, shareInfo, mContext, false);
  343 + return;
  344 + }
  345 + shareWx(bitmap, shareInfo, mContext, false);
  346 + } catch (Exception e) {
  347 + Resources res = mContext.getResources();
  348 + Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.share_logo_share_module);
  349 + Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 120, 120, true);
  350 + shareWx(thumbBmp, shareInfo, mContext, false);
  351 + }
  352 +
  353 +
  354 + }
  355 + }).start();
  356 + } else {
  357 + AlertUtil.showDeftToast(mContext, "您未安装该第三方应用,无法分享信息到该应用中!");
  358 + }
  359 + }
  360 +
  361 + /**
  362 + * 小程序分享
  363 + *
  364 + * @param context
  365 + */
  366 + public static void shareWechatApplet(Context context,
  367 + ShareInfo shareInfo) {
  368 + new Thread(new Runnable() {
  369 + @Override
  370 + public void run() {
  371 + try {
  372 + Bitmap bitmap = Glide.with(context)
  373 + .setDefaultRequestOptions(new RequestOptions().centerCrop())
  374 + .asBitmap()
  375 + .load(shareInfo.getImgurl())
  376 + .into(120, 120)
  377 + .get(2, TimeUnit.SECONDS);
  378 + if (bitmap == null) {
  379 + Resources res = context.getResources();
  380 + Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.share_logo_share_module);
  381 + Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 120, 120, true);
  382 + WechatApplet(context, shareInfo, thumbBmp);
  383 + return;
  384 + }
  385 + WechatApplet(context, shareInfo, bitmap);
  386 + } catch (Exception e) {
  387 + Resources res = context.getResources();
  388 + Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.share_logo_share_module);
  389 + Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 120, 120, true);
  390 + WechatApplet(context, shareInfo, thumbBmp);
  391 + }
  392 +
  393 + }
  394 + }).start();
  395 + }
  396 +
  397 + private static void WechatApplet(Context context,
  398 + ShareInfo info, Bitmap thumbBmp) {
  399 + IWXAPI api = WXAPIFactory.createWXAPI(context, BuildConfig.WECHAT_SHARE);
  400 + WXMiniProgramObject miniProgramObj = new WXMiniProgramObject();
  401 + miniProgramObj.webpageUrl = info.getWebpageUrl(); // 兼容低版本的网页链接
  402 + miniProgramObj.miniprogramType = info.getMiniprogramType();// 正式版:0,测试版:1,体验版:2
  403 + miniProgramObj.userName = info.getUserName(); // 小程序原始id
  404 + miniProgramObj.path = info.getPath(); //小程序页面路径
  405 + WXMediaMessage msg = new WXMediaMessage(miniProgramObj);
  406 + msg.title = info.getTitle(); // 小程序消息title
  407 + msg.description = info.getContent(); // 小程序消息desc
  408 + msg.thumbData = Util.bmpToByteArray(thumbBmp, true); // 小程序消息封面图片,小于128k
  409 +
  410 + SendMessageToWX.Req req = new SendMessageToWX.Req();
  411 + req.transaction = buildTransaction("miniProgram");
  412 + req.message = msg;
  413 + req.scene = SendMessageToWX.Req.WXSceneSession; // 目前只支持会话
  414 + api.sendReq(req);
  415 + }
  416 +
  417 +
  418 + /**
  419 + * 跳转到浏览器
  420 + *
  421 + * @param context
  422 + * @param url
  423 + */
  424 + public static void startBrowser(Context context, String url) {
  425 + AppProbeUtil.Probe_ShareTimes_To(context, AppProbeUtil.TYPE_BROWSER);
  426 + Intent intent = new Intent();
  427 + intent.setAction("android.intent.action.VIEW");
  428 + Uri content_url = Uri.parse(Util.processUrlData(url, context, false));
  429 + intent.setData(content_url);
  430 + context.startActivity(intent);
  431 + }
  432 +
  433 + private static ShareReleaseInfoUtil.ShareConfig initAppShareConfig(ShareInfo info, Context context) {
  434 + if (config == null) config = ShareReleaseInfoUtil.ShareConfig.newInstance();
  435 + if (info != null) {
  436 + if (info.isProcessWjjShare()) {
  437 + info.setUrl(TextUtils.isEmpty(info.getWjjShareUrl()) ? AppConfig.getShareDownload() : info.getWjjShareUrl());
  438 + }
  439 + String WJJ_FRIEND = Util.processUrlData(info.getUrl(), context, true);
  440 + info.setUrl(WJJ_FRIEND);
  441 + }
  442 + return config
  443 + .setImage(info.getImgurl())
  444 + .setTitle(info.getTitle())
  445 + .setSubTitle(info.getContent())
  446 + .setUrl(info.getUrl())
  447 + .setType(ShareReleaseInfoUtil.TYPE_HTML);
  448 + }
  449 +
  450 + public static void shareAppMoment(ShareInfo shareInfo, Context context) {
  451 + AppProbeUtil.Probe_ShareTimes_To(context, AppProbeUtil.TYPE_WJJ_MOMENT);
  452 + initAppShareConfig(shareInfo, context).shareRelease(context);
  453 + }
  454 +
  455 + public static void shareAppIM(ShareInfo shareInfo, Context context) {
  456 + AppProbeUtil.Probe_ShareTimes_To(context, AppProbeUtil.TYPE_WJJ_FRIEND);
  457 + initAppShareConfig(shareInfo, context).shareSend(context);
  458 + }
  459 +
  460 + /**
  461 + * 分享 图片到生活圈和分享图片到好友
  462 + *
  463 + * @param context
  464 + * @param bmp
  465 + * @param isWechat 是否是分享到好友
  466 + */
  467 + public static void shareWechatPic(Context context, Bitmap bmp, boolean isWechat) {
  468 + if (Util.isWeixinAvilible(context) || Util.isWXAppInstalledAndSupported(context)) {
  469 +
  470 + try {
  471 + IWXAPI api = WXAPIFactory.createWXAPI(context, BuildConfig.WECHAT_SHARE);
  472 + if (bmp == null) {
  473 + bmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.share_logo_share_module);
  474 + }
  475 +
  476 + //初始化 WXImageObject 和 WXMediaMessage 对象
  477 + WXImageObject imgObj = new WXImageObject(bmp);
  478 + WXMediaMessage msg = new WXMediaMessage();
  479 + msg.mediaObject = imgObj;
  480 +
  481 + //设置缩略图
  482 + Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 120, 120, true);
  483 + bmp.recycle();
  484 + msg.thumbData = Util.bmpToByteArray(thumbBmp, true);
  485 +
  486 + //构造一个Req
  487 + SendMessageToWX.Req req = new SendMessageToWX.Req();
  488 + req.transaction = buildTransaction("img");
  489 + req.message = msg;
  490 + req.scene = isWechat ? SendMessageToWX.Req.WXSceneSession : SendMessageToWX.Req.WXSceneTimeline;
  491 + ;
  492 + //调用api接口,发送数据到微信
  493 + api.sendReq(req);
  494 + } catch (Exception e) {
  495 + Log.e("异常:", e.getMessage());
  496 + }
  497 +
  498 + } else {
  499 + AlertUtil.showDeftToast(context, "您未安装该第三方应用,无法分享信息到该应用中!");
  500 + }
  501 +
  502 + }
  503 +
  504 +
  505 + /**
  506 + * 分享图片到生活圈与好友
  507 + *
  508 + * @param mContext
  509 + * @param type
  510 + * @param imgUrl
  511 + */
  512 + public static void getForwardingImgPath(Activity mContext, String type, String imgUrl) {
  513 + if (TextUtils.isEmpty(imgUrl)) return;
  514 + if (mContext == null) return;
  515 + Observable.create((ObservableOnSubscribe<String>) emitter -> {
  516 + if (FileUtils.isFileExists(imgUrl) && FileUtils.getFileByPath(imgUrl).length() > 0) {
  517 + emitter.onNext(imgUrl);
  518 + } else {
  519 + if (imgUrl.contains("http")) {
  520 + File file = Glide.with(mContext).asFile().load(imgUrl).submit().get();
  521 + if (file != null && file.exists() && file.length() > 0) {
  522 + String path = file.getAbsolutePath();
  523 + emitter.onNext(path);
  524 + } else {
  525 + emitter.onError(new Throwable("非法图片地址"));
  526 + }
  527 + } else {
  528 + emitter.onError(new Throwable("非法图片地址"));
  529 + }
  530 +
  531 + }
  532 +
  533 + }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<String>() {
  534 + @Override
  535 + public void onSubscribe(Disposable d) {
  536 +
  537 + }
  538 +
  539 + @Override
  540 + public void onNext(String content) {
  541 + if (!TextUtils.isEmpty(content)) {
  542 + if (type.equals("friends")) {
  543 + ARouter.getInstance().build("/cnconversation/SelectForwardActivity")
  544 + .withString("shareLocalContent", content)
  545 + .withInt("shareType", 0x2002)
  546 + .withInt("inType", 0x1002)
  547 + .navigation(mContext);
  548 + mContext.finish();
  549 + } else if (type.equals("life")) {
  550 + File file = new File(content); //pic 1 video 3
  551 + if (!FileUtils.isFileExists(content)) return;
  552 + ARouter.getInstance().build("/cnmain/ReleaseManagementAcityity")
  553 + .withInt("type", 4)
  554 + .withString("path", file.getPath())
  555 + .withString("name", file.getName())
  556 + .withString("parentDir", "")
  557 + .withInt("mediaType", 1)
  558 + .withInt("id", 0)
  559 + .withLong("time", 1)
  560 + .withLong("size", file.length())
  561 + .navigation(mContext);
  562 + mContext.finish();
  563 + } else {
  564 + AlertUtil.showDeftToast(mContext, "类型异常");
  565 + }
  566 + } else {
  567 + AlertUtil.showDeftToast(mContext, "非法图片地址");
  568 + }
  569 + }
  570 +
  571 + @Override
  572 + public void onError(Throwable e) {
  573 + AlertUtil.showDeftToast(mContext, e.getMessage());
  574 + }
  575 +
  576 + @Override
  577 + public void onComplete() {
  578 +
  579 + }
  580 + });
  581 + }
  582 +
  583 + public static void shareWeiBo(Activity mContext, ShareInfo shareInfo) {
  584 + if (!NetworkUtil.isConnectInternet(mContext)) {
  585 + AlertUtil.showDeftToast(mContext, "网络异常,请检查您的网络");
  586 + return;
  587 + }
  588 + if (Util.isWeiboInstallAndInit(mContext)) {
  589 + //注册微博
  590 + WbShareHandler shareHandler = new WbShareHandler(mContext);
  591 + shareHandler.registerApp();
  592 + ImageObject imageObject = new ImageObject();
  593 + WeiboMultiMessage weiboMessage = new WeiboMultiMessage();
  594 + TextObject textObject = new TextObject();
  595 + textObject.text = shareInfo.getContent() + shareInfo.getUrl();
  596 + weiboMessage.textObject = textObject;
  597 +
  598 +
  599 + weiboMessage.imageObject = imageObject;
  600 + new Thread(new Runnable() {
  601 + @Override
  602 + public void run() {
  603 + try {
  604 + Bitmap bitmap = Glide.with(mContext)
  605 + .setDefaultRequestOptions(new RequestOptions().centerCrop())
  606 + .asBitmap()
  607 + .load(shareInfo.getImgurl())
  608 + .into(120, 120)
  609 + .get(2, TimeUnit.SECONDS);
  610 + if (bitmap == null) {
  611 + Resources res = mContext.getResources();
  612 + Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.share_logo_share_module);
  613 + imageObject.setImageObject(bmp);
  614 + shareHandler.shareMessage(weiboMessage, false);
  615 + return;
  616 + } else {
  617 + imageObject.setImageObject(bitmap);
  618 + shareHandler.shareMessage(weiboMessage, false);
  619 + }
  620 + } catch (Exception e) {
  621 + Resources res = mContext.getResources();
  622 + Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.share_logo_share_module);
  623 + imageObject.setImageObject(bmp);
  624 + shareHandler.shareMessage(weiboMessage, false);
  625 + }
  626 +
  627 + }
  628 + }).start();
  629 + } else {
  630 + AlertUtil.showDeftToast(mContext, "您未安装该第三方应用,无法分享信息到该应用中!");
  631 + }
  632 +
  633 + }
  634 +
  635 +
  636 + public static void shareWbPic(Activity context, Bitmap bitmap) {
  637 + if (Util.isWeiboInstallAndInit(context)) {
  638 + ImageObject imageObject = new ImageObject();
  639 + imageObject.setImageObject(bitmap);
  640 + WeiboMultiMessage weiboMessage = new WeiboMultiMessage();
  641 + weiboMessage.imageObject = imageObject;
  642 + WbShareHandler shareHandler = new WbShareHandler(context);
  643 + shareHandler.registerApp();
  644 + shareHandler.shareMessage(weiboMessage, false);
  645 + } else {
  646 + AlertUtil.showDeftToast(context, "您未安装该第三方应用,无法分享信息到该应用中!");
  647 + }
  648 +
  649 + }
  650 +
  651 + /**
  652 + * 分享qq
  653 + *
  654 + * @param shareInfo
  655 + * @param mContext
  656 + */
  657 + public static void shareQQActivity(ShareInfo shareInfo, Activity mContext, IUiListener listener) {
  658 + if (mContext == null) return;
  659 + if (!NetworkUtil.isConnectInternet(mContext)) {
  660 + AlertUtil.showDeftToast(mContext, "网络异常,请检查您的网络");
  661 + return;
  662 + }
  663 + if (shareInfo == null || TextUtils.isEmpty(shareInfo.getUrl())) {
  664 + AlertUtil.showDeftToast(mContext, "数据异常");
  665 + }
  666 + AppProbeUtil.Probe_ShareTimes_To(mContext, AppProbeUtil.TYPE_QQ_FRIEND);
  667 + String url = Util.processUrlData(shareInfo.getUrl(), mContext, false);
  668 + if (!TextUtils.isEmpty(url) && url.length() >= 512) {
  669 + HashMap<String, String> requestMap = new HashMap<>();
  670 + requestMap.put("longUrl", url);
  671 + HttpConn.action(BaseRequest.init()
  672 + .service(ApiShareService.class)
  673 + .genShortLinks(requestMap), new NetCallBack<BaseResult<ShortLinkInfo>>() {
  674 + @Override
  675 + public void onRequestState(int state) {
  676 +
  677 + }
  678 +
  679 + @Override
  680 + public void onSuccess(BaseResult<ShortLinkInfo> data) {
  681 + if (!TextUtils.isEmpty(data.getData().getShortUrl())) {
  682 + showQQ(shareInfo, mContext, data.getData().getShortUrl(), listener);
  683 + } else {
  684 + AlertUtil.showDeftToast(mContext, "数据异常");
  685 + }
  686 + }
  687 +
  688 + @Override
  689 + public void onFailure(String errCode, String errMsg) {
  690 + AlertUtil.showDeftToast(mContext, errMsg);
  691 + }
  692 + });
  693 + } else {
  694 + showQQ(shareInfo, mContext, url, listener);
  695 + }
  696 +
  697 + }
  698 +
  699 + /**
  700 + * 自己实现监听
  701 + *
  702 + * @param shareInfo
  703 + * @param mContext
  704 + * @param url
  705 + * @param listener
  706 + */
  707 + private static void showQQ(ShareInfo shareInfo, Activity mContext, String url, IUiListener listener) {
  708 + Tencent mTencent = Tencent.createInstance(BuildConfig.QQ_SHARE, mContext);
  709 + String imgUrl;
  710 + if (!TextUtils.isEmpty(shareInfo.getImgurl()) && shareInfo.getImgurl().contains("http")) {
  711 + imgUrl = shareInfo.getImgurl();
  712 + } else {
  713 + imgUrl = AppConfig.getShareIcon();
  714 + }
  715 + if (Util.checkQQ(mContext) || Util.isQQClientAvailable(mContext) || mTencent.isQQInstalled(mContext)) {
  716 + Bundle params = new Bundle();
  717 + params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
  718 + params.putString(QQShare.SHARE_TO_QQ_TITLE, shareInfo.getTitle());// 标题
  719 + params.putString(QQShare.SHARE_TO_QQ_SUMMARY, shareInfo.getContent());// 摘要
  720 + params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, url);// 内容地址
  721 + params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL, imgUrl);// 网络图片地址
  722 + params.putString(QQShare.SHARE_TO_QQ_APP_NAME, "网家家");// 应用名称
  723 + // 分享操作要在主线程中完成
  724 + mTencent.shareToQQ(mContext, params, listener);
  725 + } else {
  726 + AlertUtil.showDeftToast(mContext, "您未安装该第三方应用,无法分享信息到该应用中!");
  727 + }
  728 + }
  729 +
  730 +}
... ...