Android: Convert PlatformPagerAdapter to Kotlin

This commit is contained in:
Charles Lombardo 2023-06-04 01:07:28 -04:00
parent ce2b63dcc0
commit e4935d4b12
2 changed files with 34 additions and 49 deletions

View File

@ -1,49 +0,0 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.adapters;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.ui.platform.Platform;
import org.dolphinemu.dolphinemu.ui.platform.PlatformGamesFragment;
public class PlatformPagerAdapter extends FragmentPagerAdapter
{
private SwipeRefreshLayout.OnRefreshListener mOnRefreshListener;
public final static int[] TAB_ICONS =
{
R.drawable.ic_gamecube,
R.drawable.ic_wii,
R.drawable.ic_folder
};
public PlatformPagerAdapter(FragmentManager fm,
SwipeRefreshLayout.OnRefreshListener onRefreshListener)
{
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
mOnRefreshListener = onRefreshListener;
}
@NonNull
@Override
public Fragment getItem(int position)
{
Platform platform = Platform.fromPosition(position);
PlatformGamesFragment fragment = PlatformGamesFragment.newInstance(platform);
fragment.setOnRefreshListener(mOnRefreshListener);
return fragment;
}
@Override
public int getCount()
{
return TAB_ICONS.length;
}
}

View File

@ -0,0 +1,34 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.adapters
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout.OnRefreshListener
import org.dolphinemu.dolphinemu.R
import org.dolphinemu.dolphinemu.ui.platform.Platform
import org.dolphinemu.dolphinemu.ui.platform.PlatformGamesFragment
class PlatformPagerAdapter(
fm: FragmentManager,
private val onRefreshListener: OnRefreshListener
) : FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
override fun getItem(position: Int): Fragment {
val platform = Platform.fromPosition(position)
val fragment = PlatformGamesFragment.newInstance(platform)
fragment.setOnRefreshListener(onRefreshListener)
return fragment
}
override fun getCount(): Int = TAB_ICONS.size
companion object {
@JvmField
val TAB_ICONS = intArrayOf(
R.drawable.ic_gamecube,
R.drawable.ic_wii,
R.drawable.ic_folder
)
}
}