From 6bc4ae74386640645b7bf88026f2dae48d48787f Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Wed, 1 Mar 2023 13:41:55 -0500 Subject: [PATCH] Android: Convert SettingDisabledWarningFragment to Kotlin --- .../ui/SettingDisabledWarningFragment.java | 85 ------------------- .../ui/SettingDisabledWarningFragment.kt | 59 +++++++++++++ 2 files changed, 59 insertions(+), 85 deletions(-) delete mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/SettingDisabledWarningFragment.java create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/SettingDisabledWarningFragment.kt diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/SettingDisabledWarningFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/SettingDisabledWarningFragment.java deleted file mode 100644 index 7e703f3fd1..0000000000 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/SettingDisabledWarningFragment.java +++ /dev/null @@ -1,85 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later - -package org.dolphinemu.dolphinemu.features.cheats.ui; - -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; - -import org.dolphinemu.dolphinemu.databinding.FragmentCheatWarningBinding; -import org.dolphinemu.dolphinemu.features.settings.model.AbstractBooleanSetting; -import org.dolphinemu.dolphinemu.features.settings.model.Settings; -import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag; -import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivity; - -public abstract class SettingDisabledWarningFragment extends Fragment - implements View.OnClickListener -{ - private View mView; - - private final AbstractBooleanSetting mSetting; - private final MenuTag mSettingShortcut; - private final int mText; - - private FragmentCheatWarningBinding mBinding; - - public SettingDisabledWarningFragment(AbstractBooleanSetting setting, MenuTag settingShortcut, - int text) - { - mSetting = setting; - mSettingShortcut = settingShortcut; - mText = text; - } - - @Nullable - @Override - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, - @Nullable Bundle savedInstanceState) - { - mBinding = FragmentCheatWarningBinding.inflate(inflater, container, false); - return mBinding.getRoot(); - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) - { - mView = view; - - mBinding.textWarning.setText(mText); - mBinding.buttonSettings.setOnClickListener(this); - - CheatsActivity activity = (CheatsActivity) requireActivity(); - CheatsActivity.setOnFocusChangeListenerRecursively(view, - (v, hasFocus) -> activity.onListViewFocusChange(hasFocus)); - } - - @Override - public void onResume() - { - super.onResume(); - - CheatsActivity activity = (CheatsActivity) requireActivity(); - try (Settings settings = activity.loadGameSpecificSettings()) - { - boolean cheatsEnabled = mSetting.getBoolean(settings); - mView.setVisibility(cheatsEnabled ? View.GONE : View.VISIBLE); - } - } - - @Override - public void onDestroyView() - { - super.onDestroyView(); - mBinding = null; - } - - public void onClick(View view) - { - SettingsActivity.launch(requireContext(), mSettingShortcut); - } -} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/SettingDisabledWarningFragment.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/SettingDisabledWarningFragment.kt new file mode 100644 index 0000000000..f67b0f3862 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/SettingDisabledWarningFragment.kt @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.dolphinemu.dolphinemu.features.cheats.ui + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import org.dolphinemu.dolphinemu.databinding.FragmentCheatWarningBinding +import org.dolphinemu.dolphinemu.features.cheats.ui.CheatsActivity.Companion.setOnFocusChangeListenerRecursively +import org.dolphinemu.dolphinemu.features.settings.model.AbstractBooleanSetting +import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag +import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivity + +abstract class SettingDisabledWarningFragment( + private val setting: AbstractBooleanSetting, + private val settingShortcut: MenuTag, + private val text: Int +) : Fragment(), View.OnClickListener { + private var _binding: FragmentCheatWarningBinding? = null + private val binding get() = _binding!! + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + _binding = FragmentCheatWarningBinding.inflate(inflater, container, false) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + binding.textWarning.setText(text) + binding.buttonSettings.setOnClickListener(this) + val activity = requireActivity() as CheatsActivity + setOnFocusChangeListenerRecursively(view) { _: View?, hasFocus: Boolean -> + activity.onListViewFocusChange(hasFocus) + } + } + + override fun onResume() { + super.onResume() + val activity = requireActivity() as CheatsActivity + activity.loadGameSpecificSettings().use { settings -> + val cheatsEnabled = setting.getBoolean(settings) + requireView().visibility = if (cheatsEnabled) View.GONE else View.VISIBLE + } + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } + + override fun onClick(view: View) { + SettingsActivity.launch(requireContext(), settingShortcut) + } +}