Merge pull request #11887 from t895/kotlin-activities
Android: Convert "activities" package to Kotlin
This commit is contained in:
commit
ce2b63dcc0
|
@ -1,128 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.activities;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import org.dolphinemu.dolphinemu.model.GameFile;
|
||||
import org.dolphinemu.dolphinemu.services.GameFileCacheManager;
|
||||
import org.dolphinemu.dolphinemu.ui.main.TvMainActivity;
|
||||
import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner;
|
||||
import org.dolphinemu.dolphinemu.utils.AppLinkHelper;
|
||||
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
|
||||
|
||||
/**
|
||||
* Linker between leanback homescreen and app
|
||||
*/
|
||||
public class AppLinkActivity extends FragmentActivity
|
||||
{
|
||||
private static final String TAG = "AppLinkActivity";
|
||||
|
||||
private AppLinkHelper.PlayAction playAction;
|
||||
private AfterDirectoryInitializationRunner mAfterDirectoryInitializationRunner;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Intent intent = getIntent();
|
||||
Uri uri = intent.getData();
|
||||
|
||||
Log.v(TAG, uri.toString());
|
||||
|
||||
if (uri.getPathSegments().isEmpty())
|
||||
{
|
||||
Log.e(TAG, "Invalid uri " + uri);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
AppLinkHelper.AppLinkAction action = AppLinkHelper.extractAction(uri);
|
||||
switch (action.getAction())
|
||||
{
|
||||
case AppLinkHelper.PLAY:
|
||||
playAction = (AppLinkHelper.PlayAction) action;
|
||||
initResources();
|
||||
break;
|
||||
case AppLinkHelper.BROWSE:
|
||||
browse();
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid Action " + action);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Need to init these since they usually occur in the main activity.
|
||||
*/
|
||||
private void initResources()
|
||||
{
|
||||
mAfterDirectoryInitializationRunner = new AfterDirectoryInitializationRunner();
|
||||
mAfterDirectoryInitializationRunner.runWithLifecycle(this, () -> tryPlay(playAction));
|
||||
|
||||
GameFileCacheManager.isLoading().observe(this, (isLoading) ->
|
||||
{
|
||||
if (!isLoading && DirectoryInitialization.areDolphinDirectoriesReady())
|
||||
{
|
||||
tryPlay(playAction);
|
||||
}
|
||||
});
|
||||
|
||||
DirectoryInitialization.start(this);
|
||||
GameFileCacheManager.startLoad();
|
||||
}
|
||||
|
||||
/**
|
||||
* Action if channel icon is selected
|
||||
*/
|
||||
private void browse()
|
||||
{
|
||||
Intent openApp = new Intent(this, TvMainActivity.class);
|
||||
startActivity(openApp);
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
private void tryPlay(AppLinkHelper.PlayAction action)
|
||||
{
|
||||
// TODO: This approach of getting the game from the game file cache without rescanning the
|
||||
// library means that we can fail to launch games if the cache file has been deleted.
|
||||
|
||||
GameFile game = GameFileCacheManager.getGameFileByGameId(action.getGameId());
|
||||
|
||||
// If game == null and the load isn't done, wait for the next GameFileCacheService broadcast.
|
||||
// If game == null and the load is done, call play with a null game, making us exit in failure.
|
||||
if (game != null || !GameFileCacheManager.isLoading().getValue())
|
||||
{
|
||||
play(action, game);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action if program(game) is selected
|
||||
*/
|
||||
private void play(AppLinkHelper.PlayAction action, GameFile game)
|
||||
{
|
||||
Log.d(TAG, "Playing game "
|
||||
+ action.getGameId()
|
||||
+ " from channel "
|
||||
+ action.getChannelId());
|
||||
|
||||
if (game == null)
|
||||
Log.e(TAG, "Invalid Game: " + action.getGameId());
|
||||
else
|
||||
startGame(game);
|
||||
finish();
|
||||
}
|
||||
|
||||
private void startGame(GameFile game)
|
||||
{
|
||||
mAfterDirectoryInitializationRunner.cancel();
|
||||
EmulationActivity.launch(this, GameFileCacheManager.findSecondDiscAndGetPaths(game), false);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.activities
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import org.dolphinemu.dolphinemu.model.GameFile
|
||||
import org.dolphinemu.dolphinemu.services.GameFileCacheManager
|
||||
import org.dolphinemu.dolphinemu.ui.main.TvMainActivity
|
||||
import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner
|
||||
import org.dolphinemu.dolphinemu.utils.AppLinkHelper
|
||||
import org.dolphinemu.dolphinemu.utils.AppLinkHelper.PlayAction
|
||||
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization
|
||||
|
||||
/**
|
||||
* Linker between leanback homescreen and app
|
||||
*/
|
||||
class AppLinkActivity : FragmentActivity() {
|
||||
private lateinit var playAction: PlayAction
|
||||
private lateinit var afterDirectoryInitializationRunner: AfterDirectoryInitializationRunner
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val uri = intent.data!!
|
||||
|
||||
Log.v(TAG, uri.toString())
|
||||
|
||||
if (uri.pathSegments.isEmpty()) {
|
||||
Log.e(TAG, "Invalid uri $uri")
|
||||
finish()
|
||||
return
|
||||
}
|
||||
|
||||
val action = AppLinkHelper.extractAction(uri)
|
||||
when (action.action) {
|
||||
AppLinkHelper.PLAY -> {
|
||||
playAction = action as PlayAction
|
||||
initResources()
|
||||
}
|
||||
|
||||
AppLinkHelper.BROWSE -> browse()
|
||||
else -> throw IllegalArgumentException("Invalid Action $action")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Need to init these since they usually occur in the main activity.
|
||||
*/
|
||||
private fun initResources() {
|
||||
afterDirectoryInitializationRunner = AfterDirectoryInitializationRunner()
|
||||
afterDirectoryInitializationRunner.runWithLifecycle(this) { tryPlay(playAction) }
|
||||
|
||||
GameFileCacheManager.isLoading().observe(this) { isLoading: Boolean? ->
|
||||
if (!isLoading!! && DirectoryInitialization.areDolphinDirectoriesReady()) {
|
||||
tryPlay(playAction)
|
||||
}
|
||||
}
|
||||
|
||||
DirectoryInitialization.start(this)
|
||||
GameFileCacheManager.startLoad()
|
||||
}
|
||||
|
||||
/**
|
||||
* Action if channel icon is selected
|
||||
*/
|
||||
private fun browse() {
|
||||
val openApp = Intent(this, TvMainActivity::class.java)
|
||||
startActivity(openApp)
|
||||
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun tryPlay(action: PlayAction) {
|
||||
// TODO: This approach of getting the game from the game file cache without rescanning the
|
||||
// library means that we can fail to launch games if the cache file has been deleted.
|
||||
val game = GameFileCacheManager.getGameFileByGameId(action.gameId)
|
||||
|
||||
// If game == null and the load isn't done, wait for the next GameFileCacheService broadcast.
|
||||
// If game == null and the load is done, call play with a null game, making us exit in failure.
|
||||
if (game != null || !GameFileCacheManager.isLoading().value!!) {
|
||||
play(action, game)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action if program(game) is selected
|
||||
*/
|
||||
private fun play(action: PlayAction, game: GameFile?) {
|
||||
Log.d(TAG, "Playing game ${action.gameId} from channel ${action.channelId}")
|
||||
game?.let { startGame(it) } ?: Log.e(TAG, "Invalid Game: " + action.gameId)
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun startGame(game: GameFile) {
|
||||
afterDirectoryInitializationRunner.cancel()
|
||||
EmulationActivity.launch(this, GameFileCacheManager.findSecondDiscAndGetPaths(game), false)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "AppLinkActivity"
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.activities;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.nononsenseapps.filepicker.AbstractFilePickerFragment;
|
||||
import com.nononsenseapps.filepicker.FilePickerActivity;
|
||||
|
||||
import org.dolphinemu.dolphinemu.fragments.CustomFilePickerFragment;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class CustomFilePickerActivity extends FilePickerActivity
|
||||
{
|
||||
public static final String EXTRA_EXTENSIONS = "dolphinemu.org.filepicker.extensions";
|
||||
|
||||
private HashSet<String> mExtensions;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Intent intent = getIntent();
|
||||
if (intent != null)
|
||||
{
|
||||
mExtensions = (HashSet<String>) intent.getSerializableExtra(EXTRA_EXTENSIONS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractFilePickerFragment<File> getFragment(
|
||||
@Nullable final String startPath, final int mode, final boolean allowMultiple,
|
||||
final boolean allowCreateDir, final boolean allowExistingFile,
|
||||
final boolean singleClick)
|
||||
{
|
||||
CustomFilePickerFragment fragment = new CustomFilePickerFragment();
|
||||
// startPath is allowed to be null. In that case, default folder should be SD-card and not "/"
|
||||
fragment.setArgs(
|
||||
startPath != null ? startPath : Environment.getExternalStorageDirectory().getPath(),
|
||||
mode, allowMultiple, allowCreateDir, allowExistingFile, singleClick);
|
||||
fragment.setExtensions(mExtensions);
|
||||
return fragment;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import com.nononsenseapps.filepicker.AbstractFilePickerFragment
|
||||
import com.nononsenseapps.filepicker.FilePickerActivity
|
||||
import org.dolphinemu.dolphinemu.fragments.CustomFilePickerFragment
|
||||
import java.io.File
|
||||
|
||||
class CustomFilePickerActivity : FilePickerActivity() {
|
||||
private var extensions: HashSet<String>? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (intent != null) {
|
||||
extensions = intent.getSerializableExtra(EXTRA_EXTENSIONS) as HashSet<String>?
|
||||
}
|
||||
}
|
||||
|
||||
override fun getFragment(
|
||||
startPath: String?,
|
||||
mode: Int,
|
||||
allowMultiple: Boolean,
|
||||
allowCreateDir: Boolean,
|
||||
allowExistingFile: Boolean,
|
||||
singleClick: Boolean
|
||||
): AbstractFilePickerFragment<File> {
|
||||
val fragment = CustomFilePickerFragment()
|
||||
// startPath is allowed to be null. In that case, default folder should be SD-card and not "/"
|
||||
fragment.setArgs(
|
||||
startPath ?: Environment.getExternalStorageDirectory().path,
|
||||
mode,
|
||||
allowMultiple,
|
||||
allowCreateDir,
|
||||
allowExistingFile,
|
||||
singleClick
|
||||
)
|
||||
fragment.setExtensions(extensions)
|
||||
return fragment
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val EXTRA_EXTENSIONS = "dolphinemu.org.filepicker.extensions"
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -50,7 +50,7 @@ class RiivolutionBootActivity : AppCompatActivity() {
|
|||
binding.textSdRoot.text = getString(R.string.riivolution_sd_root, "$loadPath/Riivolution")
|
||||
binding.buttonStart.setOnClickListener {
|
||||
if (patches != null) patches!!.saveConfig()
|
||||
EmulationActivity.launch(this, path, true)
|
||||
EmulationActivity.launch(this, path!!, true)
|
||||
}
|
||||
|
||||
lifecycleScope.launch {
|
||||
|
|
|
@ -319,7 +319,8 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
|||
}
|
||||
else
|
||||
{
|
||||
if (!EmulationActivity.getHasUserPausedEmulation() && !NativeLibrary.IsShowingAlertMessage())
|
||||
if (!EmulationActivity.Companion.getHasUserPausedEmulation() &&
|
||||
!NativeLibrary.IsShowingAlertMessage())
|
||||
{
|
||||
Log.debug("[EmulationFragment] Resuming emulation.");
|
||||
NativeLibrary.UnPauseEmulation();
|
||||
|
|
|
@ -196,7 +196,7 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
|
|||
|
||||
private void updatePauseUnpauseVisibility()
|
||||
{
|
||||
boolean paused = EmulationActivity.getHasUserPausedEmulation();
|
||||
boolean paused = EmulationActivity.Companion.getHasUserPausedEmulation();
|
||||
|
||||
mBinding.menuUnpauseEmulation.setVisibility(paused ? View.VISIBLE : View.GONE);
|
||||
mBinding.menuPauseEmulation.setVisibility(paused ? View.GONE : View.VISIBLE);
|
||||
|
|
Loading…
Reference in New Issue