修改悬浮窗样式,添加悬浮设置

This commit is contained in:
18401019693 2022-10-20 10:48:58 +08:00
parent 28137615df
commit 4b5f3a9560
14 changed files with 94 additions and 271 deletions

View File

@ -189,4 +189,7 @@ dependencies {
implementation 'com.github.tajchert:WaitingDots:0.6.1'
//
api 'com.github.princekin-f:EasyFloat:2.0.4'
// api project(path: ':recognizer')
}

View File

@ -1,5 +1,7 @@
package com.yunbao.common.manager.imrongcloud;
import static com.yunbao.common.CommonAppContext.isReady;
import android.app.Application;
import android.content.Context;
import android.util.Log;
@ -17,8 +19,6 @@ import com.yunbao.common.manager.IMLoginManager;
import org.greenrobot.eventbus.EventBus;
import java.util.ArrayList;
import io.rong.imkit.GlideKitImageEngine;
import io.rong.imkit.IMCenter;
import io.rong.imkit.RongIM;
@ -26,9 +26,7 @@ import io.rong.imkit.config.RongConfigCenter;
import io.rong.imlib.RongIMClient;
import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.Message;
import io.rong.imlib.model.MessageContent;
import static com.yunbao.common.CommonAppContext.isReady;
import io.rong.recognizer.Recognizer;
/**
* 会话列表
@ -41,6 +39,7 @@ public class RongcloudIMManager {
public static String RONG_IM_KEY = "pvxdm17jpd3hr";
private static final String CLASSNAME = "RongcloudIMManager";
static {//自动切换key
if (CommonAppConfig.HOST.contains("ceshi")) {
RONG_IM_KEY = "pvxdm17jpd3hr"; //测试服key
@ -61,13 +60,13 @@ public class RongcloudIMManager {
Log.e(CLASSNAME, "initRongIM:");
initPhotoGlide();
//初始化科大讯飞语音转文字
Recognizer.setAppId("af2efca9");
}
private static RongIMClient.OnReceiveMessageWrapperListener mListener;
/**
*
* 设置消息接受监听器
*/
public static void addRongcloudIMOnReceiveMessageListener(RongIMClient.OnReceiveMessageWrapperListener listener) {

View File

@ -266,6 +266,27 @@
android:textColor="#FF9A9A9A"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/float_settings_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="23dp"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@mipmap/live_more_icon_fenestrule" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:text="@string/small_window"
android:textColor="#FF9A9A9A"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/system_notice"

View File

@ -926,4 +926,10 @@
<string name="star_change">%s星挑战</string>
<string name="star_success">恭喜 %s完成了%s %s星 挑戰,快去一睹主播芳容吧!</string>
<string name="star"></string>
<string name="small_window_settings">小窗播放設置</string>
<string name="small_window">小窗播放</string>
<string name="app_window">APP內小窗播放</string>
<string name="app_window_hint">讓直播間內容在本APP主頁面中小窗播放</string>
<string name="system_window">APP全應用小窗播放</string>
<string name="system_window_hint">讓直播間內容在所有APP及頁面中小窗播放</string>
</resources>

View File

@ -16,6 +16,7 @@
android:name=".activity.LiveAudienceActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustPan|stateAlwaysHidden" />
<activity
android:name=".activity.LiveChooseClassActivity"

View File

@ -36,10 +36,12 @@ import com.yunbao.common.activity.WebViewActivity;
import com.yunbao.common.bean.AnchorRecommendItemModel;
import com.yunbao.common.bean.AnchorRecommendModel;
import com.yunbao.common.bean.IMLoginModel;
import com.yunbao.common.bean.LiveBean;
import com.yunbao.common.bean.LiveGiftBean;
import com.yunbao.common.bean.SlideInfoModel;
import com.yunbao.common.bean.UserBean;
import com.yunbao.common.dialog.EffectsSettingsDialog;
import com.yunbao.common.dialog.FloatSettingsDialog;
import com.yunbao.common.dialog.LiveChargeDialogFragment;
import com.yunbao.common.dialog.SlideSettingsDialog;
import com.yunbao.common.event.FollowEvent;
@ -64,7 +66,6 @@ import com.yunbao.common.views.weight.VerticalViewPager;
import com.yunbao.live.R;
import com.yunbao.live.adapter.VerticalPagerAdapter;
import com.yunbao.live.bean.ImUserBean;
import com.yunbao.common.bean.LiveBean;
import com.yunbao.live.bean.LiveChatBean;
import com.yunbao.live.dialog.LiveFansFragment;
import com.yunbao.live.dialog.LiveGiftDialogFragment;
@ -267,7 +268,6 @@ public class LiveAudienceActivity extends LiveActivity {
// 满足此种条件表明需要加载直播视频以及聊天室了
if (viewGroup.getId() == mCurrentItem && (position == 0) && mCurrentItem != mLastPosition) {
loadData(viewGroup, mCurrentItem);
manager.onPause();
}
}
@ -768,6 +768,11 @@ public class LiveAudienceActivity extends LiveActivity {
EffectsSettingsDialog effectsSettingsDialog = new EffectsSettingsDialog();
effectsSettingsDialog.show(getSupportFragmentManager(), "EffectsSettingsDialog");
break;
case FLOAT_SETTING:
FloatSettingsDialog floatSettingsDialog = new FloatSettingsDialog();
floatSettingsDialog.show(getSupportFragmentManager(), "FloatSettingsDialog");
manager.setQuitF(true);
break;
case WISH_LIST:
LiveWishListDialogFragment4Audience fragment4Audience = new LiveWishListDialogFragment4Audience();
bundle.putString(Constants.LIVE_UID, mLiveUid);

View File

@ -10,13 +10,13 @@ import androidx.recyclerview.widget.RecyclerView;
import com.yunbao.common.R;
import com.yunbao.common.bean.ActiveModel;
import com.yunbao.common.bean.LiveBean;
import com.yunbao.common.dialog.AbsDialogFragment;
import com.yunbao.common.http.base.HttpCallback;
import com.yunbao.common.http.live.LiveNetManager;
import com.yunbao.common.utils.Bus;
import com.yunbao.common.views.weight.ViewClicksAntiShake;
import com.yunbao.live.adapter.FunGamesAdapter;
import com.yunbao.common.bean.LiveBean;
import com.yunbao.live.event.LiveAudienceEvent;
import org.greenrobot.eventbus.Subscribe;
@ -149,6 +149,13 @@ public class LiveTotalDialog extends AbsDialogFragment {
.setType(LiveAudienceEvent.LiveAudienceType.SLIDE_SETTINGS));
dismiss();
});
//悬浮窗设置
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.float_settings_layout), () -> {
Bus.get().post(new LiveAudienceEvent()
.setType(LiveAudienceEvent.LiveAudienceType.FLOAT_SETTING));
dismiss();
}
);
}
@Override

View File

@ -4,8 +4,8 @@ import com.yunbao.common.bean.ActiveModel;
import com.yunbao.common.bean.AiAutomaticSpeechModel;
import com.yunbao.common.bean.AnchorRecommendItemModel;
import com.yunbao.common.bean.BaseModel;
import com.yunbao.common.bean.MsgModel;
import com.yunbao.common.bean.LiveBean;
import com.yunbao.common.bean.MsgModel;
import com.yunbao.live.bean.OpenParametersModel;
public class LiveAudienceEvent extends BaseModel {
@ -148,7 +148,8 @@ public class LiveAudienceEvent extends BaseModel {
START_MESSAGE(25, "星级消息"),
AI_AUTOMATIC_SPEECH(26, "机器人助手"),
STAR_CHALLENGE_UPGRADE_NOTIFY(27, "星级挑战成功"),
MESSAGE_BOTTOM(28, "聊天消息滚动到底部");
MESSAGE_BOTTOM(28, "聊天消息滚动到底部"),
FLOAT_SETTING(29, "悬浮窗设置");
private int type;
private String name;

View File

@ -1,148 +0,0 @@
package com.yunbao.live.views;
import android.app.Activity;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import com.lzf.easyfloat.EasyFloat;
import com.lzf.easyfloat.enums.ShowPattern;
import com.lzf.easyfloat.interfaces.FloatCallbacks;
import com.lzf.easyfloat.interfaces.OnInvokeView;
import com.tencent.live2.V2TXLivePlayer;
import com.tencent.live2.impl.V2TXLivePlayerImpl;
import com.tencent.rtmp.ui.TXCloudVideoView;
import com.yunbao.common.bean.LiveBean;
import com.yunbao.common.utils.RouteUtil;
import com.yunbao.common.views.weight.ViewClicksAntiShake;
import com.yunbao.live.R;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
/**
* 直播间悬浮窗管理
*/
public class LiveFloatView implements Function1<FloatCallbacks.Builder, Unit> {
private static LiveFloatView instance;
private LiveOnInvokeView liveOnInvokeView = null;
private Activity mContext;
private String url;
private LiveBean mLiveBean;
private int mLiveType;
private int mLiveSDK;
private int mLiveTypeVal;
private FloatCallbacks.Builder builder;
private String TAG = "LiveFloatView";
private V2TXLivePlayer mPlayer;
public static LiveFloatView getInstance() {
if (instance == null) {
instance = new LiveFloatView();
}
return instance;
}
public void builderFloat(Activity mContext, String url) {
liveOnInvokeView = new LiveOnInvokeView();
this.mContext = mContext;
this.url = url;
EasyFloat.with(mContext)
.setTag(TAG)
.setLayout(R.layout.view_flaot_live, liveOnInvokeView)
.setShowPattern(ShowPattern.CURRENT_ACTIVITY)
.setGravity(Gravity.END | Gravity.CENTER_VERTICAL, 0, 200)
.registerCallback(this)
.show();
}
public void builderSystemFloat(Activity mContext, String url) {
liveOnInvokeView = new LiveOnInvokeView();
this.mContext = mContext;
this.url = url;
EasyFloat.with(mContext)
.setTag(TAG)
.setLayout(R.layout.view_flaot_live, liveOnInvokeView)
.setShowPattern(ShowPattern.ALL_TIME)
.setGravity(Gravity.END | Gravity.CENTER_VERTICAL, 0, 200)
.registerCallback(this)
.show();
}
public LiveFloatView cacheLiveData(LiveBean mLiveBean, int mLiveType, int mLiveSDK, int mLiveTypeVal) {
this.mLiveBean = mLiveBean;
this.mLiveType = mLiveType;
this.mLiveSDK = mLiveSDK;
this.mLiveTypeVal = mLiveTypeVal;
return instance;
}
@Override
public Unit invoke(FloatCallbacks.Builder builder) {
this.builder = builder;
builder.createResult((aBoolean, s, view) -> {
Log.e("LiveFloatView", "aBoolean:" + aBoolean + "---------------------s:" + s);
if (callback != null) {
callback.invoke(aBoolean);
}
builder.dismiss(() -> {
if (mPlayer != null && mPlayer.isPlaying() == 1) {
mPlayer.stopPlay();
}
return null;
});
builder.hide(view12 -> {
if (mPlayer != null && mPlayer.isPlaying() == 1) {
mPlayer.pauseAudio();
mPlayer.pauseVideo();
}
return null;
});
return null;
});
return null;
}
/**
* 悬浮窗布局管理
*/
private class LiveOnInvokeView implements OnInvokeView {
@Override
public void invoke(View view) {
TXCloudVideoView videoView = view.findViewById(R.id.video_view);
mPlayer = new V2TXLivePlayerImpl(mContext);
mPlayer.setRenderView(videoView);
mPlayer.startPlay(url);
ViewClicksAntiShake.clicksAntiShake(view.findViewById(R.id.btn_close), new ViewClicksAntiShake.ViewClicksCallBack() {
@Override
public void onViewClicks() {
mPlayer.stopPlay();
EasyFloat.dismiss("LiveFloatView", true);
}
});
ViewClicksAntiShake.clicksAntiShake(videoView, () -> {
mPlayer.stopPlay();
RouteUtil.forwardLiveAudienceActivity(mLiveBean, mLiveType, mLiveSDK, mLiveTypeVal);
});
}
}
private LiveFloatViewCallback callback;
public LiveFloatView setCallback(LiveFloatViewCallback callback) {
this.callback = callback;
return this;
}
public interface LiveFloatViewCallback {
void invoke(Boolean aBoolean);
}
}

View File

@ -30,6 +30,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.GsonUtils;
import com.facebook.appevents.AppEventsLogger;
import com.lzf.easyfloat.EasyFloat;
import com.lzf.easyfloat.permission.PermissionUtils;
import com.tencent.imsdk.v2.V2TIMCallback;
import com.tencent.imsdk.v2.V2TIMManager;
@ -57,6 +58,7 @@ import com.yunbao.common.utils.RouteUtil;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.utils.WordUtil;
import com.yunbao.common.utils.formatBigNum;
import com.yunbao.common.views.weight.LiveFloatView;
import com.yunbao.live.R;
import com.yunbao.live.activity.LiveActivity;
import com.yunbao.live.activity.LiveAudienceActivity;
@ -175,6 +177,13 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
private OpenParametersModel openParametersModel = null;
//星级活动地址
private String activityUrl = "";
//标记是调用正常退出还是手动切后台
private boolean isQuitF = false;
public PortraitLiveManager setQuitF(boolean quitF) {
isQuitF = quitF;
return this;
}
public PortraitLiveManager(Activity context, Intent intent) {
this.mContext = context;
@ -348,70 +357,23 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
mLiveRyLinkMicPkPresenter.release();
}
if (isQuit) {
isQuitF = true;
if (PermissionUtils.checkPermission(mContext)) {
LiveFloatView.getInstance()
.cacheLiveData(mLiveBean, mLiveType, mLiveSDK, mLiveTypeVal)
.builderSystemFloat(mContext, mLiveBean.getPull());
mContext.finish();
} else {
if (mContext instanceof LiveAudienceActivity) {
if (IMLoginManager.get(mContext).isFloat()) {
DialogUitl.showSimpleDialog(mContext, null, "您未打开悬浮窗权限,是否打开", false, new DialogUitl.SimpleCallback3() {
@Override
public void onConfirmClick(Dialog dialog) {
LiveFloatView.getInstance()
.setCallback(new LiveFloatView.LiveFloatViewCallback() {
@Override
public void invoke(Boolean aBoolean) {
if (aBoolean) {
mContext.finish();
} else {
EventBus.getDefault()
.post(new LiveFloatEvent()
.setmLiveBean(mLiveBean)
.setmLiveSDK(mLiveSDK)
.setmLiveType(mLiveType)
.setmLiveTypeVal(mLiveTypeVal));
mContext.finish();
IMLoginManager.get(mContext).initFloat(true);
}
}
})
.cacheLiveData(mLiveBean, mLiveType, mLiveSDK, mLiveTypeVal)
.builderSystemFloat(mContext, mLiveBean.getPull());
}
@Override
public void onCancel() {
EventBus.getDefault()
.post(new LiveFloatEvent()
.setmLiveBean(mLiveBean)
.setmLiveSDK(mLiveSDK)
.setmLiveType(mLiveType)
.setmLiveTypeVal(mLiveTypeVal));
mContext.finish();
IMLoginManager.get(mContext).initFloat(false);
}
});
} else {
EventBus.getDefault()
.post(new LiveFloatEvent()
.setmLiveBean(mLiveBean)
.setmLiveSDK(mLiveSDK)
.setmLiveType(mLiveType)
.setmLiveTypeVal(mLiveTypeVal));
mContext.finish();
}
}
// PermissionUtils.requestPermission(mContext, new OnPermissionResult() {
// @Override
// public void permissionResult(boolean b) {
// ToastUtil.show("悬浮窗权限:"+b);
// }
// });
}
}
}
@ -430,12 +392,23 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
public void onResume() {
// if (mLivePlayViewHolder != null)
// mLivePlayViewHolder.onResume();
//判断是否有直播悬浮窗有直接关闭
if (EasyFloat.isShow("LiveFloatView")) {
EasyFloat.dismiss("LiveFloatView", true);
}
}
@Override
public void onPause() {
// if (mLivePlayViewHolder != null)
// mLivePlayViewHolder.onPause();
if (mLiveBean != null && !isQuitF) {
LiveFloatView.getInstance()
.cacheLiveData(mLiveBean, mLiveType, mLiveSDK, mLiveTypeVal)
.builderSystemFloat(mContext, mLiveBean.getPull());
mContext.finish();
}
isQuitF = false;
}
@Override
@ -1033,7 +1006,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
@Override
public void onHourRank(LiveChatBean bean, JSONObject ranks) {
if (mLiveRoomViewHolder != null) {
if (mLiveRoomViewHolder != null && !TextUtils.isEmpty(liveID)) {
mLiveRoomViewHolder.setHourRankData(ranks.getInteger(liveID));
}
}

View File

@ -1,38 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="210dp"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:layout_width="230dp"
android:layout_height="130dp"
android:layout_marginStart="25dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
app:cardCornerRadius="4dp"
app:cardElevation="0dp">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp"
app:cardCornerRadius="4dp"
app:cardElevation="0dp">
<com.tencent.rtmp.ui.TXCloudVideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.cardview.widget.CardView>
</androidx.cardview.widget.CardView>
<ImageView
android:id="@+id/btn_close"
android:layout_width="50dp"
android:layout_height="50dp"
android:paddingBottom="30dp"
android:src="@mipmap/icon_live_close_3" />
</RelativeLayout>

View File

@ -91,7 +91,7 @@ import com.yunbao.live.http.LiveHttpUtil;
import com.yunbao.live.presenter.LiveRoomCheckLivePresenter;
import com.yunbao.live.utils.LiveStorge;
import com.yunbao.live.views.ChatListViewHolder;
import com.yunbao.live.views.LiveFloatView;
import com.yunbao.common.views.weight.LiveFloatView;
import com.yunbao.main.R;
import com.yunbao.main.dialog.MainStartDialogFragment;
import com.yunbao.main.dialog.ReturnUserDialog;

View File

@ -36,9 +36,7 @@ import com.opensource.svgaplayer.SVGAVideoEntity;
import com.yunbao.common.activity.AbsActivity;
import com.yunbao.common.activity.WebViewActivity;
import com.yunbao.common.bean.ImUserInfoModel;
import com.yunbao.common.bean.LiveBean;
import com.yunbao.common.custom.TabButtonGroup;
import com.yunbao.common.event.LiveFloatEvent;
import com.yunbao.common.event.MessageIMEvent;
import com.yunbao.common.event.UpdateTablePointMe;
import com.yunbao.common.glide.ImgLoader;
@ -50,18 +48,12 @@ import com.yunbao.common.manager.imrongcloud.MessageIMManager;
import com.yunbao.common.utils.DeviceUtils;
import com.yunbao.common.utils.DialogUitl;
import com.yunbao.common.utils.ProcessResultUtil;
import com.yunbao.common.utils.RouteUtil;
import com.yunbao.common.utils.SVGAViewUtils;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.views.weight.ViewClicksAntiShake;
import com.yunbao.live.activity.LiveAudienceActivity;
import com.yunbao.live.activity.SystemMessageActivity;
import com.yunbao.live.bean.ImUserBean;
import com.yunbao.live.event.RecommendLiveRoomEvent;
import com.yunbao.live.http.ImHttpUtil;
import com.yunbao.live.http.LiveHttpUtil;
import com.yunbao.live.presenter.LiveRoomCheckLivePresenter;
import com.yunbao.live.views.LiveFloatView;
import com.yunbao.main.R;
import com.yunbao.main.adapter.SystemMessageAdapter;
import com.yunbao.main.dialog.MainStartDialogFragment;

View File

@ -1,2 +1,3 @@
include ':app', ':video', ':common', ':main', ':baidu', ':live', ':lib_country_code'
include ':app', ':video', ':common', ':main', ':live', ':lib_country_code'
//include ':FaceUnity'
//include ':recognizer'//