summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCharles Lombardo <clombardo169@gmail.com>2023-03-11 06:34:45 +0100
committerbunnei <bunneidev@gmail.com>2023-06-03 09:05:40 +0200
commit0b2350ad5b4980e77ce82a902175e4d686abbae3 (patch)
tree39d2e02f875f720920131a9878997ecc33ca93bd /src
parentandroid: Convert MainView to Kotlin (diff)
downloadyuzu-0b2350ad5b4980e77ce82a902175e4d686abbae3.tar
yuzu-0b2350ad5b4980e77ce82a902175e4d686abbae3.tar.gz
yuzu-0b2350ad5b4980e77ce82a902175e4d686abbae3.tar.bz2
yuzu-0b2350ad5b4980e77ce82a902175e4d686abbae3.tar.lz
yuzu-0b2350ad5b4980e77ce82a902175e4d686abbae3.tar.xz
yuzu-0b2350ad5b4980e77ce82a902175e4d686abbae3.tar.zst
yuzu-0b2350ad5b4980e77ce82a902175e4d686abbae3.zip
Diffstat (limited to 'src')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/platform/PlatformGamesFragment.java105
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/platform/PlatformGamesFragment.kt94
2 files changed, 94 insertions, 105 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/platform/PlatformGamesFragment.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/platform/PlatformGamesFragment.java
deleted file mode 100644
index 2d74f43ca..000000000
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/platform/PlatformGamesFragment.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package org.yuzu.yuzu_emu.ui.platform;
-
-import android.database.Cursor;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.ViewTreeObserver;
-import android.widget.TextView;
-
-import androidx.core.content.ContextCompat;
-import androidx.fragment.app.Fragment;
-import androidx.recyclerview.widget.GridLayoutManager;
-import androidx.recyclerview.widget.RecyclerView;
-import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
-
-import org.yuzu.yuzu_emu.NativeLibrary;
-import org.yuzu.yuzu_emu.YuzuApplication;
-import org.yuzu.yuzu_emu.R;
-import org.yuzu.yuzu_emu.adapters.GameAdapter;
-import org.yuzu.yuzu_emu.model.GameDatabase;
-
-public final class PlatformGamesFragment extends Fragment implements PlatformGamesView {
- private PlatformGamesPresenter mPresenter = new PlatformGamesPresenter(this);
-
- private GameAdapter mAdapter;
- private RecyclerView mRecyclerView;
- private TextView mTextView;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- View rootView = inflater.inflate(R.layout.fragment_grid, container, false);
-
- findViews(rootView);
-
- mPresenter.onCreateView();
-
- return rootView;
- }
-
- @Override
- public void onViewCreated(View view, Bundle savedInstanceState) {
- mAdapter = new GameAdapter();
-
- // Organize our grid layout based on the current view.
- if (isAdded()) {
- view.getViewTreeObserver()
- .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
- @Override
- public void onGlobalLayout() {
- if (view.getMeasuredWidth() == 0) {
- return;
- }
-
- int columns = view.getMeasuredWidth() /
- requireContext().getResources().getDimensionPixelSize(R.dimen.card_width);
- if (columns == 0) {
- columns = 1;
- }
- view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
- GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), columns);
- mRecyclerView.setLayoutManager(layoutManager);
- mRecyclerView.setAdapter(mAdapter);
- }
- });
- }
-
- // Add swipe down to refresh gesture
- final SwipeRefreshLayout pullToRefresh = view.findViewById(R.id.swipe_refresh);
- pullToRefresh.setOnRefreshListener(() -> {
- refresh();
- pullToRefresh.setRefreshing(false);
- });
- }
-
- @Override
- public void refresh() {
- GameDatabase databaseHelper = YuzuApplication.databaseHelper;
- databaseHelper.scanLibrary(databaseHelper.getWritableDatabase());
- mPresenter.refresh();
- updateTextView();
- }
-
- @Override
- public void showGames(Cursor games) {
- if (mAdapter != null) {
- mAdapter.swapCursor(games);
- }
- updateTextView();
- }
-
- private void updateTextView() {
- mTextView.setVisibility(mAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
- }
-
- private void findViews(View root) {
- mRecyclerView = root.findViewById(R.id.grid_games);
- mTextView = root.findViewById(R.id.gamelist_empty_text);
- }
-}
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/platform/PlatformGamesFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/platform/PlatformGamesFragment.kt
new file mode 100644
index 000000000..9ceea8b3f
--- /dev/null
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/platform/PlatformGamesFragment.kt
@@ -0,0 +1,94 @@
+package org.yuzu.yuzu_emu.ui.platform
+
+import android.database.Cursor
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.view.ViewTreeObserver.OnGlobalLayoutListener
+import android.widget.TextView
+import androidx.fragment.app.Fragment
+import androidx.recyclerview.widget.GridLayoutManager
+import androidx.recyclerview.widget.RecyclerView
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
+import org.yuzu.yuzu_emu.R
+import org.yuzu.yuzu_emu.YuzuApplication
+import org.yuzu.yuzu_emu.adapters.GameAdapter
+
+class PlatformGamesFragment : Fragment(), PlatformGamesView {
+ private val presenter = PlatformGamesPresenter(this)
+ private var adapter: GameAdapter? = null
+ private lateinit var recyclerView: RecyclerView
+ private lateinit var textView: TextView
+
+ override fun onCreateView(
+ inflater: LayoutInflater,
+ container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View? {
+ val rootView = inflater.inflate(R.layout.fragment_grid, container, false)
+ findViews(rootView)
+ presenter.onCreateView()
+ return rootView
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ adapter = GameAdapter()
+
+ // Organize our grid layout based on the current view.
+ if (isAdded) {
+ view.viewTreeObserver
+ .addOnGlobalLayoutListener(object : OnGlobalLayoutListener {
+ override fun onGlobalLayout() {
+ if (view.measuredWidth == 0) {
+ return
+ }
+ var columns = view.measuredWidth /
+ requireContext().resources.getDimensionPixelSize(R.dimen.card_width)
+ if (columns == 0) {
+ columns = 1
+ }
+ view.viewTreeObserver.removeOnGlobalLayoutListener(this)
+ val layoutManager = GridLayoutManager(activity, columns)
+ recyclerView.layoutManager = layoutManager
+ recyclerView.adapter = adapter
+ }
+ })
+ }
+
+ // Add swipe down to refresh gesture
+ val pullToRefresh = view.findViewById<SwipeRefreshLayout>(R.id.swipe_refresh)
+ pullToRefresh.setOnRefreshListener {
+ refresh()
+ pullToRefresh.isRefreshing = false
+ }
+ }
+
+ override fun refresh() {
+ val databaseHelper = YuzuApplication.databaseHelper
+ databaseHelper!!.scanLibrary(databaseHelper.writableDatabase)
+ presenter.refresh()
+ updateTextView()
+ }
+
+ override fun showGames(games: Cursor) {
+ if (adapter != null) {
+ adapter!!.swapCursor(games)
+ }
+ updateTextView()
+ }
+
+ private fun updateTextView() {
+ textView.visibility =
+ if (adapter!!.itemCount == 0) View.VISIBLE else View.GONE
+ }
+
+ private fun findViews(root: View) {
+ recyclerView = root.findViewById(R.id.grid_games)
+ textView = root.findViewById(R.id.gamelist_empty_text)
+ }
+
+ companion object {
+ const val TAG = "PlatformGamesFragment"
+ }
+}