diff --git a/app/src/amazon/java/org/tasks/location/PlacePicker.java b/app/src/amazon/java/org/tasks/location/PlacePicker.java deleted file mode 100644 index b298ce354..000000000 --- a/app/src/amazon/java/org/tasks/location/PlacePicker.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.tasks.location; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import org.tasks.data.Location; -import org.tasks.preferences.Preferences; - -public class PlacePicker { - - public static Intent getIntent(Activity activity) { - return null; - } - - public static Location getPlace(Context context, Intent data, Preferences preferences) { - return null; - } -} diff --git a/app/src/generic/java/org/tasks/gtasks/PlayServices.java b/app/src/generic/java/org/tasks/gtasks/PlayServices.java index 28ec2ba07..62f2d0b59 100644 --- a/app/src/generic/java/org/tasks/gtasks/PlayServices.java +++ b/app/src/generic/java/org/tasks/gtasks/PlayServices.java @@ -7,7 +7,6 @@ import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposables; import javax.inject.Inject; import org.tasks.drive.DriveLoginActivity; -import org.tasks.location.LocationPickerActivity; import org.tasks.play.AuthResultHandler; public class PlayServices { @@ -38,8 +37,4 @@ public class PlayServices { public Disposable check(MainActivity mainActivity) { return Disposables.empty(); } - - public Disposable checkMaps(LocationPickerActivity locationPickerActivity) { - return Disposables.empty(); - } } diff --git a/app/src/googleplay/java/org/tasks/gtasks/PlayServices.java b/app/src/googleplay/java/org/tasks/gtasks/PlayServices.java index ac4c8ea37..4d1b8df31 100644 --- a/app/src/googleplay/java/org/tasks/gtasks/PlayServices.java +++ b/app/src/googleplay/java/org/tasks/gtasks/PlayServices.java @@ -17,7 +17,6 @@ import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity; import io.reactivex.Single; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.schedulers.Schedulers; import java.io.IOException; import javax.inject.Inject; @@ -71,21 +70,6 @@ public class PlayServices { }); } - public Disposable checkMaps(Activity activity) { - if (preferences.useGooglePlaces() || preferences.useGoogleMaps()) { - return Single.fromCallable(this::refreshAndCheck) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(success -> { - if (!success) { - resolve(activity); - } - }); - } else { - return EmptyDisposable.INSTANCE; - } - } - public boolean refreshAndCheck() { refresh(); return isPlayServicesAvailable(); diff --git a/app/src/main/java/org/tasks/data/Place.java b/app/src/main/java/org/tasks/data/Place.java index 46c064d9c..98ca46ce0 100644 --- a/app/src/main/java/org/tasks/data/Place.java +++ b/app/src/main/java/org/tasks/data/Place.java @@ -11,6 +11,7 @@ import com.google.common.base.Strings; import com.todoroo.astrid.helper.UUIDHelper; import java.io.Serializable; import java.util.regex.Pattern; +import org.tasks.location.MapPosition; @Entity(tableName = "places") public class Place implements Serializable, Parcelable { @@ -56,12 +57,6 @@ public class Place implements Serializable, Parcelable { @ColumnInfo(name = "longitude") private double longitude; - public static Place newPlace() { - Place place = new Place(); - place.setUid(UUIDHelper.newUUID()); - return place; - } - public Place() {} @Ignore @@ -88,6 +83,12 @@ public class Place implements Serializable, Parcelable { longitude = parcel.readDouble(); } + public static Place newPlace() { + Place place = new Place(); + place.setUid(UUIDHelper.newUUID()); + return place; + } + public long getId() { return id; } @@ -152,18 +153,6 @@ public class Place implements Serializable, Parcelable { this.url = url; } - public void apply(Place place) { - if (Strings.isNullOrEmpty(address)) { - address = place.address; - } - if (Strings.isNullOrEmpty(phone)) { - phone = place.phone; - } - if (Strings.isNullOrEmpty(url)) { - url = place.url; - } - } - public String getDisplayName() { if (Strings.isNullOrEmpty(address)) { return name; @@ -177,12 +166,16 @@ public class Place implements Serializable, Parcelable { return name; } - public String getGeoUri() { + String getGeoUri() { return String.format( "geo:%s,%s?q=%s", latitude, longitude, Uri.encode(Strings.isNullOrEmpty(address) ? name : address)); } + public MapPosition getMapPosition() { + return new MapPosition(latitude, longitude); + } + @Override public boolean equals(Object o) { if (this == o) { diff --git a/app/src/main/java/org/tasks/dialogs/LocationDialog.java b/app/src/main/java/org/tasks/dialogs/LocationDialog.java index 9cbc3685c..509e3ab87 100644 --- a/app/src/main/java/org/tasks/dialogs/LocationDialog.java +++ b/app/src/main/java/org/tasks/dialogs/LocationDialog.java @@ -8,7 +8,6 @@ import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.net.Uri; import android.os.Bundle; import android.os.Parcelable; import android.view.LayoutInflater; @@ -21,9 +20,9 @@ import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnCheckedChanged; import butterknife.OnClick; -import com.google.common.base.Strings; import javax.inject.Inject; import org.tasks.R; +import org.tasks.data.Geofence; import org.tasks.data.Location; import org.tasks.injection.DialogFragmentComponent; import org.tasks.injection.ForActivity; @@ -36,8 +35,8 @@ import org.tasks.ui.Toaster; public class LocationDialog extends InjectingDialogFragment { - public static final String EXTRA_LOCATION = "extra_location"; - public static final String EXTRA_ORIGINAL = "extra_original"; + public static final String EXTRA_GEOFENCE = "extra_geofence"; + private static final String EXTRA_ORIGINAL = "extra_original"; private static final String FRAG_TAG_SEEKBAR = "frag_tag_seekbar"; private static final int REQUEST_RADIUS = 10101; @@ -55,12 +54,6 @@ public class LocationDialog extends InjectingDialogFragment { @BindView(R.id.location_departure) Switch departureView; - @BindView(R.id.location_call) - TextView callView; - - @BindView(R.id.location_url) - TextView urlView; - @BindView(R.id.location_radius_value) TextView radiusValue; @@ -82,36 +75,26 @@ public class LocationDialog extends InjectingDialogFragment { @NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { - Location location = + Location original = getArguments().getParcelable(EXTRA_ORIGINAL); + Geofence geofence = savedInstanceState == null - ? getOriginal() - : savedInstanceState.getParcelable(EXTRA_LOCATION); + ? original.geofence + : savedInstanceState.getParcelable(EXTRA_GEOFENCE); LayoutInflater layoutInflater = LayoutInflater.from(context); View view = layoutInflater.inflate(R.layout.location_details, null); ButterKnife.bind(this, view); boolean hasLocationPermission = permissionChecker.canAccessLocation(); - arrivalView.setChecked(hasLocationPermission && location.isArrival()); - departureView.setChecked(hasLocationPermission && location.isDeparture()); - updateRadius(location.getRadius()); - String phone = location.getPhone(); - if (!Strings.isNullOrEmpty(phone)) { - callView.setVisibility(View.VISIBLE); - callView.setText(getString(R.string.call_number, phone)); - } - String url = location.getUrl(); - if (!Strings.isNullOrEmpty(url)) { - urlView.setVisibility(View.VISIBLE); - urlView.setText(getString(R.string.open_url, url)); - } + arrivalView.setChecked(hasLocationPermission && geofence.isArrival()); + departureView.setChecked(hasLocationPermission && geofence.isDeparture()); + updateRadius(geofence.getRadius()); return dialogBuilder .newDialog() - .setTitle(location.getDisplayName()) + .setTitle(original.getDisplayName()) .setView(view) .setNegativeButton(android.R.string.cancel, null) .setOnCancelListener(this::sendResult) .setPositiveButton(android.R.string.ok, this::sendResult) - .setNeutralButton(R.string.delete, this::delete) .create(); } @@ -120,29 +103,17 @@ public class LocationDialog extends InjectingDialogFragment { sendResult(dialog); } - private Location toLocation() { - Location result = getOriginal(); - result.setArrival(arrivalView.isChecked()); - result.setDeparture(departureView.isChecked()); - result.setRadius((int) radiusValue.getTag()); - return result; - } - - private Location getOriginal() { - return getArguments().getParcelable(EXTRA_ORIGINAL); + private Geofence toGeofence() { + Geofence geofence = new Geofence(); + geofence.setArrival(arrivalView.isChecked()); + geofence.setDeparture(departureView.isChecked()); + geofence.setRadius((int) radiusValue.getTag()); + return geofence; } private void sendResult(DialogInterface d, int... i) { - sendResult(toLocation()); - } - - private void delete(DialogInterface d, int i) { - sendResult(null); - } - - private void sendResult(Location result) { Intent data = new Intent(); - data.putExtra(EXTRA_LOCATION, (Parcelable) result); + data.putExtra(EXTRA_GEOFENCE, (Parcelable) toGeofence()); getTargetFragment().onActivityResult(getTargetRequestCode(), RESULT_OK, data); dismiss(); } @@ -151,7 +122,7 @@ public class LocationDialog extends InjectingDialogFragment { public void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); - outState.putParcelable(EXTRA_LOCATION, toLocation()); + outState.putParcelable(EXTRA_GEOFENCE, toGeofence()); } @Override @@ -191,24 +162,10 @@ public class LocationDialog extends InjectingDialogFragment { } } - @OnClick(R.id.location_url) - void openUrl() { - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(getOriginal().getUrl())); - startActivity(intent); - } - - @OnClick(R.id.location_call) - void openDialer() { - Intent intent = new Intent(Intent.ACTION_DIAL); - intent.setData(Uri.parse("tel:" + getOriginal().getPhone())); - startActivity(intent); - } - @OnClick(R.id.location_radius) void selectRadius() { SeekBarDialog seekBarDialog = - newSeekBarDialog(R.layout.dialog_radius_seekbar, 75, 1000, toLocation().getRadius()); + newSeekBarDialog(R.layout.dialog_radius_seekbar, 75, 1000, toGeofence().getRadius()); seekBarDialog.setTargetFragment(this, REQUEST_RADIUS); seekBarDialog.show(getFragmentManager(), FRAG_TAG_SEEKBAR); } diff --git a/app/src/main/java/org/tasks/location/LocationPickerActivity.java b/app/src/main/java/org/tasks/location/LocationPickerActivity.java index 9b969dc6a..97ac0483e 100644 --- a/app/src/main/java/org/tasks/location/LocationPickerActivity.java +++ b/app/src/main/java/org/tasks/location/LocationPickerActivity.java @@ -55,9 +55,9 @@ import org.tasks.Event; import org.tasks.R; import org.tasks.billing.Inventory; import org.tasks.data.LocationDao; +import org.tasks.data.Place; import org.tasks.data.PlaceUsage; import org.tasks.dialogs.DialogBuilder; -import org.tasks.gtasks.PlayServices; import org.tasks.injection.ActivityComponent; import org.tasks.injection.ForApplication; import org.tasks.injection.InjectingAppCompatActivity; @@ -81,6 +81,7 @@ public class LocationPickerActivity extends InjectingAppCompatActivity OnPredictionPicked, OnActionExpandListener { + public static final String EXTRA_PLACE = "extra_place"; private static final String EXTRA_MAP_POSITION = "extra_map_position"; private static final String EXTRA_APPBAR_OFFSET = "extra_appbar_offset"; private static final Pattern pattern = Pattern.compile("(\\d+):(\\d+):(\\d+\\.\\d+)"); @@ -111,7 +112,6 @@ public class LocationPickerActivity extends InjectingAppCompatActivity @Inject Theme theme; @Inject Toaster toaster; @Inject Inventory inventory; - @Inject PlayServices playServices; @Inject LocationDao locationDao; @Inject PlaceSearchProvider searchProvider; @Inject PermissionChecker permissionChecker; @@ -170,7 +170,15 @@ public class LocationPickerActivity extends InjectingAppCompatActivity searchView.setVisibility(View.GONE); } - if (savedInstanceState != null) { + Place currentPlace = getIntent().getParcelableExtra(EXTRA_PLACE); + recentsAdapter.setCurrentPlace(currentPlace); + + if (savedInstanceState == null) { + if (currentPlace != null) { + mapPosition = currentPlace.getMapPosition(); + } + mapPosition = getIntent().getParcelableExtra(EXTRA_MAP_POSITION); + } else { mapPosition = savedInstanceState.getParcelable(EXTRA_MAP_POSITION); offset = savedInstanceState.getInt(EXTRA_APPBAR_OFFSET); viewModel.restoreState(savedInstanceState); @@ -305,7 +313,6 @@ public class LocationPickerActivity extends InjectingAppCompatActivity @OnClick(R.id.select_this_location) void selectLocation() { loadingIndicator.setVisibility(View.VISIBLE); - MapPosition mapPosition = map.getMapPosition(); disposables.add( Single.fromCallable( @@ -361,8 +368,7 @@ public class LocationPickerActivity extends InjectingAppCompatActivity Location location = result.getLastLocation(); if (location != null) { map.movePosition( - new MapPosition(location.getLatitude(), location.getLongitude(), 15f), - animate); + new MapPosition(location.getLatitude(), location.getLongitude()), animate); } } @@ -382,16 +388,13 @@ public class LocationPickerActivity extends InjectingAppCompatActivity org.tasks.data.Place existing = locationDao.findPlace(place.getLatitude(), place.getLongitude()); if (existing == null) { - long placeId = locationDao.insert(place); - place.setId(placeId); + place.setId(locationDao.insert(place)); } else { - existing.apply(place); - locationDao.update(existing); place = existing; } } hideKeyboard(this); - setResult(RESULT_OK, new Intent().putExtra(PlacePicker.EXTRA_PLACE, (Parcelable) place)); + setResult(RESULT_OK, new Intent().putExtra(EXTRA_PLACE, (Parcelable) place)); finish(); } @@ -401,13 +404,12 @@ public class LocationPickerActivity extends InjectingAppCompatActivity viewModel.observe(this, searchAdapter::submitList, this::returnPlace, this::handleError); - disposables = new CompositeDisposable(playServices.checkMaps(this)); - - disposables.add( - searchSubject - .debounce(SEARCH_DEBOUNCE_TIMEOUT, TimeUnit.MILLISECONDS) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(query -> viewModel.query(query, mapPosition))); + disposables = + new CompositeDisposable( + searchSubject + .debounce(SEARCH_DEBOUNCE_TIMEOUT, TimeUnit.MILLISECONDS) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(query -> viewModel.query(query, mapPosition))); } private void handleError(Event error) { diff --git a/app/src/main/java/org/tasks/location/LocationPickerAdapter.java b/app/src/main/java/org/tasks/location/LocationPickerAdapter.java index 207e51f20..3d982beeb 100644 --- a/app/src/main/java/org/tasks/location/LocationPickerAdapter.java +++ b/app/src/main/java/org/tasks/location/LocationPickerAdapter.java @@ -5,6 +5,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.recyclerview.widget.DiffUtil.ItemCallback; import androidx.recyclerview.widget.ListAdapter; import androidx.recyclerview.widget.RecyclerView; @@ -17,6 +18,7 @@ import org.tasks.location.LocationPickerAdapter.PlaceViewHolder; public class LocationPickerAdapter extends ListAdapter { private final OnLocationPicked callback; + private Place currentPlace; LocationPickerAdapter(OnLocationPicked callback) { super(new DiffCallback()); @@ -24,6 +26,10 @@ public class LocationPickerAdapter extends ListAdapter 0 ? View.GONE : View.VISIBLE); + delete.setVisibility(placeUsage.count > 0 || place.equals(currentPlace) ? View.GONE : View.VISIBLE); } } diff --git a/app/src/main/java/org/tasks/location/MapPosition.java b/app/src/main/java/org/tasks/location/MapPosition.java index 9bf9531c6..2426e7499 100644 --- a/app/src/main/java/org/tasks/location/MapPosition.java +++ b/app/src/main/java/org/tasks/location/MapPosition.java @@ -21,6 +21,10 @@ public class MapPosition implements Parcelable { private final double longitude; private final float zoom; + public MapPosition(double latitude, double longitude) { + this(latitude, longitude, 15.0f); + } + public MapPosition(double latitude, double longitude, float zoom) { this.latitude = latitude; this.longitude = longitude; diff --git a/app/src/main/java/org/tasks/location/PlacePicker.java b/app/src/main/java/org/tasks/location/PlacePicker.java deleted file mode 100644 index 38cbb1c8f..000000000 --- a/app/src/main/java/org/tasks/location/PlacePicker.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.tasks.location; - -import android.app.Activity; -import android.content.Intent; -import org.tasks.R; -import org.tasks.data.Geofence; -import org.tasks.data.Location; -import org.tasks.preferences.Preferences; -import timber.log.Timber; - -public class PlacePicker { - - static final String EXTRA_PLACE = "extra_place"; - - public static Intent getIntent(Activity activity) { - return new Intent(activity, LocationPickerActivity.class); - } - - public static Location getPlace(Intent data, Preferences preferences) { - org.tasks.data.Place result = data.getParcelableExtra(EXTRA_PLACE); - - Geofence g = new Geofence(); - g.setRadius(preferences.getInt(R.string.p_default_location_radius, 250)); - int defaultReminders = - preferences.getIntegerFromString(R.string.p_default_location_reminder_key, 1); - g.setArrival(defaultReminders == 1 || defaultReminders == 3); - g.setDeparture(defaultReminders == 2 || defaultReminders == 3); - - Location location = new Location(g, result); - Timber.i("Picked %s", location); - return location; - } -} diff --git a/app/src/main/java/org/tasks/ui/LocationControlSet.java b/app/src/main/java/org/tasks/ui/LocationControlSet.java index 46e75c7d4..8900e36b2 100644 --- a/app/src/main/java/org/tasks/ui/LocationControlSet.java +++ b/app/src/main/java/org/tasks/ui/LocationControlSet.java @@ -1,27 +1,34 @@ package org.tasks.ui; +import static com.google.common.collect.Lists.newArrayList; +import static com.google.common.collect.Lists.transform; import static org.tasks.dialogs.LocationDialog.newLocationDialog; +import static org.tasks.location.LocationPickerActivity.EXTRA_PLACE; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; +import android.os.Parcelable; import android.text.SpannableString; import android.text.Spanned; -import android.text.method.LinkMovementMethod; import android.text.style.ClickableSpan; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.core.util.Pair; import butterknife.BindView; import butterknife.OnClick; import com.google.common.base.Strings; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.astrid.data.Task; +import java.util.ArrayList; import java.util.Collections; +import java.util.List; import javax.inject.Inject; import org.tasks.R; import org.tasks.data.Geofence; @@ -32,7 +39,7 @@ import org.tasks.dialogs.DialogBuilder; import org.tasks.dialogs.LocationDialog; import org.tasks.injection.FragmentComponent; import org.tasks.location.GeofenceApi; -import org.tasks.location.PlacePicker; +import org.tasks.location.LocationPickerActivity; import org.tasks.preferences.Preferences; public class LocationControlSet extends TaskEditControlFragment { @@ -56,9 +63,8 @@ public class LocationControlSet extends TaskEditControlFragment { TextView locationAddress; @BindView(R.id.location_more) - View locationOptions; + ImageView locationOptions; - private long taskId; private Location original; private Location location; @@ -68,28 +74,85 @@ public class LocationControlSet extends TaskEditControlFragment { LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); - taskId = task.getId(); - if (savedInstanceState == null) { - original = locationDao.getGeofences(taskId); - location = original; + if (!task.isNew()) { + original = locationDao.getGeofences(task.getId()); + if (original != null) { + setLocation(new Location(original.geofence, original.place)); + } + } } else { original = savedInstanceState.getParcelable(EXTRA_ORIGINAL); - location = savedInstanceState.getParcelable(EXTRA_LOCATION); + setLocation(savedInstanceState.getParcelable(EXTRA_LOCATION)); } - updateUI(); - return view; } + private void setLocation(@Nullable Location location) { + this.location = location; + if (this.location == null) { + locationName.setText(""); + locationOptions.setVisibility(View.GONE); + locationAddress.setVisibility(View.GONE); + } else { + locationOptions.setVisibility(View.VISIBLE); + locationOptions.setImageResource( + this.location.isArrival() || this.location.isDeparture() + ? R.drawable.ic_outline_notifications_24px + : R.drawable.ic_outline_notifications_off_24px); + String name = this.location.getDisplayName(); + String address = this.location.getAddress(); + if (!Strings.isNullOrEmpty(address) && !address.equals(name)) { + locationAddress.setText(address); + locationAddress.setVisibility(View.VISIBLE); + } else { + locationAddress.setVisibility(View.GONE); + } + SpannableString spannableString = new SpannableString(name); + spannableString.setSpan( + new ClickableSpan() { + @Override + public void onClick(@NonNull View view) {} + }, + 0, + name.length(), + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + locationName.setText(spannableString); + } + } + @OnClick({R.id.location_name, R.id.location_address}) - void addAlarm(View view) { + void locationClick(View view) { if (location == null) { - startActivityForResult(PlacePicker.getIntent(getActivity()), REQUEST_LOCATION_REMINDER); + chooseLocation(); } else { - openMap(); + List> options = new ArrayList<>(); + options.add(Pair.create(R.string.open_map, this::openMap)); + if (!Strings.isNullOrEmpty(location.getPhone())) { + options.add(Pair.create(R.string.action_call, this::call)); + } + if (!Strings.isNullOrEmpty(location.getUrl())) { + options.add(Pair.create(R.string.visit_website, this::openWebsite)); + } + options.add(Pair.create(R.string.choose_new_location, this::chooseLocation)); + options.add(Pair.create(R.string.delete, () -> setLocation(null))); + dialogBuilder + .newDialog() + .setTitle(location.getDisplayName()) + .setItems( + newArrayList(transform(options, o -> getString(o.first))), + (dialog, which) -> options.get(which).second.run()) + .show(); + } + } + + private void chooseLocation() { + Intent intent = new Intent(getActivity(), LocationPickerActivity.class); + if (location != null) { + intent.putExtra(EXTRA_PLACE, (Parcelable) location.place); } + startActivityForResult(intent, REQUEST_LOCATION_REMINDER); } @OnClick(R.id.location_more) @@ -114,46 +177,34 @@ public class LocationControlSet extends TaskEditControlFragment { return TAG; } - private void updateUI() { - if (location == null) { - locationName.setText(""); - locationOptions.setVisibility(View.GONE); - locationAddress.setVisibility(View.GONE); - } else { - locationOptions.setVisibility(View.VISIBLE); - String name = location.getDisplayName(); - String address = location.getAddress(); - if (!Strings.isNullOrEmpty(address) && !address.equals(name)) { - locationAddress.setText(address); - locationAddress.setVisibility(View.VISIBLE); - } else { - locationAddress.setVisibility(View.GONE); - } - SpannableString spannableString = new SpannableString(name); - spannableString.setSpan( - new ClickableSpan() { - @Override - public void onClick(@NonNull View view) { - openMap(); - } - }, - 0, - name.length(), - Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - locationName.setText(spannableString); - locationName.setMovementMethod(LinkMovementMethod.getInstance()); - } - } - private void openMap() { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(location.getGeoUri())); startActivity(intent); } + private void openWebsite() { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(location.getUrl()))); + } + + private void call() { + startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + location.getPhone()))); + } + @Override public boolean hasChanges(Task task) { - return original == null ? location == null : !original.equals(location); + if (original == null) { + return location != null; + } + if (location == null) { + return true; + } + if (!original.place.equals(location.place)) { + return true; + } + return original.isDeparture() != location.isDeparture() + || original.isArrival() != location.isArrival() + || original.getRadius() != location.getRadius(); } @Override @@ -165,7 +216,7 @@ public class LocationControlSet extends TaskEditControlFragment { if (location != null) { Place place = location.place; Geofence geofence = location.geofence; - geofence.setTask(taskId); + geofence.setTask(task.getId()); geofence.setPlace(place.getUid()); geofence.setId(locationDao.insert(geofence)); geofenceApi.register(Collections.singletonList(location)); @@ -185,13 +236,26 @@ public class LocationControlSet extends TaskEditControlFragment { public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_LOCATION_REMINDER) { if (resultCode == Activity.RESULT_OK) { - location = PlacePicker.getPlace(data, preferences); - updateUI(); + Place place = data.getParcelableExtra(EXTRA_PLACE); + Geofence geofence = new Geofence(); + if (location == null) { + geofence.setRadius(preferences.getInt(R.string.p_default_location_radius, 250)); + int defaultReminders = + preferences.getIntegerFromString(R.string.p_default_location_reminder_key, 1); + geofence.setArrival(defaultReminders == 1 || defaultReminders == 3); + geofence.setDeparture(defaultReminders == 2 || defaultReminders == 3); + } else { + Geofence existing = location.geofence; + geofence.setArrival(existing.isArrival()); + geofence.setDeparture(existing.isDeparture()); + geofence.setRadius(existing.getRadius()); + } + setLocation(new Location(geofence, place)); } } else if (requestCode == REQUEST_LOCATION_DETAILS) { if (resultCode == Activity.RESULT_OK) { - location = data.getParcelableExtra(LocationDialog.EXTRA_LOCATION); - updateUI(); + location.geofence = data.getParcelableExtra(LocationDialog.EXTRA_GEOFENCE); + setLocation(location); } } else { super.onActivityResult(requestCode, resultCode, data); diff --git a/app/src/main/res/drawable/ic_outline_more_vert_24px.xml b/app/src/main/res/drawable/ic_outline_more_vert_24px.xml deleted file mode 100644 index 1cec69689..000000000 --- a/app/src/main/res/drawable/ic_outline_more_vert_24px.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_outline_notifications_off_24px.xml b/app/src/main/res/drawable/ic_outline_notifications_off_24px.xml new file mode 100644 index 000000000..1a1c86a89 --- /dev/null +++ b/app/src/main/res/drawable/ic_outline_notifications_off_24px.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/location_details.xml b/app/src/main/res/layout/location_details.xml index 46b920a72..8edb17f3a 100644 --- a/app/src/main/res/layout/location_details.xml +++ b/app/src/main/res/layout/location_details.xml @@ -8,37 +8,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> - - Show list chips Remind on arrival Remind on departure - Call %s - Open %s + Visit website Arrived at %s Departed %s Generating notifications - Choose a recent location + Choose a location Select this location Or choose a location Map provider @@ -883,4 +882,6 @@ File %1$s contained %2$s.\n\n Missing permissions Location permissions are needed for location reminders Location permissions are needed to find your current location + Open map + Choose new location