summaryrefslogtreecommitdiffstats
path: root/src/android
diff options
context:
space:
mode:
authorCharles Lombardo <clombardo169@gmail.com>2023-03-08 03:14:32 +0100
committerbunnei <bunneidev@gmail.com>2023-06-03 09:05:37 +0200
commit1fc66f1b30da30aa78d68dd27fc3615565bd7e6b (patch)
tree846da3ed9efd1495ebdd1f2554966e4370565f81 /src/android
parentandroid: Convert SettingsActivityView to Kotlin (diff)
downloadyuzu-1fc66f1b30da30aa78d68dd27fc3615565bd7e6b.tar
yuzu-1fc66f1b30da30aa78d68dd27fc3615565bd7e6b.tar.gz
yuzu-1fc66f1b30da30aa78d68dd27fc3615565bd7e6b.tar.bz2
yuzu-1fc66f1b30da30aa78d68dd27fc3615565bd7e6b.tar.lz
yuzu-1fc66f1b30da30aa78d68dd27fc3615565bd7e6b.tar.xz
yuzu-1fc66f1b30da30aa78d68dd27fc3615565bd7e6b.tar.zst
yuzu-1fc66f1b30da30aa78d68dd27fc3615565bd7e6b.zip
Diffstat (limited to 'src/android')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragment.java136
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragment.kt120
2 files changed, 120 insertions, 136 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragment.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragment.java
deleted file mode 100644
index 845f6b7b4..000000000
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragment.java
+++ /dev/null
@@ -1,136 +0,0 @@
-package org.yuzu.yuzu_emu.features.settings.ui;
-
-import android.content.Context;
-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 androidx.recyclerview.widget.LinearLayoutManager;
-import androidx.recyclerview.widget.RecyclerView;
-
-import org.yuzu.yuzu_emu.R;
-import org.yuzu.yuzu_emu.features.settings.model.Setting;
-import org.yuzu.yuzu_emu.features.settings.model.Settings;
-import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem;
-import org.yuzu.yuzu_emu.ui.DividerItemDecoration;
-
-import java.util.ArrayList;
-
-public final class SettingsFragment extends Fragment implements SettingsFragmentView {
- private static final String ARGUMENT_MENU_TAG = "menu_tag";
- private static final String ARGUMENT_GAME_ID = "game_id";
-
- private SettingsFragmentPresenter mPresenter = new SettingsFragmentPresenter(this);
- private SettingsActivityView mActivity;
-
- private SettingsAdapter mAdapter;
-
- public static Fragment newInstance(String menuTag, String gameId) {
- SettingsFragment fragment = new SettingsFragment();
-
- Bundle arguments = new Bundle();
- arguments.putString(ARGUMENT_MENU_TAG, menuTag);
- arguments.putString(ARGUMENT_GAME_ID, gameId);
-
- fragment.setArguments(arguments);
- return fragment;
- }
-
- @Override
- public void onAttach(@NonNull Context context) {
- super.onAttach(context);
-
- mActivity = (SettingsActivityView) context;
- mPresenter.onAttach();
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- setRetainInstance(true);
- String menuTag = getArguments().getString(ARGUMENT_MENU_TAG);
- String gameId = getArguments().getString(ARGUMENT_GAME_ID);
-
- mAdapter = new SettingsAdapter(this, getActivity());
-
- mPresenter.onCreate(menuTag, gameId);
- }
-
- @Nullable
- @Override
- public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
- return inflater.inflate(R.layout.fragment_settings, container, false);
- }
-
- @Override
- public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
- LinearLayoutManager manager = new LinearLayoutManager(getActivity());
-
- RecyclerView recyclerView = view.findViewById(R.id.list_settings);
-
- recyclerView.setAdapter(mAdapter);
- recyclerView.setLayoutManager(manager);
- recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), null));
-
- SettingsActivityView activity = (SettingsActivityView) getActivity();
-
- mPresenter.onViewCreated(activity.getSettings());
- }
-
- @Override
- public void onDetach() {
- super.onDetach();
- mActivity = null;
-
- if (mAdapter != null) {
- mAdapter.closeDialog();
- }
- }
-
- @Override
- public void onSettingsFileLoaded(Settings settings) {
- mPresenter.setSettings(settings);
- }
-
- @Override
- public void passSettingsToActivity(Settings settings) {
- if (mActivity != null) {
- mActivity.setSettings(settings);
- }
- }
-
- @Override
- public void showSettingsList(ArrayList<SettingsItem> settingsList) {
- mAdapter.setSettings(settingsList);
- }
-
- @Override
- public void loadDefaultSettings() {
- mPresenter.loadDefaultSettings();
- }
-
- @Override
- public void loadSubMenu(String menuKey) {
- mActivity.showSettingsFragment(menuKey, true, getArguments().getString(ARGUMENT_GAME_ID));
- }
-
- @Override
- public void showToastMessage(String message, boolean is_long) {
- mActivity.showToastMessage(message, is_long);
- }
-
- @Override
- public void putSetting(Setting setting) {
- mPresenter.putSetting(setting);
- }
-
- @Override
- public void onSettingChanged() {
- mActivity.onSettingChanged();
- }
-}
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragment.kt
new file mode 100644
index 000000000..27619f4f7
--- /dev/null
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragment.kt
@@ -0,0 +1,120 @@
+package org.yuzu.yuzu_emu.features.settings.ui
+
+import android.content.Context
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.fragment.app.Fragment
+import androidx.fragment.app.FragmentActivity
+import androidx.recyclerview.widget.LinearLayoutManager
+import androidx.recyclerview.widget.RecyclerView
+import com.google.android.material.divider.MaterialDividerItemDecoration
+import org.yuzu.yuzu_emu.R
+import org.yuzu.yuzu_emu.features.settings.model.Setting
+import org.yuzu.yuzu_emu.features.settings.model.Settings
+import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem
+
+class SettingsFragment : Fragment(), SettingsFragmentView {
+ override lateinit var fragmentActivity: FragmentActivity
+
+ private val presenter = SettingsFragmentPresenter(this)
+ private var activityView: SettingsActivityView? = null
+ private var adapter: SettingsAdapter? = null
+
+ override fun onAttach(context: Context) {
+ super.onAttach(context)
+ activityView = context as SettingsActivityView
+ fragmentActivity = requireActivity()
+ presenter.onAttach()
+ }
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ val menuTag = requireArguments().getString(ARGUMENT_MENU_TAG)
+ val gameId = requireArguments().getString(ARGUMENT_GAME_ID)
+ adapter = SettingsAdapter(this, requireActivity())
+ presenter.onCreate(menuTag!!, gameId!!)
+ }
+
+ override fun onCreateView(
+ inflater: LayoutInflater,
+ container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View? {
+ return inflater.inflate(R.layout.fragment_settings, container, false)
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ val manager = LinearLayoutManager(activity)
+ val recyclerView = view.findViewById<RecyclerView>(R.id.list_settings)
+ recyclerView.adapter = adapter
+ recyclerView.layoutManager = manager
+ val dividerDecoration = MaterialDividerItemDecoration(requireContext(), LinearLayoutManager.VERTICAL)
+ dividerDecoration.isLastItemDecorated = false
+ recyclerView.addItemDecoration(dividerDecoration)
+ val activity = activity as SettingsActivityView?
+ presenter.onViewCreated(activity!!.settings)
+ }
+
+ override fun onDetach() {
+ super.onDetach()
+ activityView = null
+ if (adapter != null) {
+ adapter!!.closeDialog()
+ }
+ }
+
+ override fun onSettingsFileLoaded(settings: Settings?) {
+ presenter.setSettings(settings)
+ }
+
+ override fun passSettingsToActivity(settings: Settings) {
+ if (activityView != null) {
+ activityView!!.settings = settings
+ }
+ }
+
+ override fun showSettingsList(settingsList: ArrayList<SettingsItem>) {
+ adapter!!.setSettings(settingsList)
+ }
+
+ override fun loadDefaultSettings() {
+ presenter.loadDefaultSettings()
+ }
+
+ override fun loadSubMenu(menuKey: String) {
+ activityView!!.showSettingsFragment(
+ menuKey,
+ true,
+ requireArguments().getString(ARGUMENT_GAME_ID)!!
+ )
+ }
+
+ override fun showToastMessage(message: String?, is_long: Boolean) {
+ activityView!!.showToastMessage(message!!, is_long)
+ }
+
+ override fun putSetting(setting: Setting) {
+ presenter.putSetting(setting)
+ }
+
+ override fun onSettingChanged() {
+ activityView!!.onSettingChanged()
+ }
+
+ companion object {
+ private const val ARGUMENT_MENU_TAG = "menu_tag"
+ private const val ARGUMENT_GAME_ID = "game_id"
+
+ @JvmStatic
+ fun newInstance(menuTag: String?, gameId: String?): Fragment {
+ val fragment = SettingsFragment()
+ val arguments = Bundle()
+ arguments.putString(ARGUMENT_MENU_TAG, menuTag)
+ arguments.putString(ARGUMENT_GAME_ID, gameId)
+ fragment.arguments = arguments
+ return fragment
+ }
+ }
+}