From a455305c23fba35b8da57515072ab707f777d7ac Mon Sep 17 00:00:00 2001 From: sigmabeta Date: Sat, 9 Jan 2016 20:52:59 -0500 Subject: [PATCH] Refactor AddDirectoryActivity and SettingsActivity to be launched exclusively via their own launcher method --- .../activities/AddDirectoryActivity.java | 8 +++++ .../activities/SettingsActivity.java | 7 +++++ .../dolphinemu/activities/TvMainActivity.java | 14 ++------- .../dolphinemu/adapters/GameAdapter.java | 1 - .../dolphinemu/ui/main/MainActivity.java | 13 +++----- .../dolphinemu/ui/main/MainPresenter.java | 20 +++++-------- .../dolphinemu/ui/main/MainView.java | 30 ++++++++++++++++++- 7 files changed, 59 insertions(+), 34 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/AddDirectoryActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/AddDirectoryActivity.java index f9308fc80e..09e833d1ad 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/AddDirectoryActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/AddDirectoryActivity.java @@ -1,5 +1,6 @@ package org.dolphinemu.dolphinemu.activities; +import android.app.Activity; import android.content.AsyncQueryHandler; import android.content.ContentValues; import android.content.Intent; @@ -19,6 +20,7 @@ import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.adapters.FileAdapter; import org.dolphinemu.dolphinemu.model.GameDatabase; import org.dolphinemu.dolphinemu.model.GameProvider; +import org.dolphinemu.dolphinemu.ui.main.MainPresenter; /** * An Activity that shows a list of files and folders, allowing the user to tell the app which folder(s) @@ -131,4 +133,10 @@ public class AddDirectoryActivity extends AppCompatActivity implements FileAdapt { mToolbar.setSubtitle(path); } + + public static void launch(Activity activity) + { + Intent fileChooser = new Intent(activity, AddDirectoryActivity.class); + activity.startActivityForResult(fileChooser, MainPresenter.REQUEST_ADD_DIRECTORY); + } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/SettingsActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/SettingsActivity.java index a595cdeb0f..c6ce27acfe 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/SettingsActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/SettingsActivity.java @@ -1,6 +1,7 @@ package org.dolphinemu.dolphinemu.activities; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; @@ -38,4 +39,10 @@ public final class SettingsActivity extends AppCompatActivity Intent settingsSaver = new Intent(this, SettingsSaveService.class); startService(settingsSaver); } + + public static void launch(Context context) + { + Intent settings = new Intent(context, SettingsActivity.class); + context.startActivity(settings); + } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/TvMainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/TvMainActivity.java index 23ad7230da..6d580eaafb 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/TvMainActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/TvMainActivity.java @@ -17,16 +17,12 @@ import android.support.v17.leanback.widget.OnItemViewClickedListener; import android.support.v17.leanback.widget.Presenter; import android.support.v17.leanback.widget.Row; import android.support.v17.leanback.widget.RowPresenter; -import android.widget.Toast; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.adapters.GameRowPresenter; import org.dolphinemu.dolphinemu.adapters.SettingsRowPresenter; import org.dolphinemu.dolphinemu.model.Game; -import org.dolphinemu.dolphinemu.model.GameDatabase; -import org.dolphinemu.dolphinemu.model.GameProvider; import org.dolphinemu.dolphinemu.model.TvSettingsItem; -import org.dolphinemu.dolphinemu.ui.main.MainActivity; import org.dolphinemu.dolphinemu.ui.main.MainPresenter; import org.dolphinemu.dolphinemu.ui.main.MainView; import org.dolphinemu.dolphinemu.utils.StartupHandler; @@ -103,7 +99,7 @@ public final class TvMainActivity extends Activity implements MainView */ @Override - public void setSubtitle(String subtitle) + public void setVersionString(String version) { // No-op } @@ -123,17 +119,13 @@ public final class TvMainActivity extends Activity implements MainView @Override public void launchSettingsActivity() { - Intent settings = new Intent(this, SettingsActivity.class); - startActivity(settings); + SettingsActivity.launch(this); } @Override public void launchFileListActivity() { - Intent fileChooser = new Intent(this, AddDirectoryActivity.class); - - // The second argument to this method is read below in onActivityResult(). - startActivityForResult(fileChooser, MainPresenter.REQUEST_ADD_DIRECTORY); + AddDirectoryActivity.launch(this); } @Override diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java index 2a0b0783c0..205447e054 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java @@ -17,7 +17,6 @@ import com.squareup.picasso.Picasso; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.activities.EmulationActivity; -import org.dolphinemu.dolphinemu.ui.main.MainActivity; import org.dolphinemu.dolphinemu.dialogs.GameDetailsDialog; import org.dolphinemu.dolphinemu.model.GameDatabase; import org.dolphinemu.dolphinemu.ui.main.MainPresenter; diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java index 1044266acf..372edd3249 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java @@ -14,7 +14,6 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; -import org.dolphinemu.dolphinemu.NativeLibrary; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.activities.AddDirectoryActivity; import org.dolphinemu.dolphinemu.activities.SettingsActivity; @@ -91,9 +90,9 @@ public final class MainActivity extends AppCompatActivity implements MainView */ @Override - public void setSubtitle(String subtitle) + public void setVersionString(String version) { - mToolbar.setSubtitle(subtitle); + mToolbar.setSubtitle(version); } @Override @@ -118,17 +117,13 @@ public final class MainActivity extends AppCompatActivity implements MainView @Override public void launchSettingsActivity() { - Intent settings = new Intent(this, SettingsActivity.class); - startActivity(settings); + SettingsActivity.launch(this); } @Override public void launchFileListActivity() { - Intent fileChooser = new Intent(this, AddDirectoryActivity.class); - - // The second argument to this method is read below in onActivityResult(). - startActivityForResult(fileChooser, MainPresenter.REQUEST_ADD_DIRECTORY); + AddDirectoryActivity.launch(this); } @Override diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java index d744d06f1b..97b7a39f25 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java @@ -1,25 +1,18 @@ package org.dolphinemu.dolphinemu.ui.main; -import android.content.Intent; import android.database.Cursor; -import android.util.Log; import org.dolphinemu.dolphinemu.DolphinApplication; import org.dolphinemu.dolphinemu.NativeLibrary; import org.dolphinemu.dolphinemu.R; -import org.dolphinemu.dolphinemu.activities.AddDirectoryActivity; -import org.dolphinemu.dolphinemu.activities.SettingsActivity; -import org.dolphinemu.dolphinemu.fragments.PlatformGamesFragment; import org.dolphinemu.dolphinemu.model.GameDatabase; -import org.dolphinemu.dolphinemu.model.GameProvider; -import org.dolphinemu.dolphinemu.ui.main.MainView; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action1; import rx.schedulers.Schedulers; -public class MainPresenter +public final class MainPresenter { public static final int REQUEST_ADD_DIRECTORY = 1; public static final int REQUEST_EMULATE_GAME = 2; @@ -36,14 +29,16 @@ public class MainPresenter // TODO Rather than calling into native code, this should use the commented line below. // String versionName = BuildConfig.VERSION_NAME; String versionName = NativeLibrary.GetVersionString(); - mView.setSubtitle(versionName); + mView.setVersionString(versionName); } - public void onFabClick() { + public void onFabClick() + { mView.launchFileListActivity(); } - public boolean handleOptionSelection(int itemId) { + public boolean handleOptionSelection(int itemId) + { switch (itemId) { case R.id.menu_settings: @@ -62,7 +57,8 @@ public class MainPresenter return false; } - public void handleActivityResult(int requestCode, int resultCode) { + public void handleActivityResult(int requestCode, int resultCode) + { switch (requestCode) { case REQUEST_ADD_DIRECTORY: diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainView.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainView.java index a29150f207..1d286bebf3 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainView.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainView.java @@ -3,17 +3,45 @@ package org.dolphinemu.dolphinemu.ui.main; import android.database.Cursor; +/** + * Abstraction for the screen that shows on application launch. + * Implementations will differ primarily to target touch-screen + * or non-touch screen devices. + */ public interface MainView { - void setSubtitle(String subtitle); + /** + * Pass the view the native library's version string. Displaying + * it is optional. + * + * @param version A string pulled from native code. + */ + void setVersionString(String version); + /** + * Tell the view to refresh its contents. + */ void refresh(); + /** + * Tell the view to tell the currently displayed {@link android.support.v4.app.Fragment} + * to refresh the screenshot at the given position in its list of games. + * + * @param fragmentPosition An index corresponding to the list or grid of games. + */ void refreshFragmentScreenshot(int fragmentPosition); + void launchSettingsActivity(); void launchFileListActivity(); + /** + * To be called when an asynchronous database read completes. Passes the + * result, in this case a {@link Cursor} to the view. + * + * @param platformIndex Which platform contains these games. + * @param games A Cursor containing the games read from the database. + */ void showGames(int platformIndex, Cursor games); }