diff --git a/app/src/main/java/org/tasks/data/Geofence.java b/app/src/main/java/org/tasks/data/Geofence.java index d0f687ff4..f76f9a707 100644 --- a/app/src/main/java/org/tasks/data/Geofence.java +++ b/app/src/main/java/org/tasks/data/Geofence.java @@ -1,16 +1,22 @@ package org.tasks.data; +import static org.tasks.data.Geofence.TABLE_NAME; + import android.os.Parcel; import android.os.Parcelable; import androidx.room.ColumnInfo; import androidx.room.Entity; import androidx.room.Ignore; import androidx.room.PrimaryKey; +import com.todoroo.andlib.data.Table; import java.io.Serializable; -@Entity(tableName = "geofences") +@Entity(tableName = TABLE_NAME) public class Geofence implements Serializable, Parcelable { + public static final String TABLE_NAME = "geofences"; + public static final Table TABLE = new Table(TABLE_NAME); + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { @Override diff --git a/app/src/main/java/org/tasks/data/Place.java b/app/src/main/java/org/tasks/data/Place.java index 0db6eab31..fa5678a8f 100644 --- a/app/src/main/java/org/tasks/data/Place.java +++ b/app/src/main/java/org/tasks/data/Place.java @@ -1,6 +1,7 @@ package org.tasks.data; import static com.mapbox.api.geocoding.v5.GeocodingCriteria.TYPE_ADDRESS; +import static org.tasks.data.Place.TABLE_NAME; import android.location.Location; import android.net.Uri; @@ -12,6 +13,7 @@ import androidx.room.Ignore; import androidx.room.PrimaryKey; import com.google.common.base.Strings; import com.mapbox.api.geocoding.v5.models.CarmenFeature; +import com.todoroo.andlib.data.Table; import com.todoroo.astrid.helper.UUIDHelper; import java.io.Serializable; import java.util.List; @@ -19,9 +21,12 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.tasks.location.MapPosition; -@Entity(tableName = "places") +@Entity(tableName = TABLE_NAME) public class Place implements Serializable, Parcelable { + public static final String TABLE_NAME = "places"; + public static final Table TABLE = new Table(TABLE_NAME); + public static final Creator CREATOR = new Creator() { @Override diff --git a/app/src/main/java/org/tasks/data/TaskContainer.java b/app/src/main/java/org/tasks/data/TaskContainer.java index 66d734187..2980663d8 100644 --- a/app/src/main/java/org/tasks/data/TaskContainer.java +++ b/app/src/main/java/org/tasks/data/TaskContainer.java @@ -6,6 +6,7 @@ import com.todoroo.astrid.data.Task; public class TaskContainer { @Embedded public Task task; @Embedded public GoogleTask googletask; + @Embedded public Location location; public String tags; public String caldav; public int children; @@ -130,6 +131,9 @@ public class TaskContainer { if (googletask != null ? !googletask.equals(that.googletask) : that.googletask != null) { return false; } + if (location != null ? !location.equals(that.location) : that.location != null) { + return false; + } if (tags != null ? !tags.equals(that.tags) : that.tags != null) { return false; } @@ -140,6 +144,7 @@ public class TaskContainer { public int hashCode() { int result = task != null ? task.hashCode() : 0; result = 31 * result + (googletask != null ? googletask.hashCode() : 0); + result = 31 * result + (location != null ? location.hashCode() : 0); result = 31 * result + (tags != null ? tags.hashCode() : 0); result = 31 * result + (caldav != null ? caldav.hashCode() : 0); result = 31 * result + children; @@ -158,6 +163,8 @@ public class TaskContainer { + task + ", googletask=" + googletask + + ", location=" + + location + ", tags='" + tags + '\'' @@ -207,11 +214,19 @@ public class TaskContainer { return googletask; } + public int getTargetIndent() { + return targetIndent; + } + public void setTargetIndent(int indent) { targetIndent = indent; } - public int getTargetIndent() { - return targetIndent; + public boolean hasLocation() { + return location != null; + } + + public Location getLocation() { + return location; } } diff --git a/app/src/main/java/org/tasks/tasklist/ViewHolder.java b/app/src/main/java/org/tasks/tasklist/ViewHolder.java index 684ed4e33..553552457 100644 --- a/app/src/main/java/org/tasks/tasklist/ViewHolder.java +++ b/app/src/main/java/org/tasks/tasklist/ViewHolder.java @@ -8,7 +8,9 @@ import static com.todoroo.andlib.utility.DateUtilities.getAbbreviatedRelativeDat import android.annotation.SuppressLint; import android.app.Activity; +import android.content.Intent; import android.graphics.Paint; +import android.net.Uri; import android.util.DisplayMetrics; import android.view.View; import android.view.ViewGroup; @@ -28,6 +30,7 @@ import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.ui.CheckableImageView; import java.util.List; import org.tasks.R; +import org.tasks.data.Location; import org.tasks.data.TaskContainer; import org.tasks.dialogs.Linkify; import org.tasks.locale.Locale; @@ -70,6 +73,9 @@ public class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.completeBox) CheckableImageView completeBox; + @BindView(R.id.location_chip) + Chip locationChip; + @BindView(R.id.chip_group) ChipGroup chipGroup; @@ -140,8 +146,9 @@ public class ViewHolder extends RecyclerView.ViewHolder { dueDate.setTextSize(fontSizeDetails); if (atLeastJellybeanMR1()) { - chipGroup.setLayoutDirection( - locale.isRtl() ? View.LAYOUT_DIRECTION_LTR : View.LAYOUT_DIRECTION_RTL); + int direction = locale.isRtl() ? View.LAYOUT_DIRECTION_LTR : View.LAYOUT_DIRECTION_RTL; + chipGroup.setLayoutDirection(direction); + locationChip.setLayoutDirection(direction); } else { MarginLayoutParams lp = (MarginLayoutParams) chipGroup.getLayoutParams(); lp.setMargins(lp.rightMargin, lp.topMargin, lp.leftMargin, lp.bottomMargin); @@ -206,6 +213,7 @@ public class ViewHolder extends RecyclerView.ViewHolder { setupTitleAndCheckbox(); setupDueDate(); if (preferences.getBoolean(R.string.p_show_list_indicators, true)) { + setupLocation(); setupTags(); } if (preferences.getBoolean(R.string.p_show_description, true)) { @@ -252,6 +260,22 @@ public class ViewHolder extends RecyclerView.ViewHolder { } } + private void setupLocation() { + if (task.hasLocation()) { + locationChip.setText(task.getLocation().getDisplayName()); + locationChip.setTag(task.getLocation()); + locationChip.setOnClickListener(v -> { + Location location = (Location) v.getTag(); + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse(location.getGeoUri())); + context.startActivity(intent); + }); + locationChip.setVisibility(View.VISIBLE); + } else { + locationChip.setVisibility(View.GONE); + } + } + private void setupTags() { String tags = task.getTagsString(); List tagUuids = tags != null ? newArrayList(tags.split(",")) : Lists.newArrayList(); diff --git a/app/src/main/java/org/tasks/ui/TaskListViewModel.java b/app/src/main/java/org/tasks/ui/TaskListViewModel.java index d9f2c1bd8..458b083f8 100644 --- a/app/src/main/java/org/tasks/ui/TaskListViewModel.java +++ b/app/src/main/java/org/tasks/ui/TaskListViewModel.java @@ -39,7 +39,9 @@ import java.util.Collections; import java.util.List; import javax.inject.Inject; import org.tasks.data.CaldavTask; +import org.tasks.data.Geofence; import org.tasks.data.GoogleTask; +import org.tasks.data.Place; import org.tasks.data.Tag; import org.tasks.data.TaskContainer; import org.tasks.preferences.Preferences; @@ -52,6 +54,8 @@ public class TaskListViewModel extends ViewModel implements Observer fields = Lists.newArrayList(TASKS, TAGS, GTASK, CALDAV); + List fields = Lists.newArrayList(TASKS, TAGS, GTASK, CALDAV, GEOFENCE, PLACE); Criterion tagsJoinCriterion = Criterion.and(Task.ID.eq(field(TAGS_METADATA_JOIN + ".task"))); Criterion gtaskJoinCriterion = @@ -118,9 +122,11 @@ public class TaskListViewModel extends ViewModel implements Observer + +