@Override public void onSuccess(Dataset dataset, final List<Record> newRecords) { printDataset(); callingActivity.runOnUiThread(new Runnable() { @Override public void run() { dialog.dismiss(); Log.i("Sync", String.format("%d records synced", newRecords.size())); Toast.makeText(callingActivity, "Sync Successful!", Toast.LENGTH_LONG).show(); } }); }
@Override public boolean onConflict(final Dataset dataset, final List<SyncConflict> conflicts) { callingActivity.runOnUiThread(new Runnable() { @Override public void run() { dialog.dismiss(); Log.i("Sync onConflict", String.format("%s records in conflict", conflicts.size())); List<Record> resolvedRecords = new ArrayList<Record>(); for (SyncConflict conflict : conflicts) { Log.i("Sync onConflict", String.format("remote: %s; local: %s", conflict.getRemoteRecord(), conflict.getLocalRecord())); /* resolve by taking remote records */ resolvedRecords.add(conflict.resolveWithRemoteRecord()); } dataset.resolve(resolvedRecords); Toast.makeText( callingActivity, String.format( "%s records in conflict. Resolve by taking remote records", conflicts.size()), Toast.LENGTH_LONG).show(); } }); return true; }
private void refreshGuiWithData(final List<Record> newRecords) { runOnUiThread(new Runnable() { @Override public void run() { dialog.dismiss(); refreshListData(); Log.i("Sync", String.format("%d records synced", newRecords.size())); Toast.makeText(ListRecordsActivity.this, "Successful!", Toast.LENGTH_LONG).show(); } }); }
private void refreshListData() { adapter.clear(); for (Record record : dataset.getAllRecords()) { adapter.add(record); } adapter.notifyDataSetChanged(); updateTitle(); }
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate( R.layout.record_list_item, parent, false); holder = new ViewHolder(convertView); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } Record record = getItem(position); // record key holder.tvKey.setText(record.getKey()); // if the record is modified, mark it blue holder.tvKey.setTextColor(record.isModified() ? Color.BLUE : Color.BLACK); // if the record is deleted, put a strike if (record.isDeleted()) { holder.tvKey.setPaintFlags(holder.tvKey.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); } else { holder.tvKey.setPaintFlags(holder.tvKey.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG); } // record value holder.tvValue.setText(record.getValue() == null ? "" : record .getValue()); // record sync count holder.tvSyncCount.setText(String.valueOf(record.getSyncCount())); return convertView; }
@Override public void onSuccess(Dataset dataset, List<Record> updatedRecords) { if (observer != null) { observer.onDatasetDidSync(dataset.getDatasetMetadata().getDatasetName()); } }
void printDataset() { Dataset dataset = AWSClientManager.getDataset(); for (Record record : dataset.getAllRecords()) { Log.i("sync", record.toString()); } }
@Override public boolean onConflict(final Dataset dataset, final List<SyncConflict> conflicts) { callingActivity.runOnUiThread(new Runnable() { @Override public void run() { dialog.dismiss(); Log.i("Sync onConflict", String.format("%s records in conflict", conflicts.size())); List<Record> resolvedRecords = new ArrayList<Record>(); for (SyncConflict conflict : conflicts) { Log.i("Sync onConflict", String.format("remote: %s; local: %s", conflict.getRemoteRecord(), conflict.getLocalRecord())); /* resolve by taking remote records */ resolvedRecords.add(conflict.resolveWithRemoteRecord()); /* resolve by taking local records */ // resolvedRecords.add(conflict.resolveWithLocalRecord()); /* * resolve with customized logic, e.g. * concatenate strings */ // String newValue = // conflict.getRemoteRecord().getValue() // + conflict.getLocalRecord().getValue(); // resolvedRecords.add(conflict.resolveWithValue(newValue)); } dataset.resolve(resolvedRecords); Toast.makeText( callingActivity, String.format( "%s records in conflict. Resolve by taking remote records", conflicts.size()), Toast.LENGTH_LONG).show(); } }); return true; }