Android: Convert SettingDisabledWarningFragment to Kotlin

This commit is contained in:
Charles Lombardo 2023-03-01 13:41:55 -05:00
parent 53d404c5a0
commit 6bc4ae7438
2 changed files with 59 additions and 85 deletions

View File

@ -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);
}
}

View File

@ -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)
}
}