Fixes to featured list filter exposer and json parsing

pull/14/head
Sam Bosley 13 years ago
parent 1cd9f08c28
commit fd413fab35

@ -216,8 +216,7 @@ public final class ActFmDataService {
TagService.getInstance().rename(tagData.getValue(TagData.NAME), featObject.getString("name"));
cursor.moveToNext();
}
ActFmSyncService.JsonHelper.tagFromJson(featObject, tagData);
tagData.setFlag(TagData.FLAGS, TagData.FLAG_FEATURED, true);
ActFmSyncService.JsonHelper.featuredListFromJson(featObject, tagData);
tagDataService.save(tagData);
} finally {

@ -1424,10 +1424,21 @@ public final class ActFmSyncService {
* @throws JSONException
*/
public static void tagFromJson(JSONObject json, TagData model) throws JSONException {
parseTagDataFromJson(json, model, false);
}
public static void featuredListFromJson(JSONObject json, TagData model) throws JSONException {
parseTagDataFromJson(json, model, true);
}
private static void parseTagDataFromJson(JSONObject json, TagData model, boolean featuredList) throws JSONException {
model.clearValue(TagData.REMOTE_ID);
model.setValue(TagData.REMOTE_ID, json.getLong("id"));
model.setValue(TagData.NAME, json.getString("name"));
readUser(json.getJSONObject("user"), model, TagData.USER_ID, TagData.USER);
readUser(json.getJSONObject(featuredList ? "author" : "user"), model, TagData.USER_ID, TagData.USER);
if (featuredList)
model.setFlag(TagData.FLAGS, TagData.FLAG_FEATURED, true);
if(json.has("picture"))
model.setValue(TagData.PICTURE, json.optString("picture", ""));

@ -185,11 +185,15 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
filters[0] = untagged;
for(int i = 0; i < tags.length; i++)
filters[i+1] = filterFromTag(context, tags[i], TaskCriteria.activeAndVisible());
filters[i+1] = constructFilter(context, tags[i]);
FilterCategory filter = new FilterCategory(context.getString(name), filters);
return filter;
}
protected Filter constructFilter(Context context, Tag tag) {
return filterFromTag(context, tag, TaskCriteria.activeAndVisible());
}
// --- tag manipulation activities
public abstract static class TagActivity extends Activity {

@ -2,11 +2,23 @@ package com.todoroo.astrid.tags.reusable;
import java.util.List;
import android.content.ComponentName;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.astrid.actfm.TagViewFragment;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.api.FilterWithCustomIntent;
import com.todoroo.astrid.api.FilterWithUpdate;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.TaskApiDao.TaskCriteria;
import com.todoroo.astrid.tags.TagFilterExposer;
import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.tags.TagService.Tag;
@ -22,6 +34,35 @@ public class FeaturedListFilterExposer extends TagFilterExposer {
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
}
private static FilterWithCustomIntent filterFromFeaturedList(Tag tag, Criterion criterion) {
String title = tag.tag;
QueryTemplate tagTemplate = tag.queryTemplate(criterion);
ContentValues contentValues = new ContentValues();
contentValues.put(Metadata.KEY.name, TagService.KEY);
contentValues.put(TagService.TAG.name, tag.tag);
FilterWithUpdate filter = new FilterWithUpdate(tag.tag,
title, tagTemplate,
contentValues);
Class<?> fragmentClass = FeaturedListFragment.class;
filter.customTaskList = new ComponentName(ContextManager.getContext(), fragmentClass);
if(tag.image != null)
filter.imageUrl = tag.image;
Bundle extras = new Bundle();
extras.putString(TagViewFragment.EXTRA_TAG_NAME, tag.tag);
extras.putLong(TagViewFragment.EXTRA_TAG_REMOTE_ID, tag.remoteId);
filter.customExtras = extras;
return filter;
}
@Override
protected Filter constructFilter(Context context, Tag tag) {
return filterFromFeaturedList(tag, TaskCriteria.activeAndVisible());
}
@Override
protected List<Tag> getTagList() {
return TagService.getInstance().getFeaturedLists();

Loading…
Cancel
Save