Pass Filter to CustomFilter constructor

pull/848/head
Alex Baker 5 years ago
parent 3371b16a68
commit 2fa0e700cd

@ -5,12 +5,13 @@ import static com.todoroo.andlib.utility.AndroidUtilities.mapToSerializedString;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import java.util.Map;
import org.tasks.Objects; import org.tasks.Objects;
import org.tasks.R; import org.tasks.R;
public class CustomFilter extends Filter { public class CustomFilter extends Filter {
private static final int FILTER = R.drawable.ic_outline_filter_list_24px;
/** Parcelable Creator Object */ /** Parcelable Creator Object */
public static final Parcelable.Creator<CustomFilter> CREATOR = public static final Parcelable.Creator<CustomFilter> CREATOR =
new Parcelable.Creator<CustomFilter>() { new Parcelable.Creator<CustomFilter>() {
@ -31,11 +32,13 @@ public class CustomFilter extends Filter {
private long id; private long id;
private String criterion; private String criterion;
public CustomFilter( public CustomFilter(org.tasks.data.Filter filter) {
String listingTitle, String sql, Map<String, Object> values, long id, String criterion) { // TODO: replace dirty hack for missing column
super(listingTitle, sql, values); super(
this.id = id; filter.getTitle(), filter.getSql().replace("tasks.userId=0", "1"), filter.getValuesAsMap());
this.criterion = criterion; this.id = filter.getId();
this.criterion = filter.getCriterion();
this.icon = FILTER;
} }
private CustomFilter(Parcel parcel) { private CustomFilter(Parcel parcel) {
@ -85,6 +88,7 @@ public class CustomFilter extends Filter {
@Override @Override
public boolean areContentsTheSame(@NonNull FilterListItem other) { public boolean areContentsTheSame(@NonNull FilterListItem other) {
return super.areContentsTheSame(other) && Objects.equals(criterion, ((CustomFilter) other).criterion); return super.areContentsTheSame(other)
&& Objects.equals(criterion, ((CustomFilter) other).criterion);
} }
} }

@ -248,11 +248,9 @@ public class CustomFilterActivity extends ThemedInjectingAppCompatActivity
} }
} }
org.tasks.data.Filter storeObject = persist(title, sql.toString(), values); org.tasks.data.Filter filter = persist(title, sql.toString(), values);
Filter filter = Filter customFilter = new CustomFilter(filter);
new CustomFilter( setResult(RESULT_OK, new Intent().putExtra(MainActivity.OPEN_FILTER, customFilter));
title, sql.toString(), values, storeObject.getId(), storeObject.getCriterion());
setResult(RESULT_OK, new Intent().putExtra(MainActivity.OPEN_FILTER, filter));
finish(); finish();
} }

@ -9,19 +9,14 @@ package com.todoroo.astrid.core;
import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.transform; import static com.google.common.collect.Lists.transform;
import android.text.TextUtils;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.api.CustomFilter; import com.todoroo.astrid.api.CustomFilter;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.inject.Inject; import javax.inject.Inject;
import org.tasks.R;
import org.tasks.data.FilterDao; import org.tasks.data.FilterDao;
public final class CustomFilterExposer { public final class CustomFilterExposer {
private static final int filter = R.drawable.ic_outline_filter_list_24px;
private final FilterDao filterDao; private final FilterDao filterDao;
@Inject @Inject
@ -38,24 +33,6 @@ public final class CustomFilterExposer {
} }
private Filter load(org.tasks.data.Filter savedFilter) { private Filter load(org.tasks.data.Filter savedFilter) {
if (savedFilter == null) { return savedFilter == null ? null : new CustomFilter(savedFilter);
return null;
}
String title = savedFilter.getTitle();
String sql = savedFilter.getSql();
String valuesString = savedFilter.getValues();
Map<String, Object> values = null;
if (!TextUtils.isEmpty(valuesString)) {
values = AndroidUtilities.mapFromSerializedString(valuesString);
}
sql = sql.replace("tasks.userId=0", "1"); // TODO: replace dirty hack for missing column
CustomFilter customFilter =
new CustomFilter(title, sql, values, savedFilter.getId(), savedFilter.getCriterion());
customFilter.icon = filter;
return customFilter;
} }
} }

@ -3,6 +3,9 @@ package org.tasks.data;
import androidx.room.ColumnInfo; import androidx.room.ColumnInfo;
import androidx.room.Entity; import androidx.room.Entity;
import androidx.room.PrimaryKey; import androidx.room.PrimaryKey;
import com.google.common.base.Strings;
import com.todoroo.andlib.utility.AndroidUtilities;
import java.util.Map;
@Entity(tableName = "filters") @Entity(tableName = "filters")
public class Filter { public class Filter {
@ -51,6 +54,10 @@ public class Filter {
return values; return values;
} }
public Map<String, Object> getValuesAsMap() {
return Strings.isNullOrEmpty(values) ? null : AndroidUtilities.mapFromSerializedString(values);
}
public void setValues(String values) { public void setValues(String values) {
this.values = values; this.values = values;
} }

Loading…
Cancel
Save