Avoid crash with Address parcelable.
There seems to be a bad implementation of Address parcelization that pops up in certain scenarios. We can avoid it by just excluding it from the parcel altogether.
This commit is contained in:
parent
31435128f4
commit
a5eb823a17
3 changed files with 15 additions and 15 deletions
|
@ -1,6 +1,5 @@
|
|||
package org.thoughtcrime.securesms.components.location;
|
||||
|
||||
import android.location.Address;
|
||||
import android.net.Uri;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
@ -35,10 +34,8 @@ public class SignalPlace {
|
|||
private double longitude;
|
||||
|
||||
public SignalPlace(@NonNull AddressData place) {
|
||||
Address address = place.getAddress();
|
||||
|
||||
this.name = "";
|
||||
this.address = address!= null ? address.getAddressLine(0) : "";
|
||||
this.address = place.getAddress();
|
||||
this.latitude = place.getLatitude();
|
||||
this.longitude = place.getLongitude();
|
||||
}
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
package org.thoughtcrime.securesms.maps;
|
||||
|
||||
import android.location.Address;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public final class AddressData implements Parcelable {
|
||||
|
||||
private final double latitude;
|
||||
private final double longitude;
|
||||
private final @Nullable Address address;
|
||||
private final double latitude;
|
||||
private final double longitude;
|
||||
private final String address;
|
||||
|
||||
AddressData(double latitude, double longitude, @Nullable Address address) {
|
||||
AddressData(double latitude, double longitude, @NonNull String address) {
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public @Nullable Address getAddress() {
|
||||
public @NonNull String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
|
@ -32,9 +32,10 @@ public final class AddressData implements Parcelable {
|
|||
public static final Creator<AddressData> CREATOR = new Creator<AddressData>() {
|
||||
@Override
|
||||
public AddressData createFromParcel(Parcel in) {
|
||||
//noinspection ConstantConditions
|
||||
return new AddressData(in.readDouble(),
|
||||
in.readDouble(),
|
||||
Address.CREATOR.createFromParcel(in));
|
||||
in.readString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -47,7 +48,7 @@ public final class AddressData implements Parcelable {
|
|||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeDouble(latitude);
|
||||
dest.writeDouble(longitude);
|
||||
dest.writeParcelable(address, flags);
|
||||
dest.writeString(address);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -156,8 +156,10 @@ public final class PlacePickerActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
private void finishWithAddress() {
|
||||
Intent returnIntent = new Intent();
|
||||
AddressData addressData = new AddressData(currentLocation.latitude, currentLocation.longitude, currentAddress);
|
||||
Intent returnIntent = new Intent();
|
||||
String address = currentAddress != null && currentAddress.getAddressLine(0) != null ? currentAddress.getAddressLine(0) : "";
|
||||
AddressData addressData = new AddressData(currentLocation.latitude, currentLocation.longitude, address);
|
||||
|
||||
returnIntent.putExtra(ADDRESS_INTENT, addressData);
|
||||
setResult(RESULT_OK, returnIntent);
|
||||
finish();
|
||||
|
|
Loading…
Add table
Reference in a new issue