Refactor EmulationActivity to be launched exclusively by its static launcher method

This commit is contained in:
sigmabeta 2016-01-10 13:00:01 -05:00
parent e34abd5739
commit 7ff558886a
5 changed files with 41 additions and 40 deletions

View File

@ -1,5 +1,7 @@
package org.dolphinemu.dolphinemu.activities;
import android.app.Activity;
import android.app.ActivityOptions;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
@ -30,6 +32,7 @@ import org.dolphinemu.dolphinemu.fragments.EmulationFragment;
import org.dolphinemu.dolphinemu.fragments.LoadStateFragment;
import org.dolphinemu.dolphinemu.fragments.MenuFragment;
import org.dolphinemu.dolphinemu.fragments.SaveStateFragment;
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
import java.util.List;
@ -659,4 +662,21 @@ public final class EmulationActivity extends AppCompatActivity
{
return mSelectedTitle;
}
public static void launch(Activity activity, String path, String title, String screenshotPath, int position, View sharedView)
{
Intent launcher = new Intent(activity, EmulationActivity.class);
launcher.putExtra("SelectedGame", path);
launcher.putExtra("SelectedTitle", title);
launcher.putExtra("ScreenPath", screenshotPath);
launcher.putExtra("GridPosition", position);
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(
activity,
sharedView,
"image_game_screenshot");
activity.startActivityForResult(launcher, MainPresenter.REQUEST_EMULATE_GAME, options.toBundle());
}
}

View File

@ -1,8 +1,6 @@
package org.dolphinemu.dolphinemu.adapters;
import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Intent;
import android.database.Cursor;
import android.database.DataSetObserver;
import android.graphics.Bitmap;
@ -19,7 +17,6 @@ import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
import org.dolphinemu.dolphinemu.dialogs.GameDetailsDialog;
import org.dolphinemu.dolphinemu.model.GameDatabase;
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
import org.dolphinemu.dolphinemu.viewholders.GameViewHolder;
/**
@ -217,22 +214,12 @@ public final class GameAdapter extends RecyclerView.Adapter<GameViewHolder> impl
{
GameViewHolder holder = (GameViewHolder) view.getTag();
// Start the emulation activity and send the path of the clicked ISO to it.
Intent intent = new Intent(view.getContext(), EmulationActivity.class);
intent.putExtra("SelectedGame", holder.path);
intent.putExtra("SelectedTitle", holder.title);
intent.putExtra("ScreenPath", holder.screenshotPath);
intent.putExtra("GridPosition", holder.getAdapterPosition());
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(
(Activity) view.getContext(),
holder.imageScreenshot,
"image_game_screenshot");
((Activity) view.getContext()).startActivityForResult(intent,
MainPresenter.REQUEST_EMULATE_GAME,
options.toBundle());
EmulationActivity.launch((Activity) view.getContext(),
holder.path,
holder.title,
holder.screenshotPath,
holder.getAdapterPosition(),
holder.imageScreenshot);
}
/**

View File

@ -14,7 +14,7 @@ import org.dolphinemu.dolphinemu.viewholders.TvGameViewHolder;
/**
* The Leanback library / docs call this a Presenter, but it works very
* similarly to a RecyclerView.ViewHolder.
* similarly to a RecyclerView.Adapter.
*/
public final class GameRowPresenter extends Presenter
{

View File

@ -4,7 +4,6 @@ package org.dolphinemu.dolphinemu.dialogs;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.view.View;
@ -70,18 +69,19 @@ public final class GameDetailsDialog extends DialogFragment
textDescription.setText(getArguments().getString(ARGUMENT_GAME_DESCRIPTION));
textCountry.setText(country);
textDate.setText(getArguments().getString(ARGUMENT_GAME_DATE));
buttonLaunch.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
// Start the emulation activity and send the path of the clicked ROM to it.
Intent intent = new Intent(view.getContext(), EmulationActivity.class);
intent.putExtra("SelectedGame", getArguments().getString(ARGUMENT_GAME_PATH));
intent.putExtra("SelectedTitle", getArguments().getString(ARGUMENT_GAME_TITLE));
startActivity(intent);
EmulationActivity.launch(getActivity(),
getArguments().getString(ARGUMENT_GAME_PATH),
getArguments().getString(ARGUMENT_GAME_TITLE),
getArguments().getString(ARGUMENT_GAME_SCREENSHOT_PATH),
-1,
imageGameScreen);
}
});

View File

@ -1,7 +1,6 @@
package org.dolphinemu.dolphinemu.ui.main;
import android.app.Activity;
import android.app.ActivityOptions;
import android.app.FragmentManager;
import android.content.Intent;
import android.database.Cursor;
@ -73,19 +72,14 @@ public final class TvMainActivity extends Activity implements MainView
else
{
TvGameViewHolder holder = (TvGameViewHolder) itemViewHolder;
// Start the emulation activity and send the path of the clicked ISO to it.
Intent intent = new Intent(TvMainActivity.this, EmulationActivity.class);
intent.putExtra("SelectedGame", holder.path);
intent.putExtra("SelectedTitle", holder.title);
intent.putExtra("ScreenPath", holder.screenshotPath);
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(
TvMainActivity.this,
holder.imageScreenshot,
"image_game_screenshot");
startActivity(intent, options.toBundle());
EmulationActivity.launch(TvMainActivity.this,
holder.path,
holder.title,
holder.screenshotPath,
-1,
holder.imageScreenshot);
}
}
});