Fix bugs in Setting screen & add a way to exit without saving

This commit is contained in:
sigmabeta 2016-01-24 19:31:34 -05:00
parent cf7f5d078b
commit fb04622039
17 changed files with 150 additions and 7 deletions

View File

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

View File

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

View File

@ -42,6 +42,11 @@ public interface SettingsActivityView
*/
void onSettingsFileLoaded(HashMap<String, SettingSection> 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();
}

View File

@ -128,6 +128,8 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
{
mView.putSetting(setting);
}
mView.onSettingChanged();
}
public void onSingleChoiceClick(SingleChoiceSetting item)
@ -235,6 +237,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
}
}
mView.onSettingChanged();
mClickedItem = null;
mSeekbarProgress = -1;
}

View File

@ -1,5 +1,6 @@
package org.dolphinemu.dolphinemu.ui.settings;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
@ -36,6 +37,20 @@ public final class SettingsFragment extends Fragment implements SettingsFragment
mPresenter.onAttach();
}
/**
* This version of onAttach is needed for versions below Marshmallow.
*
* @param activity
*/
@Override
public void onAttach(Activity activity)
{
super.onAttach(activity);
mActivity = (SettingsActivityView) activity;
mPresenter.onAttach();
}
@Override
public void onCreate(Bundle savedInstanceState)
{
@ -106,6 +121,12 @@ public final class SettingsFragment extends Fragment implements SettingsFragment
mAdapter.setSettings(settingsList);
}
@Override
public void loadDefaultSettings()
{
mPresenter.loadDefaultSettings();
}
@Override
public void loadSubMenu(String menuKey)
{
@ -124,6 +145,12 @@ public final class SettingsFragment extends Fragment implements SettingsFragment
mPresenter.putSetting(setting);
}
@Override
public void onSettingChanged()
{
mActivity.onSettingChanged();
}
public static final String FRAGMENT_TAG = BuildConfig.APPLICATION_ID + ".fragment.settings";
public static final String ARGUMENT_MENU_TAG = FRAGMENT_TAG + ".menu_tag";

View File

@ -59,9 +59,14 @@ public final class SettingsFragmentPresenter
mSettings.get(setting.getSection()).putSetting(setting.getKey(), setting);
}
public void loadDefaultSettings()
{
loadSettingsList();
}
public void setSettings(HashMap<String, SettingSection> settings)
{
if (mSettingsList == null)
if (mSettingsList == null && settings != null)
{
mSettings = settings;

View File

@ -39,6 +39,12 @@ public interface SettingsFragmentView
*/
void showSettingsList(ArrayList<SettingsItem> 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();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 462 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 601 B

View File

@ -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"/>
</FrameLayout>

View File

@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- TODO Please give me an icon! -->
<item
android:id="@+id/menu_up_one_level"
android:title="@string/add_directory_up_one_level"
android:showAsAction="ifRoom|withText"/>
app:showAsAction="ifRoom|withText"/>
</menu>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_exit_no_save"
android:title="@string/preferences_exit_no_save"
android:icon="@drawable/ic_cancel"
app:showAsAction="ifRoom"/>
</menu>

View File

@ -327,6 +327,7 @@
<string name="add_directory_empty_folder">That folder is empty.</string>
<!-- Preferences Screen -->
<string name="preferences_exit_no_save">Exit Without Saving</string>
<string name="preferences_cpu">CPU Settings</string>
<string name="preferences_input">Input Settings</string>
<string name="preferences_extensions">Extension Bindings</string>

View File

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