mirror of https://github.com/tasks/tasks
Add LocationFilter
parent
d6aa21c4f9
commit
0b95b11b68
@ -0,0 +1,96 @@
|
||||
package org.tasks.filters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.todoroo.andlib.sql.Criterion;
|
||||
import com.todoroo.andlib.sql.Join;
|
||||
import com.todoroo.andlib.sql.QueryTemplate;
|
||||
import com.todoroo.astrid.api.Filter;
|
||||
import com.todoroo.astrid.api.FilterListItem;
|
||||
import com.todoroo.astrid.dao.TaskDao;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.tasks.R;
|
||||
import org.tasks.data.Geofence;
|
||||
import org.tasks.data.Place;
|
||||
|
||||
public class LocationFilter extends Filter {
|
||||
|
||||
public static final Parcelable.Creator<LocationFilter> CREATOR =
|
||||
new Parcelable.Creator<LocationFilter>() {
|
||||
|
||||
@Override
|
||||
public LocationFilter createFromParcel(Parcel source) {
|
||||
return new LocationFilter(source);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public LocationFilter[] newArray(int size) {
|
||||
return new LocationFilter[size];
|
||||
}
|
||||
};
|
||||
|
||||
private Place place;
|
||||
|
||||
private LocationFilter(Parcel source) {
|
||||
super();
|
||||
readFromParcel(source);
|
||||
place = source.readParcelable(getClass().getClassLoader());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
dest.writeParcelable(place, 0);
|
||||
}
|
||||
|
||||
public LocationFilter(Place place) {
|
||||
super(place.getDisplayName(), queryTemplate(place), getValuesForNewTask(place));
|
||||
this.place = place;
|
||||
}
|
||||
|
||||
public Place getPlace() {
|
||||
return place;
|
||||
}
|
||||
|
||||
private static QueryTemplate queryTemplate(Place place) {
|
||||
return new QueryTemplate()
|
||||
.join(Join.inner(Geofence.TABLE, Task.ID.eq(Geofence.TASK)))
|
||||
.join(Join.inner(Place.TABLE, Place.UID.eq(Geofence.PLACE)))
|
||||
.where(getCriterion(place));
|
||||
}
|
||||
|
||||
private static Criterion getCriterion(Place place) {
|
||||
return Criterion.and(TaskDao.TaskCriteria.activeAndVisible(), Place.UID.eq(place.getUid()));
|
||||
}
|
||||
|
||||
private static Map<String, Object> getValuesForNewTask(Place place) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put(Place.KEY, place.getUid());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBeginningMenu() {
|
||||
return R.menu.menu_location_list_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areItemsTheSame(@NonNull FilterListItem other) {
|
||||
return other instanceof LocationFilter
|
||||
&& place.getUid().equals(((LocationFilter) other).getPlace().getUid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areContentsTheSame(@NonNull FilterListItem other) {
|
||||
return place.equals(((LocationFilter) other).getPlace()) && count == other.count;
|
||||
}
|
||||
|
||||
public void openMap(Context context) {
|
||||
place.open(context);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package org.tasks.filters;
|
||||
|
||||
import androidx.room.Embedded;
|
||||
import org.tasks.data.Place;
|
||||
|
||||
public class LocationFilters {
|
||||
@Embedded public Place place;
|
||||
public int count;
|
||||
|
||||
public LocationFilter toLocationFilter() {
|
||||
LocationFilter filter = new LocationFilter(place);
|
||||
filter.count = count;
|
||||
return filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof LocationFilters)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LocationFilters that = (LocationFilters) o;
|
||||
|
||||
if (count != that.count) {
|
||||
return false;
|
||||
}
|
||||
return place != null ? place.equals(that.place) : that.place == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = place != null ? place.hashCode() : 0;
|
||||
result = 31 * result + count;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LocationFilters{" + "place=" + place + ", count=" + count + '}';
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M20.5,3l-0.16,0.03L15,5.1 9,3 3.36,4.9c-0.21,0.07 -0.36,0.25 -0.36,0.48L3,20.5c0,0.28 0.22,0.5 0.5,0.5l0.16,-0.03L9,18.9l6,2.1 5.64,-1.9c0.21,-0.07 0.36,-0.25 0.36,-0.48L21,3.5c0,-0.28 -0.22,-0.5 -0.5,-0.5zM10,5.47l4,1.4v11.66l-4,-1.4L10,5.47zM5,6.46l3,-1.01v11.7l-3,1.16L5,6.46zM19,17.54l-3,1.01L16,6.86l3,-1.16v11.84z"/>
|
||||
</vector>
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/menu_open_map"
|
||||
android:title="@string/open_map"
|
||||
android:icon="@drawable/ic_map_24px"
|
||||
app:showAsAction="ifRoom" />
|
||||
</menu>
|
Loading…
Reference in New Issue