use of org.telegram.ui.Components.ProximitySheet in project Telegram-FOSS by Telegram-FOSS-Team.
the class LocationActivity method openProximityAlert.
private void openProximityAlert() {
if (proximityCircle == null) {
createCircle(500);
proximityCircleRadius = 500;
} else {
previousRadius = proximityCircleRadius;
}
TLRPC.User user;
if (DialogObject.isUserDialog(dialogId)) {
user = getMessagesController().getUser(dialogId);
} else {
user = null;
}
proximitySheet = new ProximitySheet(getParentActivity(), user, (move, radius) -> {
if (proximityCircle != null) {
proximityCircleRadius = radius;
proximityCircle.setPoints(Polygon.pointsAsCircle(proximityCircleCenter, radius));
if (move) {
moveToBounds(radius, true, true);
}
}
if (DialogObject.isChatDialog(dialogId)) {
return true;
}
for (int a = 0, N = markers.size(); a < N; a++) {
LiveLocation location = markers.get(a);
if (location.object == null || UserObject.isUserSelf(location.user)) {
continue;
}
TLRPC.GeoPoint point = location.object.media.geo;
Location loc = new Location("network");
loc.setLatitude(point.lat);
loc.setLongitude(point._long);
if (myLocation.distanceTo(loc) > radius) {
return true;
}
}
return false;
}, (move, radius) -> {
LocationController.SharingLocationInfo info = getLocationController().getSharingLocationInfo(dialogId);
if (info == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("ShareLocationAlertTitle", R.string.ShareLocationAlertTitle));
builder.setMessage(LocaleController.getString("ShareLocationAlertText", R.string.ShareLocationAlertText));
builder.setPositiveButton(LocaleController.getString("ShareLocationAlertButton", R.string.ShareLocationAlertButton), (dialog, id) -> shareLiveLocation(user, 900, radius));
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
return false;
}
proximitySheet.setRadiusSet();
proximityButton.setImageResource(R.drawable.msg_location_alert2);
getUndoView().showWithAction(0, UndoView.ACTION_PROXIMITY_SET, radius, user, null, null);
getLocationController().setProximityLocation(dialogId, radius, true);
return true;
}, () -> {
if (mapView != null) {
mapView.setPadding(AndroidUtilities.dp(70), 0, AndroidUtilities.dp(70), AndroidUtilities.dp(10));
}
if (!proximitySheet.getRadiusSet()) {
if (previousRadius > 0) {
proximityCircleRadius = previousRadius;
proximityCircle.setPoints(Polygon.pointsAsCircle(proximityCircleCenter, previousRadius));
} else if (proximityCircle != null) {
mapView.getOverlayManager().remove(proximityCircle);
proximityCircle = null;
}
}
proximitySheet = null;
});
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.addView(proximitySheet, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
proximitySheet.show();
}
Aggregations