添加了动态修改背景图和首页按钮

修改了飘屏功能
This commit is contained in:
2025-08-13 17:31:52 +08:00
parent bd4e7912f1
commit 96e3c86cd4
38 changed files with 1507 additions and 165 deletions

View File

@@ -5,6 +5,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@@ -28,6 +29,7 @@ import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.FragmentUtils;
import com.blankj.utilcode.util.ServiceUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.example.modulecircle.fragment.CircleFragment;
import com.example.modulenews.fragment.NewsFragment;
import com.example.moduleroom.activity.RoomActivity;
@@ -43,12 +45,14 @@ import com.qxcm.moduleutil.base.CommonAppContext;
import com.qxcm.moduleutil.bean.AppUpdateModel;
import com.qxcm.moduleutil.bean.FirstChargeBean;
import com.qxcm.moduleutil.bean.FirstChargeGiftBean;
import com.qxcm.moduleutil.bean.ThemeBean;
import com.qxcm.moduleutil.dialog.FirstChargeDialog;
import com.qxcm.moduleutil.dialog.HeavenGiftDialog;
import com.qxcm.moduleutil.dialog.RechargeDialogFragment;
import com.qxcm.moduleutil.event.RoomOutEvent;
import com.qxcm.moduleutil.event.UnreadCountEvent;
import com.qxcm.moduleutil.utils.ARouteConstants;
import com.qxcm.moduleutil.utils.BackgroundManager;
import com.qxcm.moduleutil.utils.ImageLoader;
import com.qxcm.moduleutil.utils.SpUtil;
import com.qxcm.moduleutil.utils.logger.Logger;
@@ -60,10 +64,12 @@ import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.HashMap;
import java.util.Map;
@Route(path = ARouteConstants.ME)
public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBinding> implements HomeContacts.View, View.OnClickListener {
private static int index = -1;
// private AppUpdateDialog appUpdateDialog;
public static boolean isShortsShowing() {
return index == 1;
@@ -74,6 +80,22 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
private Fragment[] fragments;
private AppUpdateDialog appUpdateDialog;
private boolean isMediaSelected = false;
private String unselectedMediaUrl = ""; // 从服务器获取
private String selectedMediaUrl = ""; // 从服务器获取
// 添加其他 tab 的图标 URL
private String unselectedTrendUrl = "";
private String selectedTrendUrl = "";
private String unselectedNewsUrl = "";
private String selectedNewsUrl = "";
private String unselectedMeUrl = "";
private String selectedMeUrl = "";
// 添加文字颜色变量
private int selectedTextColor = 0; // 选中文字颜色 (从服务器获取)
private int unselectedTextColor = 0; // 未选中文字颜色 (从服务器获取)
@Override
protected int getLayoutId() {
return R.layout.activity_main;
@@ -88,6 +110,8 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
}
@Override
protected void initData() {
MvpPre.getThemeData();
fragments = new Fragment[]{
VoiceFragment.newInstance(), // 声播
CircleFragment.newInstance(), // 语圈
@@ -98,29 +122,6 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
MvpPre.initData();
MvpPre.userFiles();
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// if (!Settings.canDrawOverlays(this)) {
// Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
// Uri.parse("package:" + getPackageName()));
// startActivityForResult(intent, 100);
// }
// } else {
// // 对于低于 Android 6.0 的设备,无需请求悬浮窗权限
// // 可在此处添加针对旧版本的处理逻辑(如果需要)
// }
// 每11秒执行一次飘屏消息
// new android.os.Handler().postDelayed(new Runnable() {
// @Override
// public void run() {
// 通过递归调用实现循环定时
// new android.os.Handler().postDelayed(this, 1000);
// }
// }, 1000);
//
}
@Override
@@ -175,6 +176,9 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
reset();
mBinding.rlMedia.setSelected(true);
FragmentUtils.showHide(0, fragments);
index = 0;
isMediaSelected = true; // 确保设置为选中状态
updateAllTabUI(); // 这会同时更新图标和文字颜色
}
@Override
@@ -275,6 +279,7 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
// mBinding.rlParty.setSelected(false);
mBinding.rlNews.setSelected(false);
mBinding.rlMe.setSelected(false);
}
private void selectShow(int postion) {
@@ -292,28 +297,45 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
switch (postion) {
case 0:
mBinding.rlMedia.setSelected(true);
// mBinding.llBottomBar.setBackgroundResource(R.drawable.icon_bbar_bg);
isMediaSelected = true;
break;
case 1:
mBinding.rlTrend.setSelected(true);
// mBinding.llBottomBar.setBackgroundResource(R.drawable.icon_bbar_bg);
break;
case 2:
mBinding.rlNews.setSelected(true);
// mBinding.llBottomBar.setBackgroundResource(R.drawable.icon_bbar_bg);
break;
case 3:
mBinding.rlMe.setSelected(true);
// mBinding.llBottomBar.setBackgroundResource(R.drawable.icon_bbar_bg);
break;
}
// 更新所有图标状态
updateMediaIcon();
updateTrendIcon();
updateNewsIcon();
updateMeIcon();
// 更新文字颜色
updateTabTextColors();
FragmentUtils.showHide(postion, fragments);
}
private void updateMediaIcon() {
String imageUrl = (index == 0) ? selectedMediaUrl : unselectedMediaUrl;
if (!TextUtils.isEmpty(imageUrl)) {
Glide.with(this)
.load(imageUrl)
.placeholder(com.qxcm.moduleutil.R.mipmap.tab_main_media_unselected) // 默认图标
.into(mBinding.imSy);
}else {
// 如果没有网络图标,使用默认的选中/未选中状态
int resId = (index == 0) ?
com.qxcm.moduleutil.R.mipmap.tab_main_media_selected :
com.qxcm.moduleutil.R.mipmap.tab_main_media_unselected;
mBinding.imTrend.setImageResource(resId);
}
}
@Override
protected void onResume() {
super.onResume();
@@ -457,6 +479,140 @@ public class MainActivity extends BaseMvpActivity<HomePresenter, ActivityMainBin
}
}
@Override
public void getThemeData(ThemeBean themeBean) {
if (themeBean != null){
selectedMediaUrl=themeBean.getHome_sel();
unselectedMediaUrl=themeBean.getHome_nor();
// 语圈 tab 图标
selectedTrendUrl = themeBean.getFind_sel();
unselectedTrendUrl = themeBean.getFind_nor();
// 消息 tab 图标
selectedNewsUrl = themeBean.getMsg_sel();
unselectedNewsUrl = themeBean.getMsg_nor();
// 我的 tab 图标
selectedMeUrl = themeBean.getMine_sel();
unselectedMeUrl = themeBean.getMine_nor();
// 获取文字颜色
try {
if (themeBean.getBtn_text_color() != null && !themeBean.getBtn_text_color().isEmpty()) {
selectedTextColor = Color.parseColor(themeBean.getBtn_text_color());
}
unselectedTextColor = Color.parseColor("#BFBFBF");
} catch (Exception e) {
// 使用默认颜色
selectedTextColor = Color.parseColor("#323232");
unselectedTextColor =Color.parseColor("#BFBFBF");
}
Map<String, String> colorMap = new HashMap<>();
colorMap.put("theme_color", themeBean.getTheme_color());
colorMap.put("btn_text_color", themeBean.getBtn_text_color());
updateThemeColors(colorMap);
// 更新 UI
updateAllTabUI();
if (themeBean.getApp_bg()!=null) {
BackgroundManager.getInstance().setBackgroundUrl(themeBean.getApp_bg());
loadNetworkBackground();
}
}
}
private void updateAllTabUI() {
index = 0;
// 更新图标
updateMediaIcon();
updateTrendIcon();
updateNewsIcon();
updateMeIcon();
// 更新文字
updateTabTextColors();
}
private void updateTrendIcon() {
String imageUrl = (index == 1) ? selectedTrendUrl : unselectedTrendUrl;
if (!TextUtils.isEmpty(imageUrl)) {
Glide.with(this)
.load(imageUrl)
.placeholder(com.qxcm.moduleutil.R.mipmap.icon_me_trend_unselect)
.into(mBinding.imTrend);
} else {
// 如果没有网络图标,使用默认的选中/未选中状态
int resId = (index == 1) ?
com.qxcm.moduleutil.R.mipmap.icon_me_trend_select :
com.qxcm.moduleutil.R.mipmap.icon_me_trend_unselect;
mBinding.imTrend.setImageResource(resId);
}
}
private void updateNewsIcon() {
String imageUrl = (index == 2) ? selectedNewsUrl : unselectedNewsUrl;
if (!TextUtils.isEmpty(imageUrl)) {
Glide.with(this)
.load(imageUrl)
.placeholder(com.qxcm.moduleutil.R.mipmap.icon_news_un_select)
.into(mBinding.ivNews);
} else {
// 如果没有网络图标,使用默认的选中/未选中状态
int resId = (index == 2) ?
com.qxcm.moduleutil.R.mipmap.icon_news_select :
com.qxcm.moduleutil.R.mipmap.icon_news_un_select;
mBinding.ivNews.setImageResource(resId);
}
}
private void updateMeIcon() {
String imageUrl = (index == 3) ? selectedMeUrl : unselectedMeUrl;
if (!TextUtils.isEmpty(imageUrl)) {
Glide.with(this)
.load(imageUrl)
.placeholder(com.qxcm.moduleutil.R.mipmap.icon_my_un_select)
.into(mBinding.imMe);
} else {
// 如果没有网络图标,使用默认的选中/未选中状态
int resId = (index == 3) ?
com.qxcm.moduleutil.R.mipmap.icon_my_select :
com.qxcm.moduleutil.R.mipmap.icon_my_un_select;
mBinding.imMe.setImageResource(resId);
}
}
private void updateTabTextColors() {
// 更新声播 tab 文字颜色
if (selectedTextColor != 0 && unselectedTextColor != 0) {
int mediaTextColor = (index == 0) ? selectedTextColor : unselectedTextColor;
mBinding.tvMedia.setTextColor(mediaTextColor);
}
// 更新语圈 tab 文字颜色
if (selectedTextColor != 0 && unselectedTextColor != 0) {
int trendTextColor = (index == 1) ? selectedTextColor : unselectedTextColor;
mBinding.tvTrend.setTextColor(trendTextColor);
}
// 更新消息 tab 文字颜色
if (selectedTextColor != 0 && unselectedTextColor != 0) {
int newsTextColor = (index == 2) ? selectedTextColor : unselectedTextColor;
mBinding.tvNews.setTextColor(newsTextColor);
}
// 更新我的 tab 文字颜色
if (selectedTextColor != 0 && unselectedTextColor != 0) {
int meTextColor = (index == 3) ? selectedTextColor : unselectedTextColor;
mBinding.tvMe.setTextColor(meTextColor);
}
}
// @Override
// protected void onPause() {
// super.onPause();

View File

@@ -6,6 +6,7 @@ import com.qxcm.moduleutil.activity.IPresenter;
import com.qxcm.moduleutil.activity.IView;
import com.qxcm.moduleutil.bean.AppUpdateModel;
import com.qxcm.moduleutil.bean.FirstChargeBean;
import com.qxcm.moduleutil.bean.ThemeBean;
public final class HomeContacts {
@@ -24,6 +25,8 @@ public final class HomeContacts {
void quitSuccess(String roomId);
void myInfoSuccess(FirstChargeBean data);
void getThemeData(ThemeBean themeBean);
}
public interface IHomePre extends IPresenter {
@@ -46,5 +49,8 @@ public final class HomeContacts {
void address_ip(String ip);
void getMyInfo(String userId);
void getThemeData();//主题接口
}
}

View File

@@ -17,6 +17,7 @@ import com.blankj.utilcode.util.ThreadUtils;
import com.qxcm.modulemain.contacts.HomeContacts;
import com.qxcm.moduleutil.bean.AppUpdateModel;
import com.qxcm.moduleutil.bean.FirstChargeBean;
import com.qxcm.moduleutil.bean.ThemeBean;
import com.qxcm.moduleutil.bean.UserBean;
import com.qxcm.moduleutil.http.BaseObserver;
import com.qxcm.moduleutil.presenter.BasePresenter;
@@ -360,4 +361,20 @@ public class HomePresenter extends BasePresenter<HomeContacts.View> implements H
}
});
}
@Override
public void getThemeData() {
api.getThemeData(new BaseObserver<ThemeBean>() {
@Override
public void onSubscribe(Disposable d) {
addDisposable(d);
}
@Override
public void onNext(ThemeBean themeBean) {
MvpRef.get().getThemeData(themeBean);
}
});
}
}

View File

@@ -45,6 +45,7 @@
android:orientation="vertical">
<ImageView
android:id="@+id/im_sy"
android:layout_width="@dimen/dp_24"
android:layout_height="@dimen/dp_24"
android:gravity="center_horizontal"
@@ -52,6 +53,7 @@
android:src="@drawable/main_bottom_bar_icon_media" />
<TextView
android:id="@+id/tv_media"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_2"
@@ -71,6 +73,7 @@
android:orientation="vertical">
<ImageView
android:id="@+id/im_trend"
android:layout_width="@dimen/dp_24"
android:layout_height="@dimen/dp_24"
android:gravity="center_horizontal"
@@ -78,6 +81,7 @@
android:src="@drawable/main_bottom_bar_icon_tend" />
<TextView
android:id="@+id/tv_trend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_2"
@@ -134,6 +138,7 @@
</RelativeLayout>
<TextView
android:id="@+id/tv_news"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/iv_news"
@@ -155,6 +160,7 @@
android:orientation="vertical">
<ImageView
android:id="@+id/im_me"
android:layout_width="@dimen/dp_24"
android:layout_height="@dimen/dp_24"
android:layout_centerInParent="true"
@@ -163,6 +169,7 @@
android:src="@drawable/main_bottom_bar_icon_me" />
<TextView
android:id="@+id/tv_me"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_2"