Refactor AddDirectoryActivity and SettingsActivity to be launched exclusively via their own launcher method

This commit is contained in:
sigmabeta 2016-01-09 20:52:59 -05:00
parent 24efce4cea
commit a455305c23
7 changed files with 59 additions and 34 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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:

View File

@ -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);
}