Skip to content

Commit

Permalink
Merge pull request #2892 from grzesiek2010/disable_sms
Browse files Browse the repository at this point in the history
Disable SMS feature
  • Loading branch information
yanokwa authored Feb 20, 2019
2 parents b41b817 + babcebc commit db01cdc
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.odk.collect.android.preferences.GeneralSharedPreferences;
import org.odk.collect.android.preferences.GeneralKeys;
import org.odk.collect.android.preferences.PreferencesActivity;
import org.odk.collect.android.preferences.Transport;
import org.odk.collect.android.provider.InstanceProviderAPI.InstanceColumns;
import org.odk.collect.android.utilities.ApplicationConstants;
import org.odk.collect.android.utilities.PlayServicesUtil;
Expand All @@ -68,6 +69,8 @@

import timber.log.Timber;

import static org.odk.collect.android.preferences.GeneralKeys.KEY_SUBMISSION_TRANSPORT_TYPE;

/**
* Responsible for displaying buttons to launch the major activities. Launches
* some activities based on returns of others.
Expand Down Expand Up @@ -113,6 +116,8 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.main_menu);
initToolbar();

disableSmsIfNeeded();

// enter data button. expects a result.
Button enterDataButton = findViewById(R.id.enter_data);
enterDataButton.setText(getString(R.string.enter_data_button));
Expand Down Expand Up @@ -648,4 +653,24 @@ public void onChange(boolean selfChange) {
}
}

private void disableSmsIfNeeded() {
if (Transport.Internet != Transport.fromPreference(GeneralSharedPreferences.getInstance().get(KEY_SUBMISSION_TRANSPORT_TYPE))) {
GeneralSharedPreferences.getInstance().save(KEY_SUBMISSION_TRANSPORT_TYPE, getString(R.string.transport_type_value_internet));

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder
.setTitle(R.string.sms_feature_disabled_dialog_title)
.setMessage(R.string.sms_feature_disabled_dialog_message)
.setPositiveButton(R.string.read_details, (dialog, which) -> {
Intent intent = new Intent(this, WebViewActivity.class);
intent.putExtra("url", "https://forum.opendatakit.org/t/17973");
startActivity(intent);
})
.setNegativeButton(R.string.ok, (dialog, which) -> dialog.dismiss());

builder
.create()
.show();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@
package org.odk.collect.android.preferences;

import android.accounts.AccountManager;
import android.app.Activity;
import android.app.AlertDialog;
//import android.app.Activity;
//import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
//import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v7.content.res.AppCompatResources;
import android.telephony.PhoneNumberUtils;
import android.text.InputFilter;
import android.text.TextUtils;
//import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ArrayAdapter;
Expand All @@ -44,7 +44,7 @@
import org.odk.collect.android.R;
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.http.CollectServerClient;
import org.odk.collect.android.listeners.OnBackPressedListener;
//import org.odk.collect.android.listeners.OnBackPressedListener;
import org.odk.collect.android.preferences.filters.ControlCharacterFilter;
import org.odk.collect.android.preferences.filters.WhitespaceFilter;
import org.odk.collect.android.utilities.FileUtils;
Expand All @@ -63,22 +63,23 @@

import static android.app.Activity.RESULT_OK;
import static org.odk.collect.android.preferences.GeneralKeys.KEY_FORMLIST_URL;
import static org.odk.collect.android.preferences.GeneralKeys.KEY_PROTOCOL;
//import static org.odk.collect.android.preferences.GeneralKeys.KEY_PROTOCOL;
import static org.odk.collect.android.preferences.GeneralKeys.KEY_SELECTED_GOOGLE_ACCOUNT;
import static org.odk.collect.android.preferences.GeneralKeys.KEY_SMS_GATEWAY;
import static org.odk.collect.android.preferences.GeneralKeys.KEY_SMS_PREFERENCE;
import static org.odk.collect.android.preferences.GeneralKeys.KEY_SUBMISSION_TRANSPORT_TYPE;
//import static org.odk.collect.android.preferences.GeneralKeys.KEY_SUBMISSION_TRANSPORT_TYPE;
import static org.odk.collect.android.preferences.GeneralKeys.KEY_SUBMISSION_URL;
import static org.odk.collect.android.utilities.DialogUtils.showDialog;
//import static org.odk.collect.android.utilities.DialogUtils.showDialog;
import static org.odk.collect.android.preferences.GeneralKeys.KEY_TRANSPORT_PREFERENCE;
import static org.odk.collect.android.utilities.gdrive.GoogleAccountsManager.REQUEST_ACCOUNT_PICKER;

public class ServerPreferencesFragment extends BasePreferenceFragment implements View.OnTouchListener,
GoogleAccountsManager.GoogleAccountSelectionListener, OnBackPressedListener {
GoogleAccountsManager.GoogleAccountSelectionListener {
private static final String KNOWN_URL_LIST = "knownUrlList";
protected EditTextPreference serverUrlPreference;
protected EditTextPreference usernamePreference;
protected EditTextPreference passwordPreference;
protected ExtendedEditTextPreference smsGatewayPreference;
//protected ExtendedEditTextPreference smsGatewayPreference;
protected EditTextPreference submissionUrlPreference;
protected EditTextPreference formListUrlPreference;
private ListPopupWindow listPopupWindow;
Expand All @@ -96,6 +97,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
Collect.getInstance().getComponent().inject(this);
}

/*
private ListPreference transportPreference;
private ExtendedPreferenceCategory smsPreferenceCategory;
Expand All @@ -104,6 +106,7 @@ public void onAttach(Activity activity) {
super.onAttach(activity);
((PreferencesActivity) activity).setOnBackPressedListener(this);
}
*/

public void addAggregatePreferences() {
if (!new AggregatePreferencesAdder(this).add()) {
Expand Down Expand Up @@ -149,9 +152,12 @@ public void addAggregatePreferences() {
passwordPreference.getEditText().setFilters(
new InputFilter[]{new ControlCharacterFilter()});

setupTransportPreferences();
//setupTransportPreferences();
getPreferenceScreen().removePreference(findPreference(KEY_TRANSPORT_PREFERENCE));
getPreferenceScreen().removePreference(findPreference(KEY_SMS_PREFERENCE));
}

/*
public void setupTransportPreferences() {
transportPreference = (ListPreference) findPreference(KEY_SUBMISSION_TRANSPORT_TYPE);
transportPreference.setOnPreferenceChangeListener(createTransportChangeListener());
Expand Down Expand Up @@ -201,6 +207,7 @@ private Preference.OnPreferenceChangeListener createTransportChangeListener() {
return true;
};
}
*/

public void addGooglePreferences() {
addPreferencesFromResource(R.xml.google_preferences);
Expand All @@ -220,7 +227,9 @@ public void addGooglePreferences() {
new ControlCharacterFilter(), new WhitespaceFilter()
});
initAccountPreferences();
setupTransportPreferences();
//setupTransportPreferences();
getPreferenceScreen().removePreference(findPreference(KEY_TRANSPORT_PREFERENCE));
getPreferenceScreen().removePreference(findPreference(KEY_SMS_PREFERENCE));
}

public void addOtherPreferences() {
Expand Down Expand Up @@ -467,6 +476,7 @@ public void onGoogleAccountSelected(String accountName) {
/**
* Shows a dialog if SMS submission is enabled but the phone number isn't set.
*/
/*
private void runSmsPhoneNumberValidation() {
Transport transport = Transport.fromPreference(GeneralSharedPreferences.getInstance().get(KEY_SUBMISSION_TRANSPORT_TYPE));
Expand Down Expand Up @@ -521,4 +531,5 @@ private void continueOnBackPressed() {
public void doBack() {
runSmsPhoneNumberValidation();
}
*/
}
3 changes: 3 additions & 0 deletions collect_app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,9 @@
<string name="background_location_disabled">This form wants to track your location but tracking is disabled. Please enable in the \u0020\u0020⋮\u0020\u0020 menu above.</string>
<string name="background_location_enabled">This form tracks your location. You can disable tracking in the \u0020\u0020⋮\u0020\u0020 menu above.</string>
<string name="open_file">Open file</string>
<string name="sms_feature_disabled_dialog_title">Sending via SMS Disabled</string>
<string name="sms_feature_disabled_dialog_message">Sending submissions via SMS has been disabled due to Google Play Store restrictions.\n\nPlease make sure the person who configured this device reads the details below and takes action.</string>
<string name="read_details">Read details</string>
<string name="google_sheets_encrypted_message">Encrypted forms can\'t be submitted to Google Sheets.</string>
<string name="number_picker_title">Number Picker</string>
</resources>
1 change: 1 addition & 0 deletions config/lint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<issue id="UnusedResources" severity="error">
<ignore path="res/values/dimens.xml"/>
<ignore regexp="ga_trackingId|google_crash_reporting_api_key|project_id"/>
<ignore regexp="sms_invalid_phone_number_description"/>
</issue>

<issue id="TimberExceptionLogging" severity="error"/>
Expand Down

0 comments on commit db01cdc

Please sign in to comment.