mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
start/stop location streaming from attachment window, use location related core bindings
This commit is contained in:
+1
-1
Submodule jni/messenger-backend updated: afee0f717f...f49cd879bd
@@ -154,6 +154,10 @@ public class DcContext {
|
||||
public native int joinSecurejoin (String qr);
|
||||
public native void sendLocationsToChat (int chat_id, int seconds);
|
||||
public native boolean isSendingLocationsToChat(int chat_id);
|
||||
|
||||
/**
|
||||
* @return true if at least one chat has location streaming enabled
|
||||
*/
|
||||
public native boolean setLocation (float latitude, float longitude, float accuracy);
|
||||
|
||||
// event handling - you should @Override this function in derived classes
|
||||
|
||||
@@ -554,7 +554,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
|
||||
private void handleAddAttachment() {
|
||||
if (attachmentTypeSelector == null) {
|
||||
attachmentTypeSelector = new AttachmentTypeSelector(this, getSupportLoaderManager(), new AttachmentTypeListener());
|
||||
attachmentTypeSelector = new AttachmentTypeSelector(this, getSupportLoaderManager(), new AttachmentTypeListener(), chatId);
|
||||
}
|
||||
attachmentTypeSelector.show(this, attachButton);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
@@ -56,8 +57,9 @@ public class AttachmentTypeSelector extends PopupWindow {
|
||||
|
||||
private @Nullable View currentAnchor;
|
||||
private @Nullable AttachmentClickedListener listener;
|
||||
private int chatId;
|
||||
|
||||
public AttachmentTypeSelector(@NonNull Context context, @NonNull LoaderManager loaderManager, @Nullable AttachmentClickedListener listener) {
|
||||
public AttachmentTypeSelector(@NonNull Context context, @NonNull LoaderManager loaderManager, @Nullable AttachmentClickedListener listener, int chatId) {
|
||||
super(context);
|
||||
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
@@ -65,6 +67,7 @@ public class AttachmentTypeSelector extends PopupWindow {
|
||||
|
||||
this.listener = listener;
|
||||
this.loaderManager = loaderManager;
|
||||
this.chatId = chatId;
|
||||
this.recentRail = ViewUtil.findById(layout, R.id.recent_photos);
|
||||
this.imageButton = ViewUtil.findById(layout, R.id.gallery_button);
|
||||
this.audioButton = ViewUtil.findById(layout, R.id.audio_button);
|
||||
@@ -83,6 +86,8 @@ public class AttachmentTypeSelector extends PopupWindow {
|
||||
this.closeButton.setOnClickListener(new CloseClickListener());
|
||||
this.recentRail.setListener(new RecentPhotoSelectedListener());
|
||||
|
||||
setLocationButtonImage(context);
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
|
||||
ViewUtil.findById(layout, R.id.location_linear_layout).setVisibility(View.INVISIBLE);
|
||||
}
|
||||
@@ -108,6 +113,7 @@ public class AttachmentTypeSelector extends PopupWindow {
|
||||
}
|
||||
|
||||
this.currentAnchor = anchor;
|
||||
setLocationButtonImage(activity);
|
||||
|
||||
showAtLocation(anchor, Gravity.BOTTOM, 0, 0);
|
||||
|
||||
@@ -149,6 +155,21 @@ public class AttachmentTypeSelector extends PopupWindow {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
private void setLocationButtonImage(Context context) {
|
||||
int resId;
|
||||
if (ApplicationContext.getInstance(context).dcContext.isSendingLocationsToChat(chatId)) {
|
||||
resId = R.drawable.ic_location_off_white_24;
|
||||
} else {
|
||||
resId = R.drawable.ic_location_on_white_24dp;
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
this.locationButton.setImageDrawable(context.getDrawable(resId));
|
||||
} else {
|
||||
this.locationButton.setImageDrawable(context.getResources().getDrawable(resId));
|
||||
}
|
||||
}
|
||||
|
||||
private void animateButtonIn(View button, int delay) {
|
||||
AnimationSet animation = new AnimationSet(true);
|
||||
Animation scale = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f,
|
||||
|
||||
@@ -3,15 +3,14 @@ package org.thoughtcrime.securesms.components;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.v7.widget.AppCompatImageView;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
|
||||
public class CircleColorImageView extends ImageView {
|
||||
public class CircleColorImageView extends AppCompatImageView {
|
||||
|
||||
public CircleColorImageView(Context context) {
|
||||
this(context, null);
|
||||
|
||||
@@ -8,6 +8,8 @@ import android.location.Location;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
@@ -64,9 +66,14 @@ public class DcLocationManager implements Observer {
|
||||
serviceBinder.stop();
|
||||
}
|
||||
|
||||
public void stopSharingLocation(int chatId) {
|
||||
ApplicationContext.getInstance(context).dcContext.sendLocationsToChat(chatId, 0);
|
||||
}
|
||||
|
||||
public void shareLocation(int duration, int chatId) {
|
||||
startLocationEngine();
|
||||
Log.d(TAG, String.format("Share location in chat %d for %d seconds", chatId, duration));
|
||||
ApplicationContext.getInstance(context).dcContext.sendLocationsToChat(chatId, duration);
|
||||
}
|
||||
|
||||
public void shareLastLocation(int chatId) {
|
||||
@@ -78,7 +85,8 @@ public class DcLocationManager implements Observer {
|
||||
|
||||
Location location = dcLocation.getLastLocation();
|
||||
Log.d(TAG, "share lastLocation: " + location.getLatitude() + ", " + location.getLongitude());
|
||||
//TODO: implement me! write share location message
|
||||
ApplicationContext.getInstance(context).dcContext.sendLocationsToChat(chatId, 1);
|
||||
ApplicationContext.getInstance(context).dcContext.setLocation((float) location.getLatitude(), (float) location.getLongitude(), location.getAccuracy());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,7 +98,12 @@ public class DcLocationManager implements Observer {
|
||||
}
|
||||
|
||||
private void writeDcLocationUpdateMessage() {
|
||||
//TODO: implement me!
|
||||
Log.d(TAG, "Share location: " + dcLocation.getLastLocation().getLatitude() + ", " + dcLocation.getLastLocation().getLongitude());
|
||||
Location lastLocation = dcLocation.getLastLocation();
|
||||
|
||||
boolean continueLocationStreaming = ApplicationContext.getInstance(context).dcContext.setLocation((float) lastLocation.getLatitude(), (float) lastLocation.getLongitude(), lastLocation.getAccuracy());
|
||||
if (!continueLocationStreaming) {
|
||||
stopLocationEngine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,16 +100,6 @@ public class MapActivity extends BaseActivity implements PermissionsListener, Ob
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
|
||||
//FIXME: only for testing --v
|
||||
DcLocationManager locationManager = ApplicationContext.getInstance(this).dcLocationManager;
|
||||
locationManager.stopLocationEngine();
|
||||
|
||||
}
|
||||
|
||||
//Android SDK callback for the result from requesting permissions
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
@@ -132,8 +122,7 @@ public class MapActivity extends BaseActivity implements PermissionsListener, Ob
|
||||
}
|
||||
|
||||
private void showDeviceLocation() {
|
||||
DcLocationManager locationManager = ApplicationContext.getInstance(this).dcLocationManager;
|
||||
locationManager.startLocationEngine();
|
||||
// TODO: draw own position on map
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ import android.widget.Toast;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
import org.thoughtcrime.securesms.MediaPreviewActivity;
|
||||
import org.thoughtcrime.securesms.MuteDialog;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.ShareLocationDialog;
|
||||
import org.thoughtcrime.securesms.attachments.Attachment;
|
||||
@@ -53,14 +52,13 @@ import org.thoughtcrime.securesms.permissions.Permissions;
|
||||
import org.thoughtcrime.securesms.providers.PersistentBlobProvider;
|
||||
import org.thoughtcrime.securesms.scribbles.ScribbleActivity;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
import org.thoughtcrime.securesms.util.ThemeUtil;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
|
||||
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture.Listener;
|
||||
import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
|
||||
import org.thoughtcrime.securesms.util.views.Stub;
|
||||
import org.thoughtcrime.securesms.util.guava.Optional;
|
||||
import org.thoughtcrime.securesms.util.views.Stub;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
@@ -391,26 +389,29 @@ public class AttachmentManager {
|
||||
}
|
||||
|
||||
public static void selectLocation(Activity activity, int chatId) {
|
||||
ApplicationContext applicationContext = ApplicationContext.getInstance(activity);
|
||||
DcLocationManager dcLocationManager = applicationContext.dcLocationManager;
|
||||
|
||||
if (applicationContext.dcContext.isSendingLocationsToChat(chatId)) {
|
||||
dcLocationManager.stopSharingLocation(chatId);
|
||||
return;
|
||||
}
|
||||
|
||||
Permissions.with(activity)
|
||||
.request(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION)
|
||||
.ifNecessary()
|
||||
.withPermanentDenialDialog(activity.getString(R.string.perm_explain_access_to_location_denied))
|
||||
.onAllGranted(() -> {
|
||||
|
||||
|
||||
ShareLocationDialog.show(activity, durationInSeconds -> {
|
||||
DcLocationManager dcLocationManager = ApplicationContext.getInstance(activity).dcLocationManager;
|
||||
switch (durationInSeconds) {
|
||||
case 1: dcLocationManager.shareLastLocation(chatId); break;
|
||||
default:
|
||||
dcLocationManager.shareLocation(durationInSeconds, chatId);
|
||||
break;
|
||||
}
|
||||
});
|
||||
})
|
||||
.execute();
|
||||
|
||||
.request(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION)
|
||||
.ifNecessary()
|
||||
.withPermanentDenialDialog(activity.getString(R.string.perm_explain_access_to_location_denied))
|
||||
.onAllGranted(() -> {
|
||||
ShareLocationDialog.show(activity, durationInSeconds -> {
|
||||
switch (durationInSeconds) {
|
||||
case 1: dcLocationManager.shareLastLocation(chatId); break;
|
||||
default:
|
||||
dcLocationManager.shareLocation(durationInSeconds, chatId);
|
||||
break;
|
||||
}
|
||||
});
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
|
||||
private @Nullable Uri getSlideUri() {
|
||||
|
||||
Reference in New Issue
Block a user