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.Parcelable;
import androidx.annotation.NonNull;
import java.util.Map;
import org.tasks.Objects;
import org.tasks.R;
public class CustomFilter extends Filter {
private static final int FILTER = R.drawable.ic_outline_filter_list_24px;
/** Parcelable Creator Object */
public static final Parcelable.Creator<CustomFilter> CREATOR =
new Parcelable.Creator<CustomFilter>() {
@ -31,11 +32,13 @@ public class CustomFilter extends Filter {
private long id;
private String criterion;
public CustomFilter(
String listingTitle, String sql, Map<String, Object> values, long id, String criterion) {
super(listingTitle, sql, values);
this.id = id;
this.criterion = criterion;
public CustomFilter(org.tasks.data.Filter filter) {
// TODO: replace dirty hack for missing column
super(
filter.getTitle(), filter.getSql().replace("tasks.userId=0", "1"), filter.getValuesAsMap());
this.id = filter.getId();
this.criterion = filter.getCriterion();
this.icon = FILTER;
}
private CustomFilter(Parcel parcel) {
@ -85,6 +88,7 @@ public class CustomFilter extends Filter {
@Override
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);
Filter filter =
new CustomFilter(
title, sql.toString(), values, storeObject.getId(), storeObject.getCriterion());
setResult(RESULT_OK, new Intent().putExtra(MainActivity.OPEN_FILTER, filter));
org.tasks.data.Filter filter = persist(title, sql.toString(), values);
Filter customFilter = new CustomFilter(filter);
setResult(RESULT_OK, new Intent().putExtra(MainActivity.OPEN_FILTER, customFilter));
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.transform;
import android.text.TextUtils;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.api.CustomFilter;
import com.todoroo.astrid.api.Filter;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.data.FilterDao;
public final class CustomFilterExposer {
private static final int filter = R.drawable.ic_outline_filter_list_24px;
private final FilterDao filterDao;
@Inject
@ -38,24 +33,6 @@ public final class CustomFilterExposer {
}
private Filter load(org.tasks.data.Filter savedFilter) {
if (savedFilter == null) {
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;
return savedFilter == null ? null : new CustomFilter(savedFilter);
}
}

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

Loading…
Cancel
Save