Skip to content

Commit

Permalink
Revert "Option to use server username for preloading (getodk#1372)"
Browse files Browse the repository at this point in the history
  • Loading branch information
lognaturel authored and yanokwa committed Sep 3, 2017
1 parent 66b00f9 commit 9ae4fdd
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.PreferenceManager;
Expand All @@ -21,11 +20,8 @@
import static org.odk.collect.android.logic.PropertyManager.PROPMGR_SUBSCRIBER_ID;
import static org.odk.collect.android.logic.PropertyManager.PROPMGR_USERNAME;
import static org.odk.collect.android.preferences.PreferenceKeys.KEY_METADATA_EMAIL;
import static org.odk.collect.android.preferences.PreferenceKeys.KEY_USERNAME_FOR_METADATA;
import static org.odk.collect.android.preferences.PreferenceKeys.KEY_METADATA_PHONENUMBER;
import static org.odk.collect.android.preferences.PreferenceKeys.KEY_METADATA_USERNAME;
import static org.odk.collect.android.preferences.PreferenceKeys.KEY_USERNAME;
import static org.odk.collect.android.preferences.PreferenceKeys.KEY_USE_SERVER_USERNAME;

public class FormMetadataFragment extends BasePreferenceFragment {
@Override
Expand All @@ -35,23 +31,6 @@ public void onCreate(Bundle savedInstanceState) {
addPreferencesFromResource(R.xml.form_metadata_preferences);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
PropertyManager pm = new PropertyManager(getActivity());

final CheckBoxPreference useServerUsername = (CheckBoxPreference) findPreference(KEY_USE_SERVER_USERNAME);
useServerUsername.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String username;
if (!useServerUsername.isChecked()) {
username = (String) GeneralSharedPreferences.getInstance().get(KEY_USERNAME);
} else {
username = (String) GeneralSharedPreferences.getInstance().get(KEY_USERNAME_FOR_METADATA);
}
GeneralSharedPreferences.getInstance().save(KEY_METADATA_USERNAME, username);
findPreference(KEY_METADATA_USERNAME).setSummary(username);
return true;
}
});

initPrefFromProp(pm, prefs, PROPMGR_USERNAME, KEY_METADATA_USERNAME);
initPrefFromProp(pm, prefs, PROPMGR_PHONE_NUMBER, KEY_METADATA_PHONENUMBER);
initPrefFromProp(pm, prefs, PROPMGR_EMAIL, KEY_METADATA_EMAIL);
Expand Down Expand Up @@ -109,8 +88,6 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
ToastUtils.showLongToast(R.string.invalid_email_address);
return false;
}
} else if (KEY_METADATA_USERNAME.equals(key)) {
GeneralSharedPreferences.getInstance().save(KEY_USERNAME_FOR_METADATA, newValueString);
}

EditTextPreference changedTextPref = (EditTextPreference) preference;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public final class PreferenceKeys {
public static final String KEY_METADATA_PHONENUMBER = "metadata_phonenumber";
public static final String KEY_METADATA_EMAIL = "metadata_email";

public static final String KEY_USE_SERVER_USERNAME = "use_server_username";
public static final String KEY_USERNAME_FOR_METADATA = "username_for_metadata";

// AGGREGATE SPECIFIC
public static final String KEY_SERVER_URL = "server_url";

Expand Down Expand Up @@ -87,7 +84,6 @@ private static HashMap<String, Object> getHashMap() {
hashMap.put(KEY_PROTOCOL, Collect.getInstance().getString(R.string.protocol_odk_default));
hashMap.put(KEY_SELECTED_GOOGLE_ACCOUNT, "");
hashMap.put(KEY_USERNAME, "");
hashMap.put(KEY_USE_SERVER_USERNAME, true);
hashMap.put(KEY_METADATA_USERNAME, "");
hashMap.put(KEY_METADATA_PHONENUMBER, "");
hashMap.put(KEY_METADATA_EMAIL, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@
import java.util.List;

import static org.odk.collect.android.preferences.PreferenceKeys.KEY_FORMLIST_URL;
import static org.odk.collect.android.preferences.PreferenceKeys.KEY_METADATA_USERNAME;
import static org.odk.collect.android.preferences.PreferenceKeys.KEY_SUBMISSION_URL;
import static org.odk.collect.android.preferences.PreferenceKeys.KEY_USE_SERVER_USERNAME;


public class ServerPreferencesFragment extends BasePreferenceFragment implements View.OnTouchListener, Preference.OnPreferenceChangeListener {
private static final String KNOWN_URL_LIST = "knownUrlList";
Expand Down Expand Up @@ -273,9 +272,6 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
}

preference.setSummary(username);
if (GeneralSharedPreferences.getInstance().getBoolean(KEY_USE_SERVER_USERNAME, true)) {
GeneralSharedPreferences.getInstance().save(KEY_METADATA_USERNAME, username);
}
clearCachedCrendentials();

// To ensure we update current credentials in CredentialsProvider
Expand Down
19 changes: 0 additions & 19 deletions collect_app/src/main/res/color/settings_color.xml

This file was deleted.

1 change: 0 additions & 1 deletion collect_app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@
<string name="invalid_email_address">Invalid email address!</string>
<string name="sort_by">Sort by</string>
<string name="server">Server</string>
<string name="use_server_username">Use server username</string>
<string name="select_value">Select value</string>
<string name="edit_value">Edit value</string>
<string name="no_value_selected">No value selected</string>
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/values/theme.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<style name="AppTheme.SettingsTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorAccent">@color/tintColor</item>
<item name="android:textColor">@color/settings_color</item>
<item name="android:textColor">@color/primaryTextColor</item>
<item name="android:textSize">18sp</item>
<item name="android:panelBackground">@android:color/white</item>
<item name="android:listDivider">@null</item>
Expand Down
8 changes: 1 addition & 7 deletions collect_app/src/main/res/xml/form_metadata_preferences.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/user_defined">
<CheckBoxPreference
android:defaultValue="true"
android:key="use_server_username"
android:title="@string/use_server_username"
android:disableDependentsState="true" />
<EditTextPreference
android:inputType="textNoSuggestions"
android:key="metadata_username"
android:title="@string/username"
android:dependency="use_server_username" />
android:title="@string/username" />
<EditTextPreference
android:inputType="phone"
android:key="metadata_phonenumber"
Expand Down

0 comments on commit 9ae4fdd

Please sign in to comment.