Skip to content

Commit dabcd43

Browse files
cypheropdomdomegg
authored andcommitted
Removed default license settings, and implemented selecting last selected license as default licence(commons-app#2170) (commons-app#2218)
* Removed default license settings, and implemented selecting last selected license as default licence(commons-app#2170) * Replace settings license tests with recent upload limit test
1 parent f5c8e7a commit dabcd43

File tree

4 files changed

+32
-53
lines changed

4 files changed

+32
-53
lines changed

app/src/androidTest/java/fr/free/nrw/commons/SettingsActivityTest.java

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
import android.content.SharedPreferences;
44
import android.preference.PreferenceManager;
55
import android.support.test.espresso.Espresso;
6-
import android.support.test.espresso.action.ViewActions;
7-
import android.support.test.espresso.assertion.ViewAssertions;
86
import android.support.test.espresso.matcher.PreferenceMatchers;
9-
import android.support.test.espresso.matcher.ViewMatchers;
107
import android.support.test.filters.LargeTest;
118
import android.support.test.rule.ActivityTestRule;
129
import android.support.test.runner.AndroidJUnit4;
@@ -17,8 +14,17 @@
1714

1815
import java.util.Map;
1916

17+
import fr.free.nrw.commons.settings.Prefs;
2018
import fr.free.nrw.commons.settings.SettingsActivity;
2119

20+
import static android.support.test.espresso.action.ViewActions.click;
21+
import static android.support.test.espresso.action.ViewActions.replaceText;
22+
import static android.support.test.espresso.assertion.ViewAssertions.matches;
23+
import static android.support.test.espresso.matcher.ViewMatchers.withId;
24+
import static android.support.test.espresso.matcher.ViewMatchers.withText;
25+
import static org.hamcrest.Matchers.allOf;
26+
import static org.junit.Assert.assertEquals;
27+
2228
@LargeTest
2329
@RunWith(AndroidJUnit4.class)
2430
public class SettingsActivityTest {
@@ -27,8 +33,7 @@ public class SettingsActivityTest {
2733

2834
@Rule
2935
public ActivityTestRule<SettingsActivity> activityRule =
30-
new ActivityTestRule<SettingsActivity>(SettingsActivity.class,
31-
false /* Initial touch mode */, true /* launch activity */) {
36+
new ActivityTestRule<SettingsActivity>(SettingsActivity.class, false, true) {
3237

3338
@Override
3439
protected void afterActivityLaunched() {
@@ -59,41 +64,31 @@ protected void afterActivityFinished() {
5964
};
6065

6166
@Test
62-
public void oneLicenseIsChecked() {
63-
// click "License" (the first item)
64-
Espresso.onData(PreferenceMatchers.withKey("defaultLicense"))
65-
.inAdapterView(ViewMatchers.withId(android.R.id.list))
66-
.atPosition(0)
67-
.perform(ViewActions.click());
67+
public void setRecentUploadLimitTo100() {
68+
// Open "Use external storage" preference
69+
Espresso.onData(PreferenceMatchers.withKey("uploads"))
70+
.inAdapterView(withId(android.R.id.list))
71+
.perform(click());
6872

69-
// test the selected item
70-
Espresso.onView(ViewMatchers.isChecked())
71-
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
72-
}
73+
// Try setting it to 100
74+
Espresso.onView(withId(android.R.id.edit))
7375

74-
@Test
75-
public void afterClickingCcby4ItWillStay() {
76-
// click "License" (the first item)
77-
Espresso.onData(PreferenceMatchers.withKey("defaultLicense"))
78-
.inAdapterView(ViewMatchers.withId(android.R.id.list))
79-
.atPosition(0)
80-
.perform(ViewActions.click());
76+
.perform(replaceText("100"));
8177

82-
// click "Attribution 4.0"
83-
Espresso.onView(
84-
ViewMatchers.withText(R.string.license_name_cc_by_four)
85-
).perform(ViewActions.click());
78+
// Click "OK"
79+
Espresso.onView(allOf(withId(android.R.id.button1), withText("OK")))
80+
.perform(click());
8681

87-
// click "License" (the first item)
88-
Espresso.onData(PreferenceMatchers.withKey("defaultLicense"))
89-
.inAdapterView(ViewMatchers.withId(android.R.id.list))
90-
.atPosition(0)
91-
.perform(ViewActions.click());
82+
// Check setting set to 100 in SharedPreferences
83+
assertEquals(
84+
100,
85+
prefs.getInt(Prefs.UPLOADS_SHOWING, 0)
86+
);
9287

93-
// test the value remains "Attribution 4.0"
94-
Espresso.onView(ViewMatchers.isChecked())
95-
.check(ViewAssertions.matches(
96-
ViewMatchers.withText(R.string.license_name_cc_by_four)
97-
));
88+
// Check displaying 100 in summary text
89+
Espresso.onData(PreferenceMatchers.withKey("uploads"))
90+
.inAdapterView(withId(android.R.id.list))
91+
.onChildView(withId(android.R.id.summary))
92+
.check(matches(withText("100")));
9893
}
9994
}

app/src/main/java/fr/free/nrw/commons/settings/SettingsFragment.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,6 @@ public void onCreate(Bundle savedInstanceState) {
4747
// Load the preferences from an XML resource
4848
addPreferencesFromResource(R.xml.preferences);
4949

50-
// Update spinner to show selected value as summary
51-
ListPreference licensePreference = (ListPreference) findPreference(Prefs.DEFAULT_LICENSE);
52-
licensePreference.setSummary(getString(Utils.licenseNameFor(licensePreference.getValue())));
53-
54-
// Keep summary updated when changing value
55-
licensePreference.setOnPreferenceChangeListener((preference, newValue) -> {
56-
preference.setSummary(getString(Utils.licenseNameFor((String) newValue)));
57-
return true;
58-
});
59-
6050
SwitchPreference themePreference = (SwitchPreference) findPreference("theme");
6151
themePreference.setOnPreferenceChangeListener((preference, newValue) -> {
6252
getActivity().recreate();

app/src/main/java/fr/free/nrw/commons/upload/UploadModel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ String getSelectedLicense() {
332332

333333
void setSelectedLicense(String licenseName) {
334334
this.license = licensesByName.get(licenseName);
335+
prefs.edit().putString(Prefs.DEFAULT_LICENSE, license).commit();
335336
}
336337

337338
Observable<Contribution> buildContributions(List<String> categoryStringList) {

app/src/main/res/xml/preferences.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@
1616
<fr.free.nrw.commons.ui.LongTitlePreferences.LongTitlePreferenceCategory
1717
android:title="@string/preference_category_general">
1818

19-
<fr.free.nrw.commons.ui.LongTitlePreferences.LongTitleListPreference
20-
android:key="defaultLicense"
21-
android:title="@string/preference_license"
22-
android:entries="@array/pref_defaultLicense_entries"
23-
android:entryValues="@array/pref_defaultLicense_values"
24-
android:defaultValue="@string/license_pref_cc_by_sa_4_0" />
25-
2619
<fr.free.nrw.commons.ui.LongTitlePreferences.LongTitleSwitchPreference
2720
android:key="useExternalStorage"
2821
android:title="@string/use_external_storage"

0 commit comments

Comments
 (0)