Partial implementation of updating user status

pull/14/head
Sam Bosley 12 years ago
parent d18d2b9397
commit 81b3e15912

@ -58,10 +58,15 @@ public final class User extends RemoteModel {
public static final LongProperty REMOTE_ID = new LongProperty( public static final LongProperty REMOTE_ID = new LongProperty(
TABLE, REMOTE_ID_PROPERTY_NAME); TABLE, REMOTE_ID_PROPERTY_NAME);
/** Friendship status */ /** Friendship status. One of the STATUS constants below */
public static final StringProperty STATUS = new StringProperty( public static final StringProperty STATUS = new StringProperty(
TABLE, "status"); TABLE, "status");
/** Friendship tatus that needs to be reported to the server.
* One of the PENDING constants below */
public static final StringProperty PENDING_STATUS = new StringProperty(
TABLE, "pendingStatus");
/** List of all properties for this model */ /** List of all properties for this model */
public static final Property<?>[] PROPERTIES = generateProperties(User.class); public static final Property<?>[] PROPERTIES = generateProperties(User.class);
@ -88,6 +93,11 @@ public final class User extends RemoteModel {
public static final String STATUS_IGNORED = "ignored"; public static final String STATUS_IGNORED = "ignored";
public static final String STATUS_BLOCKED = "blocked"; public static final String STATUS_BLOCKED = "blocked";
public static final String PENDING_REQUEST = "request";
public static final String PENDING_APPROVE = "approve";
public static final String PENDING_IGNORE = "ignore";
public static final String PENDING_UNFRIEND = "unfriend";
// --- data access boilerplate // --- data access boilerplate
public User() { public User() {

@ -890,6 +890,27 @@ public final class ActFmSyncService {
return result.optInt("time", 0); return result.optInt("time", 0);
} }
public void pushUser(User model) {
if (TextUtils.isEmpty(model.getValue(User.PENDING_STATUS)))
return;
if (model.getValue(User.REMOTE_ID) == 0)
return;
if (!checkForToken())
return;
try {
ArrayList<Object> params = new ArrayList<Object>();
params.add("token"); params.add(token);
params.add("id"); params.add(model.getValue(User.REMOTE_ID));
params.add("status"); params.add(model.getValue(User.PENDING_STATUS));
JSONObject result = actFmInvoker.invoke("user_set_status", params);
System.err.println("RESULT: " + result);
} catch (IOException e) {
handleException("user-status", e);
}
}
/** /**
* Fetch active tasks asynchronously * Fetch active tasks asynchronously

@ -29,6 +29,7 @@ import com.todoroo.astrid.billing.BillingConstants;
import com.todoroo.astrid.dao.Database; import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria; import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.dao.UserDao;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
@ -60,6 +61,8 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
@Autowired MetadataService metadataService; @Autowired MetadataService metadataService;
@Autowired UserDao userDao;
@Autowired Database database; @Autowired Database database;
private final PushQueuedArgs<Task> taskPusher = new PushQueuedArgs<Task>() { private final PushQueuedArgs<Task> taskPusher = new PushQueuedArgs<Task>() {
@ -92,6 +95,19 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
} }
}; };
private final PushQueuedArgs<User> userPusher = new PushQueuedArgs<User>() {
@Override
public User getRemoteModelInstance(TodorooCursor<User> cursor) {
return new User(cursor);
}
@Override
public void pushRemoteModel(User model) {
actFmSyncService.pushUser(model);
}
};
private final PushQueuedArgs<Metadata> filesPusher = new PushQueuedArgs<Metadata>() { private final PushQueuedArgs<Metadata> filesPusher = new PushQueuedArgs<Metadata>() {
@Override @Override
@ -160,7 +176,7 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
actFmPreferenceService.recordSyncStart(); actFmPreferenceService.recordSyncStart();
updateUserStatus(); updateUserStatus();
startUsersFetcher(callback, finisher); startUsersSync(callback, finisher);
startTagFetcher(callback, finisher); startTagFetcher(callback, finisher);
@ -207,13 +223,14 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
} }
/** fetch changes to users/friends */ /** fetch changes to users/friends */
private void startUsersFetcher(final SyncResultCallback callback, private void startUsersSync(final SyncResultCallback callback,
final AtomicInteger finisher) { final AtomicInteger finisher) {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
int time = Preferences.getInt(LAST_USERS_FETCH_TIME, 0); int time = Preferences.getInt(LAST_USERS_FETCH_TIME, 0);
try { try {
pushQueuedUsers(callback, finisher);
time = actFmSyncService.fetchUsers(); time = actFmSyncService.fetchUsers();
Preferences.setInt(LAST_USERS_FETCH_TIME, time); Preferences.setInt(LAST_USERS_FETCH_TIME, time);
} catch (JSONException e) { } catch (JSONException e) {
@ -397,6 +414,17 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
} }
private void pushQueuedUsers(final SyncResultCallback callback,
final AtomicInteger finisher) {
TodorooCursor<User> users = userDao.query(Query.select(User.PROPERTIES).where(
Criterion.and(User.PENDING_STATUS.isNotNull(), Functions.length(User.PENDING_STATUS).gt(0))));
try {
pushQueued(callback, finisher, users, true, userPusher);
} finally {
users.close();
}
}
// --- synchronize list // --- synchronize list
@Override @Override

@ -126,8 +126,17 @@ public class PersonViewFragment extends TaskListFragment {
} }
public void handleStatusButtonClicked() { public void handleStatusButtonClicked() {
// TODO: Handle this for real String status = user.getValue(User.STATUS);
System.err.println("Status for " + user.getDisplayName() + " is " + user.getValue(User.STATUS)); //$NON-NLS-1$ //$NON-NLS-2$ if (TextUtils.isEmpty(status)) { // Add friend case
user.setValue(User.PENDING_STATUS, User.PENDING_REQUEST);
} else if (User.STATUS_OTHER_PENDING.equals(status)) { // Accept friend case
user.setValue(User.PENDING_STATUS, User.PENDING_APPROVE);
}
if (user.getSetValues().containsKey(User.PENDING_STATUS.name)) {
userDao.saveExisting(user);
// Push
}
} }
@Override @Override

@ -40,7 +40,7 @@ public class Database extends AbstractDatabase {
* Database version number. This variable must be updated when database * Database version number. This variable must be updated when database
* tables are updated, as it determines whether a database needs updating. * tables are updated, as it determines whether a database needs updating.
*/ */
public static final int VERSION = 25; public static final int VERSION = 26;
/** /**
* Database name (must be unique) * Database name (must be unique)
@ -333,6 +333,9 @@ public class Database extends AbstractDatabase {
case 25: try { case 25: try {
database.execSQL("ALTER TABLE " + User.TABLE.name + " ADD " + database.execSQL("ALTER TABLE " + User.TABLE.name + " ADD " +
User.STATUS.accept(visitor, null)); User.STATUS.accept(visitor, null));
database.execSQL("ALTER TABLE " + User.TABLE.name + " ADD " +
User.PENDING_STATUS.accept(visitor, null));
} catch (SQLiteException e) { } catch (SQLiteException e) {
Log.e("astrid", "db-upgrade-" + oldVersion + "-" + newVersion, e); Log.e("astrid", "db-upgrade-" + oldVersion + "-" + newVersion, e);
} }

Loading…
Cancel
Save