mirror of
https://github.com/etesync/android
synced 2024-11-16 04:49:06 +00:00
CollectionInfo: rename url -> uid.
This commit is contained in:
parent
2e7ac65883
commit
7cefb64db2
@ -39,7 +39,7 @@ public class CollectionInfo implements Serializable {
|
||||
@Expose
|
||||
public Type type;
|
||||
|
||||
public String url; // Essentially the uuid
|
||||
public String uid;
|
||||
|
||||
@Expose
|
||||
public boolean readOnly;
|
||||
@ -69,7 +69,7 @@ public class CollectionInfo implements Serializable {
|
||||
}
|
||||
|
||||
public void updateFromJournal(JournalManager.Journal journal) {
|
||||
url = journal.getUuid();
|
||||
uid = journal.getUuid();
|
||||
version = journal.getVersion();
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ public class CollectionInfo implements Serializable {
|
||||
info.id = values.getAsLong(Collections.ID);
|
||||
info.serviceID = values.getAsLong(Collections.SERVICE_ID);
|
||||
|
||||
info.url = values.getAsString(Collections.URL);
|
||||
info.uid = values.getAsString(Collections.URL);
|
||||
info.readOnly = values.getAsInteger(Collections.READ_ONLY) != 0;
|
||||
info.displayName = values.getAsString(Collections.DISPLAY_NAME);
|
||||
info.description = values.getAsString(Collections.DESCRIPTION);
|
||||
|
@ -37,7 +37,7 @@ public class JournalModel {
|
||||
@PostLoad
|
||||
void afterLoad() {
|
||||
this.info.serviceID = service;
|
||||
this.info.url = uid;
|
||||
this.info.uid = uid;
|
||||
}
|
||||
|
||||
public Journal() {
|
||||
@ -47,7 +47,7 @@ public class JournalModel {
|
||||
public Journal(CollectionInfo info) {
|
||||
this();
|
||||
this.info = info;
|
||||
this.uid = info.url;
|
||||
this.uid = info.uid;
|
||||
this.service = info.serviceID;
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ public class JournalModel {
|
||||
}
|
||||
|
||||
public static JournalEntity fetchOrCreate(EntityDataStore<Persistable> data, CollectionInfo collection) {
|
||||
JournalEntity journalEntity = fetch(data, collection.url);
|
||||
JournalEntity journalEntity = fetch(data, collection.uid);
|
||||
if (journalEntity == null) {
|
||||
journalEntity = new JournalEntity(collection);
|
||||
} else {
|
||||
|
@ -95,7 +95,7 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection {
|
||||
|
||||
private static ContentValues valuesFromCollectionInfo(CollectionInfo info, boolean withColor) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(Calendars.NAME, info.url);
|
||||
values.put(Calendars.NAME, info.uid);
|
||||
values.put(Calendars.CALENDAR_DISPLAY_NAME, info.displayName);
|
||||
|
||||
if (withColor)
|
||||
|
@ -69,7 +69,7 @@ public class LocalTaskList extends AndroidTaskList implements LocalCollection {
|
||||
|
||||
private static ContentValues valuesFromCollectionInfo(CollectionInfo info, boolean withColor) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(TaskLists._SYNC_ID, info.url);
|
||||
values.put(TaskLists._SYNC_ID, info.uid);
|
||||
values.put(TaskLists.LIST_NAME, info.displayName);
|
||||
|
||||
if (withColor)
|
||||
|
@ -119,7 +119,7 @@ public class CalendarsSyncAdapterService extends SyncAdapterService {
|
||||
Map<String, CollectionInfo> remote = new HashMap<>();
|
||||
List<CollectionInfo> remoteCollections = JournalEntity.getCollections(data, service);
|
||||
for (CollectionInfo info : remoteCollections) {
|
||||
remote.put(info.url, info);
|
||||
remote.put(info.uid, info);
|
||||
}
|
||||
|
||||
LocalCalendar[] local = (LocalCalendar[])LocalCalendar.find(account, provider, LocalCalendar.Factory.INSTANCE, null, null);
|
||||
|
@ -61,7 +61,7 @@ public class ContactsSyncManager extends SyncManager {
|
||||
final private HttpUrl remote;
|
||||
|
||||
public ContactsSyncManager(Context context, Account account, AccountSettings settings, Bundle extras, String authority, ContentProviderClient provider, SyncResult result, HttpUrl principal, CollectionInfo info) throws InvalidAccountException, Exceptions.IntegrityException, Exceptions.GenericCryptoException {
|
||||
super(context, account, settings, extras, authority, result, info.url, CollectionInfo.Type.ADDRESS_BOOK);
|
||||
super(context, account, settings, extras, authority, result, info.uid, CollectionInfo.Type.ADDRESS_BOOK);
|
||||
this.provider = provider;
|
||||
this.remote = principal;
|
||||
}
|
||||
@ -83,7 +83,7 @@ public class ContactsSyncManager extends SyncManager {
|
||||
// prepare local address book
|
||||
localCollection = new LocalAddressBook(account, provider);
|
||||
LocalAddressBook localAddressBook = localAddressBook();
|
||||
localAddressBook.setURL(info.url);
|
||||
localAddressBook.setURL(info.uid);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
// workaround for Android 7 which sets DIRTY flag when only meta-data is changed
|
||||
@ -101,7 +101,7 @@ public class ContactsSyncManager extends SyncManager {
|
||||
values.put(ContactsContract.Settings.UNGROUPED_VISIBLE, 1);
|
||||
localAddressBook.updateSettings(values);
|
||||
|
||||
journal = new JournalEntryManager(httpClient, remote, info.url);
|
||||
journal = new JournalEntryManager(httpClient, remote, info.uid);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -167,9 +167,9 @@ public abstract class SyncAdapterService extends Service {
|
||||
|
||||
if (collections.isEmpty()) {
|
||||
CollectionInfo info = CollectionInfo.defaultForServiceType(serviceType);
|
||||
info.url = JournalManager.Journal.genUid();
|
||||
Crypto.CryptoManager crypto = new Crypto.CryptoManager(info.version, settings.password(), info.url);
|
||||
JournalManager.Journal journal = new JournalManager.Journal(crypto, info.toJson(), info.url);
|
||||
info.uid = JournalManager.Journal.genUid();
|
||||
Crypto.CryptoManager crypto = new Crypto.CryptoManager(info.version, settings.password(), info.uid);
|
||||
JournalManager.Journal journal = new JournalManager.Journal(crypto, info.toJson(), info.uid);
|
||||
journalsManager.putJournal(journal);
|
||||
collections.add(info);
|
||||
}
|
||||
@ -193,23 +193,23 @@ public abstract class SyncAdapterService extends Service {
|
||||
Map<String, CollectionInfo> existing = new HashMap<>();
|
||||
List<CollectionInfo> existingList = JournalEntity.getCollections(data, service);
|
||||
for (CollectionInfo info : existingList) {
|
||||
existing.put(info.url, info);
|
||||
existing.put(info.uid, info);
|
||||
}
|
||||
|
||||
for (CollectionInfo collection : collections) {
|
||||
App.log.log(Level.FINE, "Saving collection", collection.url);
|
||||
App.log.log(Level.FINE, "Saving collection", collection.uid);
|
||||
|
||||
collection.serviceID = service;
|
||||
JournalEntity journalEntity = JournalEntity.fetchOrCreate(data, collection);
|
||||
data.upsert(journalEntity);
|
||||
|
||||
existing.remove(collection.url);
|
||||
existing.remove(collection.uid);
|
||||
}
|
||||
|
||||
for (CollectionInfo collection : existing.values()) {
|
||||
App.log.log(Level.FINE, "Deleting collection", collection.url);
|
||||
App.log.log(Level.FINE, "Deleting collection", collection.uid);
|
||||
|
||||
JournalEntity journalEntity = data.select(JournalEntity.class).where(JournalEntity.UID.eq(collection.url)).limit(1).get().first();
|
||||
JournalEntity journalEntity = data.select(JournalEntity.class).where(JournalEntity.UID.eq(collection.uid)).limit(1).get().first();
|
||||
journalEntity.setDeleted(true);
|
||||
data.update(journalEntity);
|
||||
}
|
||||
|
@ -39,7 +39,6 @@ import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@ -366,7 +365,7 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu
|
||||
final CollectionInfo info = getItem(position);
|
||||
|
||||
TextView tv = (TextView)v.findViewById(R.id.title);
|
||||
tv.setText(TextUtils.isEmpty(info.displayName) ? info.url : info.displayName);
|
||||
tv.setText(TextUtils.isEmpty(info.displayName) ? info.uid : info.displayName);
|
||||
|
||||
tv = (TextView)v.findViewById(R.id.description);
|
||||
if (TextUtils.isEmpty(info.description))
|
||||
@ -403,7 +402,7 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu
|
||||
}
|
||||
|
||||
TextView tv = (TextView)v.findViewById(R.id.title);
|
||||
tv.setText(TextUtils.isEmpty(info.displayName) ? info.url : info.displayName);
|
||||
tv.setText(TextUtils.isEmpty(info.displayName) ? info.uid : info.displayName);
|
||||
|
||||
tv = (TextView)v.findViewById(R.id.description);
|
||||
if (TextUtils.isEmpty(info.description))
|
||||
|
@ -13,7 +13,6 @@ import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
@ -156,14 +155,14 @@ public class CreateCollectionFragment extends DialogFragment implements LoaderMa
|
||||
HttpUrl principal = HttpUrl.get(settings.getUri());
|
||||
|
||||
JournalManager journalManager = new JournalManager(HttpClient.create(getContext(), account), principal);
|
||||
if (info.url == null) {
|
||||
info.url = JournalManager.Journal.genUid();
|
||||
Crypto.CryptoManager crypto = new Crypto.CryptoManager(info.version, settings.password(), info.url);
|
||||
JournalManager.Journal journal = new JournalManager.Journal(crypto, info.toJson(), info.url);
|
||||
if (info.uid == null) {
|
||||
info.uid = JournalManager.Journal.genUid();
|
||||
Crypto.CryptoManager crypto = new Crypto.CryptoManager(info.version, settings.password(), info.uid);
|
||||
JournalManager.Journal journal = new JournalManager.Journal(crypto, info.toJson(), info.uid);
|
||||
journalManager.putJournal(journal);
|
||||
} else {
|
||||
Crypto.CryptoManager crypto = new Crypto.CryptoManager(info.version, settings.password(), info.url);
|
||||
JournalManager.Journal journal = new JournalManager.Journal(crypto, info.toJson(), info.url);
|
||||
Crypto.CryptoManager crypto = new Crypto.CryptoManager(info.version, settings.password(), info.uid);
|
||||
JournalManager.Journal journal = new JournalManager.Journal(crypto, info.toJson(), info.uid);
|
||||
journalManager.updateJournal(journal);
|
||||
}
|
||||
|
||||
|
@ -120,10 +120,10 @@ public class DeleteCollectionFragment extends DialogFragment implements LoaderMa
|
||||
HttpUrl principal = HttpUrl.get(settings.getUri());
|
||||
|
||||
JournalManager journalManager = new JournalManager(HttpClient.create(getContext(), account), principal);
|
||||
Crypto.CryptoManager crypto = new Crypto.CryptoManager(collectionInfo.version, settings.password(), collectionInfo.url);
|
||||
Crypto.CryptoManager crypto = new Crypto.CryptoManager(collectionInfo.version, settings.password(), collectionInfo.uid);
|
||||
|
||||
journalManager.deleteJournal(new JournalManager.Journal(crypto, collectionInfo.toJson(), collectionInfo.url));
|
||||
JournalEntity journalEntity = JournalEntity.fetch(data, collectionInfo.url);
|
||||
journalManager.deleteJournal(new JournalManager.Journal(crypto, collectionInfo.toJson(), collectionInfo.uid));
|
||||
JournalEntity journalEntity = JournalEntity.fetch(data, collectionInfo.uid);
|
||||
journalEntity.setDeleted(true);
|
||||
data.update(journalEntity);
|
||||
|
||||
@ -152,7 +152,7 @@ public class DeleteCollectionFragment extends DialogFragment implements LoaderMa
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
CollectionInfo collectionInfo = (CollectionInfo) getArguments().getSerializable(ARG_COLLECTION_INFO);
|
||||
String name = TextUtils.isEmpty(collectionInfo.displayName) ? collectionInfo.url : collectionInfo.displayName;
|
||||
String name = TextUtils.isEmpty(collectionInfo.displayName) ? collectionInfo.uid : collectionInfo.displayName;
|
||||
|
||||
return new AlertDialog.Builder(getContext())
|
||||
.setTitle(R.string.delete_collection_confirm_title)
|
||||
|
@ -41,7 +41,6 @@ import at.bitfire.ical4android.CalendarStorageException;
|
||||
import at.bitfire.vcard4android.ContactsStorageException;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.sql.EntityDataStore;
|
||||
import tourguide.tourguide.Overlay;
|
||||
import tourguide.tourguide.ToolTip;
|
||||
import tourguide.tourguide.TourGuide;
|
||||
|
||||
@ -64,7 +63,7 @@ public class ViewCollectionActivity extends AppCompatActivity implements Refresh
|
||||
public void refresh() {
|
||||
EntityDataStore<Persistable> data = ((App) getApplicationContext()).getData();
|
||||
|
||||
final JournalEntity journalEntity = JournalEntity.fetch(data, info.url);
|
||||
final JournalEntity journalEntity = JournalEntity.fetch(data, info.uid);
|
||||
if ((journalEntity == null) || journalEntity.isDeleted()) {
|
||||
finish();
|
||||
return;
|
||||
@ -174,14 +173,14 @@ public class ViewCollectionActivity extends AppCompatActivity implements Refresh
|
||||
protected Long doInBackground(Void... aVoids) {
|
||||
EntityDataStore<Persistable> data = ((App) getApplicationContext()).getData();
|
||||
|
||||
final JournalEntity journalEntity = JournalEntity.fetch(data, info.url);
|
||||
final JournalEntity journalEntity = JournalEntity.fetch(data, info.uid);
|
||||
|
||||
entryCount = data.count(EntryEntity.class).where(EntryEntity.JOURNAL.eq(journalEntity)).get().value();
|
||||
long count;
|
||||
|
||||
if (info.type == CollectionInfo.Type.CALENDAR) {
|
||||
try {
|
||||
LocalCalendar resource = LocalCalendar.findByName(account, getContentResolver().acquireContentProviderClient(CalendarContract.CONTENT_URI), LocalCalendar.Factory.INSTANCE, info.url);
|
||||
LocalCalendar resource = LocalCalendar.findByName(account, getContentResolver().acquireContentProviderClient(CalendarContract.CONTENT_URI), LocalCalendar.Factory.INSTANCE, info.uid);
|
||||
count = resource.count();
|
||||
} catch (FileNotFoundException | CalendarStorageException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -265,7 +265,7 @@ public class ImportFragment extends DialogFragment {
|
||||
ContentProviderClient provider = getContext().getContentResolver().acquireContentProviderClient(CalendarContract.CONTENT_URI);
|
||||
LocalCalendar localCalendar;
|
||||
try {
|
||||
localCalendar = LocalCalendar.findByName(account, provider, LocalCalendar.Factory.INSTANCE, info.url);
|
||||
localCalendar = LocalCalendar.findByName(account, provider, LocalCalendar.Factory.INSTANCE, info.uid);
|
||||
if (localCalendar == null) {
|
||||
throw new FileNotFoundException("Failed to load local resource.");
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ public class LocalCalendarImportFragment extends ListFragment {
|
||||
try {
|
||||
LocalCalendar localCalendar = LocalCalendar.findByName(account,
|
||||
getContext().getContentResolver().acquireContentProviderClient(CalendarContract.CONTENT_URI),
|
||||
LocalCalendar.Factory.INSTANCE, info.url);
|
||||
LocalCalendar.Factory.INSTANCE, info.uid);
|
||||
LocalEvent[] localEvents = fromCalendar.getAll();
|
||||
int total = localEvents.length;
|
||||
progressDialog.setMax(total);
|
||||
|
@ -137,7 +137,7 @@ public class ListEntriesFragment extends ListFragment implements AdapterView.OnI
|
||||
|
||||
@Override
|
||||
protected List<EntryEntity> doInBackground(Void... voids) {
|
||||
journalEntity = JournalModel.Journal.fetch(data, info.url);
|
||||
journalEntity = JournalModel.Journal.fetch(data, info.uid);
|
||||
return data.select(EntryEntity.class).where(EntryEntity.JOURNAL.eq(journalEntity)).orderBy(EntryEntity.ID.desc()).get().toList();
|
||||
}
|
||||
|
||||
|
@ -74,10 +74,10 @@ public class ServiceTest {
|
||||
Exception caught;
|
||||
JournalManager journalManager = new JournalManager(httpClient, remote);
|
||||
CollectionInfo info = CollectionInfo.defaultForServiceType(CollectionInfo.Type.ADDRESS_BOOK);
|
||||
info.url = JournalManager.Journal.genUid();
|
||||
info.uid = JournalManager.Journal.genUid();
|
||||
info.displayName = "Test";
|
||||
Crypto.CryptoManager crypto = new Crypto.CryptoManager(info.version, Helpers.keyBase64, info.url);
|
||||
JournalManager.Journal journal = new JournalManager.Journal(crypto, info.toJson(), info.url);
|
||||
Crypto.CryptoManager crypto = new Crypto.CryptoManager(info.version, Helpers.keyBase64, info.uid);
|
||||
JournalManager.Journal journal = new JournalManager.Journal(crypto, info.toJson(), info.uid);
|
||||
journalManager.putJournal(journal);
|
||||
|
||||
// Try pushing the same journal (uid clash)
|
||||
@ -96,7 +96,7 @@ public class ServiceTest {
|
||||
|
||||
// Update journal
|
||||
info.displayName = "Test 2";
|
||||
journal = new JournalManager.Journal(crypto, info.toJson(), info.url);
|
||||
journal = new JournalManager.Journal(crypto, info.toJson(), info.uid);
|
||||
journalManager.updateJournal(journal);
|
||||
|
||||
journals = journalManager.getJournals(Helpers.keyBase64);
|
||||
@ -111,8 +111,8 @@ public class ServiceTest {
|
||||
assertEquals(journals.size(), 0);
|
||||
|
||||
// Bad HMAC
|
||||
info.url = JournalManager.Journal.genUid();
|
||||
journal = new JournalManager.Journal(crypto, info.toJson(), info.url);
|
||||
info.uid = JournalManager.Journal.genUid();
|
||||
journal = new JournalManager.Journal(crypto, info.toJson(), info.uid);
|
||||
info.displayName = "Test 3";
|
||||
//// We assume this doesn't update the hmac.
|
||||
journal.setContent(crypto, info.toJson());
|
||||
|
Loading…
Reference in New Issue
Block a user