Do not hook up check changed listener until after view state is restored.

This commit is contained in:
Alex Hart 2022-02-24 10:56:05 -04:00
parent f4002850bb
commit 765185952e

View file

@ -40,6 +40,7 @@ public class ChatWallpaperFragment extends Fragment {
private boolean isSettingDimFromViewModel;
private ChatWallpaperViewModel viewModel;
private SwitchCompat dimInNightMode;
@Override
public @NonNull View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@ -54,7 +55,6 @@ public class ChatWallpaperFragment extends Fragment {
Toolbar toolbar = view.findViewById(R.id.toolbar);
ImageView chatWallpaperPreview = view.findViewById(R.id.chat_wallpaper_preview_background);
View setWallpaper = view.findViewById(R.id.chat_wallpaper_set_wallpaper);
SwitchCompat dimInNightMode = view.findViewById(R.id.chat_wallpaper_dark_theme_dims_wallpaper);
View chatWallpaperDim = view.findViewById(R.id.chat_wallpaper_dim);
TextView setChatColor = view.findViewById(R.id.chat_wallpaper_set_chat_color);
TextView resetChatColors = view.findViewById(R.id.chat_wallpaper_reset_chat_colors);
@ -63,6 +63,8 @@ public class ChatWallpaperFragment extends Fragment {
TextView resetAllWallpaper = view.findViewById(R.id.chat_wallpaper_reset_all_wallpapers);
AppCompatImageView recvBubble = view.findViewById(R.id.chat_wallpaper_preview_bubble_1);
dimInNightMode = view.findViewById(R.id.chat_wallpaper_dark_theme_dims_wallpaper);
toolbar.setTitle(R.string.preferences__chat_color_and_wallpaper);
toolbar.setNavigationOnClickListener(nav -> {
if (!Navigation.findNavController(nav).popBackStack()) {
@ -173,12 +175,6 @@ public class ChatWallpaperFragment extends Fragment {
});
}
dimInNightMode.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (!isSettingDimFromViewModel) {
viewModel.setDimInDarkTheme(isChecked);
}
});
viewModel.getCurrentChatColors().observe(getViewLifecycleOwner(), chatColors -> {
sentBubble.getDrawable().setColorFilter(chatColors.getChatBubbleColorFilter());
colorizerView.setBackground(chatColors.getChatBubbleMask());
@ -193,6 +189,17 @@ public class ChatWallpaperFragment extends Fragment {
sentBubble.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> viewModel.refreshChatColors());
}
@Override
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
super.onViewStateRestored(savedInstanceState);
dimInNightMode.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (!isSettingDimFromViewModel) {
viewModel.setDimInDarkTheme(isChecked);
}
});
}
@Override
public void onResume() {
super.onResume();