接入MobLink
This commit is contained in:
@@ -4,6 +4,8 @@ import com.yizhuan.xchat_android_core.share.bean.ShareCommonInfo;
|
||||
import com.yizhuan.xchat_android_core.web.bean.WebJsBeanInfo;
|
||||
import com.yizhuan.xchat_android_library.coremanager.IBaseCore;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import cn.sharesdk.framework.Platform;
|
||||
import io.reactivex.Single;
|
||||
|
||||
@@ -17,7 +19,7 @@ public interface IShareModel extends IBaseCore {
|
||||
|
||||
Single<String> shareH5(WebJsBeanInfo.DataBean webViewInfo, Platform platform, boolean httpsUrl);
|
||||
|
||||
Single<String> shareRoom(Platform platform, long roomUid, long roomId, String title, String roomAvatar);
|
||||
Single<String> shareRoom(Platform platform, long roomUid, String title, String avatar);
|
||||
|
||||
Single<String> shareFamily(Platform platform,
|
||||
String familyId,
|
||||
|
@@ -23,7 +23,6 @@ import com.yizhuan.xchat_android_library.net.rxnet.RxNet;
|
||||
import com.yizhuan.xchat_android_library.utils.ResUtil;
|
||||
import com.yizhuan.xchat_android_library.utils.SingleToastUtil;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
|
||||
import cn.sharesdk.facebook.Facebook;
|
||||
@@ -46,25 +45,15 @@ import retrofit2.http.Query;
|
||||
|
||||
public class ShareModel extends BaseModel implements IShareModel {
|
||||
|
||||
private interface MSG {
|
||||
String success = ResUtil.getString(R.string.xchat_android_core_share_sharemodel_01);
|
||||
String failed = ResUtil.getString(R.string.xchat_android_core_share_sharemodel_02);
|
||||
String cancel = ResUtil.getString(R.string.xchat_android_core_share_sharemodel_03);
|
||||
}
|
||||
|
||||
private final Api api = RxNet.create(Api.class);
|
||||
|
||||
private static final class Helper {
|
||||
public static final ShareModel INSTANCE = new ShareModel();
|
||||
private ShareModel() {
|
||||
}
|
||||
|
||||
public static ShareModel get() {
|
||||
return Helper.INSTANCE;
|
||||
}
|
||||
|
||||
private ShareModel() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Single<String> shareH5(final WebJsBeanInfo.DataBean webViewInfo, Platform platform) {
|
||||
return shareH5(webViewInfo, platform, false);
|
||||
@@ -138,64 +127,69 @@ public class ShareModel extends BaseModel implements IShareModel {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 分享房间
|
||||
*
|
||||
* @param platform 平台
|
||||
* @param roomUid 房间id
|
||||
* @param title 标题
|
||||
*/
|
||||
@Override
|
||||
public Single<String> shareRoom(Platform platform,
|
||||
final long roomUid,
|
||||
long roomId,
|
||||
String title, String room_avatar) {
|
||||
public Single<String> shareRoom(Platform platform, final long roomUid, String title, String avatar) {
|
||||
return Single.create(new SingleOnSubscribe<String>() {
|
||||
@SuppressLint("CheckResult")
|
||||
@Override
|
||||
public void subscribe(SingleEmitter<String> emitter) throws Exception {
|
||||
UserModel.get().getUserInfo(roomUid).subscribe(userInfo -> {
|
||||
//无UI API
|
||||
if (userInfo != null && platform != null) {
|
||||
Platform.ShareParams sp = new Platform.ShareParams();
|
||||
sp.setText(XChatConstants.SHARE_ROOM_TEXT);
|
||||
sp.setTitle(XChatConstants.SHARE_ROOM_TITLE);
|
||||
sp.setImageUrl(userInfo.getAvatar());
|
||||
final String siteUrl = UriProvider.IM_SERVER_URL + XChatConstants.SHARE_ROOM_URL +
|
||||
AuthModel.get().getCurrentUid() + "&uid=" + roomUid + "&room_name=" +
|
||||
URLEncoder.encode(title, "utf8") + "&room_id=" + roomId + "&room_avatar=" +
|
||||
URLEncoder.encode(room_avatar, "utf8") + "&share_name=" +
|
||||
URLEncoder.encode( UserModel.get().getCacheLoginUserInfo().getNick(), "utf8");
|
||||
//QQ空间分享
|
||||
//无UI API
|
||||
if (platform != null) {
|
||||
|
||||
sp.setSite(XChatConstants.SHARE_ROOM_TEXT);
|
||||
sp.setSiteUrl(siteUrl);
|
||||
//QQ分享
|
||||
sp.setTitleUrl(siteUrl);
|
||||
//微信朋友圈分享
|
||||
Platform.ShareParams sp = new Platform.ShareParams();
|
||||
sp.setImageUrl(avatar);
|
||||
|
||||
String tmpSiteUrl = UriProvider.IM_SERVER_URL + XChatConstants.SHARE_ROOM_URL + AuthModel.get().getCurrentUid() + "&uid=" + roomUid + "&ROOM_UID=" + roomUid;
|
||||
|
||||
final String siteUrl = tmpSiteUrl;
|
||||
|
||||
|
||||
//facebook
|
||||
if (platform.getName().equals(Facebook.NAME)) {
|
||||
sp.setTitle(XChatConstants.SHARE_ROOM_TITLE);
|
||||
sp.setText(XChatConstants.SHARE_ROOM_TEXT);
|
||||
sp.setUrl(siteUrl);
|
||||
sp.setShareType(Platform.SHARE_WEBPAGE);
|
||||
platform.setPlatformActionListener(new PlatformActionListener() {
|
||||
@Override
|
||||
public void onComplete(Platform platform1, int i, HashMap<String, Object> hashMap) {
|
||||
sendShareRoomTipMsg(roomUid);
|
||||
String shareUrl = siteUrl;
|
||||
reportShare(String.valueOf(roomUid), 1, platform1, shareUrl);
|
||||
emitter.onSuccess(MSG.success);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Platform platform1, int i, Throwable throwable) {
|
||||
emitter.onError(new Throwable(MSG.failed));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(Platform platform1, int i) {
|
||||
emitter.onError(new Throwable(MSG.cancel));
|
||||
}
|
||||
});
|
||||
platform.share(sp);
|
||||
}
|
||||
});
|
||||
//line
|
||||
else if (platform.getName().equals(Line.NAME)) {
|
||||
sp.setText(XChatConstants.SHARE_ROOM_TEXT + "[" + siteUrl + "]");
|
||||
}
|
||||
|
||||
platform.setPlatformActionListener(new PlatformActionListener() {
|
||||
@Override
|
||||
public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
|
||||
sendShareRoomTipMsg(roomUid);
|
||||
reportShare(String.valueOf(roomUid), 1, platform, siteUrl);
|
||||
emitter.onSuccess(MSG.success);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Platform platform, int i, Throwable throwable) {
|
||||
String errorMsg = MSG.failed;
|
||||
if (throwable.getMessage().contains("not installed")) {
|
||||
errorMsg = ResUtil.getString(R.string.not_install_app);
|
||||
}
|
||||
emitter.onError(new Throwable(errorMsg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(Platform platform, int i) {
|
||||
emitter.onError(new Throwable(MSG.cancel));
|
||||
}
|
||||
});
|
||||
platform.share(sp);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 向我们服务器报告分享
|
||||
*
|
||||
@@ -215,13 +209,13 @@ public class ShareModel extends BaseModel implements IShareModel {
|
||||
}
|
||||
|
||||
api.getShareRedPacket(
|
||||
String.valueOf(AuthModel.get().getCurrentUid()),
|
||||
roomUid,
|
||||
String.valueOf(shareType),
|
||||
sharePageId + "",
|
||||
shareUrl,
|
||||
AuthModel.get().getTicket()
|
||||
)
|
||||
String.valueOf(AuthModel.get().getCurrentUid()),
|
||||
roomUid,
|
||||
String.valueOf(shareType),
|
||||
sharePageId + "",
|
||||
shareUrl,
|
||||
AuthModel.get().getTicket()
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe();
|
||||
@@ -322,7 +316,6 @@ public class ShareModel extends BaseModel implements IShareModel {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Single<String> shareText(Platform platform, String text) {
|
||||
return Single.create(emitter -> {
|
||||
@@ -448,42 +441,41 @@ public class ShareModel extends BaseModel implements IShareModel {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Single<String> shareCommon(Platform platform, ShareCommonInfo info, boolean toast) {
|
||||
|
||||
return Single.create((SingleOnSubscribe<String>) emitter -> {
|
||||
Platform.ShareParams sp = new Platform.ShareParams();
|
||||
sp.setTitle(info.getTitle());
|
||||
sp.setText(info.getContent());
|
||||
sp.setImageUrl(info.getImageUrl());
|
||||
String siteUrl = info.getSiteUrl();
|
||||
//QQ空间分享
|
||||
sp.setSite(info.getTitle());
|
||||
sp.setSiteUrl(siteUrl);
|
||||
//QQ分享
|
||||
sp.setTitleUrl(siteUrl);
|
||||
//微信朋友圈分享
|
||||
sp.setUrl(siteUrl);
|
||||
sp.setShareType(Platform.SHARE_WEBPAGE);
|
||||
platform.setPlatformActionListener(new PlatformActionListener() {
|
||||
@Override
|
||||
public void onComplete(Platform platform1, int i, HashMap<String, Object> hashMap) {
|
||||
emitter.onSuccess(MSG.success);
|
||||
}
|
||||
Platform.ShareParams sp = new Platform.ShareParams();
|
||||
sp.setTitle(info.getTitle());
|
||||
sp.setText(info.getContent());
|
||||
sp.setImageUrl(info.getImageUrl());
|
||||
String siteUrl = info.getSiteUrl();
|
||||
//QQ空间分享
|
||||
sp.setSite(info.getTitle());
|
||||
sp.setSiteUrl(siteUrl);
|
||||
//QQ分享
|
||||
sp.setTitleUrl(siteUrl);
|
||||
//微信朋友圈分享
|
||||
sp.setUrl(siteUrl);
|
||||
sp.setShareType(Platform.SHARE_WEBPAGE);
|
||||
platform.setPlatformActionListener(new PlatformActionListener() {
|
||||
@Override
|
||||
public void onComplete(Platform platform1, int i, HashMap<String, Object> hashMap) {
|
||||
emitter.onSuccess(MSG.success);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Platform platform1, int i, Throwable throwable) {
|
||||
emitter.onError(new Throwable(MSG.failed));
|
||||
}
|
||||
@Override
|
||||
public void onError(Platform platform1, int i, Throwable throwable) {
|
||||
emitter.onError(new Throwable(MSG.failed));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(Platform platform1, int i) {
|
||||
emitter.onError(new Throwable(MSG.cancel));
|
||||
}
|
||||
});
|
||||
platform.share(sp);
|
||||
})
|
||||
@Override
|
||||
public void onCancel(Platform platform1, int i) {
|
||||
emitter.onError(new Throwable(MSG.cancel));
|
||||
}
|
||||
});
|
||||
platform.share(sp);
|
||||
})
|
||||
.doOnSuccess(s -> {
|
||||
if (toast) {
|
||||
SingleToastUtil.showToast(s);
|
||||
@@ -496,6 +488,13 @@ public class ShareModel extends BaseModel implements IShareModel {
|
||||
});
|
||||
}
|
||||
|
||||
private interface MSG {
|
||||
String success = ResUtil.getString(R.string.xchat_android_core_share_sharemodel_01);
|
||||
String failed = ResUtil.getString(R.string.xchat_android_core_share_sharemodel_02);
|
||||
String cancel = ResUtil.getString(R.string.xchat_android_core_share_sharemodel_03);
|
||||
}
|
||||
|
||||
|
||||
interface Api {
|
||||
|
||||
/**
|
||||
@@ -518,4 +517,8 @@ public class ShareModel extends BaseModel implements IShareModel {
|
||||
@Query("ticket") String ticket);
|
||||
}
|
||||
|
||||
private static final class Helper {
|
||||
public static final ShareModel INSTANCE = new ShareModel();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -661,4 +661,7 @@
|
||||
<string name="upgrade_model_upgrademodel_05">正在下載中...</string>
|
||||
<string name="upgrade_model_upgrademodel_06">下載中...</string>
|
||||
<string name="upgrade_model_upgrademodel_07">已是最新版本</string>
|
||||
<string name="not_install_app">未安裝該應用</string>
|
||||
<string name="wechat_share_title">HABU-Making new friends,join HABU right now. </string>
|
||||
<string name="wechat_share_content">Find and join the best groups,talk with strangers</string>
|
||||
</resources>
|
||||
|
Reference in New Issue
Block a user