diff --git a/app/src/main/java/com/gh/common/util/DisplayUtils.java b/app/src/main/java/com/gh/common/util/DisplayUtils.java index 972aebdd2b..e1526ac77a 100644 --- a/app/src/main/java/com/gh/common/util/DisplayUtils.java +++ b/app/src/main/java/com/gh/common/util/DisplayUtils.java @@ -18,13 +18,16 @@ import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; +import androidx.annotation.ColorInt; +import androidx.annotation.ColorRes; +import androidx.core.content.ContextCompat; +import androidx.core.graphics.ColorUtils; + import com.halo.assistant.HaloApp; import java.lang.reflect.Field; import java.lang.reflect.Method; -import androidx.core.content.ContextCompat; - public class DisplayUtils { /** @@ -223,6 +226,27 @@ public class DisplayUtils { } } + public static void setStatusBarColor(Activity activity, @ColorRes int colorRes) { + Window window = activity.getWindow(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + int colorInt = ContextCompat.getColor(activity, colorRes); + // 设置状态栏底色颜色 + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + window.setStatusBarColor(colorInt); + // 如果亮色,设置状态栏文字为黑色 + if (isLightColor(colorInt)) { + window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); + } else { + window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); + } + } + } + + private static boolean isLightColor(@ColorInt int color) { + return ColorUtils.calculateLuminance(color) >= 0.5; + } + private static boolean isMiuiOs() { String property = getSystemProperty("ro.miui.ui.version.name", ""); diff --git a/app/src/main/java/com/gh/gamecenter/LibaoDetailActivity.java b/app/src/main/java/com/gh/gamecenter/LibaoDetailActivity.java index 38ccb91942..a285e3696d 100644 --- a/app/src/main/java/com/gh/gamecenter/LibaoDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/LibaoDetailActivity.java @@ -1,5 +1,7 @@ package com.gh.gamecenter; +import static com.gh.gamecenter.personal.PersonalFragment.LOGIN_TAG; + import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -12,6 +14,7 @@ import android.widget.RelativeLayout; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -24,6 +27,7 @@ import com.gh.common.util.ApkActiveUtils; import com.gh.common.util.CheckLoginUtils; import com.gh.common.util.DetailDownloadUtils; import com.gh.common.util.DeviceTokenUtils; +import com.gh.common.util.DisplayUtils; import com.gh.common.util.EntranceUtils; import com.gh.common.util.ExtensionsKt; import com.gh.common.util.LibaoUtils; @@ -63,8 +67,6 @@ import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; import retrofit2.HttpException; -import static com.gh.gamecenter.personal.PersonalFragment.LOGIN_TAG; - /** * Created by khy on 2016/12/13. */ @@ -196,7 +198,7 @@ public class LibaoDetailActivity extends ToolBarActivity implements LibaoDetailA if (mLibaoEntity != null) { mLibaoEntity.setClickReceiveBtnIn(isClickReceiveBtnIn); } - + DisplayUtils.setStatusBarColor(this, mNightMode ? android.R.color.black : R.color.white); mIsScroll = true; mSkeleton = Skeleton.bind(mListSkeleton).shimmer(false).load(R.layout.activity_libaodetail_skeleton).show(); @@ -207,7 +209,7 @@ public class LibaoDetailActivity extends ToolBarActivity implements LibaoDetailA return mIsScroll; } }); - mLibaoDetailRv.addItemDecoration(new VerticalItemDecoration(this, 8, false)); + mLibaoDetailRv.addItemDecoration(getItemDecoration()); mLibaoDetailRv.setAdapter(mAdapter); mNoConnection.setOnClickListener(v -> { @@ -235,6 +237,10 @@ public class LibaoDetailActivity extends ToolBarActivity implements LibaoDetailA } + private RecyclerView.ItemDecoration getItemDecoration() { + return new VerticalItemDecoration(this, 8, false); + } + @Override protected void onPause() { super.onPause(); @@ -549,4 +555,18 @@ public class LibaoDetailActivity extends ToolBarActivity implements LibaoDetailA getLibaoDigest(mLibaoEntity.getId()); } } + + @Override + protected void onNightModeChange() { + super.onNightModeChange(); + ExtensionsKt.setRootBackgroundColor(mContentView, R.color.background); + mDetailBottom.setBackgroundColor(ContextCompat.getColor(this, R.color.background)); + mLibaoDetailRv.getRecycledViewPool().clear(); + mAdapter.notifyItemRangeChanged(0, mAdapter.getItemCount()); + if (mLibaoDetailRv.getItemDecorationCount() > 0) { + mLibaoDetailRv.removeItemDecorationAt(0); + mLibaoDetailRv.addItemDecoration(getItemDecoration()); + } + DisplayUtils.setStatusBarColor(this, mNightMode ? android.R.color.black : R.color.white); + } } diff --git a/app/src/main/java/com/gh/gamecenter/adapter/LiBaoCodeAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/LiBaoCodeAdapter.java index 08464addb4..12ba1d26b5 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/LiBaoCodeAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/LiBaoCodeAdapter.java @@ -4,6 +4,8 @@ import android.content.Context; import android.text.Html; import android.view.ViewGroup; +import androidx.core.content.ContextCompat; + import com.gh.common.util.LibaoUtils; import com.gh.gamecenter.R; import com.gh.gamecenter.adapter.viewholder.LiBaoCodeViewHolder; @@ -35,6 +37,7 @@ public class LiBaoCodeAdapter extends BaseRecyclerAdapter { @Override public void onBindViewHolder(LiBaoCodeViewHolder holder, int position) { final UserDataLibaoEntity userDataLibaoEntity = mUserDataLibaoList.get(position); + holder.binding.libaoCodeTv.setTextColor(ContextCompat.getColor(mContext,R.color.text_subtitle)); if ("ling".equals(userDataLibaoEntity.getType()) || "linged".equals(userDataLibaoEntity.getType())) { StringBuilder content = new StringBuilder(); if (mUserDataLibaoList.size() > 1) { diff --git a/app/src/main/java/com/gh/gamecenter/adapter/LibaoDetailAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/LibaoDetailAdapter.java index ac20201b99..6c2a2f7af6 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/LibaoDetailAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/LibaoDetailAdapter.java @@ -193,6 +193,7 @@ public class LibaoDetailAdapter extends BaseRecyclerAdapter { } }); + ExtensionsKt.setRootBackgroundColor( holder.binding.getRoot(),R.color.background_white); if (mLibaoEntity.getGame() != null) { holder.binding.libaodetailGameIcon.displayGameIcon(mLibaoEntity.getGame().getIcon(), mLibaoEntity.getGame().getIconSubscript()); } else { diff --git a/app/src/main/java/com/gh/gamecenter/libao/Libao1Fragment.java b/app/src/main/java/com/gh/gamecenter/libao/Libao1Fragment.java index 699111887c..e67303da95 100644 --- a/app/src/main/java/com/gh/gamecenter/libao/Libao1Fragment.java +++ b/app/src/main/java/com/gh/gamecenter/libao/Libao1Fragment.java @@ -7,11 +7,13 @@ import android.view.View; import android.view.inputmethod.EditorInfo; import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentTransaction; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.gh.base.fragment.BaseFragment; +import com.gh.common.util.ExtensionsKt; import com.gh.common.util.MtaHelper; import com.gh.common.util.TextHelper; import com.gh.gamecenter.R; @@ -178,4 +180,13 @@ public class Libao1Fragment extends BaseFragment implements SwipeRefreshLayout.O } } + @Override + protected void onNightModeChange() { + super.onNightModeChange(); + ExtensionsKt.setRootBackgroundColor(mBinding.getRoot(),R.color.background_white); + ExtensionsKt.setRootBackgroundColor(mBinding.searchBar.getRoot(),R.color.background_white); + mBinding.searchBar.searchBackground.setBackground(ContextCompat.getDrawable(requireContext(),R.drawable.actionbar_search_bg)); + mBinding.searchBar.etSearch.setHintTextColor(ContextCompat.getColor(requireContext(),R.color.text_body)); + mBinding.searchBar.etSearch.setTextColor(ContextCompat.getColor(requireContext(),R.color.text_title)); + } } diff --git a/app/src/main/java/com/gh/gamecenter/libao/Libao2Fragment.java b/app/src/main/java/com/gh/gamecenter/libao/Libao2Fragment.java index 08fa96106c..19bb0a4787 100644 --- a/app/src/main/java/com/gh/gamecenter/libao/Libao2Fragment.java +++ b/app/src/main/java/com/gh/gamecenter/libao/Libao2Fragment.java @@ -15,6 +15,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.gh.base.fragment.BaseFragment; import com.gh.common.util.CheckLoginUtils; +import com.gh.common.util.ExtensionsKt; import com.gh.common.view.CustomDividerItemDecoration; import com.gh.gamecenter.ConcernActivity; import com.gh.gamecenter.LibaoDetailActivity; @@ -71,10 +72,7 @@ public class Libao2Fragment extends BaseFragment implements SwipeRefreshLayout.O mLayoutManager = new LinearLayoutManager(getActivity()); mBinding.libao2RvList.setLayoutManager(mLayoutManager); adapter = new Libao2FragmentAdapter(getContext(), this, this, mEntrance); - Drawable insetDivider = ContextCompat.getDrawable(requireContext(), R.drawable.divider_item_line_space_16); - CustomDividerItemDecoration itemDecoration = new CustomDividerItemDecoration(requireContext(), false, false, true, false); - itemDecoration.setDrawable(insetDivider); - mBinding.libao2RvList.addItemDecoration(itemDecoration); + mBinding.libao2RvList.addItemDecoration(getItemDecoration()); mBinding.libao2RvList.setAdapter(adapter); mBinding.libao2RvList.addOnScrollListener(new RecyclerView.OnScrollListener() { @@ -98,6 +96,13 @@ public class Libao2Fragment extends BaseFragment implements SwipeRefreshLayout.O } + private RecyclerView.ItemDecoration getItemDecoration() { + Drawable insetDivider = ContextCompat.getDrawable(requireContext(), R.drawable.divider_item_line_space_16); + CustomDividerItemDecoration itemDecoration = new CustomDividerItemDecoration(requireContext(), false, false, true, false); + itemDecoration.setDrawable(insetDivider); + return itemDecoration; + } + @Override public void loadDone() { // 数据加载成功回调 mBinding.libao2SrlRefresh.setRefreshing(false); @@ -215,4 +220,16 @@ public class Libao2Fragment extends BaseFragment implements SwipeRefreshLayout.O postRunnable(runnable); } } + + @Override + protected void onNightModeChange() { + super.onNightModeChange(); + ExtensionsKt.setRootBackgroundColor(mBinding.getRoot(), R.color.background_white); + mBinding.libao2RvList.getRecycledViewPool().clear(); + adapter.notifyItemRangeChanged(0, adapter.getItemCount()); + if (mBinding.libao2RvList.getItemDecorationCount() > 0) { + mBinding.libao2RvList.removeItemDecorationAt(0); + mBinding.libao2RvList.addItemDecoration(getItemDecoration()); + } + } } diff --git a/app/src/main/java/com/gh/gamecenter/libao/Libao2FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/libao/Libao2FragmentAdapter.java index 35cfd8e759..775cf12649 100644 --- a/app/src/main/java/com/gh/gamecenter/libao/Libao2FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/libao/Libao2FragmentAdapter.java @@ -15,6 +15,7 @@ import androidx.recyclerview.widget.RecyclerView.ViewHolder; import com.gh.base.OnListClickListener; import com.gh.base.OnRequestCallBackListener; import com.gh.common.constant.ItemViewType; +import com.gh.common.util.ExtensionsKt; import com.gh.common.util.LibaoUtils; import com.gh.common.util.PlatformUtils; import com.gh.gamecenter.R; @@ -24,7 +25,6 @@ import com.gh.gamecenter.databinding.LibaoItemBinding; import com.gh.gamecenter.entity.LibaoEntity; import com.gh.gamecenter.entity.LibaoStatusEntity; import com.gh.gamecenter.manager.UserManager; -import com.gh.gamecenter.newsdetail.NewsDetailCommentViewHolder; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; import com.lightgame.adapter.BaseRecyclerAdapter; @@ -203,6 +203,7 @@ class Libao2FragmentAdapter extends BaseRecyclerAdapter { private void initLibaoViewHolder(final LibaoNormalViewHolder holder, final int position) { LibaoEntity libaoEntity = mLibaoList.get(position); holder.setClickData(libaoEntity); + ExtensionsKt.setRootBackgroundColor(holder.binding.getRoot(),R.color.background_white); holder.binding.libaoName.setText(libaoEntity.getName()); holder.binding.libaoGameIcon.displayGameIcon(libaoEntity.getIcon(), libaoEntity.getIconSubscript()); if (TextUtils.isEmpty(libaoEntity.getPlatform())) { diff --git a/app/src/main/java/com/gh/gamecenter/libao/Libao3Fragment.java b/app/src/main/java/com/gh/gamecenter/libao/Libao3Fragment.java index 33ec9759e0..e8d26c3426 100644 --- a/app/src/main/java/com/gh/gamecenter/libao/Libao3Fragment.java +++ b/app/src/main/java/com/gh/gamecenter/libao/Libao3Fragment.java @@ -14,6 +14,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.gh.base.fragment.BaseFragment; import com.gh.common.util.CheckLoginUtils; +import com.gh.common.util.ExtensionsKt; import com.gh.common.view.CustomDividerItemDecoration; import com.gh.gamecenter.R; import com.gh.gamecenter.databinding.FragmentLibao3Binding; @@ -62,10 +63,7 @@ public class Libao3Fragment extends BaseFragment implements SwipeRefreshLayout.O mLayoutManager = new LinearLayoutManager(getActivity()); mBinding.libao3RvList.setLayoutManager(mLayoutManager); adapter = new Libao3FragmentAdapter(getActivity(), this, mFilter, mEntrance); - Drawable insetDivider = ContextCompat.getDrawable(requireContext(), R.drawable.divider_item_line_space_16); - CustomDividerItemDecoration itemDecoration = new CustomDividerItemDecoration(requireContext(), false, false, true, false); - itemDecoration.setDrawable(insetDivider); - mBinding.libao3RvList.addItemDecoration(itemDecoration); + mBinding.libao3RvList.addItemDecoration(getItemDecoration()); mBinding.libao3RvList.setAdapter(adapter); mBinding.libao3RvList.addOnScrollListener(new RecyclerView.OnScrollListener() { @@ -89,6 +87,13 @@ public class Libao3Fragment extends BaseFragment implements SwipeRefreshLayout.O }); } + private RecyclerView.ItemDecoration getItemDecoration() { + Drawable insetDivider = ContextCompat.getDrawable(requireContext(), R.drawable.divider_item_line_space_16); + CustomDividerItemDecoration itemDecoration = new CustomDividerItemDecoration(requireContext(), false, false, true, false); + itemDecoration.setDrawable(insetDivider); + return itemDecoration; + } + @Override public void loadDone() { // 数据加载成功回调 mBinding.libao3SrlRefresh.setRefreshing(false); @@ -170,4 +175,21 @@ public class Libao3Fragment extends BaseFragment implements SwipeRefreshLayout.O postRunnable(runnable); } } + + @Override + protected void onNightModeChange() { + super.onNightModeChange(); + ExtensionsKt.setRootBackgroundColor(mBinding.getRoot(), R.color.background_white); + mBinding.radiogroup.setBackgroundColor(ContextCompat.getColor(requireContext(),R.color.background_white)); + mBinding.receivedRb.setBackground(ContextCompat.getDrawable(requireContext(),R.drawable.bg_button_round_selector)); + mBinding.receivedRb.setTextColor(ContextCompat.getColorStateList(requireContext(),R.color.libao_rg_button_selector)); + mBinding.expiredRb.setBackground(ContextCompat.getDrawable(requireContext(),R.drawable.bg_button_round_selector)); + mBinding.expiredRb.setTextColor(ContextCompat.getColorStateList(requireContext(),R.color.libao_rg_button_selector)); + mBinding.libao3RvList.getRecycledViewPool().clear(); + adapter.notifyItemRangeChanged(0, adapter.getItemCount()); + if (mBinding.libao3RvList.getItemDecorationCount() > 0) { + mBinding.libao3RvList.removeItemDecorationAt(0); + mBinding.libao3RvList.addItemDecoration(getItemDecoration()); + } + } } diff --git a/app/src/main/java/com/gh/gamecenter/libao/Libao3FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/libao/Libao3FragmentAdapter.java index b11adfbdc4..726489459d 100644 --- a/app/src/main/java/com/gh/gamecenter/libao/Libao3FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/libao/Libao3FragmentAdapter.java @@ -4,7 +4,6 @@ import android.content.Context; import android.text.Html; import android.text.Spanned; import android.text.TextUtils; -import android.util.Pair; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -16,7 +15,6 @@ import androidx.recyclerview.widget.RecyclerView; import com.gh.base.OnRequestCallBackListener; import com.gh.common.util.DialogHelper; -import com.gh.common.util.DialogUtils; import com.gh.common.util.ExtensionsKt; import com.gh.common.util.LibaoUtils; import com.gh.common.util.PlatformUtils; @@ -203,6 +201,7 @@ class Libao3FragmentAdapter extends BaseRecyclerAdapter if (viewHolder instanceof LibaoNormalViewHolder) { LibaoNormalViewHolder holder = (LibaoNormalViewHolder) viewHolder; final LibaoEntity libaoEntity = mLibaoList.get(position); + ExtensionsKt.setRootBackgroundColor(holder.binding.getRoot(), R.color.background_white); holder.binding.libaoName.setText(libaoEntity.getName()); holder.binding.libaoGameIcon.displayGameIcon(libaoEntity.getIcon(), libaoEntity.getIconSubscript()); if (mFilter.equals("expires:false") && libaoEntity.getExpires() > 0) { diff --git a/app/src/main/java/com/gh/gamecenter/libao/LibaoFragment.java b/app/src/main/java/com/gh/gamecenter/libao/LibaoFragment.java index 558b3d4232..8105f410e1 100644 --- a/app/src/main/java/com/gh/gamecenter/libao/LibaoFragment.java +++ b/app/src/main/java/com/gh/gamecenter/libao/LibaoFragment.java @@ -8,6 +8,7 @@ import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.WindowManager; +import android.widget.CheckedTextView; import android.widget.TextView; import androidx.annotation.NonNull; @@ -16,12 +17,14 @@ import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import com.gh.base.fragment.BaseFragment_TabLayout; +import com.gh.common.util.DisplayUtils; import com.gh.common.util.MtaHelper; import com.gh.gamecenter.ConcernActivity; import com.gh.gamecenter.R; import com.gh.gamecenter.databinding.FragmentLibaoWrapperBinding; import com.gh.gamecenter.eventbus.EBReuse; import com.gh.gamecenter.eventbus.EBUISwitch; +import com.google.android.material.tabs.TabLayout; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -83,6 +86,7 @@ public class LibaoFragment extends BaseFragment_TabLayout { @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); + DisplayUtils.setStatusBarColor(requireActivity(), mNightMode ? R.color.black : R.color.white); setNavigationTitle(R.string.title_libao); initMenu(R.menu.menu_manage); mManageMenu = getItemMenu(R.id.layout_menu_manage); @@ -142,4 +146,21 @@ public class LibaoFragment extends BaseFragment_TabLayout { public void onTouchEvent(MotionEvent event) { if (mLibao1Fragment != null) mLibao1Fragment.onTouchEvent(event); } + + @Override + protected void onNightModeChange() { + super.onNightModeChange(); + mBinding.fragmentTabRl.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.background_white)); + mBinding.divider.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.divider)); + DisplayUtils.setStatusBarColor(requireActivity(), mNightMode ? R.color.black : R.color.white); + for (int i = 0; i < mTabLayout.getTabCount(); i++) { + TabLayout.Tab tab = mTabLayout.getTabAt(i); + if (tab == null) continue; + if (tab.getCustomView() == null) continue; + View tabTitle = tab.getCustomView().findViewById(R.id.tab_title); + if (tabTitle instanceof CheckedTextView) { + ((CheckedTextView) tabTitle).setTextColor(ContextCompat.getColorStateList(requireContext(), R.color.text_tabbar_style)); + } + } + } } diff --git a/app/src/main/java/com/gh/gamecenter/libao/LibaoHistoryAdapter.java b/app/src/main/java/com/gh/gamecenter/libao/LibaoHistoryAdapter.java index e2fe4119e4..eb7661fb20 100644 --- a/app/src/main/java/com/gh/gamecenter/libao/LibaoHistoryAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/libao/LibaoHistoryAdapter.java @@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView.ViewHolder; import com.gh.base.OnRequestCallBackListener; import com.gh.common.constant.ItemViewType; import com.gh.common.util.DisplayUtils; +import com.gh.common.util.ExtensionsKt; import com.gh.common.util.LibaoUtils; import com.gh.common.util.UrlFilterUtils; import com.gh.gamecenter.R; @@ -140,7 +141,7 @@ public class LibaoHistoryAdapter extends BaseRecyclerAdapter { if (holder instanceof LibaoNormalViewHolder) { LibaoNormalViewHolder viewHolder = (LibaoNormalViewHolder) holder; LibaoEntity libaoEntity = mLibaoList.get(position); - + ExtensionsKt.setRootBackgroundColor(viewHolder.binding.getRoot(), R.color.background_white); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT , LinearLayout.LayoutParams.WRAP_CONTENT); if (position == 0 || position == getItemCount() - 1) { diff --git a/app/src/main/java/com/gh/gamecenter/libao/LibaoNewAdapter.kt b/app/src/main/java/com/gh/gamecenter/libao/LibaoNewAdapter.kt index 47e9692afa..d7086a5d67 100644 --- a/app/src/main/java/com/gh/gamecenter/libao/LibaoNewAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/libao/LibaoNewAdapter.kt @@ -7,9 +7,7 @@ import android.view.ViewGroup import com.gh.base.OnListClickListener import com.gh.base.OnRequestCallBackListener import com.gh.common.constant.ItemViewType -import com.gh.common.util.LibaoUtils -import com.gh.common.util.PlatformUtils -import com.gh.common.util.StringUtils +import com.gh.common.util.* import com.gh.gamecenter.R import com.gh.gamecenter.adapter.viewholder.FooterViewHolder import com.gh.gamecenter.adapter.viewholder.LibaoNormalViewHolder @@ -187,6 +185,7 @@ class LibaoNewAdapter( val libaoEntity = mLibaoList[position] holder.setClickData(libaoEntity) holder.binding.libaoName.text = libaoEntity.name + holder.binding.root.setRootBackgroundColor(R.color.background_white) if (TextUtils.isEmpty(libaoEntity.platform)) { holder.binding.libaoGameName.text = libaoEntity.game?.name } else { diff --git a/app/src/main/java/com/gh/gamecenter/libao/LibaoNewFragment.java b/app/src/main/java/com/gh/gamecenter/libao/LibaoNewFragment.java index 7a27a60c0a..7145c1f5c7 100644 --- a/app/src/main/java/com/gh/gamecenter/libao/LibaoNewFragment.java +++ b/app/src/main/java/com/gh/gamecenter/libao/LibaoNewFragment.java @@ -78,12 +78,8 @@ public class LibaoNewFragment extends BaseFragment implements SwipeRefreshLayout mLayoutManager = new LinearLayoutManager(getActivity()); mBinding.libao1RvList.setLayoutManager(mLayoutManager); mBinding.reuseNoConnection.getRoot().setOnClickListener(this); - mAdapter = new LibaoNewAdapter(getContext(), this, this, mEntrance); - Drawable insetDivider = ContextCompat.getDrawable(requireContext(), R.drawable.divider_item_line_space_16); - CustomDividerItemDecoration itemDecoration = new CustomDividerItemDecoration(requireContext(), false, false, true, false); - itemDecoration.setDrawable(insetDivider); - mBinding.libao1RvList.addItemDecoration(itemDecoration); + mBinding.libao1RvList.addItemDecoration(getItemDecoration()); mBinding.libao1RvList.setAdapter(mAdapter); mBinding.libao1RvList.addOnScrollListener(new RecyclerView.OnScrollListener() { @@ -168,10 +164,7 @@ public class LibaoNewFragment extends BaseFragment implements SwipeRefreshLayout mHistoryLm = new LinearLayoutManager(getActivity()); mBinding.libao1RvHistory.setLayoutManager(mHistoryLm); mBinding.libao1RvHistory.setAdapter(mHistoryAdapter); - Drawable historyInsetDivider = ContextCompat.getDrawable(requireContext(), R.drawable.divider_item_line_space_16); - CustomDividerItemDecoration historyItemDecoration = new CustomDividerItemDecoration(requireContext(), false, false, true, false); - historyItemDecoration.setDrawable(historyInsetDivider); - mBinding.libao1RvHistory.addItemDecoration(historyItemDecoration); + mBinding.libao1RvHistory.addItemDecoration(getItemDecoration()); mBinding.libao1RvHistory.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { @@ -192,6 +185,13 @@ public class LibaoNewFragment extends BaseFragment implements SwipeRefreshLayout } + private RecyclerView.ItemDecoration getItemDecoration() { + Drawable historyInsetDivider = ContextCompat.getDrawable(requireContext(), R.drawable.divider_item_line_space_16); + CustomDividerItemDecoration historyItemDecoration = new CustomDividerItemDecoration(requireContext(), false, false, true, false); + historyItemDecoration.setDrawable(historyInsetDivider); + return historyItemDecoration; + } + @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); @@ -270,4 +270,22 @@ public class LibaoNewFragment extends BaseFragment implements SwipeRefreshLayout Intent intent = LibaoDetailActivity.getIntent(getContext(), libaoEntity, view.getId() == R.id.libao_btn_status, mEntrance + "+(礼包中心:最新)"); startActivityForResult(intent, LIBAO_NEW_REQUEST); } + + @Override + protected void onNightModeChange() { + super.onNightModeChange(); + mBinding.libao1RvList.getRecycledViewPool().clear(); + mAdapter.notifyItemRangeChanged(0, mAdapter.getItemCount()); + if (mBinding.libao1RvList.getItemDecorationCount() > 0) { + mBinding.libao1RvList.removeItemDecorationAt(0); + mBinding.libao1RvList.addItemDecoration(getItemDecoration()); + } + + mBinding.libao1RvHistory.getRecycledViewPool().clear(); + mHistoryAdapter.notifyItemRangeChanged(0, mHistoryAdapter.getItemCount()); + if (mBinding.libao1RvHistory.getItemDecorationCount() > 0) { + mBinding.libao1RvHistory.removeItemDecorationAt(0); + mBinding.libao1RvHistory.addItemDecoration(getItemDecoration()); + } + } } diff --git a/app/src/main/java/com/gh/gamecenter/libao/LibaoSearchAdapter.kt b/app/src/main/java/com/gh/gamecenter/libao/LibaoSearchAdapter.kt index 7646f93a39..2d5ea7346b 100644 --- a/app/src/main/java/com/gh/gamecenter/libao/LibaoSearchAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/libao/LibaoSearchAdapter.kt @@ -6,10 +6,7 @@ import android.view.ViewGroup import com.gh.base.OnListClickListener import com.gh.base.OnRequestCallBackListener import com.gh.common.constant.ItemViewType -import com.gh.common.util.LibaoUtils -import com.gh.common.util.PlatformUtils -import com.gh.common.util.StringUtils -import com.gh.common.util.UrlFilterUtils +import com.gh.common.util.* import com.gh.gamecenter.R import com.gh.gamecenter.adapter.viewholder.FooterViewHolder import com.gh.gamecenter.adapter.viewholder.LibaoNormalViewHolder @@ -27,9 +24,11 @@ import java.util.* /** * Created by khy on 5/09/17. */ -class LibaoSearchAdapter(fragment: LibaoSearchFragment, - callBackListener: OnRequestCallBackListener, - entrance: String?) : BaseRecyclerAdapter(fragment.context) { +class LibaoSearchAdapter( + fragment: LibaoSearchFragment, + callBackListener: OnRequestCallBackListener, + entrance: String? +) : BaseRecyclerAdapter(fragment.context) { private val mFragment: LibaoSearchFragment = fragment private val mCallBackListener: OnRequestCallBackListener = callBackListener @@ -64,39 +63,39 @@ class LibaoSearchAdapter(fragment: LibaoSearchFragment, // 去掉重复数据 LibaoUtils.removeDuplicateData(mLibaoList, list) } - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(object : Response>() { - override fun onResponse(response: List?) { - mLibaoList.addAll(response!!) - notifyDataSetChanged() + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(object : Response>() { + override fun onResponse(response: List?) { + mLibaoList.addAll(response!!) + notifyDataSetChanged() - if (response.size < 20) { - isOver = true - mCallBackListener.loadDone("TAG") - } - - if (mLibaoList.size == 0) { - mCallBackListener.loadEmpty() - } else { - mCallBackListener.loadDone() - } - - if (response.isNotEmpty()) { - getLibaoStatus(response) - } - - mPage++ - isLoading = false - isNetworkError = false + if (response.size < 20) { + isOver = true + mCallBackListener.loadDone("TAG") } - override fun onFailure(e: HttpException?) { - mCallBackListener.loadError() - isNetworkError = true - isLoading = false + if (mLibaoList.size == 0) { + mCallBackListener.loadEmpty() + } else { + mCallBackListener.loadDone() } - }) + + if (response.isNotEmpty()) { + getLibaoStatus(response) + } + + mPage++ + isLoading = false + isNetworkError = false + } + + override fun onFailure(e: HttpException?) { + mCallBackListener.loadError() + isNetworkError = true + isLoading = false + } + }) } /** @@ -205,12 +204,15 @@ class LibaoSearchAdapter(fragment: LibaoSearchFragment, private fun initLibaoViewHolder(holder: LibaoNormalViewHolder, position: Int) { val libaoEntity = mLibaoList[position] holder.setClickData(libaoEntity) + holder.binding.root.setRootBackgroundColor(R.color.background_white) holder.binding.libaoName.text = libaoEntity.name if (TextUtils.isEmpty(libaoEntity.platform)) { holder.binding.libaoGameName.text = libaoEntity.game?.name } else { - holder.binding.libaoGameName.text = StringUtils.buildString(libaoEntity.game?.name, " - ", PlatformUtils.getInstance(mContext) - .getPlatformName(libaoEntity.platform)) + holder.binding.libaoGameName.text = StringUtils.buildString( + libaoEntity.game?.name, " - ", PlatformUtils.getInstance(mContext) + .getPlatformName(libaoEntity.platform) + ) } holder.binding.libaoGameIcon.displayGameIcon(libaoEntity.getIcon(), libaoEntity.getIconSubscript()) @@ -223,9 +225,10 @@ class LibaoSearchAdapter(fragment: LibaoSearchFragment, holder.binding.libaoDes.text = content if (libaoEntity.status != null) { - LibaoUtils.initLibaoBtn(mContext, holder.binding.libaoBtnStatus, libaoEntity, false, null,false, + LibaoUtils.initLibaoBtn( + mContext, holder.binding.libaoBtnStatus, libaoEntity, false, null, false, "$mEntrance+(礼包中心:最新)" - ){ + ) { notifyItemChanged(position) } if (!libaoEntity.packageName.isNullOrEmpty()) { diff --git a/app/src/main/java/com/gh/gamecenter/libao/LibaoSearchFragment.java b/app/src/main/java/com/gh/gamecenter/libao/LibaoSearchFragment.java index 186bb76451..99374c65ee 100644 --- a/app/src/main/java/com/gh/gamecenter/libao/LibaoSearchFragment.java +++ b/app/src/main/java/com/gh/gamecenter/libao/LibaoSearchFragment.java @@ -1,5 +1,7 @@ package com.gh.gamecenter.libao; +import static com.gh.gamecenter.libao.Libao1Fragment.OPEN_LIBAO_APPBAR; + import android.content.Intent; import android.graphics.drawable.Drawable; import android.view.View; @@ -11,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.gh.base.fragment.BaseFragment; +import com.gh.common.util.ExtensionsKt; import com.gh.common.view.CustomDividerItemDecoration; import com.gh.gamecenter.LibaoDetailActivity; import com.gh.gamecenter.R; @@ -20,8 +23,6 @@ import com.gh.gamecenter.eventbus.EBReuse; import org.greenrobot.eventbus.EventBus; -import static com.gh.gamecenter.libao.Libao1Fragment.OPEN_LIBAO_APPBAR; - /** * Created by khy on 5/09/17. */ @@ -67,10 +68,8 @@ public class LibaoSearchFragment extends BaseFragment implements SwipeRefreshLay mBinding.reuseNoConnection.getRoot().setOnClickListener(this); mAdapter = new LibaoSearchAdapter(this, this, mEntrance); - Drawable insetDivider = ContextCompat.getDrawable(requireContext(), R.drawable.divider_item_line_space_16); - CustomDividerItemDecoration itemDecoration = new CustomDividerItemDecoration(requireContext(), false, false, true, false); - itemDecoration.setDrawable(insetDivider); - mBinding.libaoSearchRvList.addItemDecoration(itemDecoration); + + mBinding.libaoSearchRvList.addItemDecoration(getItemDecoration()); mBinding.libaoSearchRvList.setAdapter(mAdapter); mBinding.libaoSearchRvList.addOnScrollListener(new RecyclerView.OnScrollListener() { @@ -96,6 +95,13 @@ public class LibaoSearchFragment extends BaseFragment implements SwipeRefreshLay } + private RecyclerView.ItemDecoration getItemDecoration() { + Drawable historyInsetDivider = ContextCompat.getDrawable(requireContext(), R.drawable.divider_item_line_space_16); + CustomDividerItemDecoration historyItemDecoration = new CustomDividerItemDecoration(requireContext(), false, false, true, false); + historyItemDecoration.setDrawable(historyInsetDivider); + return historyItemDecoration; + } + @Override public void loadDone() { // 数据加载成功回调 colseRefresh(); @@ -160,4 +166,16 @@ public class LibaoSearchFragment extends BaseFragment implements SwipeRefreshLay Intent intent = LibaoDetailActivity.getIntent(getContext(), libaoEntity, mEntrance + "+(礼包中心:最新)"); startActivityForResult(intent, LIBAO_SEARCH_REQUEST); } + + @Override + protected void onNightModeChange() { + super.onNightModeChange(); + ExtensionsKt.setRootBackgroundColor(mBinding.getRoot(), R.color.background); + mBinding.libaoSearchRvList.getRecycledViewPool().clear(); + mAdapter.notifyItemRangeChanged(0, mAdapter.getItemCount()); + if (mBinding.libaoSearchRvList.getItemDecorationCount() > 0) { + mBinding.libaoSearchRvList.removeItemDecorationAt(0); + mBinding.libaoSearchRvList.addItemDecoration(getItemDecoration()); + } + } } diff --git a/app/src/main/res/color/libao_rg_button_selector.xml b/app/src/main/res/color/libao_rg_button_selector.xml index e005e5da16..0dd3933b9b 100644 --- a/app/src/main/res/color/libao_rg_button_selector.xml +++ b/app/src/main/res/color/libao_rg_button_selector.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/app/src/main/res/drawable/divider_item_line_space_16.xml b/app/src/main/res/drawable/divider_item_line_space_16.xml index ca854ea6a0..f9e4138ef9 100644 --- a/app/src/main/res/drawable/divider_item_line_space_16.xml +++ b/app/src/main/res/drawable/divider_item_line_space_16.xml @@ -3,7 +3,7 @@ - + diff --git a/app/src/main/res/layout/activity_libaodetail.xml b/app/src/main/res/layout/activity_libaodetail.xml index 8fd52781e5..0ae641c3be 100644 --- a/app/src/main/res/layout/activity_libaodetail.xml +++ b/app/src/main/res/layout/activity_libaodetail.xml @@ -2,7 +2,8 @@ + android:orientation = "vertical" + android:background="@color/background"> diff --git a/app/src/main/res/layout/activity_libaodetail_skeleton.xml b/app/src/main/res/layout/activity_libaodetail_skeleton.xml index dbf613440a..0f97e0bd66 100644 --- a/app/src/main/res/layout/activity_libaodetail_skeleton.xml +++ b/app/src/main/res/layout/activity_libaodetail_skeleton.xml @@ -2,13 +2,14 @@ + android:orientation = "vertical" + android:background="@color/background"> @@ -68,7 +69,7 @@ android:layout_width = "match_parent" android:layout_height = "wrap_content" android:layout_marginTop = "8dp" - android:background = "@color/white" + android:background = "@color/background_white" android:orientation = "vertical" android:paddingLeft = "18dp" android:paddingTop = "12dp" @@ -104,7 +105,7 @@ android:layout_width = "match_parent" android:layout_height = "wrap_content" android:layout_marginTop = "8dp" - android:background = "@color/white" + android:background = "@color/background_white" android:orientation = "vertical" android:paddingLeft = "18dp" android:paddingTop = "12dp" @@ -154,7 +155,7 @@ android:layout_width = "match_parent" android:layout_height = "wrap_content" android:layout_marginTop = "8dp" - android:background = "@color/white" + android:background = "@color/background_white" android:orientation = "vertical" android:paddingLeft = "18dp" android:paddingTop = "12dp" diff --git a/app/src/main/res/layout/fragment_libao1.xml b/app/src/main/res/layout/fragment_libao1.xml index 6a39dd5051..7366b7eae8 100644 --- a/app/src/main/res/layout/fragment_libao1.xml +++ b/app/src/main/res/layout/fragment_libao1.xml @@ -3,7 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="@color/white"> + android:background="@color/background_white"> + android:background="@color/background_white"> + android:background="@color/background_white"> + android:layout_height = "match_parent" + android:background="@color/background"> + android:background="@color/background_white"> @@ -78,7 +78,7 @@ android:layout_width="60dp" android:layout_height="28dp" android:gravity="center" - android:textColor="@color/white" + android:textColor="@color/text_white" android:textSize="12sp" />