Commit fb7f9749 authored by Ricki Hirner's avatar Ricki Hirner

Allow renaming of accounts

* allow renaming of accounts
* always open AccountActivity, even if there are no services (so that users can delete the account from within DAVdroid)
parent 900f1fd8
Pipeline #4977048 passed with stage
in 16 minutes and 28 seconds
......@@ -8,17 +8,16 @@
package at.bitfire.davdroid.model;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import java.util.logging.Level;
import aQute.service.reporter.Messages;
import at.bitfire.davdroid.App;
import lombok.Cleanup;
......@@ -186,4 +185,11 @@ public class ServiceDB {
}
}
public static void onRenameAccount(@NonNull SQLiteDatabase db, @NonNull String oldName, @NonNull String newName) {
ContentValues values = new ContentValues(1);
values.put(Services.ACCOUNT_NAME, newName);
db.update(Services._TABLE, values, Services.ACCOUNT_NAME + "=?", new String[] { oldName });
}
}
......@@ -9,6 +9,7 @@ package at.bitfire.davdroid.resource;
import android.accounts.Account;
import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.database.Cursor;
......@@ -16,6 +17,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Parcel;
import android.os.RemoteException;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Groups;
import android.provider.ContactsContract.RawContacts;
import android.support.annotation.NonNull;
......@@ -226,4 +228,14 @@ public class LocalAddressBook extends AndroidAddressBook implements LocalCollect
}
}
// HELPERS
public static void onRenameAccount(@NonNull ContentResolver resolver, @NonNull String oldName, @NonNull String newName) throws RemoteException {
@Cleanup("release") ContentProviderClient client = resolver.acquireContentProviderClient(ContactsContract.AUTHORITY);
ContentValues values = new ContentValues(1);
values.put(RawContacts.ACCOUNT_NAME, newName);
client.update(RawContacts.CONTENT_URI, values, RawContacts.ACCOUNT_NAME + "=?", new String[] { oldName });
}
}
......@@ -251,4 +251,5 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection {
return new LocalCalendar[size];
}
}
}
......@@ -9,6 +9,8 @@
package at.bitfire.davdroid.resource;
import android.accounts.Account;
import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
......@@ -164,4 +166,15 @@ public class LocalTaskList extends AndroidTaskList implements LocalCollection {
return new LocalTaskList[size];
}
}
// HELPERS
public static void onRenameAccount(@NonNull ContentResolver resolver, @NonNull String oldName, @NonNull String newName) throws RemoteException {
@Cleanup("release") ContentProviderClient client = resolver.acquireContentProviderClient(TaskProvider.ProviderName.OpenTasks.authority);
ContentValues values = new ContentValues(1);
values.put(Tasks.ACCOUNT_NAME, newName);
client.update(Tasks.getContentUri(TaskProvider.ProviderName.OpenTasks.authority), values, Tasks.ACCOUNT_NAME + "=?", new String[] { oldName });
}
}
......@@ -20,6 +20,10 @@
android:title="@string/account_settings"
app:showAsAction="ifRoom"/>
<item android:id="@+id/rename_account"
android:title="@string/account_rename"
app:showAsAction="never"/>
<item android:id="@+id/delete_account"
android:title="@string/account_delete"
app:showAsAction="never"/>
......
......@@ -79,6 +79,9 @@
<string name="account_synchronize_now">Jetzt synchronisieren</string>
<string name="account_synchronizing_now">Synchronisation gestartet</string>
<string name="account_settings">Konto-Einstellungen</string>
<string name="account_rename">Konto umbenennen</string>
<string name="account_rename_new_name">Ungespeicherte lokale Änderungen können verloren gehen. Nach dem Umbenennen muss neu synchronisiert werden. Neuer Kontoname:</string>
<string name="account_rename_rename">Umbenennen</string>
<string name="account_delete">Konto löschen</string>
<string name="account_delete_confirmation_title">Konto wirklich löschen?</string>
<string name="account_delete_confirmation_text">Alle Adressbücher, Kalender und Aufgabenlisten werden vom Gerät (nicht am Server) gelöscht.</string>
......
......@@ -96,6 +96,9 @@
<string name="account_synchronize_now">Synchronize now</string>
<string name="account_synchronizing_now">Synchronizing now</string>
<string name="account_settings">Account settings</string>
<string name="account_rename">Rename account</string>
<string name="account_rename_new_name">Unsaved local data may be dismissed. Re-synchronization is required after renaming. New account name:</string>
<string name="account_rename_rename">Rename</string>
<string name="account_delete">Delete account</string>
<string name="account_delete_confirmation_title">Really delete account?</string>
<string name="account_delete_confirmation_text">All local copies of address books, calendars and task lists will be deleted.</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment