Merge pull request #540 from domdomegg/tidySettings

Remove unused code in settingsFragment
This commit is contained in:
Yusuke Matsubara 2017-05-15 00:43:57 +09:00 committed by GitHub
commit b0b6e9bfd3
6 changed files with 29 additions and 28 deletions

View file

@ -84,9 +84,9 @@ public class SettingsActivityTest {
.atPosition(0)
.perform(ViewActions.click());
// click "CC BY-4.0"
// click "Attribution 4.0"
Espresso.onView(
ViewMatchers.withText(R.string.license_name_cc_by_4_0)
ViewMatchers.withText(R.string.license_name_cc_by_four)
).perform(ViewActions.click());
// click "License" (the first item)
@ -95,10 +95,10 @@ public class SettingsActivityTest {
.atPosition(0)
.perform(ViewActions.click());
// test the value remains "CC BY-4.0"
// test the value remains "Attribution 4.0"
Espresso.onView(ViewMatchers.isChecked())
.check(ViewAssertions.matches(
ViewMatchers.withText(R.string.license_name_cc_by_4_0)
ViewMatchers.withText(R.string.license_name_cc_by_four)
));
}

View file

@ -24,24 +24,10 @@ public class SettingsFragment extends PreferenceFragment {
// Update spinner to show selected value as summary
ListPreference licensePreference = (ListPreference) findPreference(Prefs.DEFAULT_LICENSE);
// WARNING: ORDERING NEEDS TO MATCH FOR THE LICENSE NAMES AND DISPLAY VALUES
licensePreference.setEntries(new String[]{
getString(R.string.license_name_cc0),
getString(R.string.license_name_cc_by_3_0),
getString(R.string.license_name_cc_by_4_0),
getString(R.string.license_name_cc_by_sa_3_0),
getString(R.string.license_name_cc_by_sa_4_0)
});
licensePreference.setEntryValues(new String[]{
Prefs.Licenses.CC0,
Prefs.Licenses.CC_BY_3,
Prefs.Licenses.CC_BY_4,
Prefs.Licenses.CC_BY_SA_3,
Prefs.Licenses.CC_BY_SA_4
});
licensePreference.setSummary(getString(Utils.licenseNameFor(licensePreference.getValue())));
licensePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener(){
// Keep summary updated when changing value
licensePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
preference.setSummary(getString(Utils.licenseNameFor((String) newValue)));
@ -97,4 +83,4 @@ public class SettingsFragment extends PreferenceFragment {
}
}
}

View file

@ -115,6 +115,13 @@ public class SingleUploadFragment extends Fragment {
licenseSpinner.setAdapter(adapter);
int position = licenseItems.indexOf(getString(Utils.licenseNameFor(license)));
// Check position is valid
if (position < 0) {
Timber.d("Invalid position: %d. Using default license", position);
position = 4;
}
Timber.d("Position: %d %s", position, getString(Utils.licenseNameFor(license)));
licenseSpinner.setSelection(position);

View file

@ -8,10 +8,10 @@
<item>@string/license_name_cc_by_sa_four</item>
</array>
<array name="pref_defaultLicense_values">
<item>@string/license_name_cc0</item>
<item>@string/license_name_cc_by_3_0</item>
<item>@string/license_name_cc_by_4_0</item>
<item>@string/license_name_cc_by_sa_3_0</item>
<item>@string/license_name_cc_by_sa_4_0</item>
<item>@string/license_pref_cc0</item>
<item>@string/license_pref_cc_by_3_0</item>
<item>@string/license_pref_cc_by_4_0</item>
<item>@string/license_pref_cc_by_sa_3_0</item>
<item>@string/license_pref_cc_by_sa_4_0</item>
</array>
</resources>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="license_pref_cc0" translatable="false">CC0</string>
<string name="license_pref_cc_by_3_0" translatable="false">CC BY 3.0</string>
<string name="license_pref_cc_by_sa_3_0" translatable="false">CC BY-SA 3.0</string>
<string name="license_pref_cc_by_4_0" translatable="false">CC BY 4.0</string>
<string name="license_pref_cc_by_sa_4_0" translatable="false">CC BY-SA 4.0</string>
</resources>

View file

@ -8,7 +8,7 @@
android:title="@string/preference_license"
android:entries="@array/pref_defaultLicense_entries"
android:entryValues="@array/pref_defaultLicense_values"
android:defaultValue="@string/license_name_cc_by_sa_4_0"
android:defaultValue="@string/license_pref_cc_by_sa_4_0"
/>
<CheckBoxPreference