diff options
| author | 2023-03-07 21:14:32 -0500 | |
|---|---|---|
| committer | 2023-06-03 00:05:37 -0700 | |
| commit | 1fc66f1b30da30aa78d68dd27fc3615565bd7e6b (patch) | |
| tree | 846da3ed9efd1495ebdd1f2554966e4370565f81 /src/android | |
| parent | android: Convert SettingsActivityView to Kotlin (diff) | |
| download | yuzu-1fc66f1b30da30aa78d68dd27fc3615565bd7e6b.tar.gz yuzu-1fc66f1b30da30aa78d68dd27fc3615565bd7e6b.tar.xz yuzu-1fc66f1b30da30aa78d68dd27fc3615565bd7e6b.zip | |
android: Convert SettingsFragment to Kotlin
Diffstat (limited to 'src/android')
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 @@ | |||
| 1 | package org.yuzu.yuzu_emu.features.settings.ui; | ||
| 2 | |||
| 3 | import android.content.Context; | ||
| 4 | import android.os.Bundle; | ||
| 5 | import android.view.LayoutInflater; | ||
| 6 | import android.view.View; | ||
| 7 | import android.view.ViewGroup; | ||
| 8 | |||
| 9 | import androidx.annotation.NonNull; | ||
| 10 | import androidx.annotation.Nullable; | ||
| 11 | import androidx.fragment.app.Fragment; | ||
| 12 | import androidx.recyclerview.widget.LinearLayoutManager; | ||
| 13 | import androidx.recyclerview.widget.RecyclerView; | ||
| 14 | |||
| 15 | import org.yuzu.yuzu_emu.R; | ||
| 16 | import org.yuzu.yuzu_emu.features.settings.model.Setting; | ||
| 17 | import org.yuzu.yuzu_emu.features.settings.model.Settings; | ||
| 18 | import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem; | ||
| 19 | import org.yuzu.yuzu_emu.ui.DividerItemDecoration; | ||
| 20 | |||
| 21 | import java.util.ArrayList; | ||
| 22 | |||
| 23 | public final class SettingsFragment extends Fragment implements SettingsFragmentView { | ||
| 24 | private static final String ARGUMENT_MENU_TAG = "menu_tag"; | ||
| 25 | private static final String ARGUMENT_GAME_ID = "game_id"; | ||
| 26 | |||
| 27 | private SettingsFragmentPresenter mPresenter = new SettingsFragmentPresenter(this); | ||
| 28 | private SettingsActivityView mActivity; | ||
| 29 | |||
| 30 | private SettingsAdapter mAdapter; | ||
| 31 | |||
| 32 | public static Fragment newInstance(String menuTag, String gameId) { | ||
| 33 | SettingsFragment fragment = new SettingsFragment(); | ||
| 34 | |||
| 35 | Bundle arguments = new Bundle(); | ||
| 36 | arguments.putString(ARGUMENT_MENU_TAG, menuTag); | ||
| 37 | arguments.putString(ARGUMENT_GAME_ID, gameId); | ||
| 38 | |||
| 39 | fragment.setArguments(arguments); | ||
| 40 | return fragment; | ||
| 41 | } | ||
| 42 | |||
| 43 | @Override | ||
| 44 | public void onAttach(@NonNull Context context) { | ||
| 45 | super.onAttach(context); | ||
| 46 | |||
| 47 | mActivity = (SettingsActivityView) context; | ||
| 48 | mPresenter.onAttach(); | ||
| 49 | } | ||
| 50 | |||
| 51 | @Override | ||
| 52 | public void onCreate(Bundle savedInstanceState) { | ||
| 53 | super.onCreate(savedInstanceState); | ||
| 54 | |||
| 55 | setRetainInstance(true); | ||
| 56 | String menuTag = getArguments().getString(ARGUMENT_MENU_TAG); | ||
| 57 | String gameId = getArguments().getString(ARGUMENT_GAME_ID); | ||
| 58 | |||
| 59 | mAdapter = new SettingsAdapter(this, getActivity()); | ||
| 60 | |||
| 61 | mPresenter.onCreate(menuTag, gameId); | ||
| 62 | } | ||
| 63 | |||
| 64 | @Nullable | ||
| 65 | @Override | ||
| 66 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
| 67 | return inflater.inflate(R.layout.fragment_settings, container, false); | ||
| 68 | } | ||
| 69 | |||
| 70 | @Override | ||
| 71 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||
| 72 | LinearLayoutManager manager = new LinearLayoutManager(getActivity()); | ||
| 73 | |||
| 74 | RecyclerView recyclerView = view.findViewById(R.id.list_settings); | ||
| 75 | |||
| 76 | recyclerView.setAdapter(mAdapter); | ||
| 77 | recyclerView.setLayoutManager(manager); | ||
| 78 | recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), null)); | ||
| 79 | |||
| 80 | SettingsActivityView activity = (SettingsActivityView) getActivity(); | ||
| 81 | |||
| 82 | mPresenter.onViewCreated(activity.getSettings()); | ||
| 83 | } | ||
| 84 | |||
| 85 | @Override | ||
| 86 | public void onDetach() { | ||
| 87 | super.onDetach(); | ||
| 88 | mActivity = null; | ||
| 89 | |||
| 90 | if (mAdapter != null) { | ||
| 91 | mAdapter.closeDialog(); | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | @Override | ||
| 96 | public void onSettingsFileLoaded(Settings settings) { | ||
| 97 | mPresenter.setSettings(settings); | ||
| 98 | } | ||
| 99 | |||
| 100 | @Override | ||
| 101 | public void passSettingsToActivity(Settings settings) { | ||
| 102 | if (mActivity != null) { | ||
| 103 | mActivity.setSettings(settings); | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | @Override | ||
| 108 | public void showSettingsList(ArrayList<SettingsItem> settingsList) { | ||
| 109 | mAdapter.setSettings(settingsList); | ||
| 110 | } | ||
| 111 | |||
| 112 | @Override | ||
| 113 | public void loadDefaultSettings() { | ||
| 114 | mPresenter.loadDefaultSettings(); | ||
| 115 | } | ||
| 116 | |||
| 117 | @Override | ||
| 118 | public void loadSubMenu(String menuKey) { | ||
| 119 | mActivity.showSettingsFragment(menuKey, true, getArguments().getString(ARGUMENT_GAME_ID)); | ||
| 120 | } | ||
| 121 | |||
| 122 | @Override | ||
| 123 | public void showToastMessage(String message, boolean is_long) { | ||
| 124 | mActivity.showToastMessage(message, is_long); | ||
| 125 | } | ||
| 126 | |||
| 127 | @Override | ||
| 128 | public void putSetting(Setting setting) { | ||
| 129 | mPresenter.putSetting(setting); | ||
| 130 | } | ||
| 131 | |||
| 132 | @Override | ||
| 133 | public void onSettingChanged() { | ||
| 134 | mActivity.onSettingChanged(); | ||
| 135 | } | ||
| 136 | } | ||
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 @@ | |||
| 1 | package org.yuzu.yuzu_emu.features.settings.ui | ||
| 2 | |||
| 3 | import android.content.Context | ||
| 4 | import android.os.Bundle | ||
| 5 | import android.view.LayoutInflater | ||
| 6 | import android.view.View | ||
| 7 | import android.view.ViewGroup | ||
| 8 | import androidx.fragment.app.Fragment | ||
| 9 | import androidx.fragment.app.FragmentActivity | ||
| 10 | import androidx.recyclerview.widget.LinearLayoutManager | ||
| 11 | import androidx.recyclerview.widget.RecyclerView | ||
| 12 | import com.google.android.material.divider.MaterialDividerItemDecoration | ||
| 13 | import org.yuzu.yuzu_emu.R | ||
| 14 | import org.yuzu.yuzu_emu.features.settings.model.Setting | ||
| 15 | import org.yuzu.yuzu_emu.features.settings.model.Settings | ||
| 16 | import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem | ||
| 17 | |||
| 18 | class SettingsFragment : Fragment(), SettingsFragmentView { | ||
| 19 | override lateinit var fragmentActivity: FragmentActivity | ||
| 20 | |||
| 21 | private val presenter = SettingsFragmentPresenter(this) | ||
| 22 | private var activityView: SettingsActivityView? = null | ||
| 23 | private var adapter: SettingsAdapter? = null | ||
| 24 | |||
| 25 | override fun onAttach(context: Context) { | ||
| 26 | super.onAttach(context) | ||
| 27 | activityView = context as SettingsActivityView | ||
| 28 | fragmentActivity = requireActivity() | ||
| 29 | presenter.onAttach() | ||
| 30 | } | ||
| 31 | |||
| 32 | override fun onCreate(savedInstanceState: Bundle?) { | ||
| 33 | super.onCreate(savedInstanceState) | ||
| 34 | val menuTag = requireArguments().getString(ARGUMENT_MENU_TAG) | ||
| 35 | val gameId = requireArguments().getString(ARGUMENT_GAME_ID) | ||
| 36 | adapter = SettingsAdapter(this, requireActivity()) | ||
| 37 | presenter.onCreate(menuTag!!, gameId!!) | ||
| 38 | } | ||
| 39 | |||
| 40 | override fun onCreateView( | ||
| 41 | inflater: LayoutInflater, | ||
| 42 | container: ViewGroup?, | ||
| 43 | savedInstanceState: Bundle? | ||
| 44 | ): View? { | ||
| 45 | return inflater.inflate(R.layout.fragment_settings, container, false) | ||
| 46 | } | ||
| 47 | |||
| 48 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
| 49 | val manager = LinearLayoutManager(activity) | ||
| 50 | val recyclerView = view.findViewById<RecyclerView>(R.id.list_settings) | ||
| 51 | recyclerView.adapter = adapter | ||
| 52 | recyclerView.layoutManager = manager | ||
| 53 | val dividerDecoration = MaterialDividerItemDecoration(requireContext(), LinearLayoutManager.VERTICAL) | ||
| 54 | dividerDecoration.isLastItemDecorated = false | ||
| 55 | recyclerView.addItemDecoration(dividerDecoration) | ||
| 56 | val activity = activity as SettingsActivityView? | ||
| 57 | presenter.onViewCreated(activity!!.settings) | ||
| 58 | } | ||
| 59 | |||
| 60 | override fun onDetach() { | ||
| 61 | super.onDetach() | ||
| 62 | activityView = null | ||
| 63 | if (adapter != null) { | ||
| 64 | adapter!!.closeDialog() | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | override fun onSettingsFileLoaded(settings: Settings?) { | ||
| 69 | presenter.setSettings(settings) | ||
| 70 | } | ||
| 71 | |||
| 72 | override fun passSettingsToActivity(settings: Settings) { | ||
| 73 | if (activityView != null) { | ||
| 74 | activityView!!.settings = settings | ||
| 75 | } | ||
| 76 | } | ||
| 77 | |||
| 78 | override fun showSettingsList(settingsList: ArrayList<SettingsItem>) { | ||
| 79 | adapter!!.setSettings(settingsList) | ||
| 80 | } | ||
| 81 | |||
| 82 | override fun loadDefaultSettings() { | ||
| 83 | presenter.loadDefaultSettings() | ||
| 84 | } | ||
| 85 | |||
| 86 | override fun loadSubMenu(menuKey: String) { | ||
| 87 | activityView!!.showSettingsFragment( | ||
| 88 | menuKey, | ||
| 89 | true, | ||
| 90 | requireArguments().getString(ARGUMENT_GAME_ID)!! | ||
| 91 | ) | ||
| 92 | } | ||
| 93 | |||
| 94 | override fun showToastMessage(message: String?, is_long: Boolean) { | ||
| 95 | activityView!!.showToastMessage(message!!, is_long) | ||
| 96 | } | ||
| 97 | |||
| 98 | override fun putSetting(setting: Setting) { | ||
| 99 | presenter.putSetting(setting) | ||
| 100 | } | ||
| 101 | |||
| 102 | override fun onSettingChanged() { | ||
| 103 | activityView!!.onSettingChanged() | ||
| 104 | } | ||
| 105 | |||
| 106 | companion object { | ||
| 107 | private const val ARGUMENT_MENU_TAG = "menu_tag" | ||
| 108 | private const val ARGUMENT_GAME_ID = "game_id" | ||
| 109 | |||
| 110 | @JvmStatic | ||
| 111 | fun newInstance(menuTag: String?, gameId: String?): Fragment { | ||
| 112 | val fragment = SettingsFragment() | ||
| 113 | val arguments = Bundle() | ||
| 114 | arguments.putString(ARGUMENT_MENU_TAG, menuTag) | ||
| 115 | arguments.putString(ARGUMENT_GAME_ID, gameId) | ||
| 116 | fragment.arguments = arguments | ||
| 117 | return fragment | ||
| 118 | } | ||
| 119 | } | ||
| 120 | } | ||