summaryrefslogtreecommitdiff
path: root/src/android
diff options
context:
space:
mode:
authorGravatar Charles Lombardo2023-03-11 00:34:45 -0500
committerGravatar bunnei2023-06-03 00:05:40 -0700
commit0b2350ad5b4980e77ce82a902175e4d686abbae3 (patch)
tree39d2e02f875f720920131a9878997ecc33ca93bd /src/android
parentandroid: Convert MainView to Kotlin (diff)
downloadyuzu-0b2350ad5b4980e77ce82a902175e4d686abbae3.tar.gz
yuzu-0b2350ad5b4980e77ce82a902175e4d686abbae3.tar.xz
yuzu-0b2350ad5b4980e77ce82a902175e4d686abbae3.zip
android: Convert PlatformGamesFragment to Kotlin
Diffstat (limited to 'src/android')
-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 @@
1package org.yuzu.yuzu_emu.ui.platform;
2
3import android.database.Cursor;
4import android.os.Bundle;
5import android.view.LayoutInflater;
6import android.view.View;
7import android.view.ViewGroup;
8import android.view.ViewTreeObserver;
9import android.widget.TextView;
10
11import androidx.core.content.ContextCompat;
12import androidx.fragment.app.Fragment;
13import androidx.recyclerview.widget.GridLayoutManager;
14import androidx.recyclerview.widget.RecyclerView;
15import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
16
17import org.yuzu.yuzu_emu.NativeLibrary;
18import org.yuzu.yuzu_emu.YuzuApplication;
19import org.yuzu.yuzu_emu.R;
20import org.yuzu.yuzu_emu.adapters.GameAdapter;
21import org.yuzu.yuzu_emu.model.GameDatabase;
22
23public final class PlatformGamesFragment extends Fragment implements PlatformGamesView {
24 private PlatformGamesPresenter mPresenter = new PlatformGamesPresenter(this);
25
26 private GameAdapter mAdapter;
27 private RecyclerView mRecyclerView;
28 private TextView mTextView;
29
30 @Override
31 public void onCreate(Bundle savedInstanceState) {
32 super.onCreate(savedInstanceState);
33 }
34
35 @Override
36 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
37 View rootView = inflater.inflate(R.layout.fragment_grid, container, false);
38
39 findViews(rootView);
40
41 mPresenter.onCreateView();
42
43 return rootView;
44 }
45
46 @Override
47 public void onViewCreated(View view, Bundle savedInstanceState) {
48 mAdapter = new GameAdapter();
49
50 // Organize our grid layout based on the current view.
51 if (isAdded()) {
52 view.getViewTreeObserver()
53 .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
54 @Override
55 public void onGlobalLayout() {
56 if (view.getMeasuredWidth() == 0) {
57 return;
58 }
59
60 int columns = view.getMeasuredWidth() /
61 requireContext().getResources().getDimensionPixelSize(R.dimen.card_width);
62 if (columns == 0) {
63 columns = 1;
64 }
65 view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
66 GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), columns);
67 mRecyclerView.setLayoutManager(layoutManager);
68 mRecyclerView.setAdapter(mAdapter);
69 }
70 });
71 }
72
73 // Add swipe down to refresh gesture
74 final SwipeRefreshLayout pullToRefresh = view.findViewById(R.id.swipe_refresh);
75 pullToRefresh.setOnRefreshListener(() -> {
76 refresh();
77 pullToRefresh.setRefreshing(false);
78 });
79 }
80
81 @Override
82 public void refresh() {
83 GameDatabase databaseHelper = YuzuApplication.databaseHelper;
84 databaseHelper.scanLibrary(databaseHelper.getWritableDatabase());
85 mPresenter.refresh();
86 updateTextView();
87 }
88
89 @Override
90 public void showGames(Cursor games) {
91 if (mAdapter != null) {
92 mAdapter.swapCursor(games);
93 }
94 updateTextView();
95 }
96
97 private void updateTextView() {
98 mTextView.setVisibility(mAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
99 }
100
101 private void findViews(View root) {
102 mRecyclerView = root.findViewById(R.id.grid_games);
103 mTextView = root.findViewById(R.id.gamelist_empty_text);
104 }
105}
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 @@
1package org.yuzu.yuzu_emu.ui.platform
2
3import android.database.Cursor
4import android.os.Bundle
5import android.view.LayoutInflater
6import android.view.View
7import android.view.ViewGroup
8import android.view.ViewTreeObserver.OnGlobalLayoutListener
9import android.widget.TextView
10import androidx.fragment.app.Fragment
11import androidx.recyclerview.widget.GridLayoutManager
12import androidx.recyclerview.widget.RecyclerView
13import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
14import org.yuzu.yuzu_emu.R
15import org.yuzu.yuzu_emu.YuzuApplication
16import org.yuzu.yuzu_emu.adapters.GameAdapter
17
18class PlatformGamesFragment : Fragment(), PlatformGamesView {
19 private val presenter = PlatformGamesPresenter(this)
20 private var adapter: GameAdapter? = null
21 private lateinit var recyclerView: RecyclerView
22 private lateinit var textView: TextView
23
24 override fun onCreateView(
25 inflater: LayoutInflater,
26 container: ViewGroup?,
27 savedInstanceState: Bundle?
28 ): View? {
29 val rootView = inflater.inflate(R.layout.fragment_grid, container, false)
30 findViews(rootView)
31 presenter.onCreateView()
32 return rootView
33 }
34
35 override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
36 adapter = GameAdapter()
37
38 // Organize our grid layout based on the current view.
39 if (isAdded) {
40 view.viewTreeObserver
41 .addOnGlobalLayoutListener(object : OnGlobalLayoutListener {
42 override fun onGlobalLayout() {
43 if (view.measuredWidth == 0) {
44 return
45 }
46 var columns = view.measuredWidth /
47 requireContext().resources.getDimensionPixelSize(R.dimen.card_width)
48 if (columns == 0) {
49 columns = 1
50 }
51 view.viewTreeObserver.removeOnGlobalLayoutListener(this)
52 val layoutManager = GridLayoutManager(activity, columns)
53 recyclerView.layoutManager = layoutManager
54 recyclerView.adapter = adapter
55 }
56 })
57 }
58
59 // Add swipe down to refresh gesture
60 val pullToRefresh = view.findViewById<SwipeRefreshLayout>(R.id.swipe_refresh)
61 pullToRefresh.setOnRefreshListener {
62 refresh()
63 pullToRefresh.isRefreshing = false
64 }
65 }
66
67 override fun refresh() {
68 val databaseHelper = YuzuApplication.databaseHelper
69 databaseHelper!!.scanLibrary(databaseHelper.writableDatabase)
70 presenter.refresh()
71 updateTextView()
72 }
73
74 override fun showGames(games: Cursor) {
75 if (adapter != null) {
76 adapter!!.swapCursor(games)
77 }
78 updateTextView()
79 }
80
81 private fun updateTextView() {
82 textView.visibility =
83 if (adapter!!.itemCount == 0) View.VISIBLE else View.GONE
84 }
85
86 private fun findViews(root: View) {
87 recyclerView = root.findViewById(R.id.grid_games)
88 textView = root.findViewById(R.id.gamelist_empty_text)
89 }
90
91 companion object {
92 const val TAG = "PlatformGamesFragment"
93 }
94}