From d14939c8935443f09e16d95f8004faaeadce5ee7 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Mon, 6 Feb 2023 15:57:56 +0800 Subject: [PATCH 01/10] create ShareUtil --- .../com/yunbao/common/utils/ShareUtil.java | 20 +++++++++++++++++++ config.gradle | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 common/src/main/java/com/yunbao/common/utils/ShareUtil.java diff --git a/common/src/main/java/com/yunbao/common/utils/ShareUtil.java b/common/src/main/java/com/yunbao/common/utils/ShareUtil.java new file mode 100644 index 000000000..1f1058449 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/utils/ShareUtil.java @@ -0,0 +1,20 @@ +package com.yunbao.common.utils; + +import android.graphics.Bitmap; + +/** + * 分享工具 + */ +public class ShareUtil { + public static void share(String content) { + share(content, null); + } + + public static void share(Bitmap bitmap) { + share(null,bitmap); + } + + public static void share(String content, Bitmap bitmap) { + + } +} diff --git a/config.gradle b/config.gradle index 66e026ffe..2a10a28f4 100644 --- a/config.gradle +++ b/config.gradle @@ -27,6 +27,6 @@ ext { // true表示谷歌支付 false isGooglePlay : false, //是否上报异常日志 - isUploadLog : true + isUploadLog : false ] } \ No newline at end of file From ce8088059acea736c8f012bfcf9deb192a591d7a Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Tue, 7 Feb 2023 15:45:42 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E6=9A=82=E5=AD=98=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=87=A0=E4=B8=AA=E7=94=A8intent=E6=89=93=E5=BC=80=E5=88=86?= =?UTF-8?q?=E4=BA=AB=E7=9A=84=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/server/ShareBroadcastReceiver.java | 20 +++++++++ .../com/yunbao/common/utils/ShareUtil.java | 43 ++++++++++++++++--- .../main/views/MainHomeLiveViewHolder.java | 38 +++++++++++++++- 3 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 common/src/main/java/com/yunbao/common/server/ShareBroadcastReceiver.java diff --git a/common/src/main/java/com/yunbao/common/server/ShareBroadcastReceiver.java b/common/src/main/java/com/yunbao/common/server/ShareBroadcastReceiver.java new file mode 100644 index 000000000..ad39af5f2 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/server/ShareBroadcastReceiver.java @@ -0,0 +1,20 @@ +package com.yunbao.common.server; + +import static android.content.Intent.EXTRA_CHOSEN_COMPONENT; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +public class ShareBroadcastReceiver extends BroadcastReceiver { + public static final int REQUEST_CODE = 888; + private static final String TAG = "分享log"; + + @Override + public void onReceive(Context context, Intent intent) { + Log.i(TAG, "onReceive"); + Log.i(TAG, intent.getAction() + " | " + intent.getParcelableExtra(EXTRA_CHOSEN_COMPONENT)); + + } +} diff --git a/common/src/main/java/com/yunbao/common/utils/ShareUtil.java b/common/src/main/java/com/yunbao/common/utils/ShareUtil.java index 1f1058449..45416e44f 100644 --- a/common/src/main/java/com/yunbao/common/utils/ShareUtil.java +++ b/common/src/main/java/com/yunbao/common/utils/ShareUtil.java @@ -1,20 +1,53 @@ package com.yunbao.common.utils; +import static android.app.PendingIntent.FLAG_IMMUTABLE; +import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; +import static android.content.Intent.EXTRA_CHOSEN_COMPONENT; + +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; import android.graphics.Bitmap; +import android.net.Uri; + +import com.yunbao.common.server.ShareBroadcastReceiver; + +import java.io.File; /** * 分享工具 */ public class ShareUtil { - public static void share(String content) { - share(content, null); + + public static void share(Context context, String content) { + share(context, content, null); } - public static void share(Bitmap bitmap) { - share(null,bitmap); + public static void share(Context context, File image) { + share(context, null, image); } - public static void share(String content, Bitmap bitmap) { + public static void share(Context context, String content, File image) { + Intent shareIntent = new Intent(Intent.ACTION_SEND); + + if (image != null) { + Uri uri = Uri.fromFile(image); + shareIntent.putExtra(Intent.EXTRA_STREAM, uri); + shareIntent.setType("image/*"); + //当用户选择短信时使用sms_body取得文字 + shareIntent.putExtra("sms_body", content); + } else { + shareIntent.setType("text/plain"); + } + shareIntent.putExtra(Intent.EXTRA_TEXT, content); + //自定义选择框的标题 + PendingIntent pi = PendingIntent.getBroadcast(context, ShareBroadcastReceiver.REQUEST_CODE, + new Intent(context, ShareBroadcastReceiver.class), PendingIntent.FLAG_MUTABLE); + context.registerReceiver(new ShareBroadcastReceiver(),new IntentFilter(EXTRA_CHOSEN_COMPONENT)); + shareIntent = Intent.createChooser(shareIntent, null, pi.getIntentSender()); + context.startActivity(Intent.createChooser(shareIntent, "Share")); + //系统默认标题 } } diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java index f9ae99960..2ffc00e7e 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java @@ -3,7 +3,10 @@ package com.yunbao.main.views; import android.animation.ObjectAnimator; import android.app.Dialog; import android.content.Context; +import android.content.Intent; import android.graphics.Outline; +import android.net.Uri; +import android.os.Environment; import android.text.TextUtils; import android.util.Log; import android.view.View; @@ -11,6 +14,7 @@ import android.view.ViewGroup; import android.view.ViewOutlineProvider; import android.widget.ImageView; +import androidx.core.content.FileProvider; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -36,6 +40,7 @@ import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.MicStatusManager; import com.yunbao.common.utils.RouteUtil; +import com.yunbao.common.utils.ShareUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.views.CustomViewHolder; import com.yunbao.live.event.LiveRoomChangeEvent; @@ -54,6 +59,7 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; +import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -330,7 +336,7 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); } @Override @@ -361,6 +367,34 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement .setOnBannerClickListener(new OnBannerClickListener() { @Override public void onBannerClick(List datas, int p) { + if (true) { + System.err.println("cache = " + mContext.getCacheDir().getAbsolutePath()); + String type = "image/*"; + String filename = "/ztest/myPhoto.jpg"; + String mediaPath = Environment.getExternalStorageDirectory() + filename; + // Create the new Intent using the 'Send' action. + Intent share = new Intent(Intent.ACTION_SEND); + + // Set the MIME type + share.setType(type); + + // Create the URI from the media + File media = new File(mediaPath); + Uri uri = FileProvider.getUriForFile(mContext, + mContext.getPackageName() + ".fileprovider", + media + ); + + // Add the URI to the Intent. + share.putExtra(Intent.EXTRA_STREAM, uri); + share.putExtra(Intent.EXTRA_TEXT, "test"); + // Broadcast the Intent. + // share.setPackage("com.whatsapp"); //WhatsApp + + // share = new Intent(Intent.ACTION_VIEW, Uri.parse("https://line.me/R/share?text=test")); //Line + mContext.startActivity(Intent.createChooser(share, "Share to")); + return; + } if (mBannerList != null) { if (p >= 0 && p < mBannerList.size()) { BannerBean bean = mBannerList.get(p); @@ -423,7 +457,7 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement LiveRoomViewHolder.mHandler.removeCallbacksAndMessages(null); } if (!"".endsWith(Constants.mStream)) { - if(MicStatusManager.getInstance().isMic(liveUid)){ + if (MicStatusManager.getInstance().isMic(liveUid)) { MicStatusManager.getInstance().showDownMicDialog(mContext); return; } From 3c80038bef890795c958a48a4c90ff1b6e946595 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Wed, 8 Feb 2023 16:01:35 +0800 Subject: [PATCH 03/10] update Share --- Share/.gitignore | 1 + Share/build.gradle | 73 +++++++++++++++ Share/consumer-rules.pro | 0 Share/proguard-rules.pro | 21 +++++ .../yunbao/share/ExampleInstrumentedTest.java | 26 ++++++ Share/src/main/AndroidManifest.xml | 20 +++++ .../com/yunbao/share/AbsShareInterface.java | 25 ++++++ .../main/java/com/yunbao/share/ICallback.java | 6 ++ .../java/com/yunbao/share/ShareBuilder.java | 40 +++++++++ .../java/com/yunbao/share/ShareManager.java | 67 ++++++++++++++ .../yunbao/share/platform/FacebookShare.java | 52 +++++++++++ .../com/yunbao/share/platform/Instagram.java | 29 ++++++ .../java/com/yunbao/share/platform/Line.java | 33 +++++++ .../yunbao/share/platform/MessengerShare.java | 63 +++++++++++++ .../yunbao/share/platform/TwitterShare.java | 60 +++++++++++++ .../com/yunbao/share/platform/WhatsApp.java | 24 +++++ .../share/receiver/TwitterResultReceiver.java | 28 ++++++ Share/src/main/res/values/strings.xml | 4 + .../com/yunbao/share/ExampleUnitTest.java | 17 ++++ main/build.gradle | 1 + .../yunbao/main/activity/TestActivity.java | 89 ++++++++++++++++++- .../main/views/MainHomeLiveViewHolder.java | 6 +- settings.gradle | 4 +- 23 files changed, 683 insertions(+), 6 deletions(-) create mode 100644 Share/.gitignore create mode 100644 Share/build.gradle create mode 100644 Share/consumer-rules.pro create mode 100644 Share/proguard-rules.pro create mode 100644 Share/src/androidTest/java/com/yunbao/share/ExampleInstrumentedTest.java create mode 100644 Share/src/main/AndroidManifest.xml create mode 100644 Share/src/main/java/com/yunbao/share/AbsShareInterface.java create mode 100644 Share/src/main/java/com/yunbao/share/ICallback.java create mode 100644 Share/src/main/java/com/yunbao/share/ShareBuilder.java create mode 100644 Share/src/main/java/com/yunbao/share/ShareManager.java create mode 100644 Share/src/main/java/com/yunbao/share/platform/FacebookShare.java create mode 100644 Share/src/main/java/com/yunbao/share/platform/Instagram.java create mode 100644 Share/src/main/java/com/yunbao/share/platform/Line.java create mode 100644 Share/src/main/java/com/yunbao/share/platform/MessengerShare.java create mode 100644 Share/src/main/java/com/yunbao/share/platform/TwitterShare.java create mode 100644 Share/src/main/java/com/yunbao/share/platform/WhatsApp.java create mode 100644 Share/src/main/java/com/yunbao/share/receiver/TwitterResultReceiver.java create mode 100644 Share/src/main/res/values/strings.xml create mode 100644 Share/src/test/java/com/yunbao/share/ExampleUnitTest.java diff --git a/Share/.gitignore b/Share/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/Share/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/Share/build.gradle b/Share/build.gradle new file mode 100644 index 000000000..039fa8b89 --- /dev/null +++ b/Share/build.gradle @@ -0,0 +1,73 @@ +apply plugin: 'com.android.library' +apply plugin: 'img-optimizer' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' + + +android { + compileSdkVersion rootProject.ext.android.compileSdkVersion + buildToolsVersion rootProject.ext.android.buildToolsVersion + packagingOptions { + pickFirst "lib/armeabi/libyuvutils.so" + pickFirst "lib/arm64-v8a/libyuvutils.so" + pickFirst "lib/armeabi-v7a/libyuvutils.so" + pickFirst "lib/armeabi/libyuvtools.so" + pickFirst "lib/arm64-v8a/libyuvtools.so" + pickFirst "lib/armeabi-v7a/libyuvtools.so" + exclude "lib/arm64-v8a/libmmcv_api_handgesture.so" + exclude "lib/arm64-v8a/libmmcv_api_express.so" + exclude "lib/arm64-v8a/libMediaEncoder.so" + exclude "lib/arm64-v8a/libarcore_sdk_c.so" + exclude "lib/arm64-v8a/libmediadecoder.so" + exclude "lib/arm64-v8a/libMediaMuxer.so" + exclude "lib/arm64-v8a/libarcore_sdk_jni.so" + exclude "lib/arm64-v8a/libMediaUtils.so" + exclude "lib/arm64-v8a/libcosmosffmpeg.so" + + } + + defaultConfig { + minSdkVersion rootProject.ext.android.minSdkVersion + targetSdkVersion rootProject.ext.android.targetSdkVersion + versionCode rootProject.ext.android.versionCode + versionName rootProject.ext.android.versionName + manifestPlaceholders = rootProject.ext.manifestPlaceholders + ndk { + abiFilters "armeabi-v7a", "arm64-v8a" + } + } + aaptOptions { + cruncherEnabled = false + useNewCruncher = false + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} +repositories { + flatDir { + dirs 'libs', '../libs' + } +} +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation rootProject.ext.dependencies["appcompat-androidx"] + implementation rootProject.ext.dependencies["recyclerview-androidx"] + //common + implementation project(path: ':common') + //Twitter + implementation 'com.twitter.sdk.android:twitter:3.1.1' + //facebook & Messenger + implementation 'com.facebook.android:facebook-share:15.2.0' + + + +} diff --git a/Share/consumer-rules.pro b/Share/consumer-rules.pro new file mode 100644 index 000000000..e69de29bb diff --git a/Share/proguard-rules.pro b/Share/proguard-rules.pro new file mode 100644 index 000000000..481bb4348 --- /dev/null +++ b/Share/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/Share/src/androidTest/java/com/yunbao/share/ExampleInstrumentedTest.java b/Share/src/androidTest/java/com/yunbao/share/ExampleInstrumentedTest.java new file mode 100644 index 000000000..73039a6f1 --- /dev/null +++ b/Share/src/androidTest/java/com/yunbao/share/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.yunbao.share; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.yunbao.share.test", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/Share/src/main/AndroidManifest.xml b/Share/src/main/AndroidManifest.xml new file mode 100644 index 000000000..e0f407337 --- /dev/null +++ b/Share/src/main/AndroidManifest.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Share/src/main/java/com/yunbao/share/AbsShareInterface.java b/Share/src/main/java/com/yunbao/share/AbsShareInterface.java new file mode 100644 index 000000000..618643b15 --- /dev/null +++ b/Share/src/main/java/com/yunbao/share/AbsShareInterface.java @@ -0,0 +1,25 @@ +package com.yunbao.share; + +import android.content.Context; +import android.net.Uri; + +import androidx.core.content.FileProvider; + +import java.io.File; + +public abstract class AbsShareInterface { + protected final Context mContext; + + public AbsShareInterface(Context context) { + this.mContext = context; + } + + public abstract void share(ShareBuilder builder,ICallback callback); + + public Uri fileToUri(File file){ + return FileProvider.getUriForFile(mContext, + mContext.getPackageName() + ".fileprovider", + file + ); + } +} diff --git a/Share/src/main/java/com/yunbao/share/ICallback.java b/Share/src/main/java/com/yunbao/share/ICallback.java new file mode 100644 index 000000000..777da4d81 --- /dev/null +++ b/Share/src/main/java/com/yunbao/share/ICallback.java @@ -0,0 +1,6 @@ +package com.yunbao.share; + +public interface ICallback { + void onSuccess(); + void onFailure(); +} diff --git a/Share/src/main/java/com/yunbao/share/ShareBuilder.java b/Share/src/main/java/com/yunbao/share/ShareBuilder.java new file mode 100644 index 000000000..96b4d0f51 --- /dev/null +++ b/Share/src/main/java/com/yunbao/share/ShareBuilder.java @@ -0,0 +1,40 @@ +package com.yunbao.share; + +import java.io.File; + +public class ShareBuilder { + private String text; + private String link; + private File file; + + public static ShareBuilder builder(){ + return new ShareBuilder(); + } + + public ShareBuilder setText(String text) { + this.text = text; + return this; + } + + public ShareBuilder setLink(String link) { + this.link = link; + return this; + } + + public ShareBuilder setFile(File file) { + this.file = file; + return this; + } + + public String getText() { + return text; + } + + public String getLink() { + return link; + } + + public File getFile() { + return file; + } +} diff --git a/Share/src/main/java/com/yunbao/share/ShareManager.java b/Share/src/main/java/com/yunbao/share/ShareManager.java new file mode 100644 index 000000000..01c72b3b9 --- /dev/null +++ b/Share/src/main/java/com/yunbao/share/ShareManager.java @@ -0,0 +1,67 @@ +package com.yunbao.share; + +import android.content.Context; +import android.content.IntentFilter; + +import com.twitter.sdk.android.tweetcomposer.TweetUploadService; +import com.yunbao.share.platform.FacebookShare; +import com.yunbao.share.platform.Instagram; +import com.yunbao.share.platform.Line; +import com.yunbao.share.platform.MessengerShare; +import com.yunbao.share.platform.TwitterShare; +import com.yunbao.share.platform.WhatsApp; +import com.yunbao.share.receiver.TwitterResultReceiver; + +public class ShareManager { + public static final int SHARE_Twitter = 0; + public static final int SHARE_Facebook = 1; + public static final int SHARE_Instagram = 2; + public static final int SHARE_WhatsApp = 3; + public static final int SHARE_Line = 4; + public static final int SHARE_Messenger = 5; + + private static ShareManager manager = null; + + public static ShareManager getInstance(Context context) { + if (manager == null) { + manager = new ShareManager(context); + } + return manager; + + } + + private ShareManager(Context context) { + IntentFilter filter = new IntentFilter(TweetUploadService.UPLOAD_SUCCESS); + filter.addAction(TweetUploadService.UPLOAD_FAILURE); + filter.addAction(TweetUploadService.TWEET_COMPOSE_CANCEL); + context.registerReceiver(new TwitterResultReceiver(), filter); + } + + public void createShare(ShareBuilder builder, Context context, int type, ICallback callback) { + AbsShareInterface share = null; + switch (type) { + case SHARE_Twitter: + share = new TwitterShare(context); + break; + case SHARE_Facebook: + share = new FacebookShare(context); + break; + case SHARE_Instagram: + share = new Instagram(context); + break; + case SHARE_WhatsApp: + share = new WhatsApp(context); + break; + case SHARE_Line: + share = new Line(context); + break; + case SHARE_Messenger: + share = new MessengerShare(context); + break; + } + if (share != null) { + share.share(builder, callback); + } + } + +} diff --git a/Share/src/main/java/com/yunbao/share/platform/FacebookShare.java b/Share/src/main/java/com/yunbao/share/platform/FacebookShare.java new file mode 100644 index 000000000..b5877f33a --- /dev/null +++ b/Share/src/main/java/com/yunbao/share/platform/FacebookShare.java @@ -0,0 +1,52 @@ +package com.yunbao.share.platform; + +import android.app.Activity; +import android.content.Context; +import android.net.Uri; +import android.util.Log; + +import androidx.annotation.NonNull; + +import com.facebook.CallbackManager; +import com.facebook.FacebookCallback; +import com.facebook.FacebookException; +import com.facebook.share.Sharer; +import com.facebook.share.model.ShareLinkContent; +import com.facebook.share.widget.ShareDialog; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.share.AbsShareInterface; +import com.yunbao.share.ICallback; +import com.yunbao.share.ShareBuilder; + +public class FacebookShare extends AbsShareInterface { + public static CallbackManager callbackManager; + public FacebookShare(Context context) { + super(context); + } + + @Override + public void share(ShareBuilder builder, ICallback callback) { + callbackManager= CallbackManager.Factory.create(); + ShareLinkContent content = new ShareLinkContent.Builder() + .setContentUrl(Uri.parse(builder.getLink())) + .build(); + ShareDialog dialog=new ShareDialog((Activity) mContext); + dialog.registerCallback(callbackManager, new FacebookCallback() { + @Override + public void onSuccess(Sharer.Result result) { + ToastUtil.show("Facebook分享成功"); + } + + @Override + public void onCancel() { + ToastUtil.show("Facebook分享取消"); + } + + @Override + public void onError(@NonNull FacebookException e) { + ToastUtil.show("Facebook分享失败:"+e.toString()); + } + }); + dialog.show(content); + } +} diff --git a/Share/src/main/java/com/yunbao/share/platform/Instagram.java b/Share/src/main/java/com/yunbao/share/platform/Instagram.java new file mode 100644 index 000000000..34dd61e20 --- /dev/null +++ b/Share/src/main/java/com/yunbao/share/platform/Instagram.java @@ -0,0 +1,29 @@ +package com.yunbao.share.platform; + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; + +import androidx.core.content.FileProvider; + +import com.yunbao.share.AbsShareInterface; +import com.yunbao.share.ICallback; +import com.yunbao.share.ShareBuilder; + +public class Instagram extends AbsShareInterface { + public Instagram(Context context) { + super(context); + } + + @Override + public void share(ShareBuilder builder, ICallback callback) { + String type = "image/*"; + Intent share = new Intent(Intent.ACTION_SEND); + Uri uri = fileToUri(builder.getFile()); + share.setType(type); + share.putExtra(Intent.EXTRA_STREAM, uri); + share.setPackage("com.instagram.android"); + mContext.startActivity(Intent.createChooser(share, "Share to")); + callback.onSuccess(); + } +} diff --git a/Share/src/main/java/com/yunbao/share/platform/Line.java b/Share/src/main/java/com/yunbao/share/platform/Line.java new file mode 100644 index 000000000..d3a081b47 --- /dev/null +++ b/Share/src/main/java/com/yunbao/share/platform/Line.java @@ -0,0 +1,33 @@ +package com.yunbao.share.platform; + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; + +import com.yunbao.share.AbsShareInterface; +import com.yunbao.share.ICallback; +import com.yunbao.share.ShareBuilder; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.nio.charset.Charset; + +public class Line extends AbsShareInterface { + + public Line(Context context) { + super(context); + } + + @Override + public void share(ShareBuilder builder, ICallback callback) { + try { + Intent share = new Intent(Intent.ACTION_VIEW, Uri.parse("https://line.me/R/share?text=" + URLEncoder.encode(builder.getLink(), "UTF-8"))); + mContext.startActivity(share); + callback.onSuccess(); + } catch (UnsupportedEncodingException e) { + callback.onFailure(); + throw new RuntimeException(e); + } + } + +} diff --git a/Share/src/main/java/com/yunbao/share/platform/MessengerShare.java b/Share/src/main/java/com/yunbao/share/platform/MessengerShare.java new file mode 100644 index 000000000..2d482fb85 --- /dev/null +++ b/Share/src/main/java/com/yunbao/share/platform/MessengerShare.java @@ -0,0 +1,63 @@ +package com.yunbao.share.platform; + +import android.app.Activity; +import android.content.Context; +import android.net.Uri; + +import androidx.annotation.NonNull; + +import com.facebook.CallbackManager; +import com.facebook.FacebookCallback; +import com.facebook.FacebookException; +import com.facebook.share.Sharer; +import com.facebook.share.model.ShareLinkContent; +import com.facebook.share.model.SharePhoto; +import com.facebook.share.model.SharePhotoContent; +import com.facebook.share.widget.MessageDialog; +import com.facebook.share.widget.ShareDialog; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.share.AbsShareInterface; +import com.yunbao.share.ICallback; +import com.yunbao.share.ShareBuilder; + +public class MessengerShare extends AbsShareInterface { + public static CallbackManager callbackManager; + + public MessengerShare(Context context) { + super(context); + } + + @Override + public void share(ShareBuilder builder, ICallback callback) { + callbackManager = CallbackManager.Factory.create(); + /* ShareLinkContent content = new ShareLinkContent.Builder() + .setContentUrl(Uri.parse(builder.getLink())) + .build();*/ + SharePhoto photo = new SharePhoto.Builder() + .setImageUrl(fileToUri(builder.getFile())) + .build(); + SharePhotoContent content=new SharePhotoContent.Builder() + .addPhoto(photo) + .build(); + MessageDialog dialog = new MessageDialog((Activity) mContext); + dialog.registerCallback(callbackManager, new FacebookCallback() { + @Override + public void onSuccess(Sharer.Result result) { + ToastUtil.show("Messenger分享成功"); + } + + @Override + public void onCancel() { + ToastUtil.show("Messenger分享取消"); + } + + @Override + public void onError(@NonNull FacebookException e) { + ToastUtil.show("Messenger分享失败:" + e.toString()); + e.printStackTrace(); + } + }); + ToastUtil.show(dialog.canShow(content)+" <"); + dialog.show(content); + } +} diff --git a/Share/src/main/java/com/yunbao/share/platform/TwitterShare.java b/Share/src/main/java/com/yunbao/share/platform/TwitterShare.java new file mode 100644 index 000000000..3e15977b4 --- /dev/null +++ b/Share/src/main/java/com/yunbao/share/platform/TwitterShare.java @@ -0,0 +1,60 @@ +package com.yunbao.share.platform; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; + +import com.twitter.sdk.android.core.Callback; +import com.twitter.sdk.android.core.Result; +import com.twitter.sdk.android.core.Twitter; +import com.twitter.sdk.android.core.TwitterApiClient; +import com.twitter.sdk.android.core.TwitterAuthToken; +import com.twitter.sdk.android.core.TwitterCore; +import com.twitter.sdk.android.core.TwitterException; +import com.twitter.sdk.android.core.TwitterSession; +import com.twitter.sdk.android.core.identity.TwitterAuthClient; +import com.twitter.sdk.android.core.services.AccountService; +import com.twitter.sdk.android.tweetcomposer.ComposerActivity; +import com.twitter.sdk.android.tweetcomposer.TweetComposer; +import com.yunbao.share.AbsShareInterface; +import com.yunbao.share.ICallback; +import com.yunbao.share.ShareBuilder; + +public class TwitterShare extends AbsShareInterface { + public TwitterShare(Context context) { + super(context); + Twitter.initialize(context); + + } + + @Override + public void share(ShareBuilder date, ICallback callback) { + +/* + new TwitterAuthClient().authorize((Activity) mContext, new Callback() { + @Override + public void success(Result result) { + //获取以下登录成功返回信息进行登录验证 + + //获取登录用户信息 + final TwitterSession activeSession=TwitterCore.getInstance().getSessionManager().getActiveSession(); + Intent intent = new ComposerActivity.Builder(mContext) + .session(activeSession) + .image(fileToUri(date.getFile())) + .text(date.getText()) + .hashtags("#twitter") + .createIntent(); + mContext.startActivity(intent); + + } + @Override + public void failure(TwitterException e) { + } + });*/ + + TweetComposer.Builder builder = new TweetComposer.Builder(mContext) + .text(date.getText()) + .image(fileToUri(date.getFile())); + builder.show(); + } +} diff --git a/Share/src/main/java/com/yunbao/share/platform/WhatsApp.java b/Share/src/main/java/com/yunbao/share/platform/WhatsApp.java new file mode 100644 index 000000000..d8002d32c --- /dev/null +++ b/Share/src/main/java/com/yunbao/share/platform/WhatsApp.java @@ -0,0 +1,24 @@ +package com.yunbao.share.platform; + +import android.content.Context; +import android.content.Intent; + +import com.yunbao.share.AbsShareInterface; +import com.yunbao.share.ICallback; +import com.yunbao.share.ShareBuilder; + +public class WhatsApp extends AbsShareInterface { + public WhatsApp(Context context) { + super(context); + } + + @Override + public void share(ShareBuilder builder, ICallback callback) { + Intent sendIntent = new Intent(); + sendIntent.setAction(Intent.ACTION_SEND); + sendIntent.putExtra(Intent.EXTRA_TEXT, builder.getText()); + sendIntent.setType("text/plain"); + sendIntent.setPackage("com.whatsapp"); + mContext.startActivity(sendIntent); + } +} diff --git a/Share/src/main/java/com/yunbao/share/receiver/TwitterResultReceiver.java b/Share/src/main/java/com/yunbao/share/receiver/TwitterResultReceiver.java new file mode 100644 index 000000000..0ff6d9eb9 --- /dev/null +++ b/Share/src/main/java/com/yunbao/share/receiver/TwitterResultReceiver.java @@ -0,0 +1,28 @@ +package com.yunbao.share.receiver; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +import com.twitter.sdk.android.tweetcomposer.TweetUploadService; +import com.yunbao.common.utils.ToastUtil; + +public class TwitterResultReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + Log.i("分享log", "onReceive: "+intent.getAction()); + if (TweetUploadService.UPLOAD_SUCCESS.equals(intent.getAction())) { + ToastUtil.show("推特分享成功"); + // success + final Long tweetId = intent.getExtras().getLong(TweetUploadService.EXTRA_TWEET_ID); + } else if (TweetUploadService.UPLOAD_FAILURE.equals(intent.getAction())) { + // failure + ToastUtil.show("推特分享失败"); + final Intent retryIntent = intent.getExtras().getParcelable(TweetUploadService.EXTRA_RETRY_INTENT); + } else if (TweetUploadService.TWEET_COMPOSE_CANCEL.equals(intent.getAction())) { + // cancel + ToastUtil.show("推特分享取消"); + } + } +} diff --git a/Share/src/main/res/values/strings.xml b/Share/src/main/res/values/strings.xml new file mode 100644 index 000000000..56f090ba5 --- /dev/null +++ b/Share/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + ZWRrZnRUNlBlcHVxMXpsMzVmb2k6MTpjaQ + aq0eV4R1pqMK_AAeKRWnjPr7ErGMGgTPGgZJdm73WeRY-Kluws + \ No newline at end of file diff --git a/Share/src/test/java/com/yunbao/share/ExampleUnitTest.java b/Share/src/test/java/com/yunbao/share/ExampleUnitTest.java new file mode 100644 index 000000000..633872460 --- /dev/null +++ b/Share/src/test/java/com/yunbao/share/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.yunbao.share; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/main/build.gradle b/main/build.gradle index 7f44838fc..09093d9dc 100644 --- a/main/build.gradle +++ b/main/build.gradle @@ -73,6 +73,7 @@ dependencies { api project(':video') api project(':common') api project(':FaceUnity')//新娱美颜 + api project(':Share')//分享 implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.4.0' annotationProcessor rootProject.ext.dependencies["arouter-compiler"] diff --git a/main/src/main/java/com/yunbao/main/activity/TestActivity.java b/main/src/main/java/com/yunbao/main/activity/TestActivity.java index d4094b529..b2ebdd7c7 100644 --- a/main/src/main/java/com/yunbao/main/activity/TestActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/TestActivity.java @@ -1,23 +1,106 @@ package com.yunbao.main.activity; +import android.content.Intent; import android.os.Bundle; +import android.os.Environment; import android.text.SpannableStringBuilder; +import android.util.Log; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; import com.yunbao.main.R; +import com.yunbao.share.ICallback; +import com.yunbao.share.ShareBuilder; +import com.yunbao.share.ShareManager; +import com.yunbao.share.platform.FacebookShare; +import com.yunbao.share.platform.MessengerShare; + +import java.io.File; public class TestActivity extends AppCompatActivity { private TextView contextLayout; + private ListView listView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_test); - contextLayout = findViewById(R.id.context_layout); - SpannableStringBuilder builder = new SpannableStringBuilder(); + listView = new ListView(this); + setContentView(listView); + String[] strs = new String[]{ + "Twitter", + "Facebook", + "Instagram", + "WhatsApp", + "Messenger", + "Line" + }; + String filename = "/ztest/myPhoto.jpg"; + String mediaPath = Environment.getExternalStorageDirectory() + filename; + File media = new File(mediaPath); + ShareBuilder builder = new ShareBuilder() + .setFile(media) + .setLink("http://blog.yutou233.cn") + .setText("测试Test http://blog.yutou233.cn"); + ICallback callback = new ICallback() { + @Override + public void onSuccess() { + } + + @Override + public void onFailure() { + + } + }; + listView.setAdapter(new ArrayAdapter(this, android.R.layout.simple_expandable_list_item_1, strs)); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + switch (position) { + case 0: + ShareManager.getInstance(TestActivity.this) + .createShare(builder, TestActivity.this, ShareManager.SHARE_Twitter, callback); + break; + case 1: + ShareManager.getInstance(TestActivity.this) + .createShare(builder, TestActivity.this, ShareManager.SHARE_Facebook, callback); + break; + case 4: + ShareManager.getInstance(TestActivity.this) + .createShare(builder, TestActivity.this, ShareManager.SHARE_Messenger, callback); + break; + case 2: + ShareManager.getInstance(TestActivity.this) + .createShare(builder, TestActivity.this, ShareManager.SHARE_Instagram, callback); + break; + case 3: + ShareManager.getInstance(TestActivity.this) + .createShare(builder, TestActivity.this, ShareManager.SHARE_WhatsApp, callback); + break; + case 5: + ShareManager.getInstance(TestActivity.this) + .createShare(builder, TestActivity.this, ShareManager.SHARE_Line, callback); + break; + + } + } + }); + } + + @Override + protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { + super.onActivityResult(requestCode, resultCode, data); + Log.i("分享log", "onActivityResult() called with: requestCode = [" + requestCode + "], resultCode = [" + resultCode + "], data = [" + data + "]"); + if (FacebookShare.callbackManager != null) { + FacebookShare.callbackManager.onActivityResult(requestCode, resultCode, data); + } else if (MessengerShare.callbackManager != null) { + MessengerShare.callbackManager.onActivityResult(requestCode, resultCode, data); + } } } \ No newline at end of file diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java index 2ffc00e7e..4b8688cb1 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java @@ -50,6 +50,7 @@ import com.yunbao.live.utils.LiveStorge; import com.yunbao.live.views.LiveRoomViewHolder; import com.yunbao.main.R; import com.yunbao.main.activity.MainActivity; +import com.yunbao.main.activity.TestActivity; import com.yunbao.main.adapter.MainHomeLiveAdapter; import com.yunbao.main.adapter.MainHomeLivesClassAdapter; import com.yunbao.main.http.MainHttpConsts; @@ -368,7 +369,7 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement @Override public void onBannerClick(List datas, int p) { if (true) { - System.err.println("cache = " + mContext.getCacheDir().getAbsolutePath()); + /* System.err.println("cache = " + mContext.getCacheDir().getAbsolutePath()); String type = "image/*"; String filename = "/ztest/myPhoto.jpg"; String mediaPath = Environment.getExternalStorageDirectory() + filename; @@ -392,7 +393,8 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement // share.setPackage("com.whatsapp"); //WhatsApp // share = new Intent(Intent.ACTION_VIEW, Uri.parse("https://line.me/R/share?text=test")); //Line - mContext.startActivity(Intent.createChooser(share, "Share to")); + mContext.startActivity(Intent.createChooser(share, "Share to"));*/ + mContext.startActivity(new Intent(mContext, TestActivity.class)); return; } if (mBannerList != null) { diff --git a/settings.gradle b/settings.gradle index 80fd1059a..d78bfefaf 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,6 @@ include ':app', ':video', ':common', ':main', ':baidu', ':live', ':lib_country_code' include ':FaceUnity' //include ':baidu' -//include ':recognizer'//融云语音转文字模块 \ No newline at end of file +//include ':recognizer'//融云语音转文字模块 +include ':Share' +include ':Share' From 15b232f52a5f8398a2192c866eb24ac0470b88a3 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Thu, 9 Feb 2023 10:04:13 +0800 Subject: [PATCH 04/10] update Share --- Share/src/main/AndroidManifest.xml | 34 ++++++++++++++++--- .../yunbao/share/platform/MessengerShare.java | 13 +++---- common/build.gradle | 4 +-- .../yunbao/main/activity/TestActivity.java | 6 ++-- 4 files changed, 38 insertions(+), 19 deletions(-) diff --git a/Share/src/main/AndroidManifest.xml b/Share/src/main/AndroidManifest.xml index e0f407337..0f2b62f39 100644 --- a/Share/src/main/AndroidManifest.xml +++ b/Share/src/main/AndroidManifest.xml @@ -1,7 +1,31 @@ - - + + + + + + + + + + + + + + + - - - + + + diff --git a/Share/src/main/java/com/yunbao/share/platform/MessengerShare.java b/Share/src/main/java/com/yunbao/share/platform/MessengerShare.java index 2d482fb85..b84e7aad7 100644 --- a/Share/src/main/java/com/yunbao/share/platform/MessengerShare.java +++ b/Share/src/main/java/com/yunbao/share/platform/MessengerShare.java @@ -9,6 +9,7 @@ import androidx.annotation.NonNull; import com.facebook.CallbackManager; import com.facebook.FacebookCallback; import com.facebook.FacebookException; +import com.facebook.FacebookSdk; import com.facebook.share.Sharer; import com.facebook.share.model.ShareLinkContent; import com.facebook.share.model.SharePhoto; @@ -25,25 +26,20 @@ public class MessengerShare extends AbsShareInterface { public MessengerShare(Context context) { super(context); + FacebookSdk.setIsDebugEnabled(true); } @Override public void share(ShareBuilder builder, ICallback callback) { callbackManager = CallbackManager.Factory.create(); - /* ShareLinkContent content = new ShareLinkContent.Builder() + ShareLinkContent content = new ShareLinkContent.Builder() .setContentUrl(Uri.parse(builder.getLink())) - .build();*/ - SharePhoto photo = new SharePhoto.Builder() - .setImageUrl(fileToUri(builder.getFile())) - .build(); - SharePhotoContent content=new SharePhotoContent.Builder() - .addPhoto(photo) .build(); MessageDialog dialog = new MessageDialog((Activity) mContext); dialog.registerCallback(callbackManager, new FacebookCallback() { @Override public void onSuccess(Sharer.Result result) { - ToastUtil.show("Messenger分享成功"); + ToastUtil.show("Messenger分享成功:"+result.getPostId()); } @Override @@ -57,7 +53,6 @@ public class MessengerShare extends AbsShareInterface { e.printStackTrace(); } }); - ToastUtil.show(dialog.canShow(content)+" <"); dialog.show(content); } } diff --git a/common/build.gradle b/common/build.gradle index bc5c7ddd9..7943cde8a 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -162,8 +162,8 @@ dependencies { api 'cn.rongcloud.sdk:im_kit:5.2.5.4' // 即时通讯 UI 基础组件 //融云小视频模块 api 'cn.rongcloud.sdk:sight:5.2.5.4' - api 'com.facebook.android:facebook-android-sdk:15.0.1' - implementation 'com.facebook.android:facebook-android-sdk:15.0.1' + api 'com.facebook.android:facebook-android-sdk:15.2.0' + implementation 'com.facebook.android:facebook-android-sdk:15.2.0' api('com.twitter.sdk.android:twitter-core:3.1.1@aar') { transitive = true diff --git a/main/src/main/java/com/yunbao/main/activity/TestActivity.java b/main/src/main/java/com/yunbao/main/activity/TestActivity.java index b2ebdd7c7..cdda47aa8 100644 --- a/main/src/main/java/com/yunbao/main/activity/TestActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/TestActivity.java @@ -45,8 +45,8 @@ public class TestActivity extends AppCompatActivity { File media = new File(mediaPath); ShareBuilder builder = new ShareBuilder() .setFile(media) - .setLink("http://blog.yutou233.cn") - .setText("测试Test http://blog.yutou233.cn"); + .setLink("https://www.baidu.com") + .setText("测试Test https://www.baidu.com"); ICallback callback = new ICallback() { @Override public void onSuccess() { @@ -96,7 +96,7 @@ public class TestActivity extends AppCompatActivity { @Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); - Log.i("分享log", "onActivityResult() called with: requestCode = [" + requestCode + "], resultCode = [" + resultCode + "], data = [" + data + "]"); + Log.i("分享log", "onActivityResult() called with: requestCode = [" + requestCode + "], resultCode = [" + resultCode + "], data = [" + data.getAction() + "]"); if (FacebookShare.callbackManager != null) { FacebookShare.callbackManager.onActivityResult(requestCode, resultCode, data); } else if (MessengerShare.callbackManager != null) { From a50a7140fd4263b0c9c176a11908c8384cb01761 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Mon, 13 Feb 2023 11:21:40 +0800 Subject: [PATCH 05/10] update Share --- .../java/com/yunbao/share/platform/Line.java | 4 ++-- .../yunbao/share/platform/MessengerShare.java | 7 ++++++- .../com/yunbao/share/platform/WhatsApp.java | 18 ++++++++++++------ config.gradle | 4 ++-- .../com/yunbao/main/activity/TestActivity.java | 3 ++- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Share/src/main/java/com/yunbao/share/platform/Line.java b/Share/src/main/java/com/yunbao/share/platform/Line.java index d3a081b47..67c2e46b5 100644 --- a/Share/src/main/java/com/yunbao/share/platform/Line.java +++ b/Share/src/main/java/com/yunbao/share/platform/Line.java @@ -21,10 +21,10 @@ public class Line extends AbsShareInterface { @Override public void share(ShareBuilder builder, ICallback callback) { try { - Intent share = new Intent(Intent.ACTION_VIEW, Uri.parse("https://line.me/R/share?text=" + URLEncoder.encode(builder.getLink(), "UTF-8"))); + Intent share = new Intent(Intent.ACTION_VIEW, Uri.parse("https://line.me/R/share?text=" + URLEncoder.encode(builder.getText(), "UTF-8"))); mContext.startActivity(share); callback.onSuccess(); - } catch (UnsupportedEncodingException e) { + } catch (Exception e) { callback.onFailure(); throw new RuntimeException(e); } diff --git a/Share/src/main/java/com/yunbao/share/platform/MessengerShare.java b/Share/src/main/java/com/yunbao/share/platform/MessengerShare.java index b84e7aad7..e0efe6a86 100644 --- a/Share/src/main/java/com/yunbao/share/platform/MessengerShare.java +++ b/Share/src/main/java/com/yunbao/share/platform/MessengerShare.java @@ -40,6 +40,7 @@ public class MessengerShare extends AbsShareInterface { @Override public void onSuccess(Sharer.Result result) { ToastUtil.show("Messenger分享成功:"+result.getPostId()); + callback.onSuccess(); } @Override @@ -53,6 +54,10 @@ public class MessengerShare extends AbsShareInterface { e.printStackTrace(); } }); - dialog.show(content); + if(dialog.canShow(content)) { + dialog.show(content); + }else{ + callback.onFailure(); + } } } diff --git a/Share/src/main/java/com/yunbao/share/platform/WhatsApp.java b/Share/src/main/java/com/yunbao/share/platform/WhatsApp.java index d8002d32c..e662d9caa 100644 --- a/Share/src/main/java/com/yunbao/share/platform/WhatsApp.java +++ b/Share/src/main/java/com/yunbao/share/platform/WhatsApp.java @@ -14,11 +14,17 @@ public class WhatsApp extends AbsShareInterface { @Override public void share(ShareBuilder builder, ICallback callback) { - Intent sendIntent = new Intent(); - sendIntent.setAction(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_TEXT, builder.getText()); - sendIntent.setType("text/plain"); - sendIntent.setPackage("com.whatsapp"); - mContext.startActivity(sendIntent); + try { + Intent sendIntent = new Intent(); + sendIntent.setAction(Intent.ACTION_SEND); + sendIntent.putExtra(Intent.EXTRA_TEXT, builder.getText()); + sendIntent.setType("text/plain"); + sendIntent.setPackage("com.whatsapp"); + mContext.startActivity(sendIntent); + callback.onSuccess(); + } catch (Exception e) { + callback.onFailure(); + } + } } diff --git a/config.gradle b/config.gradle index 2a10a28f4..980717524 100644 --- a/config.gradle +++ b/config.gradle @@ -10,9 +10,9 @@ ext { manifestPlaceholders = [ //正式 - serverHost : "https://napi.yaoulive.com", +// serverHost : "https://napi.yaoulive.com", // -// serverHost : "https://ceshi.yaoulive.com", + serverHost : "https://ceshi.yaoulive.com", //腾讯地图 txMapAppKey : "EOZBZ-ASLCU-4XPV3-BDCHZ-4E3Q7-H4BWB", diff --git a/main/src/main/java/com/yunbao/main/activity/TestActivity.java b/main/src/main/java/com/yunbao/main/activity/TestActivity.java index cdda47aa8..21ff40fd2 100644 --- a/main/src/main/java/com/yunbao/main/activity/TestActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/TestActivity.java @@ -13,6 +13,7 @@ import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; +import com.yunbao.common.utils.ToastUtil; import com.yunbao.main.R; import com.yunbao.share.ICallback; import com.yunbao.share.ShareBuilder; @@ -55,7 +56,7 @@ public class TestActivity extends AppCompatActivity { @Override public void onFailure() { - + ToastUtil.show("分享失败,应用未安装"); } }; listView.setAdapter(new ArrayAdapter(this, android.R.layout.simple_expandable_list_item_1, strs)); From 60da4531143c45bb6a80d66a686211bb0ed67aaf Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Mon, 13 Feb 2023 16:05:20 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=8D=95=E8=8E=B7=E5=90=8E=E6=9D=80=E6=AD=BB?= =?UTF-8?q?=E8=BF=9B=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/shayu/phonelive/AppContext.java | 8 ++--- .../com/shayu/phonelive/NeverCrashUtils.java | 3 +- .../main/views/MainHomeLiveViewHolder.java | 32 +++---------------- 3 files changed, 9 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index 4cc9e4c31..af69b040a 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -278,17 +278,17 @@ public class AppContext extends CommonAppContext { Log.e("ApplicationError", "主线程异常");//此处log只是展示,当debug为true时,主类内部log会打印异常信息 e.printStackTrace(); //闪退后finish所有Activity并且杀死进程 - for (WeakReference activity : activities) { + /* for (WeakReference activity : activities) { if (activity != null && activity.get() != null) { activity.get().finish(); } } - /* Process.killProcess(Process.myPid()); - System.exit(0);*/ + *//* Process.killProcess(Process.myPid()); + System.exit(0);*//* setFirebaseCrashData(); new Handler(Looper.getMainLooper()).postDelayed(() -> { throw new RuntimeException(e); - }, 100); + }, 100);*/ }) .setUncaughtCrashHandler((t, e) -> { Log.e("ApplicationError", "子线程异常");//此处log只是展示,当debug为true时,主类内部log会打印异常信息 diff --git a/app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java b/app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java index f99f3a492..93f23b13b 100644 --- a/app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java +++ b/app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java @@ -101,10 +101,9 @@ public class NeverCrashUtils { Log.e(TAG, "未捕获的主线程异常行为", e); } e.printStackTrace(); - Toast.makeText(application, "发生闪退", Toast.LENGTH_SHORT).show(); + Toast.makeText(application, "发生闪退:"+e.getMessage(), Toast.LENGTH_SHORT).show(); FileUtil.saveStringToFile(new File(application.getDir("files", Context.MODE_PRIVATE).getAbsolutePath()), throwableToString(e), "error.log"); getMainCrashHandler().mainException(Looper.getMainLooper().getThread(), e); - return; } } }); diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java index 4b8688cb1..b1659c847 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java @@ -368,34 +368,10 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement .setOnBannerClickListener(new OnBannerClickListener() { @Override public void onBannerClick(List datas, int p) { - if (true) { - /* System.err.println("cache = " + mContext.getCacheDir().getAbsolutePath()); - String type = "image/*"; - String filename = "/ztest/myPhoto.jpg"; - String mediaPath = Environment.getExternalStorageDirectory() + filename; - // Create the new Intent using the 'Send' action. - Intent share = new Intent(Intent.ACTION_SEND); - - // Set the MIME type - share.setType(type); - - // Create the URI from the media - File media = new File(mediaPath); - Uri uri = FileProvider.getUriForFile(mContext, - mContext.getPackageName() + ".fileprovider", - media - ); - - // Add the URI to the Intent. - share.putExtra(Intent.EXTRA_STREAM, uri); - share.putExtra(Intent.EXTRA_TEXT, "test"); - // Broadcast the Intent. - // share.setPackage("com.whatsapp"); //WhatsApp - - // share = new Intent(Intent.ACTION_VIEW, Uri.parse("https://line.me/R/share?text=test")); //Line - mContext.startActivity(Intent.createChooser(share, "Share to"));*/ - mContext.startActivity(new Intent(mContext, TestActivity.class)); - return; + if (false) { + throw new NullPointerException("空指针测试异常"); + // mContext.startActivity(new Intent(mContext, TestActivity.class)); + //return; } if (mBannerList != null) { if (p >= 0 && p < mBannerList.size()) { From 9e5a61f66c58f4b13b338ae9022291acd9366b3b Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Tue, 21 Mar 2023 18:20:11 +0800 Subject: [PATCH 07/10] update --- .../main/java/com/yunbao/main/activity/TestActivity.java | 7 +++++++ .../java/com/yunbao/main/views/MainHomeLiveViewHolder.java | 1 - .../java/com/yunbao/main/views/MainHomeViewHolder.java | 3 +++ settings.gradle | 3 +-- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/main/src/main/java/com/yunbao/main/activity/TestActivity.java b/main/src/main/java/com/yunbao/main/activity/TestActivity.java index 866d9d5cd..21ff40fd2 100644 --- a/main/src/main/java/com/yunbao/main/activity/TestActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/TestActivity.java @@ -1,7 +1,14 @@ package com.yunbao.main.activity; +import android.content.Intent; import android.os.Bundle; +import android.os.Environment; import android.text.SpannableStringBuilder; +import android.util.Log; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java index b1659c847..a461986fc 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java @@ -50,7 +50,6 @@ import com.yunbao.live.utils.LiveStorge; import com.yunbao.live.views.LiveRoomViewHolder; import com.yunbao.main.R; import com.yunbao.main.activity.MainActivity; -import com.yunbao.main.activity.TestActivity; import com.yunbao.main.adapter.MainHomeLiveAdapter; import com.yunbao.main.adapter.MainHomeLivesClassAdapter; import com.yunbao.main.http.MainHttpConsts; diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeViewHolder.java index 6fb5f18d4..5997268aa 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeViewHolder.java @@ -40,6 +40,9 @@ public class MainHomeViewHolder extends AbsMainHomeParentViewHolder { super.init(); img_trophy = (ImageView) findViewById(R.id.img_trophy); + img_trophy.setOnClickListener(v -> { + mContext.startActivity(new Intent(mContext, TestActivity.class)); + }); ImgLoader.display(mContext, "https://downs.yaoulive.com/gif_trophy.gif", img_trophy); diff --git a/settings.gradle b/settings.gradle index d78bfefaf..e1b3b91be 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,5 +2,4 @@ include ':app', ':video', ':common', ':main', ':baidu', ':live', ':lib_country_ include ':FaceUnity' //include ':baidu' //include ':recognizer'//融云语音转文字模块 -include ':Share' -include ':Share' +include ':Share' \ No newline at end of file From 26cb58463a0a026f9c6f20bdbe461fafad6cb78f Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Fri, 31 Mar 2023 13:34:57 +0800 Subject: [PATCH 08/10] =?UTF-8?q?update=20=E7=9B=B4=E6=92=AD=E9=96=93?= =?UTF-8?q?=E5=88=86=E4=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/share/AbsShareInterface.java | 11 +- .../java/com/yunbao/share/ShareBuilder.java | 40 ------ .../java/com/yunbao/share/ShareManager.java | 67 --------- .../adapters/InviteRewardListAdapter.java | 67 +++++++++ .../share/adapters/ShareAppAdapter.java | 134 +++++++++++++++++ .../yunbao/share/bean/InviteRewardBean.java | 63 ++++++++ .../com/yunbao/share/bean/ShareBuilder.java | 136 ++++++++++++++++++ .../yunbao/share/platform/FacebookShare.java | 3 +- .../com/yunbao/share/platform/Instagram.java | 4 +- .../java/com/yunbao/share/platform/Line.java | 4 +- .../yunbao/share/platform/MessengerShare.java | 5 +- .../yunbao/share/platform/TwitterShare.java | 49 ++++--- .../com/yunbao/share/platform/WhatsApp.java | 2 +- .../com/yunbao/share/ui/InvitePopDialog.java | 131 +++++++++++++++++ .../share/ui/InviteRewardPopDialog.java | 131 +++++++++++++++++ .../com/yunbao/share/ui/SharePopDialog.java | 119 +++++++++++++++ .../src/main/res/drawable/background_fff.xml | 9 ++ Share/src/main/res/drawable/bg_btn.xml | 9 ++ .../src/main/res/drawable/bg_invite_title.xml | 10 ++ .../main/res/layout/dialog_invite_list.xml | 56 ++++++++ Share/src/main/res/layout/dialog_share.xml | 66 +++++++++ .../main/res/layout/item_invite_reward.xml | 46 ++++++ Share/src/main/res/layout/item_share_app.xml | 34 +++++ .../main/res/layout/view_share_preview.xml | 74 ++++++++++ .../src/main/res/mipmap/bg_dialog_inviet.png | Bin 0 -> 322335 bytes Share/src/main/res/mipmap/bg_dialog_share.png | Bin 0 -> 84764 bytes .../main/res/mipmap/icon_share_facebook.png | Bin 0 -> 5643 bytes .../main/res/mipmap/icon_share_instagram.png | Bin 0 -> 6451 bytes Share/src/main/res/mipmap/icon_share_line.png | Bin 0 -> 7972 bytes .../main/res/mipmap/icon_share_messenger.png | Bin 0 -> 6388 bytes .../main/res/mipmap/icon_share_twitter.png | Bin 0 -> 6040 bytes Share/src/main/res/mipmap/icon_share_url.png | Bin 0 -> 955 bytes .../main/res/mipmap/icon_share_whatsapp.png | Bin 0 -> 7350 bytes Share/src/main/res/values/strings.xml | 11 ++ .../common/event/CustomDrawerPopupEvent.java | 11 ++ .../common/views/CustomDrawerPopupView.java | 12 +- .../common/views/MoreMenuPopupView.java | 9 ++ .../main/res/layout/custom_drawer_popup.xml | 43 +++--- common/src/main/res/layout/view_more_menu.xml | 23 ++- .../res/mipmap-xxhdpi/ic_custom_share.png | Bin 0 -> 1359 bytes live/build.gradle | 2 +- .../live/activity/LiveAudienceActivity.java | 16 +++ .../yunbao/live/event/LiveAudienceEvent.java | 3 +- .../yunbao/main/activity/TestActivity.java | 71 --------- .../yunbao/main/views/MainHomeViewHolder.java | 9 +- 45 files changed, 1242 insertions(+), 238 deletions(-) delete mode 100644 Share/src/main/java/com/yunbao/share/ShareBuilder.java delete mode 100644 Share/src/main/java/com/yunbao/share/ShareManager.java create mode 100644 Share/src/main/java/com/yunbao/share/adapters/InviteRewardListAdapter.java create mode 100644 Share/src/main/java/com/yunbao/share/adapters/ShareAppAdapter.java create mode 100644 Share/src/main/java/com/yunbao/share/bean/InviteRewardBean.java create mode 100644 Share/src/main/java/com/yunbao/share/bean/ShareBuilder.java create mode 100644 Share/src/main/java/com/yunbao/share/ui/InvitePopDialog.java create mode 100644 Share/src/main/java/com/yunbao/share/ui/InviteRewardPopDialog.java create mode 100644 Share/src/main/java/com/yunbao/share/ui/SharePopDialog.java create mode 100644 Share/src/main/res/drawable/background_fff.xml create mode 100644 Share/src/main/res/drawable/bg_btn.xml create mode 100644 Share/src/main/res/drawable/bg_invite_title.xml create mode 100644 Share/src/main/res/layout/dialog_invite_list.xml create mode 100644 Share/src/main/res/layout/dialog_share.xml create mode 100644 Share/src/main/res/layout/item_invite_reward.xml create mode 100644 Share/src/main/res/layout/item_share_app.xml create mode 100644 Share/src/main/res/layout/view_share_preview.xml create mode 100644 Share/src/main/res/mipmap/bg_dialog_inviet.png create mode 100644 Share/src/main/res/mipmap/bg_dialog_share.png create mode 100644 Share/src/main/res/mipmap/icon_share_facebook.png create mode 100644 Share/src/main/res/mipmap/icon_share_instagram.png create mode 100644 Share/src/main/res/mipmap/icon_share_line.png create mode 100644 Share/src/main/res/mipmap/icon_share_messenger.png create mode 100644 Share/src/main/res/mipmap/icon_share_twitter.png create mode 100644 Share/src/main/res/mipmap/icon_share_url.png create mode 100644 Share/src/main/res/mipmap/icon_share_whatsapp.png create mode 100644 common/src/main/res/mipmap-xxhdpi/ic_custom_share.png diff --git a/Share/src/main/java/com/yunbao/share/AbsShareInterface.java b/Share/src/main/java/com/yunbao/share/AbsShareInterface.java index 618643b15..fed5ddee8 100644 --- a/Share/src/main/java/com/yunbao/share/AbsShareInterface.java +++ b/Share/src/main/java/com/yunbao/share/AbsShareInterface.java @@ -1,10 +1,15 @@ package com.yunbao.share; import android.content.Context; +import android.content.IntentFilter; import android.net.Uri; import androidx.core.content.FileProvider; +import com.twitter.sdk.android.tweetcomposer.TweetUploadService; +import com.yunbao.share.bean.ShareBuilder; +import com.yunbao.share.receiver.TwitterResultReceiver; + import java.io.File; public abstract class AbsShareInterface { @@ -12,9 +17,13 @@ public abstract class AbsShareInterface { public AbsShareInterface(Context context) { this.mContext = context; + IntentFilter filter = new IntentFilter(TweetUploadService.UPLOAD_SUCCESS); + filter.addAction(TweetUploadService.UPLOAD_FAILURE); + filter.addAction(TweetUploadService.TWEET_COMPOSE_CANCEL); + context.registerReceiver(new TwitterResultReceiver(), filter); } - public abstract void share(ShareBuilder builder,ICallback callback); + public abstract void share(ShareBuilder builder, ICallback callback); public Uri fileToUri(File file){ return FileProvider.getUriForFile(mContext, diff --git a/Share/src/main/java/com/yunbao/share/ShareBuilder.java b/Share/src/main/java/com/yunbao/share/ShareBuilder.java deleted file mode 100644 index 96b4d0f51..000000000 --- a/Share/src/main/java/com/yunbao/share/ShareBuilder.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.yunbao.share; - -import java.io.File; - -public class ShareBuilder { - private String text; - private String link; - private File file; - - public static ShareBuilder builder(){ - return new ShareBuilder(); - } - - public ShareBuilder setText(String text) { - this.text = text; - return this; - } - - public ShareBuilder setLink(String link) { - this.link = link; - return this; - } - - public ShareBuilder setFile(File file) { - this.file = file; - return this; - } - - public String getText() { - return text; - } - - public String getLink() { - return link; - } - - public File getFile() { - return file; - } -} diff --git a/Share/src/main/java/com/yunbao/share/ShareManager.java b/Share/src/main/java/com/yunbao/share/ShareManager.java deleted file mode 100644 index 01c72b3b9..000000000 --- a/Share/src/main/java/com/yunbao/share/ShareManager.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.yunbao.share; - -import android.content.Context; -import android.content.IntentFilter; - -import com.twitter.sdk.android.tweetcomposer.TweetUploadService; -import com.yunbao.share.platform.FacebookShare; -import com.yunbao.share.platform.Instagram; -import com.yunbao.share.platform.Line; -import com.yunbao.share.platform.MessengerShare; -import com.yunbao.share.platform.TwitterShare; -import com.yunbao.share.platform.WhatsApp; -import com.yunbao.share.receiver.TwitterResultReceiver; - -public class ShareManager { - public static final int SHARE_Twitter = 0; - public static final int SHARE_Facebook = 1; - public static final int SHARE_Instagram = 2; - public static final int SHARE_WhatsApp = 3; - public static final int SHARE_Line = 4; - public static final int SHARE_Messenger = 5; - - private static ShareManager manager = null; - - public static ShareManager getInstance(Context context) { - if (manager == null) { - manager = new ShareManager(context); - } - return manager; - - } - - private ShareManager(Context context) { - IntentFilter filter = new IntentFilter(TweetUploadService.UPLOAD_SUCCESS); - filter.addAction(TweetUploadService.UPLOAD_FAILURE); - filter.addAction(TweetUploadService.TWEET_COMPOSE_CANCEL); - context.registerReceiver(new TwitterResultReceiver(), filter); - } - - public void createShare(ShareBuilder builder, Context context, int type, ICallback callback) { - AbsShareInterface share = null; - switch (type) { - case SHARE_Twitter: - share = new TwitterShare(context); - break; - case SHARE_Facebook: - share = new FacebookShare(context); - break; - case SHARE_Instagram: - share = new Instagram(context); - break; - case SHARE_WhatsApp: - share = new WhatsApp(context); - break; - case SHARE_Line: - share = new Line(context); - break; - case SHARE_Messenger: - share = new MessengerShare(context); - break; - } - if (share != null) { - share.share(builder, callback); - } - } - -} diff --git a/Share/src/main/java/com/yunbao/share/adapters/InviteRewardListAdapter.java b/Share/src/main/java/com/yunbao/share/adapters/InviteRewardListAdapter.java new file mode 100644 index 000000000..27f03e25d --- /dev/null +++ b/Share/src/main/java/com/yunbao/share/adapters/InviteRewardListAdapter.java @@ -0,0 +1,67 @@ +package com.yunbao.share.adapters; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.pdlive.shayu.R; +import com.yunbao.share.bean.InviteRewardBean; + +import java.util.List; + +public class InviteRewardListAdapter extends RecyclerView.Adapter { + private Context mContext; + private List list; + + public InviteRewardListAdapter(Context mContext) { + this.mContext = mContext; + } + + public void setList(List list) { + this.list = list; + } + + @NonNull + @Override + public RewardViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new RewardViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_invite_reward,parent,false)); + } + + @Override + public void onBindViewHolder(@NonNull RewardViewHolder holder, int position) { + holder.setData(list.get(position),position); + } + + @Override + public int getItemCount() { + return list.size(); + } + + + public static class RewardViewHolder extends RecyclerView.ViewHolder { + private final TextView item1; + private final TextView item2; + private final TextView item3; + private final TextView item4; + + public RewardViewHolder(@NonNull View itemView) { + super(itemView); + item1 = itemView.findViewById(R.id.item1); + item2 = itemView.findViewById(R.id.item2); + item3 = itemView.findViewById(R.id.item3); + item4 = itemView.findViewById(R.id.item4); + } + + void setData(InviteRewardBean bean, int position) { + item1.setText(bean.getUsername()); + item2.setText(bean.getInviteTime()); + item3.setText(bean.getType()); + item4.setText(bean.getReward()); + } + } +} diff --git a/Share/src/main/java/com/yunbao/share/adapters/ShareAppAdapter.java b/Share/src/main/java/com/yunbao/share/adapters/ShareAppAdapter.java new file mode 100644 index 000000000..db5772505 --- /dev/null +++ b/Share/src/main/java/com/yunbao/share/adapters/ShareAppAdapter.java @@ -0,0 +1,134 @@ +package com.yunbao.share.adapters; + +import android.content.Context; +import android.os.Environment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.DrawableRes; +import androidx.annotation.NonNull; +import androidx.annotation.StringRes; +import androidx.recyclerview.widget.RecyclerView; + +import com.pdlive.shayu.R; +import com.yunbao.share.ICallback; +import com.yunbao.share.bean.ShareBuilder; +import com.yunbao.share.platform.FacebookShare; +import com.yunbao.share.platform.Instagram; +import com.yunbao.share.platform.Line; +import com.yunbao.share.platform.MessengerShare; +import com.yunbao.share.platform.TwitterShare; +import com.yunbao.share.platform.WhatsApp; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +public class ShareAppAdapter extends RecyclerView.Adapter { + private Context mContext; + private List list; + + public ShareAppAdapter(Context mContext) { + list = new ArrayList<>(); + this.mContext = mContext; + } + + public void setList(List list) { + this.list = list; + notifyDataSetChanged(); + } + + @NonNull + @Override + public AppViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new AppViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_share_app, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull AppViewHolder holder, int position) { + ShareBuilder builder = list.get(position); + switch (builder.getType()) { + case ShareBuilder.APP_FACEBOOK: + holder.setData(builder, R.mipmap.icon_share_facebook, R.string.dialog_share_app_facebook); + break; + case ShareBuilder.APP_LINE: + holder.setData(builder, R.mipmap.icon_share_line, R.string.dialog_share_app_line); + break; + case ShareBuilder.APP_TWITTER: + holder.setData(builder, R.mipmap.icon_share_twitter, R.string.dialog_share_app_twitter); + break; + case ShareBuilder.APP_WHATSAPP: + holder.setData(builder, R.mipmap.icon_share_whatsapp, R.string.dialog_share_app_whatsapp); + break; + case ShareBuilder.APP_MESSENGER: + holder.setData(builder, R.mipmap.icon_share_messenger, R.string.dialog_share_app_messenger); + break; + case ShareBuilder.APP_INSTAGRAM: + holder.setData(builder, R.mipmap.icon_share_instagram, R.string.dialog_share_app_instagram); + break; + } + } + + @Override + public int getItemCount() { + return list.size(); + } + + public static class AppViewHolder extends RecyclerView.ViewHolder { + ImageView icon; + TextView title; + + public AppViewHolder(@NonNull View itemView) { + super(itemView); + icon = itemView.findViewById(R.id.share_app_icon); + title = itemView.findViewById(R.id.share_app_name); + } + + public void setData(ShareBuilder bean, @DrawableRes int iconId, @StringRes int appName) { + icon.setImageResource(iconId); + title.setText(appName); + String filename = "/ztest/myPhoto.jpg"; + String mediaPath = Environment.getExternalStorageDirectory() + filename; + File media = new File(mediaPath); + bean.setFile(media); + itemView.setOnClickListener(v -> { + switch (bean.getType()) { + case ShareBuilder.APP_FACEBOOK: + new FacebookShare(itemView.getContext()).share(bean, new ShareCallback()); + break; + case ShareBuilder.APP_LINE: + new Line(itemView.getContext()).share(bean, new ShareCallback()); + break; + case ShareBuilder.APP_TWITTER: + new TwitterShare(itemView.getContext()).share(bean, new ShareCallback()); + break; + case ShareBuilder.APP_WHATSAPP: + new WhatsApp(itemView.getContext()).share(bean, new ShareCallback()); + break; + case ShareBuilder.APP_MESSENGER: + new MessengerShare(itemView.getContext()).share(bean, new ShareCallback()); + break; + case ShareBuilder.APP_INSTAGRAM: + new Instagram(itemView.getContext()).share(bean, new ShareCallback()); + break; + } + }); + } + + private static class ShareCallback implements ICallback { + + @Override + public void onSuccess() { + + } + + @Override + public void onFailure() { + + } + } + } +} diff --git a/Share/src/main/java/com/yunbao/share/bean/InviteRewardBean.java b/Share/src/main/java/com/yunbao/share/bean/InviteRewardBean.java new file mode 100644 index 000000000..af999aaa8 --- /dev/null +++ b/Share/src/main/java/com/yunbao/share/bean/InviteRewardBean.java @@ -0,0 +1,63 @@ +package com.yunbao.share.bean; + +import androidx.annotation.NonNull; + +public class InviteRewardBean{ + private String username; + private String inviteTime; + private String type; + private String reward; + + public InviteRewardBean() { + } + + public InviteRewardBean(String username, String inviteTime, String type, String reward) { + this.username = username; + this.inviteTime = inviteTime; + this.type = type; + this.reward = reward; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getInviteTime() { + return inviteTime; + } + + public void setInviteTime(String inviteTime) { + this.inviteTime = inviteTime; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getReward() { + return reward; + } + + public void setReward(String reward) { + this.reward = reward; + } + + @NonNull + @Override + public String toString() { + return "InviteRewardBean{" + + "username='" + username + '\'' + + ", inviteTime='" + inviteTime + '\'' + + ", type='" + type + '\'' + + ", reward='" + reward + '\'' + + '}'; + } +} diff --git a/Share/src/main/java/com/yunbao/share/bean/ShareBuilder.java b/Share/src/main/java/com/yunbao/share/bean/ShareBuilder.java new file mode 100644 index 000000000..bfe1da282 --- /dev/null +++ b/Share/src/main/java/com/yunbao/share/bean/ShareBuilder.java @@ -0,0 +1,136 @@ +package com.yunbao.share.bean; + +import androidx.annotation.NonNull; + +import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.utils.StringUtil; + +import java.io.File; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; + +public class ShareBuilder { + public static final int APP_FACEBOOK = 0; + public static final int APP_LINE = 1; + public static final int APP_TWITTER = 2; + public static final int APP_WHATSAPP = 3; + public static final int APP_MESSENGER = 4; + public static final int APP_INSTAGRAM = 5; + + private String text; + private String link; + private File file; + private int type; + private String uid; + private String anchorId; + private String anchorName; + private String anchorAvatar; + + public static String createLiveShareLink(String shareUid, String anchorId, String anchorName, String anchorAvatar) { + try { + return String.format(CommonAppConfig.HOST + + "/h5/activity/FriendInvitation/liveShare.html?user_id=%s&anchor_id=%s&anchor_name=%s&anchor_avatar=%s&isGoogle=%s", + shareUid, + anchorId, + URLEncoder.encode(anchorName, "UTF-8"), + URLEncoder.encode(anchorAvatar, "UTF-8"), + CommonAppConfig.IS_GOOGLE_PLAY ? "1" : "0" + ); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } + public static String createInviteLink(String shareUid){ + return String.format("https://www.pdlive.com/public/app/download/index.html?user_id=%s&isGoogle=%s", + shareUid, + CommonAppConfig.IS_GOOGLE_PLAY ? "1" : "0" + ); + } + + public static ShareBuilder builder(int type) { + return new ShareBuilder(type); + } + + private ShareBuilder(int type) { + this.type = type; + } + + public int getType() { + return type; + } + + public String getUid() { + return uid; + } + + public void setUid(String uid) { + this.uid = uid; + } + + public String getAnchorId() { + return anchorId; + } + + public void setAnchorId(String anchorId) { + this.anchorId = anchorId; + } + + public String getAnchorName() { + return anchorName; + } + + public void setAnchorName(String anchorName) { + this.anchorName = anchorName; + } + + public String getAnchorAvatar() { + return anchorAvatar; + } + + public void setAnchorAvatar(String anchorAvatar) { + this.anchorAvatar = anchorAvatar; + } + + public ShareBuilder setText(String text) { + this.text = text; + return this; + } + + public ShareBuilder setLink(String link) { + this.link = link; + return this; + } + + public ShareBuilder setFile(File file) { + this.file = file; + return this; + } + + public String getText() { + if (StringUtil.isEmpty(text)) { + return getLink(); + } + return text + "\n" + getLink(); + } + + public String getLink() { + if (StringUtil.isEmpty(link)) { + link = createLiveShareLink(uid, anchorId, anchorName, anchorAvatar); + } + return link; + } + + public File getFile() { + return file; + } + + @NonNull + @Override + public String toString() { + return "ShareBuilder{" + + "text='" + text + '\'' + + ", link='" + link + '\'' + + ", file=" + file + + '}'; + } +} diff --git a/Share/src/main/java/com/yunbao/share/platform/FacebookShare.java b/Share/src/main/java/com/yunbao/share/platform/FacebookShare.java index b5877f33a..118e90406 100644 --- a/Share/src/main/java/com/yunbao/share/platform/FacebookShare.java +++ b/Share/src/main/java/com/yunbao/share/platform/FacebookShare.java @@ -3,7 +3,6 @@ package com.yunbao.share.platform; import android.app.Activity; import android.content.Context; import android.net.Uri; -import android.util.Log; import androidx.annotation.NonNull; @@ -16,7 +15,7 @@ import com.facebook.share.widget.ShareDialog; import com.yunbao.common.utils.ToastUtil; import com.yunbao.share.AbsShareInterface; import com.yunbao.share.ICallback; -import com.yunbao.share.ShareBuilder; +import com.yunbao.share.bean.ShareBuilder; public class FacebookShare extends AbsShareInterface { public static CallbackManager callbackManager; diff --git a/Share/src/main/java/com/yunbao/share/platform/Instagram.java b/Share/src/main/java/com/yunbao/share/platform/Instagram.java index 34dd61e20..da876e6fb 100644 --- a/Share/src/main/java/com/yunbao/share/platform/Instagram.java +++ b/Share/src/main/java/com/yunbao/share/platform/Instagram.java @@ -4,11 +4,9 @@ import android.content.Context; import android.content.Intent; import android.net.Uri; -import androidx.core.content.FileProvider; - import com.yunbao.share.AbsShareInterface; import com.yunbao.share.ICallback; -import com.yunbao.share.ShareBuilder; +import com.yunbao.share.bean.ShareBuilder; public class Instagram extends AbsShareInterface { public Instagram(Context context) { diff --git a/Share/src/main/java/com/yunbao/share/platform/Line.java b/Share/src/main/java/com/yunbao/share/platform/Line.java index 67c2e46b5..bbad5c934 100644 --- a/Share/src/main/java/com/yunbao/share/platform/Line.java +++ b/Share/src/main/java/com/yunbao/share/platform/Line.java @@ -6,11 +6,9 @@ import android.net.Uri; import com.yunbao.share.AbsShareInterface; import com.yunbao.share.ICallback; -import com.yunbao.share.ShareBuilder; +import com.yunbao.share.bean.ShareBuilder; -import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -import java.nio.charset.Charset; public class Line extends AbsShareInterface { diff --git a/Share/src/main/java/com/yunbao/share/platform/MessengerShare.java b/Share/src/main/java/com/yunbao/share/platform/MessengerShare.java index e0efe6a86..0080b3d47 100644 --- a/Share/src/main/java/com/yunbao/share/platform/MessengerShare.java +++ b/Share/src/main/java/com/yunbao/share/platform/MessengerShare.java @@ -12,14 +12,11 @@ import com.facebook.FacebookException; import com.facebook.FacebookSdk; import com.facebook.share.Sharer; import com.facebook.share.model.ShareLinkContent; -import com.facebook.share.model.SharePhoto; -import com.facebook.share.model.SharePhotoContent; import com.facebook.share.widget.MessageDialog; -import com.facebook.share.widget.ShareDialog; import com.yunbao.common.utils.ToastUtil; import com.yunbao.share.AbsShareInterface; import com.yunbao.share.ICallback; -import com.yunbao.share.ShareBuilder; +import com.yunbao.share.bean.ShareBuilder; public class MessengerShare extends AbsShareInterface { public static CallbackManager callbackManager; diff --git a/Share/src/main/java/com/yunbao/share/platform/TwitterShare.java b/Share/src/main/java/com/yunbao/share/platform/TwitterShare.java index 3e15977b4..fbd73b0b5 100644 --- a/Share/src/main/java/com/yunbao/share/platform/TwitterShare.java +++ b/Share/src/main/java/com/yunbao/share/platform/TwitterShare.java @@ -1,24 +1,15 @@ package com.yunbao.share.platform; -import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.net.Uri; -import com.twitter.sdk.android.core.Callback; -import com.twitter.sdk.android.core.Result; import com.twitter.sdk.android.core.Twitter; -import com.twitter.sdk.android.core.TwitterApiClient; -import com.twitter.sdk.android.core.TwitterAuthToken; -import com.twitter.sdk.android.core.TwitterCore; -import com.twitter.sdk.android.core.TwitterException; -import com.twitter.sdk.android.core.TwitterSession; -import com.twitter.sdk.android.core.identity.TwitterAuthClient; -import com.twitter.sdk.android.core.services.AccountService; -import com.twitter.sdk.android.tweetcomposer.ComposerActivity; -import com.twitter.sdk.android.tweetcomposer.TweetComposer; import com.yunbao.share.AbsShareInterface; import com.yunbao.share.ICallback; -import com.yunbao.share.ShareBuilder; +import com.yunbao.share.bean.ShareBuilder; + +import java.net.URLEncoder; public class TwitterShare extends AbsShareInterface { public TwitterShare(Context context) { @@ -51,10 +42,32 @@ public class TwitterShare extends AbsShareInterface { public void failure(TwitterException e) { } });*/ - - TweetComposer.Builder builder = new TweetComposer.Builder(mContext) - .text(date.getText()) - .image(fileToUri(date.getFile())); - builder.show(); + /* TweetComposer.Builder builder; + if (date.getFile() == null) { + try { + builder=new TweetComposer.Builder(mContext) + .text(date.getText()) + .url(new URL(date.getLink())); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + } else { + builder = new TweetComposer.Builder(mContext) + .text(date.getText()) + .image(fileToUri(date.getFile())); + } + builder.show();*/ + try { + Intent sendIntent = new Intent(); + sendIntent.setAction(Intent.ACTION_VIEW); + sendIntent.putExtra(Intent.EXTRA_TEXT, date.getLink()); + // sendIntent.setType("text/plain"); + //sendIntent.setPackage("com.twitter.composer.ComposerShareActivity"); + sendIntent.setData(Uri.parse("https://twitter.com/intent/tweet?text=" +URLEncoder.encode(date.getText(),"UTF-8"))); + mContext.startActivity(sendIntent); + callback.onSuccess(); + } catch (Exception e) { + callback.onFailure(); + } } } diff --git a/Share/src/main/java/com/yunbao/share/platform/WhatsApp.java b/Share/src/main/java/com/yunbao/share/platform/WhatsApp.java index e662d9caa..51485e6fb 100644 --- a/Share/src/main/java/com/yunbao/share/platform/WhatsApp.java +++ b/Share/src/main/java/com/yunbao/share/platform/WhatsApp.java @@ -5,7 +5,7 @@ import android.content.Intent; import com.yunbao.share.AbsShareInterface; import com.yunbao.share.ICallback; -import com.yunbao.share.ShareBuilder; +import com.yunbao.share.bean.ShareBuilder; public class WhatsApp extends AbsShareInterface { public WhatsApp(Context context) { diff --git a/Share/src/main/java/com/yunbao/share/ui/InvitePopDialog.java b/Share/src/main/java/com/yunbao/share/ui/InvitePopDialog.java new file mode 100644 index 000000000..fc109bffc --- /dev/null +++ b/Share/src/main/java/com/yunbao/share/ui/InvitePopDialog.java @@ -0,0 +1,131 @@ +package com.yunbao.share.ui; + +import static android.content.Context.CLIPBOARD_SERVICE; + +import android.app.Dialog; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.lxj.xpopup.XPopup; +import com.makeramen.roundedimageview.RoundedImageView; +import com.pdlive.shayu.R; +import com.yunbao.common.dialog.AbsDialogPopupWindow; +import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; +import com.yunbao.share.bean.ShareBuilder; +import com.yunbao.share.adapters.ShareAppAdapter; + +import java.util.ArrayList; +import java.util.List; + +public class InvitePopDialog extends AbsDialogPopupWindow { + private ShareAppAdapter adapter; + private RecyclerView list; + private RoundedImageView avatar; + private TextView info; + private TextView link; + private List data; + + private String uid; + private String anchorId; + private String anchorName; + private String anchorAvatar; + + public InvitePopDialog(@NonNull Context context) { + super(context); + } + + public InvitePopDialog setUid(String uid) { + this.uid = uid; + return this; + } + + public InvitePopDialog setAnchorId(String anchorId) { + this.anchorId = anchorId; + return this; + } + + public InvitePopDialog setAnchorName(String anchorName) { + this.anchorName = anchorName; + return this; + } + + public InvitePopDialog setAnchorAvatar(String anchorAvatar) { + this.anchorAvatar = anchorAvatar; + return this; + } + + @Override + public void buildDialog(XPopup.Builder builder) { + + } + + @Override + public int bindLayoutId() { + return R.layout.dialog_share; + } + + + @Override + protected void onCreate() { + super.onCreate(); + findViewById(R.id.close).setOnClickListener(v -> dismiss()); + findViewById(R.id.share_copy).setOnClickListener(v -> copyLink()); + findViewById(R.id.share_title).setOnClickListener(v -> copyLink()); + findViewById(R.id.share_preview).setVisibility(GONE); + findViewById(R.id.share_dialog).setBackgroundResource(R.mipmap.bg_dialog_inviet); + ((TextView) findViewById(R.id.share_title)).setText(R.string.dialog_invite_title); + ((TextView) findViewById(R.id.share_title)).setTextColor(R.drawable.bg_invite_title); + list = findViewById(R.id.share_apps_list); + avatar = findViewById(R.id.share_avatar); + info = findViewById(R.id.share_info); + link = findViewById(R.id.share_link); + adapter = new ShareAppAdapter(getContext()); + list.setLayoutManager(new GridLayoutManager(getContext(), 3)); + list.setAdapter(adapter); + initData(); + } + + private void initData() { + data = new ArrayList<>(); + data.add(builder(ShareBuilder.APP_FACEBOOK)); + data.add(builder(ShareBuilder.APP_LINE)); + data.add(builder(ShareBuilder.APP_TWITTER)); + data.add(builder(ShareBuilder.APP_WHATSAPP)); + data.add(builder(ShareBuilder.APP_MESSENGER)); + // data.add(builder(ShareBuilder.APP_INSTAGRAM)); + adapter.setList(data); + + } + + private ShareBuilder builder(int type) { + ShareBuilder builder = ShareBuilder.builder(type); + //builder.setText(WordUtil.getString(R.string.dialog_share_info)); + builder.setLink(ShareBuilder.createInviteLink(uid)); + builder.setUid(uid); + builder.setAnchorId(anchorId); + builder.setAnchorName(anchorName); + builder.setAnchorAvatar(anchorAvatar); + return builder; + } + + private void copyLink() { + ClipboardManager cm = (ClipboardManager) getContext().getSystemService(CLIPBOARD_SERVICE); + ClipData clipData = ClipData.newPlainText("text", link.getText().toString()); + cm.setPrimaryClip(clipData); + ToastUtil.show(WordUtil.getString(com.yunbao.common.R.string.copy_success)); + DialogUitl.showSimpleDialog(getContext(), ShareBuilder.createInviteLink(uid), new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + dialog.dismiss(); + } + }); + } +} diff --git a/Share/src/main/java/com/yunbao/share/ui/InviteRewardPopDialog.java b/Share/src/main/java/com/yunbao/share/ui/InviteRewardPopDialog.java new file mode 100644 index 000000000..1ac8acecc --- /dev/null +++ b/Share/src/main/java/com/yunbao/share/ui/InviteRewardPopDialog.java @@ -0,0 +1,131 @@ +package com.yunbao.share.ui; + +import static android.content.Context.CLIPBOARD_SERVICE; + +import android.app.Dialog; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.lxj.xpopup.XPopup; +import com.makeramen.roundedimageview.RoundedImageView; +import com.pdlive.shayu.R; +import com.yunbao.common.dialog.AbsDialogPopupWindow; +import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; +import com.yunbao.share.bean.ShareBuilder; +import com.yunbao.share.adapters.ShareAppAdapter; + +import java.util.ArrayList; +import java.util.List; + +public class InviteRewardPopDialog extends AbsDialogPopupWindow { + private ShareAppAdapter adapter; + private RecyclerView list; + private RoundedImageView avatar; + private TextView info; + private TextView link; + private List data; + + private String uid; + private String anchorId; + private String anchorName; + private String anchorAvatar; + + public InviteRewardPopDialog(@NonNull Context context) { + super(context); + } + + public InviteRewardPopDialog setUid(String uid) { + this.uid = uid; + return this; + } + + public InviteRewardPopDialog setAnchorId(String anchorId) { + this.anchorId = anchorId; + return this; + } + + public InviteRewardPopDialog setAnchorName(String anchorName) { + this.anchorName = anchorName; + return this; + } + + public InviteRewardPopDialog setAnchorAvatar(String anchorAvatar) { + this.anchorAvatar = anchorAvatar; + return this; + } + + @Override + public void buildDialog(XPopup.Builder builder) { + + } + + @Override + public int bindLayoutId() { + return R.layout.dialog_share; + } + + + @Override + protected void onCreate() { + super.onCreate(); + findViewById(R.id.close).setOnClickListener(v -> dismiss()); + findViewById(R.id.share_copy).setOnClickListener(v -> copyLink()); + findViewById(R.id.share_title).setOnClickListener(v -> copyLink()); + findViewById(R.id.share_preview).setVisibility(GONE); + findViewById(R.id.share_dialog).setBackgroundResource(R.mipmap.bg_dialog_inviet); + ((TextView) findViewById(R.id.share_title)).setText(R.string.dialog_invite_title); + ((TextView) findViewById(R.id.share_title)).setTextColor(R.drawable.bg_invite_title); + list = findViewById(R.id.share_apps_list); + avatar = findViewById(R.id.share_avatar); + info = findViewById(R.id.share_info); + link = findViewById(R.id.share_link); + adapter = new ShareAppAdapter(getContext()); + list.setLayoutManager(new LinearLayoutManager(getContext(),RecyclerView.VERTICAL,false)); + list.setAdapter(adapter); + initData(); + } + + private void initData() { + data = new ArrayList<>(); + data.add(builder(ShareBuilder.APP_FACEBOOK)); + data.add(builder(ShareBuilder.APP_LINE)); + data.add(builder(ShareBuilder.APP_TWITTER)); + data.add(builder(ShareBuilder.APP_WHATSAPP)); + data.add(builder(ShareBuilder.APP_MESSENGER)); + // data.add(builder(ShareBuilder.APP_INSTAGRAM)); + adapter.setList(data); + + } + + private ShareBuilder builder(int type) { + ShareBuilder builder = ShareBuilder.builder(type); + //builder.setText(WordUtil.getString(R.string.dialog_share_info)); + builder.setLink(ShareBuilder.createInviteLink(uid)); + builder.setUid(uid); + builder.setAnchorId(anchorId); + builder.setAnchorName(anchorName); + builder.setAnchorAvatar(anchorAvatar); + return builder; + } + + private void copyLink() { + ClipboardManager cm = (ClipboardManager) getContext().getSystemService(CLIPBOARD_SERVICE); + ClipData clipData = ClipData.newPlainText("text", link.getText().toString()); + cm.setPrimaryClip(clipData); + ToastUtil.show(WordUtil.getString(com.yunbao.common.R.string.copy_success)); + DialogUitl.showSimpleDialog(getContext(), ShareBuilder.createInviteLink(uid), new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + dialog.dismiss(); + } + }); + } +} diff --git a/Share/src/main/java/com/yunbao/share/ui/SharePopDialog.java b/Share/src/main/java/com/yunbao/share/ui/SharePopDialog.java new file mode 100644 index 000000000..85a1735f9 --- /dev/null +++ b/Share/src/main/java/com/yunbao/share/ui/SharePopDialog.java @@ -0,0 +1,119 @@ +package com.yunbao.share.ui; + +import static android.content.Context.CLIPBOARD_SERVICE; + +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.lxj.xpopup.XPopup; +import com.makeramen.roundedimageview.RoundedImageView; +import com.pdlive.shayu.R; +import com.yunbao.common.dialog.AbsDialogPopupWindow; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; +import com.yunbao.share.bean.ShareBuilder; +import com.yunbao.share.adapters.ShareAppAdapter; + +import java.util.ArrayList; +import java.util.List; + +public class SharePopDialog extends AbsDialogPopupWindow { + private ShareAppAdapter adapter; + private RecyclerView list; + private RoundedImageView avatar; + private TextView info; + private TextView link; + private List data; + + private String uid; + private String anchorId; + private String anchorName; + private String anchorAvatar; + + public SharePopDialog(@NonNull Context context) { + super(context); + } + + public SharePopDialog setUid(String uid) { + this.uid = uid; + return this; + } + + public SharePopDialog setAnchorId(String anchorId) { + this.anchorId = anchorId; + return this; + } + + public SharePopDialog setAnchorName(String anchorName) { + this.anchorName = anchorName; + return this; + } + + public SharePopDialog setAnchorAvatar(String anchorAvatar) { + this.anchorAvatar = anchorAvatar; + return this; + } + + @Override + public void buildDialog(XPopup.Builder builder) { + + } + + @Override + public int bindLayoutId() { + return R.layout.dialog_share; + } + + + @Override + protected void onCreate() { + super.onCreate(); + findViewById(R.id.close).setOnClickListener(v -> dismiss()); + findViewById(R.id.share_copy).setOnClickListener(v -> copyLink()); + list = findViewById(R.id.share_apps_list); + avatar = findViewById(R.id.share_avatar); + info = findViewById(R.id.share_info); + link = findViewById(R.id.share_link); + adapter = new ShareAppAdapter(getContext()); + list.setLayoutManager(new GridLayoutManager(getContext(), 3)); + list.setAdapter(adapter); + initData(); + } + + private void initData() { + data = new ArrayList<>(); + data.add(builder(ShareBuilder.APP_FACEBOOK)); + data.add(builder(ShareBuilder.APP_LINE)); + data.add(builder(ShareBuilder.APP_TWITTER)); + data.add(builder(ShareBuilder.APP_WHATSAPP)); + data.add(builder(ShareBuilder.APP_MESSENGER)); + //data.add(builder(ShareBuilder.APP_INSTAGRAM)); + adapter.setList(data); + String url=ShareBuilder.createLiveShareLink(uid,anchorId,anchorName,anchorAvatar).substring(0,40)+"..."; + link.setText(url); + ImgLoader.display(getContext(),anchorAvatar,avatar); + } + private ShareBuilder builder(int type){ + ShareBuilder builder=ShareBuilder.builder(type); + builder.setText(WordUtil.getString(R.string.dialog_share_info)); + builder.setUid(uid); + builder.setAnchorId(anchorId); + builder.setAnchorName(anchorName); + builder.setAnchorAvatar(anchorAvatar); + return builder; + } + + private void copyLink() { + ClipboardManager cm = (ClipboardManager) getContext().getSystemService(CLIPBOARD_SERVICE); + ClipData clipData = ClipData.newPlainText("text", ShareBuilder.createLiveShareLink(uid,anchorId,anchorName,anchorAvatar)); + cm.setPrimaryClip(clipData); + ToastUtil.show(WordUtil.getString(com.yunbao.common.R.string.copy_success)); + } +} diff --git a/Share/src/main/res/drawable/background_fff.xml b/Share/src/main/res/drawable/background_fff.xml new file mode 100644 index 000000000..2b3a47e26 --- /dev/null +++ b/Share/src/main/res/drawable/background_fff.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/Share/src/main/res/drawable/bg_btn.xml b/Share/src/main/res/drawable/bg_btn.xml new file mode 100644 index 000000000..f7cda2e72 --- /dev/null +++ b/Share/src/main/res/drawable/bg_btn.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/Share/src/main/res/drawable/bg_invite_title.xml b/Share/src/main/res/drawable/bg_invite_title.xml new file mode 100644 index 000000000..1d7b0cf28 --- /dev/null +++ b/Share/src/main/res/drawable/bg_invite_title.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Share/src/main/res/layout/dialog_invite_list.xml b/Share/src/main/res/layout/dialog_invite_list.xml new file mode 100644 index 000000000..877aab9e3 --- /dev/null +++ b/Share/src/main/res/layout/dialog_invite_list.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Share/src/main/res/layout/dialog_share.xml b/Share/src/main/res/layout/dialog_share.xml new file mode 100644 index 000000000..65b31da1c --- /dev/null +++ b/Share/src/main/res/layout/dialog_share.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Share/src/main/res/layout/item_invite_reward.xml b/Share/src/main/res/layout/item_invite_reward.xml new file mode 100644 index 000000000..33cbd0d57 --- /dev/null +++ b/Share/src/main/res/layout/item_invite_reward.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Share/src/main/res/layout/item_share_app.xml b/Share/src/main/res/layout/item_share_app.xml new file mode 100644 index 000000000..789064f41 --- /dev/null +++ b/Share/src/main/res/layout/item_share_app.xml @@ -0,0 +1,34 @@ + + + + + + + \ No newline at end of file diff --git a/Share/src/main/res/layout/view_share_preview.xml b/Share/src/main/res/layout/view_share_preview.xml new file mode 100644 index 000000000..f7c1e97f2 --- /dev/null +++ b/Share/src/main/res/layout/view_share_preview.xml @@ -0,0 +1,74 @@ + + + + + + + + + +