mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-15 05:47:56 -07:00
Android: Make last platform tab selection an INI setting
This commit is contained in:
parent
bebeb935a5
commit
53ccc7a2d1
@ -39,6 +39,8 @@ public final class SettingsFile
|
||||
public static final String FILE_NAME_GCPAD = "GCPadNew";
|
||||
public static final String FILE_NAME_WIIMOTE = "WiimoteNew";
|
||||
|
||||
public static final String KEY_DSP_ENGINE = "DSPEngine";
|
||||
public static final String KEY_LAST_PLATFORM_TAB = "LastPlatformTab";
|
||||
|
||||
public static final String KEY_CPU_CORE = "CPUCore";
|
||||
public static final String KEY_DUAL_CORE = "CPUThread";
|
||||
@ -47,7 +49,6 @@ public final class SettingsFile
|
||||
public static final String KEY_SPEED_LIMIT = "EmulationSpeed";
|
||||
public static final String KEY_VIDEO_BACKEND = "GFXBackend";
|
||||
|
||||
public static final String KEY_DSP_ENGINE = "DSPEngine";
|
||||
public static final String KEY_DSP_HLE = "DSPHLE";
|
||||
public static final String KEY_DSP_ENABLE_JIT = "EnableJIT";
|
||||
public static final String KEY_AUDIO_STRETCH = "AudioStretch";
|
||||
|
@ -4,6 +4,7 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
@ -16,14 +17,17 @@ import androidx.appcompat.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.dolphinemu.dolphinemu.NativeLibrary;
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
|
||||
import org.dolphinemu.dolphinemu.adapters.PlatformPagerAdapter;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivity;
|
||||
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
|
||||
import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner;
|
||||
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
|
||||
import org.dolphinemu.dolphinemu.services.GameFileCacheService;
|
||||
import org.dolphinemu.dolphinemu.ui.platform.Platform;
|
||||
@ -55,8 +59,6 @@ public final class MainActivity extends AppCompatActivity implements MainView
|
||||
|
||||
setSupportActionBar(mToolbar);
|
||||
|
||||
mTabLayout.setupWithViewPager(mViewPager);
|
||||
|
||||
// Set up the FAB.
|
||||
mFab.setOnClickListener(view -> mPresenter.onFabClick());
|
||||
|
||||
@ -68,16 +70,8 @@ public final class MainActivity extends AppCompatActivity implements MainView
|
||||
|
||||
if (PermissionsHandler.hasWriteAccess(this))
|
||||
{
|
||||
PlatformPagerAdapter platformPagerAdapter = new PlatformPagerAdapter(
|
||||
getSupportFragmentManager(), this);
|
||||
mViewPager.setAdapter(platformPagerAdapter);
|
||||
mViewPager.setOffscreenPageLimit(platformPagerAdapter.getCount());
|
||||
showGames();
|
||||
GameFileCacheService.startLoad(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
mViewPager.setVisibility(View.INVISIBLE);
|
||||
new AfterDirectoryInitializationRunner()
|
||||
.run(this, this::setPlatformTabsAndStartGameFileCacheService);
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,29 +196,22 @@ public final class MainActivity extends AppCompatActivity implements MainView
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
|
||||
{
|
||||
switch (requestCode)
|
||||
if (requestCode == PermissionsHandler.REQUEST_CODE_WRITE_PERMISSION)
|
||||
{
|
||||
case PermissionsHandler.REQUEST_CODE_WRITE_PERMISSION:
|
||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
|
||||
{
|
||||
DirectoryInitialization.start(this);
|
||||
PlatformPagerAdapter platformPagerAdapter = new PlatformPagerAdapter(
|
||||
getSupportFragmentManager(), this);
|
||||
mViewPager.setAdapter(platformPagerAdapter);
|
||||
mViewPager.setOffscreenPageLimit(platformPagerAdapter.getCount());
|
||||
mTabLayout.setupWithViewPager(mViewPager);
|
||||
mViewPager.setVisibility(View.VISIBLE);
|
||||
GameFileCacheService.startLoad(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
Toast.makeText(this, R.string.write_permission_needed, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
break;
|
||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
|
||||
{
|
||||
DirectoryInitialization.start(this);
|
||||
new AfterDirectoryInitializationRunner()
|
||||
.run(this, this::setPlatformTabsAndStartGameFileCacheService);
|
||||
}
|
||||
else
|
||||
{
|
||||
Toast.makeText(this, R.string.write_permission_needed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
}
|
||||
|
||||
@ -259,4 +246,41 @@ public final class MainActivity extends AppCompatActivity implements MainView
|
||||
|
||||
return (PlatformGamesView) getSupportFragmentManager().findFragmentByTag(fragmentTag);
|
||||
}
|
||||
|
||||
// Don't call this before DirectoryInitialization completes.
|
||||
private void setPlatformTabsAndStartGameFileCacheService()
|
||||
{
|
||||
PlatformPagerAdapter platformPagerAdapter = new PlatformPagerAdapter(
|
||||
getSupportFragmentManager(), this);
|
||||
mViewPager.setAdapter(platformPagerAdapter);
|
||||
mViewPager.setOffscreenPageLimit(platformPagerAdapter.getCount());
|
||||
mTabLayout.setupWithViewPager(mViewPager);
|
||||
mTabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager)
|
||||
{
|
||||
@Override
|
||||
public void onTabSelected(@NonNull TabLayout.Tab tab)
|
||||
{
|
||||
super.onTabSelected(tab);
|
||||
NativeLibrary
|
||||
.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_ANDROID,
|
||||
SettingsFile.KEY_LAST_PLATFORM_TAB, Integer.toString(tab.getPosition()));
|
||||
}
|
||||
});
|
||||
|
||||
String platformTab = NativeLibrary
|
||||
.GetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_ANDROID,
|
||||
SettingsFile.KEY_LAST_PLATFORM_TAB, "0");
|
||||
|
||||
try
|
||||
{
|
||||
mViewPager.setCurrentItem(Integer.parseInt(platformTab));
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
mViewPager.setCurrentItem(0);
|
||||
}
|
||||
|
||||
showGames();
|
||||
GameFileCacheService.startLoad(this);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user