diff --git a/jni/messenger-backend b/jni/messenger-backend index afee0f717..f49cd879b 160000 --- a/jni/messenger-backend +++ b/jni/messenger-backend @@ -1 +1 @@ -Subproject commit afee0f717f1b91a99e649a9d69d975eed811eee3 +Subproject commit f49cd879bd41f8c74e4f65835b0aa742b6e2745c diff --git a/src/com/b44t/messenger/DcContext.java b/src/com/b44t/messenger/DcContext.java index b9dab72de..a8c4dcfec 100644 --- a/src/com/b44t/messenger/DcContext.java +++ b/src/com/b44t/messenger/DcContext.java @@ -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 diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index 9be82b202..c59791b55 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -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); } diff --git a/src/org/thoughtcrime/securesms/components/AttachmentTypeSelector.java b/src/org/thoughtcrime/securesms/components/AttachmentTypeSelector.java index 096ebc050..1b8691647 100644 --- a/src/org/thoughtcrime/securesms/components/AttachmentTypeSelector.java +++ b/src/org/thoughtcrime/securesms/components/AttachmentTypeSelector.java @@ -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, diff --git a/src/org/thoughtcrime/securesms/components/CircleColorImageView.java b/src/org/thoughtcrime/securesms/components/CircleColorImageView.java index 179c80aec..1bb04a48b 100644 --- a/src/org/thoughtcrime/securesms/components/CircleColorImageView.java +++ b/src/org/thoughtcrime/securesms/components/CircleColorImageView.java @@ -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); diff --git a/src/org/thoughtcrime/securesms/geolocation/DcLocationManager.java b/src/org/thoughtcrime/securesms/geolocation/DcLocationManager.java index b3cba85c6..4b3054af7 100644 --- a/src/org/thoughtcrime/securesms/geolocation/DcLocationManager.java +++ b/src/org/thoughtcrime/securesms/geolocation/DcLocationManager.java @@ -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(); + } } } diff --git a/src/org/thoughtcrime/securesms/map/MapActivity.java b/src/org/thoughtcrime/securesms/map/MapActivity.java index a02678ce2..e38487a01 100644 --- a/src/org/thoughtcrime/securesms/map/MapActivity.java +++ b/src/org/thoughtcrime/securesms/map/MapActivity.java @@ -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 } diff --git a/src/org/thoughtcrime/securesms/mms/AttachmentManager.java b/src/org/thoughtcrime/securesms/mms/AttachmentManager.java index 9f424a1b2..7b24e4928 100644 --- a/src/org/thoughtcrime/securesms/mms/AttachmentManager.java +++ b/src/org/thoughtcrime/securesms/mms/AttachmentManager.java @@ -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() {