Skip to content

Commit

Permalink
Merges autosend wifi and cellular to a list preference
Browse files Browse the repository at this point in the history
  • Loading branch information
shobhitagarwal1612 committed May 31, 2017
1 parent 260fff7 commit c4fa6ca
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 49 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.google.gms:google-services:3.0.0'
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public final class AdminKeys {
private static final String KEY_INSTANCE_FORM_SYNC = "instance_form_sync";
private static final String KEY_APP_LANGUAGE = "app_language";

private static final String KEY_AUTOSEND_WIFI = "autosend_wifi";
private static final String KEY_AUTOSEND_NETWORK = "autosend_network";
private static final String KEY_AUTOSEND = "autosend";

private static final String KEY_NAVIGATION = "navigation";
private static final String KEY_CONSTRAINT_BEHAVIOR = "constraint_behavior";
Expand Down Expand Up @@ -78,8 +77,7 @@ public final class AdminKeys {
ag(KEY_DELETE_AFTER_SEND, PreferenceKeys.KEY_DELETE_AFTER_SEND),
ag(KEY_INSTANCE_FORM_SYNC, PreferenceKeys.KEY_INSTANCE_SYNC),

ag(KEY_AUTOSEND_WIFI, PreferenceKeys.KEY_AUTOSEND_WIFI),
ag(KEY_AUTOSEND_NETWORK, PreferenceKeys.KEY_AUTOSEND_NETWORK),
ag(KEY_AUTOSEND, PreferenceKeys.KEY_AUTOSEND),

ag(KEY_NAVIGATION, PreferenceKeys.KEY_NAVIGATION),
ag(KEY_CONSTRAINT_BEHAVIOR, PreferenceKeys.KEY_CONSTRAINT_BEHAVIOR),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public final class PreferenceKeys {

public static final String KEY_HIGH_RESOLUTION = "high_resolution";

public static final String KEY_AUTOSEND_WIFI = "autosend_wifi";
public static final String KEY_AUTOSEND_NETWORK = "autosend_network";
public static final String KEY_AUTOSEND = "autosend";

public static final String KEY_NAVIGATION = "navigation";
public static final String KEY_CONSTRAINT_BEHAVIOR = "constraint_behavior";
Expand Down Expand Up @@ -93,8 +92,7 @@ private static HashMap<String, Object> getHashMap() {
hashMap.put(KEY_COMPLETED_DEFAULT, true);
hashMap.put(KEY_MAP_SDK, "google_maps");
hashMap.put(KEY_MAP_BASEMAP, "streets");
hashMap.put(KEY_AUTOSEND_WIFI, false);
hashMap.put(KEY_AUTOSEND_NETWORK, false);
hashMap.put(KEY_AUTOSEND, "off");
return hashMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static org.odk.collect.android.preferences.PreferenceKeys.GOOGLE_MAPS_BASEMAP_DEFAULT;
import static org.odk.collect.android.preferences.PreferenceKeys.KEY_ANALYTICS;
import static org.odk.collect.android.preferences.PreferenceKeys.KEY_APP_LANGUAGE;
import static org.odk.collect.android.preferences.PreferenceKeys.KEY_AUTOSEND;
import static org.odk.collect.android.preferences.PreferenceKeys.KEY_CONSTRAINT_BEHAVIOR;
import static org.odk.collect.android.preferences.PreferenceKeys.KEY_FONT_SIZE;
import static org.odk.collect.android.preferences.PreferenceKeys.KEY_FORMLIST_URL;
Expand Down Expand Up @@ -66,6 +67,26 @@ public void onCreate(final Bundle savedInstanceState) {
initAnalyticsPref();
initSplashPrefs();
initMapPrefs();
initAutoSendPrefs();
}

private void initAutoSendPrefs() {
final ListPreference autosend = (ListPreference) findPreference(KEY_AUTOSEND);

if (autosend == null) {
return;
}

autosend.setSummary(autosend.getEntry());
autosend.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
int index = ((ListPreference) preference).findIndexOfValue(newValue.toString());
String entry = (String) ((ListPreference) preference).getEntries()[index];
preference.setSummary(entry);
return true;
}
});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ private boolean interfaceIsEnabled(Context context,
// make sure autosend is enabled on the given connected interface
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(context);
boolean sendwifi = sharedPreferences.getBoolean(
PreferenceKeys.KEY_AUTOSEND_WIFI, false);
boolean sendnetwork = sharedPreferences.getBoolean(
PreferenceKeys.KEY_AUTOSEND_NETWORK, false);
String autosend = sharedPreferences.getString(PreferenceKeys.KEY_AUTOSEND, "off");
boolean sendwifi = autosend.equals("wifi_only");
boolean sendnetwork = autosend.equals("cellular_only");
if (autosend.equals("wifi_and_cellular")) {
sendwifi = true;
sendnetwork = true;
}

return (currentNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI
&& sendwifi || currentNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE
Expand Down
12 changes: 12 additions & 0 deletions collect_app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,16 @@ the specific language governing permissions and limitations under the License. -
<item>Seconds</item>
<item>Minutes</item>
</string-array>
<string-array name="autosend_selector_entries">
<item>@string/off</item>
<item>@string/wifi_autosend</item>
<item>@string/cellular_autosend</item>
<item>@string/wifi_cellular_autosend</item>
</string-array>
<string-array name="autosend_selector_entries_values" translatable="false">
<item>off</item>
<item>wifi_only</item>
<item>cellular_only</item>
<item>wifi_and_cellular</item>
</string-array>
</resources>
19 changes: 12 additions & 7 deletions collect_app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,16 @@
<string name="take_picture_instruction">Tap the screen to take a picture</string>
<string name="request_permission">This application needs camera permission.</string>
<string name="camera_error">This device doesn\'t support the Camera2 API.</string>
<string name="form_entry_setting">Form Entry Settings</string>
<string name="form_entry_settings_summary">Tap to manage form entry items</string>
<string name="user_settings">User Settings</string>
<string name="user_setting_summary">Tap to manage general settings items</string>
<string name="main_menu_settings">Main Menu Settings</string>
<string name="main_menu_settings_summary">Tap to manage main menu items</string>
<string name="user_access_control">User Access Control</string>
<string name="form_entry_setting">Form Entry Settings</string>
<string name="form_entry_settings_summary">Tap to manage form entry items</string>
<string name="user_settings">User Settings</string>
<string name="user_setting_summary">Tap to manage general settings items</string>
<string name="main_menu_settings">Main Menu Settings</string>
<string name="main_menu_settings_summary">Tap to manage main menu items</string>
<string name="user_access_control">User Access Control</string>
<string name="autosend_selector_title">Autosend</string>
<string name="off">Off</string>
<string name="wifi_autosend">Wifi only</string>
<string name="cellular_autosend">Cellular only</string>
<string name="wifi_cellular_autosend">Wifi or cellular</string>
</resources>
12 changes: 3 additions & 9 deletions collect_app/src/main/res/xml/admin_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,11 @@
android:summary="@string/found_in_settings"
android:title="@string/form_metadata"/>
<CheckBoxPreference
android:id="@+id/autosend_wifi"
android:id="@+id/autosend"
android:defaultValue="true"
android:key="autosend_wifi"
android:key="autosend"
android:summary="@string/found_in_settings"
android:title="@string/autosend_wifi"/>
<CheckBoxPreference
android:id="@+id/autosend_network"
android:defaultValue="true"
android:key="autosend_network"
android:summary="@string/found_in_settings"
android:title="@string/autosend_network"/>
android:title="@string/autosend"/>
<CheckBoxPreference
android:id="@+id/navigation"
android:defaultValue="true"
Expand Down
32 changes: 12 additions & 20 deletions collect_app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<PreferenceScreen
android:key="@string/server_preferences"
android:icon="@drawable/server"
android:key="@string/server_preferences"
android:title="@string/server_preferences">
<ListPreference
android:id="@+id/protocol"
Expand All @@ -21,27 +21,19 @@
android:title="@string/form_metadata"/>
</PreferenceScreen>

<PreferenceScreen
android:key="@string/autosend"
<ListPreference
android:id="@+id/autosend"
android:defaultValue="off"
android:dialogTitle="@string/autosend_selector_title"
android:entries="@array/autosend_selector_entries"
android:entryValues="@array/autosend_selector_entries_values"
android:icon="@drawable/auto_button"
android:title="@string/autosend">
<SwitchPreference
android:id="@+id/autosend_wifi"
android:defaultValue="false"
android:key="autosend_wifi"
android:summary="@string/autosend_wifi_summary"
android:title="@string/autosend_wifi"/>
<SwitchPreference
android:id="@+id/autosend_network"
android:defaultValue="false"
android:key="autosend_network"
android:summary="@string/autosend_network_summary"
android:title="@string/autosend_network"/>
</PreferenceScreen>
android:key="autosend"
android:title="@string/autosend"/>

<PreferenceScreen
android:key="@string/client"
android:icon="@drawable/user_interface"
android:key="@string/client"
android:title="@string/client">
<ListPreference
android:id="@+id/constraint_behavior"
Expand Down Expand Up @@ -112,8 +104,8 @@
</PreferenceScreen>

<PreferenceScreen
android:key="@string/map_preferences"
android:icon="@drawable/google_maps"
android:key="@string/map_preferences"
android:title="@string/map_preferences">

<ListPreference
Expand All @@ -136,8 +128,8 @@
</PreferenceScreen>

<PreferenceCategory
android:key="@string/analytics_preferences"
android:icon="@drawable/cloud_sync"
android:key="@string/analytics_preferences"
android:title="@string/analytics_preferences">
<CheckBoxPreference
android:id="@+id/analytics"
Expand Down

0 comments on commit c4fa6ca

Please sign in to comment.