diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java index 95e4d04746..b1103998b3 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java @@ -25,7 +25,6 @@ import org.dolphinemu.dolphinemu.adapters.SettingsRowPresenter; import org.dolphinemu.dolphinemu.model.Game; import org.dolphinemu.dolphinemu.model.TvSettingsItem; import org.dolphinemu.dolphinemu.ui.settings.SettingsActivity; -import org.dolphinemu.dolphinemu.utils.SettingsFile; import org.dolphinemu.dolphinemu.utils.StartupHandler; import org.dolphinemu.dolphinemu.viewholders.TvGameViewHolder; @@ -115,7 +114,7 @@ public final class TvMainActivity extends Activity implements MainView @Override public void launchSettingsActivity(String menuTag) { - SettingsActivity.launch(this, SettingsFile.FILE_NAME_DOLPHIN); + SettingsActivity.launch(this, menuTag); } @Override @@ -236,7 +235,7 @@ public final class TvMainActivity extends Activity implements MainView rowItems.add(new TvSettingsItem(R.id.menu_settings_video, R.drawable.ic_settings_graphics_tv, - R.string.grid_menu_core_settings)); + R.string.grid_menu_video_settings)); rowItems.add(new TvSettingsItem(R.id.button_add_directory, R.drawable.ic_add_tv, diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivity.java index 9af89ae48a..c84c145f6e 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivity.java @@ -6,6 +6,9 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.widget.Toast; import org.dolphinemu.dolphinemu.BuildConfig; @@ -32,6 +35,27 @@ public final class SettingsActivity extends AppCompatActivity implements Setting mPresenter.onCreate(savedInstanceState, filename); } + @Override + public boolean onCreateOptionsMenu(Menu menu) + { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.menu_settings, menu); + + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) + { + return mPresenter.handleOptionsItem(item.getItemId()); + } + + @Override + protected void onSaveInstanceState(Bundle outState) + { + mPresenter.saveState(outState); + } + /** * If this is called, the user has left the settings screen (potentially through the * home button) and will expect their changes to be persisted. So we kick off an @@ -96,6 +120,17 @@ public final class SettingsActivity extends AppCompatActivity implements Setting } } + @Override + public void onSettingsFileNotFound() + { + SettingsFragmentView fragment = getFragment(); + + if (fragment != null) + { + fragment.loadDefaultSettings(); + } + } + @Override public void showToastMessage(String message) { @@ -108,6 +143,12 @@ public final class SettingsActivity extends AppCompatActivity implements Setting getFragmentManager().popBackStackImmediate(); } + @Override + public void onSettingChanged() + { + mPresenter.onSettingChanged(); + } + private SettingsFragment getFragment() { return (SettingsFragment) getFragmentManager().findFragmentByTag(SettingsFragment.FRAGMENT_TAG); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivityPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivityPresenter.java index 46d95e47f6..8c16443cec 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivityPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivityPresenter.java @@ -3,6 +3,8 @@ package org.dolphinemu.dolphinemu.ui.settings; import android.os.Bundle; +import org.dolphinemu.dolphinemu.BuildConfig; +import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.model.settings.SettingSection; import org.dolphinemu.dolphinemu.utils.Log; import org.dolphinemu.dolphinemu.utils.SettingsFile; @@ -15,6 +17,8 @@ import rx.schedulers.Schedulers; public final class SettingsActivityPresenter { + private static final String SHOULD_SAVE = BuildConfig.APPLICATION_ID + ".should_save"; + private SettingsActivityView mView; private String mFileName; @@ -22,6 +26,8 @@ public final class SettingsActivityPresenter private int mStackCount; + private boolean mShouldSave; + public SettingsActivityPresenter(SettingsActivityView view) { mView = view; @@ -51,12 +57,16 @@ public final class SettingsActivityPresenter public void call(Throwable throwable) { Log.error("[SettingsActivityPresenter] Error reading file " + filename + ".ini: "+ throwable.getMessage()); - mView.onSettingsFileLoaded(null); + mView.onSettingsFileNotFound(); } }); mView.showSettingsFragment(mFileName, false); } + else + { + mShouldSave = savedInstanceState.getBoolean(SHOULD_SAVE); + } } public void setSettings(HashMap settings) @@ -71,7 +81,7 @@ public final class SettingsActivityPresenter public void onStop(boolean finishing) { - if (mSettingsBySection != null && finishing) + if (mSettingsBySection != null && finishing && mShouldSave) { Log.debug("[SettingsActivity] Settings activity stopping. Saving settings to INI..."); SettingsFile.saveFile(mFileName, mSettingsBySection) @@ -114,4 +124,27 @@ public final class SettingsActivityPresenter mView.finish(); } } + + public boolean handleOptionsItem(int itemId) + { + switch (itemId) + { + case R.id.menu_exit_no_save: + mShouldSave = false; + mView.finish(); + return true; + } + + return false; + } + + public void onSettingChanged() + { + mShouldSave = true; + } + + public void saveState(Bundle outState) + { + outState.putBoolean(SHOULD_SAVE, mShouldSave); + } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivityView.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivityView.java index 84221b0220..0a14440087 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivityView.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivityView.java @@ -42,6 +42,11 @@ public interface SettingsActivityView */ void onSettingsFileLoaded(HashMap settings); + /** + * Called when an asynchronous load operation fails. + */ + void onSettingsFileNotFound(); + /** * Display a popup text message on screen. * @@ -58,4 +63,10 @@ public interface SettingsActivityView * End the activity. */ void finish(); + + /** + * Called by a containing Fragment to tell the Activity that a setting was changed; + * unless this has been called, the Activity will not save to disk. + */ + void onSettingChanged(); } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsAdapter.java index c83c578f06..72ff6049b1 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsAdapter.java @@ -128,6 +128,8 @@ public final class SettingsAdapter extends RecyclerView.Adapter settings) { - if (mSettingsList == null) + if (mSettingsList == null && settings != null) { mSettings = settings; diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragmentView.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragmentView.java index c437863c94..66ea466b54 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragmentView.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragmentView.java @@ -39,6 +39,12 @@ public interface SettingsFragmentView */ void showSettingsList(ArrayList settingsList); + /** + * Called by the containing Activity when an asynchronous load operation fails. + * Instructs the Fragment to load the settings screen with defaults selected. + */ + void loadDefaultSettings(); + /** * @return The Fragment's containing activity. */ @@ -65,4 +71,9 @@ public interface SettingsFragmentView * @param setting The (possibly previously missing) new setting. */ void putSetting(Setting setting); + + /** + * Have the fragment tell the containing Activity that a setting was modified. + */ + void onSettingChanged(); } diff --git a/Source/Android/app/src/main/res/drawable-hdpi/ic_cancel.png b/Source/Android/app/src/main/res/drawable-hdpi/ic_cancel.png new file mode 100644 index 0000000000..fc5a294ed5 Binary files /dev/null and b/Source/Android/app/src/main/res/drawable-hdpi/ic_cancel.png differ diff --git a/Source/Android/app/src/main/res/drawable-mdpi/ic_cancel.png b/Source/Android/app/src/main/res/drawable-mdpi/ic_cancel.png new file mode 100644 index 0000000000..9813279c0d Binary files /dev/null and b/Source/Android/app/src/main/res/drawable-mdpi/ic_cancel.png differ diff --git a/Source/Android/app/src/main/res/drawable-xhdpi/ic_cancel.png b/Source/Android/app/src/main/res/drawable-xhdpi/ic_cancel.png new file mode 100644 index 0000000000..0b00a33a72 Binary files /dev/null and b/Source/Android/app/src/main/res/drawable-xhdpi/ic_cancel.png differ diff --git a/Source/Android/app/src/main/res/drawable-xxhdpi/ic_cancel.png b/Source/Android/app/src/main/res/drawable-xxhdpi/ic_cancel.png new file mode 100644 index 0000000000..717c7b5919 Binary files /dev/null and b/Source/Android/app/src/main/res/drawable-xxhdpi/ic_cancel.png differ diff --git a/Source/Android/app/src/main/res/drawable-xxxhdpi/ic_cancel.png b/Source/Android/app/src/main/res/drawable-xxxhdpi/ic_cancel.png new file mode 100644 index 0000000000..9ef2d8f9fb Binary files /dev/null and b/Source/Android/app/src/main/res/drawable-xxxhdpi/ic_cancel.png differ diff --git a/Source/Android/app/src/main/res/layout/fragment_grid.xml b/Source/Android/app/src/main/res/layout/fragment_grid.xml index eb46ff8458..3711602198 100644 --- a/Source/Android/app/src/main/res/layout/fragment_grid.xml +++ b/Source/Android/app/src/main/res/layout/fragment_grid.xml @@ -11,5 +11,5 @@ android:layout_height="match_parent" android:layout_marginLeft="@dimen/activity_horizontal_margin" android:layout_marginRight="@dimen/activity_horizontal_margin" - tools:listitem="@layout/grid_card_game"/> + tools:listitem="@layout/card_game"/> \ No newline at end of file diff --git a/Source/Android/app/src/main/res/menu/menu_add_directory.xml b/Source/Android/app/src/main/res/menu/menu_add_directory.xml index 667d28a4f0..7bc27379d1 100644 --- a/Source/Android/app/src/main/res/menu/menu_add_directory.xml +++ b/Source/Android/app/src/main/res/menu/menu_add_directory.xml @@ -1,8 +1,9 @@ - + + app:showAsAction="ifRoom|withText"/> \ No newline at end of file diff --git a/Source/Android/app/src/main/res/menu/menu_settings.xml b/Source/Android/app/src/main/res/menu/menu_settings.xml new file mode 100644 index 0000000000..13353030ac --- /dev/null +++ b/Source/Android/app/src/main/res/menu/menu_settings.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml index cf98d53bb9..db5cc8355a 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -327,6 +327,7 @@ That folder is empty. + Exit Without Saving CPU Settings Input Settings Extension Bindings diff --git a/Source/Android/build.gradle b/Source/Android/build.gradle index 04b57996fc..469472dc22 100644 --- a/Source/Android/build.gradle +++ b/Source/Android/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.0.0-alpha5' + classpath 'com.android.tools.build:gradle:2.0.0-alpha7' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files