Skip to content

Commit 4ba28e3

Browse files
slowhillEzra Fernandez
andauthored
[2.0.2] Fix NPE in LyftButton#displayCost (#27)
* version bump * Fix NPE on displayCost * Prepare for release 2.0.2 * Update CHANGELOG.md Co-authored-by: Ezra Fernandez <[email protected]> Co-authored-by: Ezra Fernandez <[email protected]>
1 parent 560ddbe commit 4ba28e3

File tree

9 files changed

+66
-14
lines changed

9 files changed

+66
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Version 2.0.2 *(2020-09-20)*
2+
----------------------------
3+
* Fixed a bug that caused an NPE when attempting to display a price on the Lyft Button.
4+
15
Version 2.0.1 *(2019-11-18)*
26
----------------------------
37
* Fixed a bug that prevented promo codes from being applied to the Lyft Button.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ repositories {
1919
}
2020
2121
dependencies {
22-
compile 'com.lyft:lyft-android-sdk:2.0.1'
22+
compile 'com.lyft:lyft-android-sdk:2.0.2'
2323
}
2424
```
2525

2626
If you only want to use the [Lyft API Wrapper](https://github.com/lyft/lyft-android-sdk#lyft-api-wrapper) or [Deeplink](https://github.com/lyft/lyft-android-sdk#deeplinking) portion of the SDK, you can pull them individually.
2727
```gradle
28-
compile 'com.lyft:lyft-android-sdk-networking:2.0.1' // Lyft API Wrapper
29-
compile 'com.lyft:lyft-android-sdk-deeplink:2.0.1' // Deeplink
28+
compile 'com.lyft:lyft-android-sdk-networking:2.0.2' // Lyft API Wrapper
29+
compile 'com.lyft:lyft-android-sdk-deeplink:2.0.2' // Deeplink
3030
```
3131

3232
### Maven:
3333
```xml
3434
<dependency>
3535
<groupId>com.lyft</groupId>
3636
<artifactId>lyft-android-sdk</artifactId>
37-
<version>2.0.1</version>
37+
<version>2.0.2</version>
3838
<type>aar</type>
3939
</dependency>
4040
```

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ subprojects {
3939
ext.googlePlayVersion = '17.0.0'
4040
ext.jetbrainsVersion = '15.0'
4141
ext.junitVersion = '4.12'
42-
ext.lyftSdkVersionCode = 2
42+
ext.lyftSdkVersionCode = 3
4343
ext.lyftSdkVersionName = VERSION_NAME
4444
ext.mockitoVersion = '2.25.0'
4545
ext.okhttpVersion = '3.3.1'

deeplink/src/main/java/com/lyft/deeplink/DeepLink.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
public class DeepLink {
1010

1111
private static final String LYFT_PACKAGE_NAME = "me.lyft.android";
12-
private static final String SDK_VERSION = "2.0.1";
12+
private static final String SDK_VERSION = BuildConfig.VERSION_NAME;
1313

1414
/**
1515
* @return true if Lyft app is installed on the device.

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
GROUP=com.lyft
2-
VERSION_NAME=2.0.1
2+
VERSION_NAME=2.0.2
33

44
POM_DESCRIPTION=Lyft Android SDK
55

lyft-button/src/main/java/com/lyft/lyftbutton/LyftButton.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.res.TypedArray;
55
import android.text.TextUtils;
66
import android.util.AttributeSet;
7+
import android.util.Log;
78
import android.view.Gravity;
89
import android.view.View;
910
import android.widget.ImageView;
@@ -174,11 +175,22 @@ public void onFailure(Throwable t) {
174175

175176
private void displayEta(Eta eta) {
176177
int etaMinutes = eta.eta_seconds / 60;
177-
rideTypeEtaText.setText(String.valueOf(
178-
getResources().getString(R.string.ridetype_eta_text, eta.display_name, etaMinutes)));
178+
rideTypeEtaText.setText(getResources().getString(R.string.ridetype_eta_text, eta.display_name, etaMinutes));
179179
}
180180

181181
private void displayCost(CostEstimate costEstimate) {
182+
if (costEstimate.estimated_cost_cents_max == null
183+
|| costEstimate.estimated_cost_cents_min == null) {
184+
Log.w(
185+
LyftButton.class.getName(),
186+
String.format(
187+
"Required fields from Cost Estimate has returned as null. Estimated cost must be non-null to display the cost. %s",
188+
costEstimate.toString())
189+
);
190+
191+
return;
192+
}
193+
182194
costContainer.setVisibility(VISIBLE);
183195

184196
if (TextUtils.isEmpty(costEstimate.primetime_percentage) || "0%".equals(costEstimate.primetime_percentage)) {
@@ -190,10 +202,10 @@ private void displayCost(CostEstimate costEstimate) {
190202
float minCost = costEstimate.estimated_cost_cents_min / 100f;
191203
float maxCost = costEstimate.estimated_cost_cents_max / 100f;
192204
if (minCost == maxCost) {
193-
costText.setText(String.valueOf(getResources().getString(R.string.fixed_cost_amount, minCost)));
205+
costText.setText(getResources().getString(R.string.fixed_cost_amount, minCost));
194206
} else {
195207
costText.setText(
196-
String.valueOf(getResources().getString(R.string.cost_estimate_range, (int) minCost, (int) maxCost)));
208+
getResources().getString(R.string.cost_estimate_range, (int) minCost, (int) maxCost));
197209
}
198210
}
199211

networking/build.gradle

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1-
apply plugin: 'java'
1+
apply plugin: 'com.android.library'
22

33
targetCompatibility = '1.7'
44
sourceCompatibility = '1.7'
55

6+
android {
7+
compileSdkVersion androidCompileSDK
8+
buildToolsVersion androidBuildToolsVersion
9+
10+
defaultConfig {
11+
minSdkVersion androidMinSdk
12+
targetSdkVersion androidTargetSDK
13+
versionCode lyftSdkVersionCode
14+
versionName lyftSdkVersionName
15+
}
16+
buildTypes {
17+
release {
18+
minifyEnabled false
19+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20+
}
21+
}
22+
}
23+
624
dependencies {
725
implementation 'org.jetbrains:annotations-java5:' + jetbrainsVersion
826
implementation 'com.squareup.okhttp3:okhttp:' + okhttpVersion

networking/src/main/java/com/lyft/networking/RequestInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class RequestInterceptor implements Interceptor {
99

1010
static final String AUTHORIZATION_HEADER = "Authorization";
1111
static final String USER_AGENT_HEADER = "User-Agent";
12-
private static final String USER_AGENT = "lyft-mobile-sdk:android::2.0.0";
12+
private static final String USER_AGENT = String.format("lyft-mobile-sdk:android::%s", BuildConfig.VERSION_NAME);
1313
private final String clientToken;
1414

1515
RequestInterceptor(String clientToken) {

test-utils/build.gradle

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1-
apply plugin: 'java'
1+
apply plugin: 'com.android.library'
22

33
targetCompatibility = '1.7'
44
sourceCompatibility = '1.7'
55

6+
android {
7+
compileSdkVersion androidCompileSDK
8+
buildToolsVersion androidBuildToolsVersion
9+
10+
defaultConfig {
11+
minSdkVersion androidMinSdk
12+
targetSdkVersion androidTargetSDK
13+
versionCode lyftSdkVersionCode
14+
versionName lyftSdkVersionName
15+
}
16+
buildTypes {
17+
release {
18+
minifyEnabled false
19+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20+
}
21+
}
22+
}
23+
624
dependencies {
725
implementation 'com.squareup.retrofit2:retrofit-mock:' + retrofitVersion
826
implementation project(path: ':networking')

0 commit comments

Comments
 (0)