send POI messages from map

This commit is contained in:
cyBerta
2019-04-26 21:06:46 +02:00
parent 8cbe052761
commit 3060678d64
7 changed files with 123 additions and 23 deletions
+14 -3
View File
@@ -2,10 +2,10 @@
<android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dp"
android:layout_height="70dp"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:background="@drawable/map_bubble_add_poi"
android:paddingTop="8dp"
>
android:paddingTop="8dp">
<TextView
android:layout_width="wrap_content"
@@ -32,10 +32,12 @@
android:layout_marginEnd="4dp"
android:maxLines="1"
android:maxLength="16"
android:textAlignment="center"
android:layout_gravity="center"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/sendView"
android:layout_gravity="center_vertical"
@@ -49,6 +51,15 @@
android:contentDescription="@string/menu_send"
android:scaleType="fitCenter"
/>
<ProgressBar
android:id="@+id/sending_progress"
android:layout_width="35dp"
android:layout_height="35dp"
android:visibility="gone"
tools:visibility="visible"
/>
</RelativeLayout>
</LinearLayout>
@@ -1,30 +1,30 @@
package org.thoughtcrime.securesms.map;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.v7.widget.LinearLayoutCompat;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
import com.b44t.messenger.DcContext;
import com.b44t.messenger.DcMsg;
import com.mapbox.mapboxsdk.geometry.LatLng;
import org.thoughtcrime.securesms.ApplicationContext;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
import org.thoughtcrime.securesms.connect.DcHelper;
import static org.thoughtcrime.securesms.util.BitmapUtil.generateColoredBitmap;
/**
* Created by cyberta on 24.04.19.
*/
public class AddPoiView extends LinearLayoutCompat {
private ImageButton sendView;
private EditText messageView;
private ProgressBar progressBar;
private LatLng latLng;
private SendingTask.OnMessageSentListener listener;
private int chatId;
public AddPoiView(Context context) {
this(context, null);
@@ -39,17 +39,36 @@ public class AddPoiView extends LinearLayoutCompat {
inflate(context, R.layout.add_poi_view, this);
sendView = this.findViewById(R.id.sendView);
messageView = this.findViewById(R.id.message_view);
progressBar = this.findViewById(R.id.sending_progress);
sendView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//TODO: submit change
// DcHelper.getContext(AddPoiView.this.getContext()).
messageView.requestFocus();
sendView.setOnClickListener(v -> {
if (messageView.getText().toString().length() == 0) {
return;
}
progressBar.setVisibility(VISIBLE);
sendView.setVisibility(INVISIBLE);
DcContext dcContext = DcHelper.getContext(AddPoiView.this.getContext());
DcMsg msg = new DcMsg(dcContext, DcMsg.DC_MSG_TEXT);
msg.setLocation((float) latLng.getLatitude(), (float) latLng.getLongitude());
msg.setText(messageView.getText().toString());
SendingTask.Model model = new SendingTask.Model(msg, chatId, listener);
new SendingTask(AddPoiView.this.getContext()).execute(model);
});
}
public void setLatLng(LatLng latLng) {
this.latLng = latLng;
}
public void setChatId(int chatId) {
this.chatId = chatId;
}
public void setOnMessageSentListener(SendingTask.OnMessageSentListener listener) {
this.listener = listener;
}
}
@@ -24,6 +24,7 @@ import static org.thoughtcrime.securesms.map.MapDataManager.MARKER_CHAR;
import static org.thoughtcrime.securesms.map.MapDataManager.MARKER_ICON;
import static org.thoughtcrime.securesms.map.MapDataManager.MARKER_SELECTED;
import static org.thoughtcrime.securesms.map.MapDataManager.MESSAGE_ID;
import static org.thoughtcrime.securesms.map.MapDataManager.IS_POI;
import static org.thoughtcrime.securesms.map.MapDataManager.TIMESTAMP;
/**
@@ -91,10 +92,11 @@ public class DataCollector {
pointFeature.addNumberProperty(MESSAGE_ID, locations.getMsgId(i));
pointFeature.addNumberProperty(ACCURACY, locations.getAccuracy(i));
pointFeature.addStringProperty(MARKER_CHAR, codepointChar);
pointFeature.addBooleanProperty(IS_POI,locations.isIndependent(i));
pointFeature.addStringProperty(MARKER_ICON, contactMapMetadata.getMarkerIcon());
sortedPointFeatures.addFirst(pointFeature);
if (sortedPointFeatures.size() > 1) {
if (!locations.isIndependent(i) && sortedPointFeatures.size() > 1) {
Point lastPoint = (Point) sortedPointFeatures.get(1).geometry();
ArrayList<Point> lineSegmentPoints = new ArrayList<>(3);
lineSegmentPoints.add(lastPoint);
@@ -111,11 +113,15 @@ public class DataCollector {
}
if (sortedPointFeatures.size() > 0) {
Feature lastPostion = sortedPointFeatures.getFirst();
lastPostion.addStringProperty(LAST_POSITION_ICON, contactMapMetadata.getMarkerLastPositon());
lastPostion.removeProperty(MARKER_ICON);
lastPostion.addBooleanProperty(LAST_LOCATION, true);
lastPositions.put(contactId, lastPostion);
for (Feature position : sortedPointFeatures) {
if (!position.getBooleanProperty(IS_POI)) {
position.addStringProperty(LAST_POSITION_ICON, contactMapMetadata.getMarkerLastPositon());
position.removeProperty(MARKER_ICON);
position.addBooleanProperty(LAST_LOCATION, true);
lastPositions.put(contactId, position);
break;
}
}
}
featureCollections.put(contactMapMetadata.getMarkerFeatureCollection(), sortedPointFeatures);
@@ -52,13 +52,14 @@ public class MapActivity extends BaseActivity implements Observer, TimeRangeSlid
private MapboxMap mapboxMap;
DCMapFragment mapFragment;
MarkerViewManager markerViewManager;
private int chatId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
final int chatId = getIntent().getIntExtra(CHAT_ID, -1);
chatId = getIntent().getIntExtra(CHAT_ID, -1);
if (chatId == -1) {
finish();
@@ -187,6 +188,9 @@ public class MapActivity extends BaseActivity implements Observer, TimeRangeSlid
Prefs.setMapZoom(this.getApplicationContext(), mapDataManager.getChatId(), mapboxMap.getCameraPosition().zoom);
mapDataManager.onDestroy();
}
if (markerViewManager != null) {
markerViewManager.onDestroy();
}
}
@Override
@@ -285,6 +289,8 @@ public class MapActivity extends BaseActivity implements Observer, TimeRangeSlid
} else {
AddPoiView addPoiView = new AddPoiView(this);
addPoiView.setLatLng(point);
addPoiView.setChatId(chatId);
addPoiView.setOnMessageSentListener(markerViewManager);
markerViewManager.addMarker(new MarkerView(point, addPoiView));
}
return true;
@@ -81,6 +81,7 @@ public class MapDataManager implements DcEventCenter.DcEventDelegate, GenerateIn
public static final String ACCURACY = "ACCURACY";
public static final String MARKER_CHAR = "MARKER_CHAR";
public static final String MARKER_ICON = "MARKER_ICON";
public static final String IS_POI = "IS_POI";
public static final String LAST_POSITION_ICON = "LAST_POSITION_ICON";
private static final String INFO_WINDOW_SRC = "INFO_WINDOW_SRC";
private static final String LAST_POSITION_LAYER = "LAST_POSITION_LAYER";
@@ -12,7 +12,7 @@ import java.util.List;
/**
* Class responsible for synchronising views at a LatLng on top of a Map.
*/
public class MarkerViewManager implements MapView.OnDidFinishRenderingFrameListener {
public class MarkerViewManager implements MapView.OnDidFinishRenderingFrameListener, SendingTask.OnMessageSentListener {
private final MapView mapView;
private final MapboxMap mapboxMap;
@@ -101,4 +101,9 @@ public class MarkerViewManager implements MapView.OnDidFinishRenderingFrameListe
marker.update();
}
}
@Override
public void onMessageSent() {
removeMarkers();
}
}
@@ -0,0 +1,52 @@
package org.thoughtcrime.securesms.map;
import android.content.Context;
import android.os.AsyncTask;
import com.b44t.messenger.DcContext;
import com.b44t.messenger.DcMsg;
import org.thoughtcrime.securesms.connect.DcHelper;
public class SendingTask extends AsyncTask<SendingTask.Model, SendingTask.Model, SendingTask.Model> {
public interface OnMessageSentListener {
void onMessageSent();
}
public static class Model {
private final DcMsg msg;
private final int chatId;
private final OnMessageSentListener callback;
public Model(DcMsg msg,
int chatId,
OnMessageSentListener callback) {
this.msg = msg;
this.chatId = chatId;
this.callback = callback;
}
}
private final DcContext dcContext;
public SendingTask(Context context) {
this.dcContext = DcHelper.getContext(context);
}
@Override
protected Model doInBackground(Model... param) {
Model m = param[0];
if(m.msg!=null) {
dcContext.sendMsg(m.chatId, m.msg);
}
return m;
}
@Override
protected void onPostExecute(Model result) {
if (result.callback != null) {
result.callback.onMessageSent();
}
}
}