now we store each message we see into the hash to prevent showing users duplicates

pull/14/head
Tim Su 14 years ago
parent 1d72228a29
commit 5091cba352

@ -16,15 +16,20 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.text.TextUtils;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.RestClient;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.dao.StoreObjectDao;
import com.todoroo.astrid.dao.StoreObjectDao.StoreObjectCriteria;
import com.todoroo.astrid.data.StoreObject;
import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.producteev.ProducteevUtilities;
import com.todoroo.astrid.utility.AstridPreferences;
import com.todoroo.astrid.utility.Constants;
/**
@ -45,6 +50,7 @@ public class UpdateMessageService {
@Autowired protected RestClient restClient;
@Autowired private GtasksPreferenceService gtasksPreferenceService;
@Autowired private AddOnService addOnService;
@Autowired private StoreObjectDao storeObjectDao;
private Context context;
@ -74,14 +80,6 @@ public class UpdateMessageService {
return !(context instanceof Activity);
}
private boolean updatesHaveNotChanged(String latest) {
String savedUpdates = AstridPreferences.getLatestUpdates();
if(AndroidUtilities.equals(savedUpdates, latest))
return true;
AstridPreferences.setLatestUpdates(latest);
return false;
}
protected void displayUpdateDialog(StringBuilder builder) {
final Activity activity = (Activity) context;
if(activity == null)
@ -90,9 +88,6 @@ public class UpdateMessageService {
final String html = "<html><body style='color: white'>" +
builder.append("</body></html>").toString();
if(updatesHaveNotChanged(html))
return;
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
@ -137,6 +132,10 @@ public class UpdateMessageService {
continue;
}
}
if(messageAlreadySeen(date, message))
continue;
if(date != null)
builder.append("<b>" + date + "</b><br />");
builder.append(message);
@ -145,6 +144,27 @@ public class UpdateMessageService {
return builder;
}
private boolean messageAlreadySeen(String date, String message) {
if(date != null)
message = date + message;
String hash = AndroidUtilities.md5(message);
TodorooCursor<StoreObject> cursor = storeObjectDao.query(Query.select(StoreObject.ID).
where(StoreObjectCriteria.byTypeAndItem(UpdateMessage.TYPE, hash)));
try {
if(cursor.getCount() > 0)
return true;
} finally {
cursor.close();
}
StoreObject newUpdateMessage = new StoreObject();
newUpdateMessage.setValue(StoreObject.TYPE, UpdateMessage.TYPE);
newUpdateMessage.setValue(UpdateMessage.HASH, hash);
storeObjectDao.persist(newUpdateMessage);
return false;
}
private JSONArray checkForUpdates() {
PackageManager pm = ContextManager.getContext().getPackageManager();
try {
@ -165,4 +185,17 @@ public class UpdateMessageService {
}
}
/** store object for messages a user has seen */
private static class UpdateMessage {
/** type*/
public static final String TYPE = "update-message"; //$NON-NLS-1$
/** message contents */
public static final StringProperty HASH = new StringProperty(StoreObject.TABLE,
StoreObject.ITEM.name);
}
}

@ -12,7 +12,6 @@ import com.todoroo.andlib.utility.Preferences;
public class AstridPreferences {
private static final String P_CURRENT_VERSION = "cv"; //$NON-NLS-1$
private static final String P_LATEST_UPDATES = "up"; //$NON-NLS-1$
/** Set preference defaults, if unset. called at startup */
public static void setPreferenceDefaults() {
@ -46,14 +45,4 @@ public class AstridPreferences {
Preferences.setInt(P_CURRENT_VERSION, version);
}
/** LatestUpdates: latest astrid updates from server */
public static String getLatestUpdates() {
return Preferences.getStringValue(P_LATEST_UPDATES);
}
/** LatestUpdates: latest astrid updates from server */
public static void setLatestUpdates(String updates) {
Preferences.setString(P_LATEST_UPDATES, updates);
}
}

Loading…
Cancel
Save