日夜间模式的切换(视频、我的收藏部分) https://git.shanqu.cc/halo/android/assistant-android/-/issues/65

This commit is contained in:
张玉久
2022-05-10 10:47:15 +08:00
parent 029a12c481
commit 64ae5d02fb
18 changed files with 136 additions and 34 deletions

View File

@ -3,15 +3,33 @@ package com.gh.gamecenter;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.NonNull;
import com.gh.common.util.EntranceUtils;
import com.gh.common.util.ExtensionsKt;
import com.gh.gamecenter.collection.CollectionWrapperFragment;
/**
* Created by khy on 18/07/17.
*/
public class CollectionActivity extends NormalActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ExtensionsKt.updateStatusBarColor(this, R.color.black, R.color.white);
}
@Override
protected boolean isAutoResetViewBackgroundEnabled() {
return true;
}
@Override
protected void onNightModeChange() {
super.onNightModeChange();
ExtensionsKt.updateStatusBarColor(this, R.color.black, R.color.white);
}
@NonNull
public static Intent getCollectionActivity(Context context, String entrance) {

View File

@ -4,6 +4,11 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.RecyclerView;
import com.gh.common.util.CollectionUtils;
import com.gh.common.util.EntranceUtils;
import com.gh.common.view.CustomDividerItemDecoration;
@ -20,11 +25,6 @@ import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.jetbrains.annotations.NotNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.RecyclerView;
/**
* Created by khy on 22/12/17.
*/
@ -97,4 +97,13 @@ public class AnswerFragment extends ListFragment<AnswerEntity, AnswerViewModel>
itemDecoration.setDrawable(insetDivider);
return itemDecoration;
}
@Override
protected void onNightModeChange() {
super.onNightModeChange();
if (mListRv != null && mListRv.getItemDecorationCount() > 0) {
mListRv.removeItemDecorationAt(0);
mListRv.addItemDecoration(getItemDecoration());
}
}
}

View File

@ -4,6 +4,10 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import com.gh.common.util.CollectionUtils;
import com.gh.common.util.DataCollectionUtils;
import com.gh.common.util.DialogHelper;
@ -23,10 +27,6 @@ import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.jetbrains.annotations.NotNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
/**
* Created by khy on 18/07/17.
*/
@ -44,7 +44,7 @@ public class ArticleFragment extends ListFragment<NewsEntity, ArticleViewModel>
public void onCreate(@Nullable Bundle savedInstanceState) {
mType = getArguments().getString(EntranceUtils.KEY_TYPE, COLLECTION);
super.onCreate(savedInstanceState);
mCachedView.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.white));
mCachedView.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.background_white));
}
@Override
@ -121,4 +121,14 @@ public class ArticleFragment extends ListFragment<NewsEntity, ArticleViewModel>
itemDecoration.setDrawable(insetDivider);
return itemDecoration;
}
@Override
protected void onNightModeChange() {
super.onNightModeChange();
mCachedView.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.background_white));
if (mListRv != null && mListRv.getItemDecorationCount() > 0) {
mListRv.removeItemDecorationAt(0);
mListRv.addItemDecoration(getItemDecoration());
}
}
}

View File

@ -27,7 +27,7 @@ class CommunityArticleFragment : ListFragment<ArticleEntity, CommunityArticleVie
override fun onCreate(savedInstanceState: Bundle?) {
mType = arguments?.getString(EntranceUtils.KEY_TYPE, Type.COLLECTION.value) ?: Type.COLLECTION.value
super.onCreate(savedInstanceState)
mCachedView.setBackgroundColor(R.color.white.toColor())
mCachedView.setBackgroundColor(R.color.background_white.toColor(requireContext()))
}
override fun provideListAdapter(): CommunityArticleAdapter {
@ -74,13 +74,23 @@ class CommunityArticleFragment : ListFragment<ArticleEntity, CommunityArticleVie
}
override fun getItemDecoration(): RecyclerView.ItemDecoration {
val itemDecoration = CustomDividerItemDecoration(requireContext(),
val itemDecoration = CustomDividerItemDecoration(
requireContext(),
onlyDecorateTheFirstItem = false,
notDecorateTheFirstItem = false,
notDecorateTheLastItem = true,
notDecorateTheFirstTwoItems = false
)
itemDecoration.setDrawable(R.drawable.divider_item_line_space_16.toDrawable()!!)
itemDecoration.setDrawable(R.drawable.divider_item_line_space_16.toDrawable(requireContext())!!)
return itemDecoration
}
override fun onNightModeChange() {
super.onNightModeChange()
mCachedView.setBackgroundColor(R.color.background_white.toColor(requireContext()))
if ((mListRv?.itemDecorationCount ?: 0) > 0) {
mListRv?.removeItemDecorationAt(0)
mListRv?.addItemDecoration(itemDecoration)
}
}
}

View File

@ -1,11 +1,12 @@
package com.gh.gamecenter.collection;
import static com.gh.common.constant.Config.URL_ARTICLE;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
@ -30,8 +31,6 @@ import java.util.List;
import io.reactivex.Observable;
import static com.gh.common.constant.Config.URL_ARTICLE;
/**
* Created by khy on 18/07/17.
*/
@ -43,7 +42,7 @@ public class ToolsFragment extends ListFragment<ToolBoxEntity, NormalListViewMod
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mCachedView.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.white));
mCachedView.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.background_white));
}
@Override
@ -84,4 +83,14 @@ public class ToolsFragment extends ListFragment<ToolBoxEntity, NormalListViewMod
itemDecoration.setDrawable(insetDivider);
return itemDecoration;
}
@Override
protected void onNightModeChange() {
super.onNightModeChange();
mCachedView.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.background_white));
if (mListRv != null && mListRv.getItemDecorationCount() > 0) {
mListRv.removeItemDecorationAt(0);
mListRv.addItemDecoration(getItemDecoration());
}
}
}

View File

@ -3,7 +3,9 @@ package com.gh.gamecenter.video
import com.gh.base.BaseRecyclerViewHolder
import com.gh.common.util.ImageUtils
import com.gh.common.util.TimeUtils
import com.gh.common.util.setRootBackgroundDrawable
import com.gh.common.util.toSimpleCount
import com.gh.gamecenter.R
import com.gh.gamecenter.databinding.VideoNewItemBinding
import com.gh.gamecenter.entity.MyVideoEntity
@ -11,6 +13,7 @@ class VideoItemViewHolder(var binding: VideoNewItemBinding) : BaseRecyclerViewHo
fun bindVideoItem(entity: MyVideoEntity) {
binding.run {
root.setRootBackgroundDrawable(R.drawable.background_shape_white_radius_6)
ImageUtils.display(videoCover, entity.poster)
videoLikeCount.text = entity.vote.toSimpleCount()
videoCommentCount.text = entity.commentCount.toSimpleCount()

View File

@ -16,9 +16,11 @@ class VideoDataActivity : BaseActivity() {
DisplayUtils.transparentStatusBar(this)
val containerFragment = supportFragmentManager.findFragmentByTag(VideoDataFragment::class.java.simpleName)
?: VideoDataFragment().with(intent.extras)
?: VideoDataFragment().with(intent.extras)
// 若 placeholder 外层为 RelativeLayout 的话,会出现莫名的偏移
supportFragmentManager.beginTransaction().replace(R.id.placeholder, containerFragment, VideoDataFragment::class.java.simpleName).commitAllowingStateLoss()
supportFragmentManager.beginTransaction().replace(R.id.placeholder, containerFragment, VideoDataFragment::class.java.simpleName)
.commitAllowingStateLoss()
}
override fun isAutoResetViewBackgroundEnabled(): Boolean = true
}

View File

@ -5,6 +5,7 @@ import android.view.LayoutInflater
import android.view.View
import androidx.core.content.ContextCompat
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.RecyclerView
import com.gh.base.fragment.BaseFragment
import com.gh.common.util.DisplayUtils
import com.gh.common.util.dip2px
@ -15,6 +16,7 @@ import com.gh.common.view.VerticalItemDecoration
import com.gh.gamecenter.R
import com.gh.gamecenter.databinding.FragmentVideoDataBinding
import com.gh.gamecenter.mvvm.Status
import splitties.views.dsl.core.add
class VideoDataFragment : BaseFragment<Any>() {
private lateinit var mViewModel: VideoDataViewModel
@ -45,7 +47,7 @@ class VideoDataFragment : BaseFragment<Any>() {
mAdapter = VideoDataAdapter(requireContext())
mBinding.listRv.apply {
layoutManager = FixLinearLayoutManager(requireContext())
addItemDecoration(VerticalItemDecoration(requireContext(), 40F, false, R.color.white))
addItemDecoration(getItemDecoration())
adapter = mAdapter
}
mViewModel.loadData()
@ -62,7 +64,10 @@ class VideoDataFragment : BaseFragment<Any>() {
loadErrorControl()
}
})
}
private fun getItemDecoration(): RecyclerView.ItemDecoration {
return VerticalItemDecoration(requireContext(), 40F, false, R.color.background_white)
}
private fun loadErrorControl() {
@ -74,4 +79,12 @@ class VideoDataFragment : BaseFragment<Any>() {
mViewModel.loadData()
}
}
override fun onNightModeChange() {
super.onNightModeChange()
if (mBinding.listRv.itemDecorationCount > 0) {
mBinding.listRv.removeItemDecorationAt(0)
mBinding.listRv.addItemDecoration(getItemDecoration())
}
}
}

View File

@ -4,6 +4,8 @@ import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProviders
import com.gh.base.BaseActivity
@ -65,8 +67,10 @@ class GameVideoActivity : ToolBarActivity() {
mViewModel = ViewModelProviders.of(this, factory).get(GameVideoViewModel::class.java)
mViewModel.gameViewInfo.observeNonNull(this, callback = {
if (it.status == Status.SUCCESS) {
mBinding.gameIcon.displayGameIcon(it.data?.game?.getIcon()
?: it.data?.gameIcon, it.data?.game?.iconSubscript)
mBinding.gameIcon.displayGameIcon(
it.data?.game?.getIcon()
?: it.data?.gameIcon, it.data?.game?.iconSubscript
)
mBinding.gameName.text = it.data?.game?.name
mBinding.likeCount.text = NumberUtils.transSimpleCount(it.data?.likeCount ?: 0)
mBinding.videoCount.text = NumberUtils.transSimpleCount(it.data?.videoCount ?: 0)
@ -87,6 +91,21 @@ class GameVideoActivity : ToolBarActivity() {
return R.drawable.ic_toolbar_back_white
}
override fun isAutoResetViewBackgroundEnabled(): Boolean = true
override fun onNightModeChange() {
mToolbar.setBackgroundColor(R.color.transparent.toColor(this))
mToolbar.setNavigationIcon(R.drawable.ic_toolbar_back_white)
mBinding.tabContainer.setBackgroundColor(R.color.background_white.toColor(this))
for (i in 0 until mBinding.tabLayout.tabCount) {
val tab = mBinding.tabLayout.getTabAt(i)
if (tab != null) {
val customView = tab.view.getChildAt(1) as? TextView
customView?.setTextColor(ContextCompat.getColorStateList(this, R.color.text_tabbar_style))
}
}
}
companion object {
@JvmStatic

View File

@ -21,11 +21,13 @@ class GameVideoFragment : ListFragment<MyVideoEntity, NormalListViewModel<MyVide
override fun provideListAdapter(): GameVideoAdapter {
if (mAdapter == null) {
mAdapter = GameVideoAdapter(requireContext(),
mListViewModel,
mEntrance,
arguments?.getString(EntranceUtils.KEY_SORT),
arguments?.getString(EntranceUtils.KEY_GAMEID) ?: "")
mAdapter = GameVideoAdapter(
requireContext(),
mListViewModel,
mEntrance,
arguments?.getString(EntranceUtils.KEY_SORT),
arguments?.getString(EntranceUtils.KEY_GAMEID) ?: ""
)
}
return mAdapter!!
}
@ -61,4 +63,10 @@ class GameVideoFragment : ListFragment<MyVideoEntity, NormalListViewModel<MyVide
val sort = arguments?.getString(EntranceUtils.KEY_SORT)
return api.getGameVideo(gameId, sort, page, Config.VIDEO_PAGE_SIZE)
}
override fun onNightModeChange() {
super.onNightModeChange()
mListRv.recycledViewPool.clear()
mAdapter?.notifyItemRangeChanged(0, mAdapter?.itemCount ?: 0)
}
}