@@ -27,9 +27,9 @@ import com.blankj.utilcode.util.FragmentUtils;
import com.blankj.utilcode.util.LogUtils ;
import com.blankj.utilcode.util.ToastUtils ;
import com.bumptech.glide.Glide ;
import com.example.moduleactivity.RoomManager ;
import com.example.modulecircle.fragment.CircleFragment ;
import com.example.modulenews.fragment.NewsFragment ;
import com.example.moduleroom.activity.RoomActivity ;
import com.example.modulevocal.fragment.VocalRangeFragment ;
import com.example.modulevoice.fragment.VoiceFragment ;
import com.xscm.modulemain.R ;
@@ -38,11 +38,15 @@ import com.xscm.modulemain.databinding.ActivityMainBinding;
import com.xscm.modulemain.presenter.HomePresenter ;
import com.xscm.moduleutil.activity.BaseMvpActivity ;
import com.xscm.moduleutil.adapter.AppUpdateDialog ;
import com.xscm.moduleutil.base.AppStateManager ;
import com.xscm.moduleutil.base.CommonAppContext ;
import com.xscm.moduleutil.base.RoomManager ;
import com.xscm.moduleutil.bean.AppUpdateModel ;
import com.xscm.moduleutil.bean.FirstChargeBean ;
import com.xscm.moduleutil.bean.FirstChargeGiftBean ;
import com.xscm.moduleutil.bean.ThemeBean ;
import com.xscm.moduleutil.bean.room.RoomOnline ;
import com.xscm.moduleutil.bean.room.RoomOnlineBean ;
import com.xscm.moduleutil.dialog.FirstChargeDialog ;
import com.xscm.moduleutil.dialog.RechargeDialogFragment ;
import com.xscm.moduleutil.event.RoomOutEvent ;
@@ -61,6 +65,7 @@ import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
@Route ( path = ARouteConstants . ME )
@@ -98,7 +103,6 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
}
@Override
protected void onCreate ( @Nullable Bundle savedInstanceState ) {
super . onCreate ( savedInstanceState ) ;
@@ -115,9 +119,12 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
// 检查是否有正在播放的房间
if ( CommonAppContext . getInstance ( ) . isPlaying ) {
// 如果有正在播放的房间,直接退出应用
finish( ) ;
android. os . Process. killProcess( android. os . Process . myPid ( ) ) ;
System. exit ( 0 ) ;
// finish() ;
// android.os. Process. killProcess( android.os.Process.myPid()) ;
// System.exit(0) ;
// exitApp();
clearAllOtherTasksAndRestart ( ) ;
return ;
}
@@ -138,6 +145,7 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
} ) ;
}
}
@Override
protected void initData ( ) {
MvpPre . getThemeData ( ) ;
@@ -152,8 +160,27 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
MvpPre . initData ( ) ;
MvpPre . userFiles ( ) ;
V2TIMManager . getConversationManager ( ) . getTotalUnreadMessageCount ( new V2TIMValueCallback < Long > ( ) {
@Override
public void onSuccess ( Long aLong ) {
if ( aLong = = 0 ) {
mBinding . tvMessage . setVisibility ( View . GONE ) ;
mBinding . tvMessage . setText ( " 0 " ) ;
} else {
mBinding . tvMessage . setVisibility ( View . VISIBLE ) ;
}
mBinding . tvMessage . setText ( String . valueOf ( aLong ) ) ;
}
@Override
public void onError ( int code , String desc ) {
}
} ) ;
}
@Override
protected void onActivityResult ( int requestCode , int resultCode , @Nullable Intent data ) {
super . onActivityResult ( requestCode , resultCode , data ) ;
@@ -181,16 +208,16 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
setIntent ( intent ) ;
// 检查是否需要跳转到房间
if ( shouldRestoreRoom( ) ) {
ARouter. getInstance( ) . build ( ARouteConstants. ROOM_DETAILS )
. withString( " form " , " 首页 " )
. withString( " roomId " , CommonAppContext. getInstance( ) . playId )
. withFlags( Intent. FLAG_ACTIVITY_CLEAR_TOP | Intent. FLAG_ACTIVITY_SINGLE_TOP )
. navigation( ) ;
// RoomManager.instance( CommonAppContext.getInstance()).joinRoomWithRoomId(CommonAppContext.getInstance().playId, true);
return ;
}
// if ( shouldRestoreRoom()) {
// ARouter. getInstance().build( ARouteConstants. ROOM_DETAILS)
// . withString("form", "首页" )
// . withString("roomId", CommonAppContext. getInstance(). playId)
// . withFlags( Intent. FLAG_ACTIVITY_CLEAR_TOP | Intent. FLAG_ACTIVITY_SINGLE_TOP)
// . navigation() ;
//
//// RoomManager.instance( CommonAppContext.getInstance()).joinRoomWithRoomId(CommonAppContext.getInstance().playId, true);
// return;
// }
// 处理tab切换
checkTab ( intent . getIntExtra ( " tab " , - 1 ) ) ;
@@ -201,6 +228,7 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
selectShow ( tab ) ;
}
}
private boolean isExit = false ; // 标记是否准备退出
private Handler mHandler = new Handler ( ) ;
@@ -211,9 +239,11 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
// 检查是否有正在播放的房间
if ( CommonAppContext . getInstance ( ) . isPlaying ) {
// 如果有正在播放的房间,直接退出应用
finish( ) ;
android. os . Process. killProcess( android. os . Process . myPid ( ) ) ;
System. exit ( 0 ) ;
// finish() ;
// android.os. Process. killProcess( android.os.Process.myPid()) ;
// System.exit(0) ;
// exitApp();
clearAllOtherTasksAndRestart ( ) ;
return true ;
}
@@ -232,7 +262,22 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
}
return super . onKeyDown ( keyCode , event ) ;
}
// 最推荐的方法
private void clearAllOtherTasksAndRestart ( ) {
// Intent intent = new Intent(this, MainActivity.class);
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
// intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
// startActivity(intent);
// 可选: finish当前Activity
// if (!isFinishing()) {
// finish();
// }
// 可选:如果上面的方法不够彻底,可以配合使用
Runtime . getRuntime ( ) . gc ( ) ; // 建议垃圾回收
}
/**
* 优雅地退出应用,避免闪屏
*/
@@ -281,7 +326,7 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
index = 0 ;
isMediaSelected = true ; // 确保设置为选中状态
selectedTextColor = ColorManager . getInstance ( ) . getPrimaryColorInt ( ) ;
unselectedTextColor = Color . parseColor ( " #000000 " ) ;
unselectedTextColor = Color . parseColor ( " #000000 " ) ;
updateAllTabUI ( ) ; // 这会同时更新图标和文字颜色
}
@@ -321,9 +366,26 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
} else if ( id = = R . id . riv ) {
String roomId = CommonAppContext . getInstance ( ) . playId ;
if ( ! TextUtils . isEmpty ( roomId ) ) {
// RoomManager.instance( CommonAppContext. getInstance()).joinRoomWithRoomId(roomId, true) ;
ARouter . getInstance ( ) . build ( ARouteConstants . ROOM_DETAILS ) . withString ( " form " , " 首页 " ) . withString ( " roomId " , roomId ) . navigation ( ) ;
RoomManager. getInstance ( ) . fetchRoomDataAndEnter ( this , CommonAppContext. getInstance( ) . playId , " " ) ;
// MvpPre.getRoomOnline(roomId, "1", "100");
// AppStateManager stateManager = AppStateManager.getInstance();
// if (stateManager.isRoomActivityActive()) {
// // RoomActivity可用, 直接回到该Activity
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT).withString("form", "首页").withString("roomId", roomId).navigation();
//
// } else {
// RoomActivity不可用, 重新创建
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("form", "首页").withString("roomId", roomId).navigation();
// }
}
// String roomId = CommonAppContext.getInstance().playId;
// if (!TextUtils.isEmpty(roomId)) {
//// RoomManager.instance( CommonAppContext.getInstance()).joinRoomWithRoomId(roomId, true);
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("form", "首页").withString("roomId", roomId).navigation();
// }
} else if ( id = = R . id . iv_shouchl ) { //首充
FirstChargeDialog firstChargeDialog = new FirstChargeDialog ( this ) ;
firstChargeDialog . show ( ) ;
@@ -428,7 +490,7 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
. load ( imageUrl )
. placeholder ( com . xscm . moduleutil . R . mipmap . tab_main_media_unselected ) // 默认图标
. into ( mBinding . imSy ) ;
} else {
} else {
// 如果没有网络图标,使用默认的选中/未选中状态
int resId = ( index = = 0 ) ?
com . xscm . moduleutil . R . mipmap . tab_main_media_selected :
@@ -452,15 +514,15 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
super . onResume ( ) ;
// 修改判断条件:不仅检查 isTaskRoot, 还要检查是否是从后台恢复
if ( shouldRestoreRoom( ) ) {
ARouter. getInstance( ) . build ( ARouteConstants. ROOM_DETAILS )
. withString( " form " , " 首页 " )
. withString( " roomId " , CommonAppContext. getInstance( ) . playId )
. withFlags( Intent. FLAG_ACTIVITY_CLEAR_TOP | Intent. FLAG_ACTIVITY_NEW_TASK )
. navigation( ) ;
// RoomManager.instance( CommonAppContext.getInstance()).joinRoomWithRoomId(CommonAppContext.getInstance().playId, true);
return ;
}
// if ( shouldRestoreRoom()) {
// ARouter. getInstance().build( ARouteConstants. ROOM_DETAILS)
// . withString("form", "首页" )
// . withString("roomId", CommonAppContext. getInstance(). playId)
// . withFlags( Intent. FLAG_ACTIVITY_CLEAR_TOP | Intent. FLAG_ACTIVITY_NEW_TASK)
// . navigation() ;
//// RoomManager.instance( CommonAppContext.getInstance()).joinRoomWithRoomId(CommonAppContext.getInstance().playId, true);
// return;
// }
MvpPre . loginIm ( ) ;
Logger . i ( " MainActivity " , " onResume " ) ;
@@ -478,23 +540,9 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
}
V2TIMManager . getConversationManager ( ) . getTotalUnreadMessageCount ( new V2TIMValueCallback < Long > ( ) {
@Override
public void onSuccess ( Long aLong ) {
if ( aLong = = 0 ) {
mBinding . tvMessage . setVisibility ( View . GONE ) ;
mBinding . tvMessage . setText ( " 0 " ) ;
} else {
mBinding . tvMessage . setVisibility ( View . VISIBLE ) ;
}
mBinding . tvMessage . setText ( String . valueOf ( aLong ) ) ;
}
@Override
public void onError ( int code , String desc ) {
}
} ) ;
MvpPre . getMyInfo ( SpUtil . getUserId ( ) + " " ) ; //获取首充是否需要展示
@@ -504,10 +552,22 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
@Subscribe ( threadMode = ThreadMode . MAIN )
public void onEvent ( UnreadCountEvent event ) {
if ( event . getALong ( ) = = 0 ) {
mBinding . tvMessage . s etVisibility ( View . GONE ) ;
mBinding . tvMessage . setText ( " 0 " ) ;
if ( event . g etBLong ( ) = = 0 ) {
mBinding . tvMessage . setVisibility ( View . GONE ) ;
} else {
mBinding . tvMessage . setVisibility ( View . VISIBLE ) ;
mBinding . tvMessage . setText ( String . valueOf ( event . getBLong ( ) ) ) ;
}
// mBinding.tvMessage.setVisibility(View.GONE);
// mBinding.tvMessage.setText("0");
} else if ( event . getALong ( ) > 0 ) {
mBinding . tvMessage . setText ( String . valueOf ( event . getALong ( ) ) ) ;
mBinding . tvMessage . setVisibility ( View . VISIBLE ) ;
if ( event . getBLong ( ) = = 0 ) {
mBinding . tvMessage . setText ( String . valueOf ( event . getALong ( ) ) ) ;
} else {
mBinding . tvMessage . setText ( String . valueOf ( event . getALong ( ) + event . getBLong ( ) ) ) ;
}
}
}
@@ -604,9 +664,9 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
@Override
public void getThemeData ( ThemeBean themeBean ) {
if ( themeBean ! = null ) {
selectedMediaUrl = themeBean . getHome_sel ( ) ;
unselectedMediaUrl = themeBean . getHome_nor ( ) ;
if ( themeBean ! = null ) {
selectedMediaUrl = themeBean . getHome_sel ( ) ;
unselectedMediaUrl = themeBean . getHome_nor ( ) ;
// 语圈 tab 图标
selectedTrendUrl = themeBean . getFind_sel ( ) ;
@@ -624,18 +684,18 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
if ( themeBean . getBtn_text_color ( ) ! = null & & ! themeBean . getBtn_text_color ( ) . isEmpty ( ) ) {
selectedTextColor = Color . parseColor ( themeBean . getBtn_text_color ( ) ) ;
}
unselectedTextColor = Color . parseColor ( " #000000 " ) ;
unselectedTextColor = Color . parseColor ( " #000000 " ) ;
} catch ( Exception e ) {
// 使用默认颜色
selectedTextColor = ColorManager . getInstance ( ) . getPrimaryColorInt ( ) ;
unselectedTextColor = Color . parseColor ( " #000000 " ) ;
unselectedTextColor = Color . parseColor ( " #000000 " ) ;
}
Map < String , String > colorMap = new HashMap < > ( ) ;
colorMap . put ( " theme_color " , themeBean . getTheme_color ( ) ) ;
colorMap . put ( " btn_text_color " , themeBean . getBtn_text_color ( ) ) ;
// 更新 UI
updateAllTabUI ( ) ;
if ( themeBean . getApp_bg ( ) ! = null ) {
if ( themeBean . getApp_bg ( ) ! = null ) {
BackgroundManager . getInstance ( ) . setBackgroundUrl ( themeBean . getApp_bg ( ) ) ;
loadNetworkBackground ( ) ;
}
@@ -643,6 +703,43 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
}
@Override
public void getRoomOnline ( RoomOnline onlineBean ) {
if ( onlineBean ! = null ) {
List < RoomOnlineBean > onlineBeans = onlineBean . getOff_pit ( ) ;
List < RoomOnlineBean > onlineList = onlineBean . getOn_pit ( ) ;
boolean isPlaying = false ;
if ( onlineBeans ! = null ) {
for ( RoomOnlineBean onlineBean1 : onlineBeans ) {
if ( onlineBean1 . getUser_id ( ) = = SpUtil . getUserId ( ) ) {
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("form", "首页").withString("roomId", CommonAppContext.getInstance().playId).navigation();
isPlaying = true ;
break ;
}
}
}
if ( onlineList ! = null ) {
for ( RoomOnlineBean onlineBean1 : onlineList ) {
if ( onlineBean1 . getUser_id ( ) = = SpUtil . getUserId ( ) ) {
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("form", "首页").withString("roomId", CommonAppContext.getInstance().playId).navigation();
isPlaying = true ;
break ;
}
}
}
if ( ! isPlaying ) {
RoomManager . getInstance ( ) . fetchRoomDataAndEnter ( this , CommonAppContext . getInstance ( ) . playId , " " ) ;
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP).withString("form", "首页").withString("roomId", CommonAppContext.getInstance().playId).navigation();
} else {
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("form", "首页").withString("roomId", CommonAppContext.getInstance().playId).navigation();
RoomManager . getInstance ( ) . fetchRoomDataAndEnter ( this , CommonAppContext . getInstance ( ) . playId , " " ) ;
}
}
}
private void updateAllTabUI ( ) {
index = 0 ;
// 更新图标
@@ -734,7 +831,6 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
}
// @Override
// protected void onPause() {
// super.onPause();