Skip to content
This repository has been archived by the owner on Feb 14, 2019. It is now read-only.

Commit

Permalink
Merge pull request #45 from spark/prod_fix
Browse files Browse the repository at this point in the history
Prod fix
  • Loading branch information
CityVibes authored May 3, 2017
2 parents 2f47ddc + 6df1366 commit 1e7db32
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 30 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.4.6
=====
* Adding organization customization options as deprecated, trying to use deprecated organization option will result in exception.

0.4.5
=====
* Adding back email field for organization sign up.
Expand Down
4 changes: 2 additions & 2 deletions devicesetup/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'me.tatarka.retrolambda'

// This is the library version used when deploying the artifact
version = '0.4.5'
version = '0.4.6'

ext {
bintrayRepo = 'android'
Expand Down Expand Up @@ -80,7 +80,7 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')

compile 'io.particle:cloudsdk:0.4.3'
compile 'io.particle:cloudsdk:0.4.4'

compile 'com.google.code.findbugs:jsr305:3.0.1'
compile 'com.google.code.gson:gson:2.7'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.util.Patterns;
import android.view.Gravity;
import android.view.View;
Expand Down Expand Up @@ -58,6 +57,7 @@ public class CreateAccountActivity extends BaseActivity {
private Switch companyChoiceView;

private boolean useOrganizationSignup;
private boolean useProductionSignup;

private final CompoundButton.OnCheckedChangeListener companyAccountCheckedListener =
(CompoundButton buttonView, boolean isChecked) -> {
Expand Down Expand Up @@ -99,6 +99,7 @@ protected void onCreate(Bundle savedInstanceState) {

companyChoiceView.setOnCheckedChangeListener(companyAccountCheckedListener);
useOrganizationSignup = getResources().getBoolean(R.bool.organization);
useProductionSignup = getResources().getBoolean(R.bool.productMode);

Button submit = Ui.findView(this, R.id.action_create_account);
submit.setOnClickListener(view -> attemptCreateAccount());
Expand Down Expand Up @@ -218,8 +219,15 @@ private void attemptSignUp() {
createAccountTask = Async.executeAsync(cloud, new Async.ApiWork<ParticleCloud, Void>() {
@Override
public Void callApi(@NonNull ParticleCloud particleCloud) throws ParticleCloudException {
if (useOrganizationSignup) {
particleCloud.signUpAndLogInWithCustomer(signUpInfo, getResources().getInteger(R.integer.product_id));
if (useOrganizationSignup && !useProductionSignup) {
throw new ParticleCloudException(new Exception("Organization is deprecated, use productMode instead."));
// particleCloud.signUpAndLogInWithCustomer(signUpInfo, getString(R.string.organization_slug));
} else if (useProductionSignup) {
int productId = getResources().getInteger(R.integer.product_id);
if (productId == 0) {
throw new ParticleCloudException(new Exception("Product id must be set when productMode is in use."));
}
particleCloud.signUpAndLogInWithCustomer(signUpInfo, productId);
} else {
particleCloud.signUpWithUser(signUpInfo);
}
Expand Down Expand Up @@ -254,7 +262,7 @@ private void singUpTaskSuccess(String email, String password, AccountInfo accoun
if (isFinishing()) {
return;
}
if (useOrganizationSignup) {
if (useOrganizationSignup || useProductionSignup) {
// with org setup, we're already logged in upon successful account creation
onLoginSuccess(cloud);
SEGAnalytics.track("Auth: Signed Up New Customer");
Expand All @@ -277,7 +285,8 @@ private void signUpTaskFailure(@NonNull ParticleCloudException error) {
} else if (error.getResponseData() != null) {

if (error.getResponseData().getHttpStatusCode() == 401
&& getResources().getBoolean(R.bool.organization)) {
&& (getResources().getBoolean(R.bool.organization) ||
getResources().getBoolean(R.bool.productMode))) {
msg = getString(R.string.create_account_account_already_exists_for_email_address);
} else {
msg = error.getServerErrorMsg();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,16 @@ private void onReadyButtonClicked(View v) {
@Override
public ClaimCodeResponse callApi(@NonNull ParticleCloud sparkCloud) throws ParticleCloudException {
Resources res = ctx.getResources();
if (res.getBoolean(R.bool.organization)) {
return sparkCloud.generateClaimCodeForOrg(res.getInteger(R.integer.product_id));
if (res.getBoolean(R.bool.organization) && !res.getBoolean(R.bool.productMode)) {
throw new ParticleCloudException(new Exception("Organization is deprecated, use productMode instead."));
// return sparkCloud.generateClaimCodeForOrg(res.getString(R.string.organization_slug),
// res.getString(R.string.product_slug));
} else if (res.getBoolean(R.bool.productMode)) {
int productId = res.getInteger(R.integer.product_id);
if (productId == 0) {
throw new ParticleCloudException(new Exception("Product id must be set when productMode is in use."));
}
return sparkCloud.generateClaimCode(productId);
} else {
return sparkCloud.generateClaimCode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ public void reenableWifiNetworks() {

private Set<SSID> loadSSIDsWithKey(String key) {
// log.v("loadSSIDsWithKey(" + key + ")");
Set<SSID> ssids = Funcy.transformSet(prefs.getStringSet(key, set()), SSID::from);
// log.v("Loaded saved SSIDS: " + ssids);
return ssids;
// log.v("Loaded saved SSIDS: " + ssids);
return Funcy.transformSet(prefs.getStringSet(key, set()), SSID::from);
}

@SuppressLint("CommitPrefEdits")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,7 @@ public Network getNetworkForSSID(SSID ssid) {
Arrays.asList(connectivityManager.getAllNetworks()),
network -> {
NetworkInfo networkInfo = connectivityManager.getNetworkInfo(network);
if (!Py.truthy(networkInfo.getExtraInfo())) {
return false;
}
return SSID.from(networkInfo.getExtraInfo()).equals(ssid);
return Py.truthy(networkInfo.getExtraInfo()) && SSID.from(networkInfo.getExtraInfo()).equals(ssid);
}
);
}
Expand Down
6 changes: 6 additions & 0 deletions devicesetup/src/main/res/values/customization.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@
<string name="header_text_font_name">fonts/roboto_light.ttf</string>

<!-- enable invite codes, other APIs -->
<!-- {@deprecated Use productMode instead.} -->
<bool name="organization">false</bool>
<bool name="productMode">false</bool>
<!-- {@deprecated Organization settings have been deprecated - set product name and ID only.} -->
<string name="organization_slug">CHANGE_ME</string>
<!-- {@deprecated Set productId number instead.} -->
<string name="product_slug">CHANGE_ME</string>
<integer name="product_id">0</integer>

<!-- FIXME: unused, remove? -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import java.util.Date;
Expand All @@ -19,19 +18,8 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
ParticleDeviceSetupLibrary.init(this.getApplicationContext());

Ui.findView(this, R.id.start_setup_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
invokeDeviceSetup();
}
});

Ui.findView(this, R.id.start_setup_custom_intent_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
invokeDeviceSetupWithCustomIntentBuilder();
}
});
Ui.findView(this, R.id.start_setup_button).setOnClickListener(view -> invokeDeviceSetup());
Ui.findView(this, R.id.start_setup_custom_intent_button).setOnClickListener(v -> invokeDeviceSetupWithCustomIntentBuilder());

String setupLaunchTime = this.getIntent().getStringExtra(EXTRA_SETUP_LAUNCHED_TIME);

Expand Down

0 comments on commit 1e7db32

Please sign in to comment.