Fix chosen location not being sent sometimes.

This commit is contained in:
Clark
2023-06-06 11:42:24 -04:00
committed by Cody Henthorne
parent eae066b3a2
commit c491c9dc8c
5 changed files with 105 additions and 39 deletions

View File

@@ -1,9 +1,7 @@
package org.thoughtcrime.securesms.components.location;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
@@ -11,16 +9,20 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
import java.util.concurrent.ExecutionException;
public class SignalMapView extends LinearLayout {
private MapView mapView;
@@ -53,42 +55,50 @@ public class SignalMapView extends LinearLayout {
public ListenableFuture<Bitmap> display(final SignalPlace place) {
final SettableFuture<Bitmap> future = new SettableFuture<>();
this.mapView.onCreate(null);
this.mapView.onResume();
this.mapView.setVisibility(View.VISIBLE);
this.imageView.setVisibility(View.GONE);
this.mapView.getMapAsync(new OnMapReadyCallback() {
this.textView.setText(place.getDescription());
snapshot(place, mapView).addListener(new ListenableFuture.Listener<Bitmap>() {
@Override
public void onMapReady(final GoogleMap googleMap) {
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(place.getLatLong(), 13));
googleMap.addMarker(new MarkerOptions().position(place.getLatLong()));
googleMap.setBuildingsEnabled(true);
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.getUiSettings().setAllGesturesEnabled(false);
googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
googleMap.snapshot(new GoogleMap.SnapshotReadyCallback() {
@Override
public void onSnapshotReady(Bitmap bitmap) {
future.set(bitmap);
imageView.setImageBitmap(bitmap);
imageView.setVisibility(View.VISIBLE);
mapView.setVisibility(View.GONE);
mapView.onPause();
mapView.onDestroy();
}
});
}
});
public void onSuccess(Bitmap result) {
future.set(result);
imageView.setImageBitmap(result);
imageView.setVisibility(View.VISIBLE);
}
@Override
public void onFailure(ExecutionException e) {
future.setException(e);
}
});
this.textView.setText(place.getDescription());
return future;
}
public static ListenableFuture<Bitmap> snapshot(final LatLng place, @NonNull final MapView mapView) {
final SettableFuture<Bitmap> future = new SettableFuture<>();
mapView.onCreate(null);
mapView.onResume();
mapView.setVisibility(View.VISIBLE);
mapView.getMapAsync(googleMap -> {
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(place, 13));
googleMap.addMarker(new MarkerOptions().position(place));
googleMap.setBuildingsEnabled(true);
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.getUiSettings().setAllGesturesEnabled(false);
googleMap.setOnMapLoadedCallback(() -> googleMap.snapshot(bitmap -> {
future.set(bitmap);
mapView.setVisibility(View.GONE);
mapView.onPause();
mapView.onDestroy();
}));
});
return future;
}
public static ListenableFuture<Bitmap> snapshot(final SignalPlace place, @NonNull final MapView mapView) {
return snapshot(place.getLatLong(), mapView);
}
}