Skip to content

Commit 812992c

Browse files
committed
Merge fixes and formatting
1 parent aac45bd commit 812992c

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

calcdialog/src/main/java/com/maltaisn/calcdialog/CalcPresenter.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.maltaisn.calcdialog;
1818

1919
import android.os.Bundle;
20-
import android.os.Parcelable;
2120

2221
import java.math.BigDecimal;
2322
import java.math.RoundingMode;
@@ -114,9 +113,7 @@ void detach() {
114113
}
115114

116115
void writeStateToBundle(Bundle bundle) {
117-
if (expression != null) {
118-
bundle.putParcelable("expression", expression);
119-
}
116+
bundle.putParcelable("expression", expression);
120117
if (currentValue != null) {
121118
bundle.putSerializable("currentValue", currentValue);
122119
}
@@ -132,12 +129,9 @@ void writeStateToBundle(Bundle bundle) {
132129
}
133130

134131
private void readStateFromBundle(Bundle bundle) {
135-
//noinspection ConstantConditions
136-
if (bundle.containsKey("expression")) {
137-
Parcelable parcelable = bundle.getParcelable("expression");
138-
if (parcelable != null){
139-
this.expression = (Expression) parcelable;
140-
}
132+
Expression expr = bundle.getParcelable("expression");
133+
if (expr != null) {
134+
this.expression = expr;
141135
}
142136
if (bundle.containsKey("currentValue")) {
143137
currentValue = (BigDecimal) bundle.getSerializable("currentValue");

calcdialog/src/main/java/com/maltaisn/calcdialog/CalcSettings.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import android.os.Parcel;
2121
import android.os.Parcelable;
2222

23-
import java.lang.UnsupportedOperationException;
24-
import java.lang.NullPointerException;
2523
import java.math.BigDecimal;
2624
import java.math.RoundingMode;
2725
import java.text.NumberFormat;
@@ -291,18 +289,18 @@ public boolean isOrderOfOperationsApplied() {
291289
private CalcSettings(Parcel in) {
292290
Bundle bundle = in.readBundle(getClass().getClassLoader());
293291
if (bundle != null) {
294-
295292
requestCode = bundle.getInt("requestCode");
296293

297-
//noinspection ConstantConditions
298294
if (bundle.containsKey("nbFormat")) {
299295
try {
300-
nbFormat = (NumberFormat) bundle.getSerializable("nbFormat");
296+
NumberFormat fmt = (NumberFormat) bundle.getSerializable("nbFormat");
297+
if (fmt != null) nbFormat = fmt;
301298
} catch (NullPointerException npe) {
302299
// Catch NPE exception on some Android 9 devices
303300
// see https://stackoverflow.com/q/53541154/8941877
304301
}
305302
}
303+
306304
//noinspection ConstantConditions
307305
numpadLayout = (CalcNumpadLayout) bundle.getSerializable("numpadLayout");
308306
isExpressionShown = bundle.getBoolean("isExpressionShown");
@@ -311,12 +309,15 @@ private CalcSettings(Parcel in) {
311309
isSignBtnShown = bundle.getBoolean("isSignBtnShown");
312310
shouldEvaluateOnOperation = bundle.getBoolean("shouldEvaluateOnOperation");
313311

314-
if (bundle.containsKey("initialValue"))
312+
if (bundle.containsKey("initialValue")) {
315313
initialValue = (BigDecimal) bundle.getSerializable("initialValue");
316-
if (bundle.containsKey("minValue"))
314+
}
315+
if (bundle.containsKey("minValue")) {
317316
minValue = (BigDecimal) bundle.getSerializable("minValue");
318-
if (bundle.containsKey("maxValue"))
317+
}
318+
if (bundle.containsKey("maxValue")) {
319319
maxValue = (BigDecimal) bundle.getSerializable("maxValue");
320+
}
320321
isOrderOfOperationsApplied = bundle.getBoolean("isOrderOfOperationsApplied");
321322
}
322323
}
@@ -326,9 +327,7 @@ public void writeToParcel(@NonNull Parcel out, int flags) {
326327
Bundle bundle = new Bundle();
327328

328329
bundle.putInt("requestCode", requestCode);
329-
if (nbFormat != null){
330-
bundle.putSerializable("nbFormat", nbFormat);
331-
}
330+
bundle.putSerializable("nbFormat", nbFormat);
332331
bundle.putSerializable("numpadLayout", numpadLayout);
333332
bundle.putBoolean("isExpressionShown", isExpressionShown);
334333
bundle.putBoolean("isZeroShownWhenNoValue", isZeroShownWhenNoValue);
@@ -341,9 +340,9 @@ public void writeToParcel(@NonNull Parcel out, int flags) {
341340
if (maxValue != null) bundle.putSerializable("maxValue", maxValue);
342341
bundle.putBoolean("isOrderOfOperationsApplied", isOrderOfOperationsApplied);
343342

344-
try{
343+
try {
345344
out.writeBundle(bundle);
346-
} catch (UnsupportedOperationException uoe){
345+
} catch (UnsupportedOperationException uoe) {
347346
// Workaround for issue https://issuetracker.google.com/issues/37043137
348347
}
349348
}

0 commit comments

Comments
 (0)