Started with infrastructure for featured lists

pull/14/head
Sam Bosley 13 years ago
parent e76e3ce8ca
commit e4295194a5

@ -128,6 +128,9 @@ public final class TagData extends RemoteModel {
/** whether tag is emergent */
public static final int FLAG_EMERGENT = 1 << 2;
/** whether tag represents a featured list */
public static final int FLAG_FEATURED = 1 << 3;
// --- defaults
/** Default values container */

@ -339,6 +339,15 @@
<activity android:name="com.todoroo.astrid.people.PeopleViewActivity"
android:windowSoftInputMode="stateHidden|adjustResize"/>
<!-- Featured lists -->
<receiver android:name="com.todoroo.astrid.tags.reusable.FeaturedListFilterExposer">
<intent-filter>
<action android:name="com.timsu.astrid.REQUEST_FEATURED_LISTS"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
<!-- alarms -->
<receiver android:name="com.todoroo.astrid.alarms.AlarmTaskRepeatListener">
<intent-filter>

@ -17,6 +17,7 @@ import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Join;
import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
@ -202,6 +203,28 @@ public final class ActFmDataService {
}
}
@SuppressWarnings("nls")
public void saveFeaturedList(JSONObject featObject) throws JSONException {
TodorooCursor<TagData> cursor = tagDataService.query(Query.select(TagData.PROPERTIES).where(
Criterion.and(Functions.bitwiseAnd(TagData.FLAGS, TagData.FLAG_FEATURED).gt(0),TagData.REMOTE_ID.eq(featObject.get("id")))));
try {
cursor.moveToNext();
TagData tagData = new TagData();
if (!cursor.isAfterLast()) {
tagData.readFromCursor(cursor);
if(!tagData.getValue(TagData.NAME).equals(featObject.getString("name")))
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);
tagDataService.save(tagData);
} finally {
cursor.close();
}
}
/**
* Save / Merge JSON user
* @param userObject

@ -833,6 +833,20 @@ public final class ActFmSyncService {
return result.optInt("time", 0);
}
public int fetchFeaturedLists(int serverTime) throws JSONException, IOException {
if (!checkForToken())
return 0;
JSONObject result = actFmInvoker.invoke("featured_lists",
"token", token, "modified_after", serverTime);
JSONArray featuredLists = result.getJSONArray("list");
for (int i = 0; i < featuredLists.length(); i++) {
JSONObject featObject = featuredLists.getJSONObject(i);
actFmDataService.saveFeaturedList(featObject);
}
return result.optInt("time", 0);
}
public int fetchUsers() throws JSONException, IOException {
if (!checkForToken())
return 0;

@ -132,6 +132,8 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
private static final String LAST_TAG_FETCH_TIME = "actfm_lastTag"; //$NON-NLS-1$
private static final String LAST_FEATURED_TAG_FETCH_TIME = "actfm_last_featuredTag"; //$NON-NLS-1$
private static final String LAST_USERS_FETCH_TIME = "actfm_lastUsers"; //$NON-NLS-1$
// --- synchronize active tasks
@ -143,9 +145,9 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
new Thread(new Runnable() {
public void run() {
callback.started();
callback.incrementMax(140);
callback.incrementMax(160);
final AtomicInteger finisher = new AtomicInteger(4);
final AtomicInteger finisher = new AtomicInteger(5);
actFmPreferenceService.recordSyncStart();
updateUserStatus();
@ -156,6 +158,8 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
startUpdatesFetcher(manual, callback, finisher);
startFeaturedListFetcher(callback, finisher);
actFmSyncService.waitUntilEmpty();
startTaskFetcher(manual, callback, finisher);
@ -252,7 +256,30 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
}
}
});
}
/** fetch changes to tags */
private void startFeaturedListFetcher(final SyncResultCallback callback,
final AtomicInteger finisher) {
new Thread(new Runnable() {
@Override
public void run() {
int time = Preferences.getInt(LAST_FEATURED_TAG_FETCH_TIME, 0);
try {
time = actFmSyncService.fetchFeaturedLists(time);
Preferences.setInt(LAST_FEATURED_TAG_FETCH_TIME, time);
} catch (JSONException e) {
handler.handleException("actfm-sync", e, e.toString()); //$NON-NLS-1$
} catch (IOException e) {
handler.handleException("actfm-sync", e, e.toString()); //$NON-NLS-1$
} finally {
callback.incrementProgress(20);
if(finisher.decrementAndGet() == 0) {
finishSync(callback);
}
}
}
}).start();
}
/** @return runnable to fetch changes to tags */

@ -17,8 +17,8 @@ public class PeopleListFragment extends FilterListFragment {
@Override
protected int getLayout(Activity activity) {
if (AndroidUtilities.isTabletSized(activity))
return R.layout.people_list_fragment_3pane;
return R.layout.filter_list_fragment_alternative_3pane;
else
return R.layout.people_list_fragment;
return R.layout.filter_list_fragment_alternative;
}
}

@ -4,6 +4,7 @@
package com.todoroo.astrid.tags;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.BroadcastReceiver;
@ -140,7 +141,7 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
}
private FilterListItem[] prepareFilters(Context context) {
protected FilterListItem[] prepareFilters(Context context) {
DependencyInjectionService.getInstance().inject(this);
ContextManager.setContext(context);
@ -154,11 +155,15 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
}
private void addTags(ArrayList<FilterListItem> list) {
ArrayList<Tag> tagList = TagService.getInstance().getTagList();
List<Tag> tagList = getTagList();
list.add(filterFromTags(tagList.toArray(new Tag[tagList.size()]),
R.string.tag_FEx_header));
}
protected List<Tag> getTagList() {
return TagService.getInstance().getTagList();
}
private FilterCategory filterFromTags(Tag[] tags, int name) {
Filter[] filters = new Filter[tags.length + 1];

@ -325,7 +325,7 @@ public final class TagService {
tagData.readFromCursor(cursor);
String tagName = tagData.getValue(TagData.NAME).trim();
Tag tag = new Tag(tagData);
if(tagData.getValue(TagData.DELETION_DATE) > 0 || tagData.getFlag(TagData.FLAGS, TagData.FLAG_EMERGENT)) {
if(tagData.getValue(TagData.DELETION_DATE) > 0 || tagData.getFlag(TagData.FLAGS, TagData.FLAG_EMERGENT) || tagData.getFlag(TagData.FLAGS, TagData.FLAG_FEATURED)) {
tags.remove(tagName);
continue;
}
@ -351,6 +351,37 @@ public final class TagService {
return tagList;
}
public ArrayList<Tag> getFeaturedLists() {
HashMap<String, Tag> tags = new HashMap<String, Tag>();
TodorooCursor<TagData> cursor = tagDataService.query(Query.select(TagData.PROPERTIES)
.where(Functions.bitwiseAnd(TagData.FLAGS, TagData.FLAG_FEATURED).gt(0)));
try {
TagData tagData = new TagData();
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
tagData.readFromCursor(cursor);
if (tagData.getValue(TagData.DELETION_DATE) > 0)
continue;
String tagName = tagData.getValue(TagData.NAME).trim();
Tag tag = new Tag(tagData);
if(TextUtils.isEmpty(tag.tag))
continue;
tags.put(tagName, tag);
}
} finally {
cursor.close();
}
ArrayList<Tag> tagList = new ArrayList<Tag>(tags.values());
Collections.sort(tagList,
new Comparator<Tag>() {
@Override
public int compare(Tag object1, Tag object2) {
return object1.tag.compareToIgnoreCase(object2.tag);
}
});
return tagList;
}
/**
* Save the given array of tags into the database
* @param taskId

@ -0,0 +1,37 @@
package com.todoroo.astrid.tags.reusable;
import android.app.Activity;
import android.content.Intent;
import android.content.IntentFilter;
import android.widget.ListView;
import com.todoroo.astrid.adapter.FilterAdapter;
import com.todoroo.astrid.utility.Constants;
public class FeaturedListFilterAdapter extends FilterAdapter {
public static final String BROADCAST_REQUEST_FEATURED_LISTS = Constants.PACKAGE + ".REQUEST_FEATURED_LISTS"; //$NON-NLS-1$
public static final String BROADCAST_SEND_FEATURED_LISTS = Constants.PACKAGE + ".SEND_FEATURED_LISTS"; //$NON-NLS-1$
public FeaturedListFilterAdapter(Activity activity, ListView listView,
int rowLayout, boolean skipIntentFilters) {
super(activity, listView, rowLayout, skipIntentFilters);
}
@Override
public void getLists() {
Intent broadcastIntent = new Intent(BROADCAST_REQUEST_FEATURED_LISTS);
activity.sendBroadcast(broadcastIntent);
}
@Override
public void registerRecevier() {
IntentFilter peopleFilter = new IntentFilter(BROADCAST_SEND_FEATURED_LISTS);
activity.registerReceiver(filterReceiver, peopleFilter);
getLists();
}
@Override
public void unregisterRecevier() {
activity.unregisterReceiver(filterReceiver);
}
}

@ -0,0 +1,30 @@
package com.todoroo.astrid.tags.reusable;
import java.util.List;
import android.content.Context;
import android.content.Intent;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.tags.TagFilterExposer;
import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.tags.TagService.Tag;
public class FeaturedListFilterExposer extends TagFilterExposer {
@Override
public void onReceive(Context context, Intent intent) {
FilterListItem[] listAsArray = prepareFilters(context);
Intent broadcastIntent = new Intent(FeaturedListFilterAdapter.BROADCAST_SEND_FEATURED_LISTS);
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, listAsArray);
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
}
@Override
protected List<Tag> getTagList() {
return TagService.getInstance().getFeaturedLists();
}
}

@ -14,6 +14,8 @@
android:layout_alignParentTop="true"
android:scrollbars="vertical"
android:divider="@android:color/transparent"
android:dividerHeight="1px"
android:background="@android:color/transparent"
android:cacheColorHint="#00000000"/>
</LinearLayout>

@ -14,6 +14,8 @@
android:layout_alignParentTop="true"
android:scrollbars="vertical"
android:divider="@android:color/transparent"
android:dividerHeight="1px"
android:background="@android:color/transparent"
android:cacheColorHint="#00000000"/>
</LinearLayout>

@ -14,6 +14,8 @@
android:layout_alignParentTop="true"
android:scrollbars="vertical"
android:divider="@android:color/transparent"
android:dividerHeight="1px"
android:background="@android:color/transparent"
android:cacheColorHint="#00000000"/>
</LinearLayout>
Loading…
Cancel
Save