From 28e7c9165818a5c24ca8b8ee85460dd7cdda7087 Mon Sep 17 00:00:00 2001 From: Ricki Hirner Date: Sun, 20 Mar 2016 17:41:05 +0100 Subject: [PATCH] Initiate DAV service refresh after migration * initiate DAV service refresh after migration * minor refactoring of sync adapter classes * minor UI changes --- .../at/bitfire/davdroid/AccountSettings.java | 36 ++++++--- .../main/java/at/bitfire/davdroid/App.java | 1 + .../davdroid/resource/LocalCalendar.java | 2 +- .../syncadapter/CalendarSyncManager.java | 19 +---- .../CalendarsSyncAdapterService.java | 31 ++------ .../ContactsSyncAdapterService.java | 32 ++------ .../syncadapter/SyncAdapterService.java | 69 +++++++++++++++++ .../davdroid/syncadapter/SyncManager.java | 7 +- .../syncadapter/TasksSyncAdapterService.java | 31 ++------ .../syncadapter/TasksSyncManager.java | 19 +---- .../bitfire/davdroid/ui/AccountActivity.java | 2 +- .../davdroid/ui/AccountListFragment.java | 74 +++---------------- .../davdroid/ui/AccountSettingsActivity.java | 6 +- .../bitfire/davdroid/ui/AccountsActivity.java | 7 ++ .../davdroid/ui/StartupDialogFragment.java | 4 +- .../res/drawable/ic_account_circle_white.xml | 17 +++++ app/src/main/res/drawable/ic_forum_dark.xml | 18 +++++ .../{ic_help_light.xml => ic_help_dark.xml} | 5 +- .../res/drawable/ic_new_releases_light.xml | 17 +++++ app/src/main/res/drawable/side_nav_bar.xml | 5 +- app/src/main/res/layout/account_list_item.xml | 45 +++-------- app/src/main/res/layout/accounts_content.xml | 25 ++++--- app/src/main/res/layout/activity_account.xml | 6 +- .../res/menu/activity_accounts_drawer.xml | 40 ++++++---- app/src/main/res/menu/activity_login.xml | 2 +- app/src/main/res/values/strings.xml | 23 +++--- app/src/main/res/values/styles.xml | 1 + 27 files changed, 277 insertions(+), 267 deletions(-) create mode 100644 app/src/main/java/at/bitfire/davdroid/syncadapter/SyncAdapterService.java create mode 100644 app/src/main/res/drawable/ic_account_circle_white.xml create mode 100644 app/src/main/res/drawable/ic_forum_dark.xml rename app/src/main/res/drawable/{ic_help_light.xml => ic_help_dark.xml} (88%) create mode 100644 app/src/main/res/drawable/ic_new_releases_light.xml diff --git a/app/src/main/java/at/bitfire/davdroid/AccountSettings.java b/app/src/main/java/at/bitfire/davdroid/AccountSettings.java index 7b1e9cc1..65a20c66 100644 --- a/app/src/main/java/at/bitfire/davdroid/AccountSettings.java +++ b/app/src/main/java/at/bitfire/davdroid/AccountSettings.java @@ -16,9 +16,11 @@ import android.content.ContentResolver; import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; +import android.content.Intent; import android.content.PeriodicSync; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; +import android.graphics.drawable.BitmapDrawable; import android.net.Uri; import android.os.Bundle; import android.provider.CalendarContract; @@ -86,9 +88,11 @@ public class AccountSettings { if (version < CURRENT_VERSION) { Notification notify = new NotificationCompat.Builder(context) - .setSmallIcon(R.drawable.ic_launcher) + .setSmallIcon(R.drawable.ic_new_releases_light) + .setLargeIcon(((BitmapDrawable)context.getResources().getDrawable(R.drawable.ic_launcher)).getBitmap()) .setContentTitle(context.getString(R.string.settings_version_update)) - .setContentText(context.getString(R.string.settings_version_update_warning)) + .setContentText(context.getString(R.string.settings_version_update_settings_updated)) + .setSubText(context.getString(R.string.settings_version_update_install_hint)) .setCategory(NotificationCompat.CATEGORY_SYSTEM) .setPriority(NotificationCompat.PRIORITY_HIGH) .setLocalOnly(true) @@ -258,6 +262,8 @@ public class AccountSettings { // Don't show a warning for Android updates anymore accountManager.setUserData(account, "last_android_version", null); + Long serviceCardDAV = null, serviceCalDAV = null; + ServiceDB.OpenHelper dbHelper = new ServiceDB.OpenHelper(context); try { SQLiteDatabase db = dbHelper.getWritableDatabase(); @@ -276,11 +282,11 @@ public class AccountSettings { ContentValues values = new ContentValues(); values.put(Services.ACCOUNT_NAME, account.name); values.put(Services.SERVICE, Services.SERVICE_CARDDAV); - long service = db.insert(Services._TABLE, null, values); + serviceCardDAV = db.insert(Services._TABLE, null, values); // insert address book values.clear(); - values.put(Collections.SERVICE_ID, service); + values.put(Collections.SERVICE_ID, serviceCardDAV); values.put(Collections.URL, url); values.put(Collections.SYNC, 1); db.insert(Collections._TABLE, null, values); @@ -288,10 +294,11 @@ public class AccountSettings { // insert home set HttpUrl homeSet = HttpUrl.parse(url).resolve("../"); values.clear(); - values.put(HomeSets.SERVICE_ID, service); + values.put(HomeSets.SERVICE_ID, serviceCardDAV); values.put(HomeSets.URL, homeSet.toString()); db.insert(HomeSets._TABLE, null, values); } + } catch (ContactsStorageException e) { App.log.log(Level.SEVERE, "Couldn't migrate address book", e); } finally { @@ -339,12 +346,12 @@ public class AccountSettings { ContentValues values = new ContentValues(); values.put(Services.ACCOUNT_NAME, account.name); values.put(Services.SERVICE, Services.SERVICE_CALDAV); - long service = db.insert(Services._TABLE, null, values); + serviceCalDAV = db.insert(Services._TABLE, null, values); // insert collections for (String url : collections) { values.clear(); - values.put(Collections.SERVICE_ID, service); + values.put(Collections.SERVICE_ID, serviceCalDAV); values.put(Collections.URL, url); values.put(Collections.SYNC, 1); db.insert(Collections._TABLE, null, values); @@ -353,16 +360,27 @@ public class AccountSettings { // insert home sets for (HttpUrl homeSet : homeSets) { values.clear(); - values.put(HomeSets.SERVICE_ID, service); + values.put(HomeSets.SERVICE_ID, serviceCalDAV); values.put(HomeSets.URL, homeSet.toString()); db.insert(HomeSets._TABLE, null, values); } } - } finally { dbHelper.close(); } + // initiate service detection (refresh) to get display names, colors etc. + Intent refresh = new Intent(context, DavService.class); + refresh.setAction(DavService.ACTION_REFRESH_COLLECTIONS); + if (serviceCardDAV != null) { + refresh.putExtra(DavService.EXTRA_DAV_SERVICE_ID, serviceCardDAV); + context.startService(refresh); + } + if (serviceCalDAV != null) { + refresh.putExtra(DavService.EXTRA_DAV_SERVICE_ID, serviceCalDAV); + context.startService(refresh); + } + accountManager.setUserData(account, KEY_SETTINGS_VERSION, "3"); } diff --git a/app/src/main/java/at/bitfire/davdroid/App.java b/app/src/main/java/at/bitfire/davdroid/App.java index a4abf7e1..eb829e7b 100644 --- a/app/src/main/java/at/bitfire/davdroid/App.java +++ b/app/src/main/java/at/bitfire/davdroid/App.java @@ -123,6 +123,7 @@ public class App extends Application implements SharedPreferences.OnSharedPrefer if (dir != null) try { String pattern = new File(dir, "davdroid%u-" + DateFormatUtils.format(System.currentTimeMillis(), "yyyyMMdd-HHmmss") + ".txt").toString(); + log.info("Logging to " + pattern); FileHandler fileHandler = new FileHandler(pattern); fileHandler.setFormatter(PlainTextFormatter.DEFAULT); diff --git a/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java b/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java index e685c95e..04e27675 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java @@ -45,7 +45,7 @@ import lombok.Cleanup; public class LocalCalendar extends AndroidCalendar implements LocalCollection { - public static final int defaultColor = 0xFFC3EA6E; // "DAVdroid green" + public static final int defaultColor = 0xFF8bc34a; // light green 500 public static final String COLUMN_CTAG = Calendars.CAL_SYNC1; diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarSyncManager.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarSyncManager.java index b21feb9f..e8d0d7ff 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarSyncManager.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarSyncManager.java @@ -79,23 +79,8 @@ public class CalendarSyncManager extends SyncManager { } @Override - protected void queryCapabilities() throws DavException, IOException, HttpException, CalendarStorageException { - davCollection.propfind(0, DisplayName.NAME, CalendarColor.NAME, GetCTag.NAME); - - // update name and color - App.log.info("Setting calendar name and color (if available)"); - ContentValues values = new ContentValues(2); - - DisplayName pDisplayName = (DisplayName)davCollection.properties.get(DisplayName.NAME); - if (pDisplayName != null && !TextUtils.isEmpty(pDisplayName.displayName)) - values.put(Calendars.CALENDAR_DISPLAY_NAME, pDisplayName.displayName); - - CalendarColor pColor = (CalendarColor)davCollection.properties.get(CalendarColor.NAME); - if (pColor != null && pColor.color != null) - values.put(Calendars.CALENDAR_COLOR, pColor.color); - - if (values.size() > 0) - localCalendar().update(values); + protected void queryCapabilities() throws DavException, IOException, HttpException { + davCollection.propfind(0, GetCTag.NAME); } @Override diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java index cbef37ba..e7f13cf1 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java @@ -35,41 +35,24 @@ import at.bitfire.davdroid.resource.LocalCalendar; import at.bitfire.ical4android.CalendarStorageException; import lombok.Cleanup; -public class CalendarsSyncAdapterService extends Service { - private static SyncAdapter syncAdapter; - private OpenHelper dbHelper; +public class CalendarsSyncAdapterService extends SyncAdapterService { @Override public void onCreate() { - dbHelper = new OpenHelper(this); - syncAdapter = new SyncAdapter(this, dbHelper.getReadableDatabase()); + super.onCreate(); + syncAdapter = new SyncAdapter(this, dbHelper); } - @Override - public void onDestroy() { - dbHelper.close(); - } - @Override - public IBinder onBind(Intent intent) { - return syncAdapter.getSyncAdapterBinder(); - } - + private static class SyncAdapter extends SyncAdapterService.SyncAdapter { - private static class SyncAdapter extends AbstractThreadedSyncAdapter { - private final SQLiteDatabase db; - - public SyncAdapter(Context context, SQLiteDatabase db) { - super(context, false); - this.db = db; + public SyncAdapter(Context context, OpenHelper dbHelper) { + super(context, dbHelper); } @Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { - App.log.info("Starting calendar sync (" + authority + ")"); - - // required for ical4j and dav4android (ServiceLoader) - Thread.currentThread().setContextClassLoader(getContext().getClassLoader()); + super.onPerformSync(account, extras, authority, provider, syncResult); try { updateLocalCalendars(provider, account); diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncAdapterService.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncAdapterService.java index 940e3ebf..90d35c52 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncAdapterService.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncAdapterService.java @@ -25,6 +25,7 @@ import android.support.annotation.Nullable; import java.util.List; +import at.bitfire.davdroid.AccountSettings; import at.bitfire.davdroid.App; import at.bitfire.davdroid.model.CollectionInfo; import at.bitfire.davdroid.model.ServiceDB; @@ -32,41 +33,24 @@ import at.bitfire.davdroid.model.ServiceDB.Collections; import at.bitfire.davdroid.model.ServiceDB.OpenHelper; import lombok.Cleanup; -public class ContactsSyncAdapterService extends Service { - private static ContactsSyncAdapter syncAdapter; - private OpenHelper dbHelper; +public class ContactsSyncAdapterService extends SyncAdapterService { @Override public void onCreate() { - dbHelper = new OpenHelper(this); - syncAdapter = new ContactsSyncAdapter(this, dbHelper.getReadableDatabase()); + super.onCreate(); + syncAdapter = new ContactsSyncAdapter(this, dbHelper); } - @Override - public void onDestroy() { - dbHelper.close(); - } - @Override - public IBinder onBind(Intent intent) { - return syncAdapter.getSyncAdapterBinder(); - } - + private static class ContactsSyncAdapter extends SyncAdapter { - private static class ContactsSyncAdapter extends AbstractThreadedSyncAdapter { - private final SQLiteDatabase db; - - public ContactsSyncAdapter(Context context, @NonNull SQLiteDatabase db) { - super(context, false); - this.db = db; + public ContactsSyncAdapter(Context context, OpenHelper dbHelper) { + super(context, dbHelper); } @Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { - App.log.info("Starting address book sync (" + authority + ")"); - - // required for dav4android (ServiceLoader) - Thread.currentThread().setContextClassLoader(getContext().getClassLoader()); + super.onPerformSync(account, extras, authority, provider, syncResult); Long service = getService(account); if (service != null) { diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncAdapterService.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncAdapterService.java new file mode 100644 index 00000000..d85b865c --- /dev/null +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncAdapterService.java @@ -0,0 +1,69 @@ +/* + * Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/gpl.html + */ + +package at.bitfire.davdroid.syncadapter; + +import android.accounts.Account; +import android.app.Service; +import android.content.AbstractThreadedSyncAdapter; +import android.content.ContentProviderClient; +import android.content.Context; +import android.content.Intent; +import android.content.SyncResult; +import android.database.sqlite.SQLiteDatabase; +import android.os.Bundle; +import android.os.IBinder; +import android.support.annotation.Nullable; + +import at.bitfire.davdroid.AccountSettings; +import at.bitfire.davdroid.App; +import at.bitfire.davdroid.model.ServiceDB; + +public abstract class SyncAdapterService extends Service { + + ServiceDB.OpenHelper dbHelper; + AbstractThreadedSyncAdapter syncAdapter; + + @Override + public void onCreate() { + dbHelper = new ServiceDB.OpenHelper(this); + } + + @Override + public void onDestroy() { + dbHelper.close(); + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return syncAdapter.getSyncAdapterBinder(); + } + + + public static abstract class SyncAdapter extends AbstractThreadedSyncAdapter { + protected final SQLiteDatabase db; + + public SyncAdapter(Context context, ServiceDB.OpenHelper dbHelper) { + super(context, false); + db = dbHelper.getReadableDatabase(); + } + + @Override + public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { + App.log.info("Starting " + authority + " sync"); + + // required for dav4android (ServiceLoader) + Thread.currentThread().setContextClassLoader(getContext().getClassLoader()); + + // peek into AccountSettings to cause possible migration (v0.9 -> v1.0) + new AccountSettings(getContext(), account); + } + } + +} diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java index 15f7aefa..74a6f64b 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java @@ -46,6 +46,7 @@ import at.bitfire.davdroid.R; import at.bitfire.davdroid.resource.LocalCollection; import at.bitfire.davdroid.resource.LocalResource; import at.bitfire.davdroid.ui.AccountActivity; +import at.bitfire.davdroid.ui.AccountSettingsActivity; import at.bitfire.davdroid.ui.DebugInfoActivity; import at.bitfire.ical4android.CalendarStorageException; import at.bitfire.vcard4android.ContactsStorageException; @@ -112,7 +113,7 @@ abstract public class SyncManager { httpClient = HttpClient.create(context, account); // dismiss previous error notifications - notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(account.name, this.notificationId = notificationId); } @@ -209,8 +210,8 @@ abstract public class SyncManager { final Intent detailsIntent; if (e instanceof UnauthorizedException) { - detailsIntent = new Intent(context, AccountActivity.class); - detailsIntent.putExtra(AccountActivity.EXTRA_ACCOUNT, account); + detailsIntent = new Intent(context, AccountSettingsActivity.class); + detailsIntent.putExtra(AccountSettingsActivity.EXTRA_ACCOUNT, account); } else { detailsIntent = new Intent(context, DebugInfoActivity.class); detailsIntent.putExtra(DebugInfoActivity.KEY_EXCEPTION, e); diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncAdapterService.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncAdapterService.java index 8a102e7c..b84b6bd5 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncAdapterService.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncAdapterService.java @@ -35,41 +35,24 @@ import at.bitfire.ical4android.CalendarStorageException; import at.bitfire.ical4android.TaskProvider; import lombok.Cleanup; -public class TasksSyncAdapterService extends Service { - private static SyncAdapter syncAdapter; - private OpenHelper dbHelper; +public class TasksSyncAdapterService extends SyncAdapterService { @Override public void onCreate() { - dbHelper = new OpenHelper(this); - syncAdapter = new SyncAdapter(this, dbHelper.getReadableDatabase()); + super.onCreate(); + syncAdapter = new SyncAdapter(this, dbHelper); } - @Override - public void onDestroy() { - dbHelper.close(); - } - @Override - public IBinder onBind(Intent intent) { - return syncAdapter.getSyncAdapterBinder(); - } - + private static class SyncAdapter extends SyncAdapterService.SyncAdapter { - private static class SyncAdapter extends AbstractThreadedSyncAdapter { - private final SQLiteDatabase db; - - public SyncAdapter(Context context, SQLiteDatabase db) { - super(context, false); - this.db = db; + public SyncAdapter(Context context, OpenHelper dbHelper) { + super(context, dbHelper); } @Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient providerClient, SyncResult syncResult) { - App.log.info("Starting task sync (" + authority + ")"); - - // required for ical4j and dav4android (ServiceLoader) - Thread.currentThread().setContextClassLoader(getContext().getClassLoader()); + super.onPerformSync(account, extras, authority, providerClient, syncResult); try { @Cleanup TaskProvider provider = TaskProvider.acquire(getContext().getContentResolver(), TaskProvider.ProviderName.OpenTasks); diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncManager.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncManager.java index cd735723..4d24e6df 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncManager.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncManager.java @@ -83,23 +83,8 @@ public class TasksSyncManager extends SyncManager { } @Override - protected void queryCapabilities() throws DavException, IOException, HttpException, CalendarStorageException { - davCollection.propfind(0, DisplayName.NAME, CalendarColor.NAME, GetCTag.NAME); - - // update name and color - App.log.info("Setting task list name and color (if available)"); - ContentValues values = new ContentValues(2); - - DisplayName pDisplayName = (DisplayName)davCollection.properties.get(DisplayName.NAME); - if (pDisplayName != null && !TextUtils.isEmpty(pDisplayName.displayName)) - values.put(TaskLists.LIST_NAME, pDisplayName.displayName); - - CalendarColor pColor = (CalendarColor)davCollection.properties.get(CalendarColor.NAME); - if (pColor != null && pColor.color != null) - values.put(TaskLists.LIST_COLOR, pColor.color); - - if (values.size() > 0) - localTaskList().update(values); + protected void queryCapabilities() throws DavException, IOException, HttpException { + davCollection.propfind(0, GetCTag.NAME); } @Override diff --git a/app/src/main/java/at/bitfire/davdroid/ui/AccountActivity.java b/app/src/main/java/at/bitfire/davdroid/ui/AccountActivity.java index dfaae9d8..4f7ef3c0 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/AccountActivity.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/AccountActivity.java @@ -413,7 +413,7 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu private List readCollections(@NonNull SQLiteDatabase db, long service) { List collections = new LinkedList<>(); @Cleanup Cursor cursor = db.query(Collections._TABLE, Collections._COLUMNS, Collections.SERVICE_ID + "=?", - new String[]{ String.valueOf(service )}, null, null, Collections.SUPPORTS_VEVENT + " DESC," + Collections.DISPLAY_NAME); + new String[]{ String.valueOf(service) }, null, null, Collections.SUPPORTS_VEVENT + " DESC," + Collections.DISPLAY_NAME); while (cursor.moveToNext()) { ContentValues values = new ContentValues(); DatabaseUtils.cursorRowToContentValues(cursor, values); diff --git a/app/src/main/java/at/bitfire/davdroid/ui/AccountListFragment.java b/app/src/main/java/at/bitfire/davdroid/ui/AccountListFragment.java index 40627a75..f2a278f4 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/AccountListFragment.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/AccountListFragment.java @@ -13,8 +13,6 @@ import android.accounts.AccountManager; import android.accounts.OnAccountsUpdateListener; import android.content.Context; import android.content.Intent; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.support.v4.app.LoaderManager; @@ -29,18 +27,11 @@ import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; -import java.util.LinkedList; -import java.util.List; - import at.bitfire.davdroid.AccountsChangedReceiver; import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.R; -import at.bitfire.davdroid.model.ServiceDB.OpenHelper; -import at.bitfire.davdroid.model.ServiceDB.Services; -import lombok.Cleanup; -import lombok.RequiredArgsConstructor; -public class AccountListFragment extends ListFragment implements LoaderManager.LoaderCallbacks>, AdapterView.OnItemClickListener { +public class AccountListFragment extends ListFragment implements LoaderManager.LoaderCallbacks, AdapterView.OnItemClickListener { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -61,47 +52,39 @@ public class AccountListFragment extends ListFragment implements LoaderManager.L @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - AccountInfo info = (AccountInfo)getListAdapter().getItem(position); + Account account = (Account)getListAdapter().getItem(position); Intent intent = new Intent(getContext(), AccountActivity.class); - intent.putExtra(AccountActivity.EXTRA_ACCOUNT, info.account); + intent.putExtra(AccountActivity.EXTRA_ACCOUNT, account); startActivity(intent); } // loader - @RequiredArgsConstructor - protected static class AccountInfo { - final Account account; - Long cardDavService, calDavService; - } - @Override - public Loader> onCreateLoader(int id, Bundle args) { + public Loader onCreateLoader(int id, Bundle args) { return new AccountLoader(getContext()); } @Override - public void onLoadFinished(Loader> loader, List accounts) { + public void onLoadFinished(Loader loader, Account[] accounts) { AccountListAdapter adapter = (AccountListAdapter)getListAdapter(); adapter.clear(); adapter.addAll(accounts); } @Override - public void onLoaderReset(Loader> loader) { + public void onLoaderReset(Loader loader) { ((AccountListAdapter)getListAdapter()).clear(); } - private static class AccountLoader extends AsyncTaskLoader> implements OnAccountsUpdateListener { + private static class AccountLoader extends AsyncTaskLoader implements OnAccountsUpdateListener { private final AccountManager accountManager; - private final OpenHelper dbHelper; public AccountLoader(Context context) { super(context); accountManager = AccountManager.get(context); - dbHelper = new OpenHelper(context); } @Override @@ -120,43 +103,15 @@ public class AccountListFragment extends ListFragment implements LoaderManager.L } @Override - public List loadInBackground() { - List accounts = new LinkedList<>(); - try { - SQLiteDatabase db = dbHelper.getReadableDatabase(); - - for (Account account : accountManager.getAccountsByType(Constants.ACCOUNT_TYPE)) { - AccountInfo info = new AccountInfo(account); - - // query services of this account - @Cleanup Cursor cursor = db.query( - Services._TABLE, - new String[] { Services.ID, Services.SERVICE }, - Services.ACCOUNT_NAME + "=?", new String[] { account.name }, - null, null, null); - while (cursor.moveToNext()) { - long id = cursor.getLong(0); - - String service = cursor.getString(1); - if (Services.SERVICE_CARDDAV.equals(service)) - info.cardDavService = id; - if (Services.SERVICE_CALDAV.equals(service)) - info.calDavService = id; - } - - accounts.add(info); - } - } finally { - dbHelper.close(); - } - return accounts; + public Account[] loadInBackground() { + return accountManager.getAccountsByType(Constants.ACCOUNT_TYPE); } } // list adapter - static class AccountListAdapter extends ArrayAdapter { + static class AccountListAdapter extends ArrayAdapter { public AccountListAdapter(Context context) { super(context, R.layout.account_list_item); } @@ -166,16 +121,11 @@ public class AccountListFragment extends ListFragment implements LoaderManager.L if (v == null) v = LayoutInflater.from(getContext()).inflate(R.layout.account_list_item, parent, false); - AccountInfo info = getItem(position); + Account account = getItem(position); TextView tv = (TextView)v.findViewById(R.id.account_name); - tv.setText(info.account.name); + tv.setText(account.name); - tv = (TextView)v.findViewById(R.id.carddav); - tv.setVisibility(info.cardDavService != null ? View.VISIBLE : View.GONE); - - tv = (TextView)v.findViewById(R.id.caldav); - tv.setVisibility(info.calDavService != null ? View.VISIBLE : View.GONE); return v; } } diff --git a/app/src/main/java/at/bitfire/davdroid/ui/AccountSettingsActivity.java b/app/src/main/java/at/bitfire/davdroid/ui/AccountSettingsActivity.java index 02f96442..7d1ae053 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/AccountSettingsActivity.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/AccountSettingsActivity.java @@ -173,13 +173,13 @@ public class AccountSettingsActivity extends AppCompatActivity { prefSyncTasks.setSummary(R.string.settings_sync_summary_not_available); } - final Preference prefTimeRangePastDays = findPreference("caldav_time_range_past_days"); + final EditTextPreference prefTimeRangePastDays = (EditTextPreference)findPreference("caldav_time_range_past_days"); Integer pastDays = settings.getTimeRangePastDays(); if (pastDays != null) { - //prefTimeRangePastDays.setText(pastDays.toString()); + prefTimeRangePastDays.setText(pastDays.toString()); prefTimeRangePastDays.setSummary(getResources().getQuantityString(R.plurals.settings_sync_time_range_past_days, pastDays, pastDays)); } else { - //prefTimeRangePastDays.setText(null); + prefTimeRangePastDays.setText(null); prefTimeRangePastDays.setSummary(R.string.settings_sync_time_range_past_none); } prefTimeRangePastDays.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { diff --git a/app/src/main/java/at/bitfire/davdroid/ui/AccountsActivity.java b/app/src/main/java/at/bitfire/davdroid/ui/AccountsActivity.java index aae51412..0b8ab344 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/AccountsActivity.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/AccountsActivity.java @@ -73,10 +73,17 @@ public class AccountsActivity extends AppCompatActivity implements NavigationVie public boolean onNavigationItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.nav_about: + startActivity(new Intent(Intent.ACTION_VIEW, Constants.webUri.buildUpon().appendEncodedPath("source/").build())); break; case R.id.nav_website: startActivity(new Intent(Intent.ACTION_VIEW, Constants.webUri)); break; + case R.id.nav_faq: + startActivity(new Intent(Intent.ACTION_VIEW, Constants.webUri.buildUpon().appendEncodedPath("faq/").build())); + break; + case R.id.nav_forums: + startActivity(new Intent(Intent.ACTION_VIEW, Constants.webUri.buildUpon().appendEncodedPath("forums/").build())); + break; case R.id.nav_donate: startActivity(new Intent(Intent.ACTION_VIEW, Constants.webUri.buildUpon().appendEncodedPath("donate/").build())); break; diff --git a/app/src/main/java/at/bitfire/davdroid/ui/StartupDialogFragment.java b/app/src/main/java/at/bitfire/davdroid/ui/StartupDialogFragment.java index ffdec345..6c3d639c 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/StartupDialogFragment.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/StartupDialogFragment.java @@ -97,10 +97,10 @@ public class StartupDialogFragment extends DialogFragment { public void onClick(DialogInterface dialog, int which) { } }) - .setNeutralButton(R.string.startup_development_version_show_forums, new DialogInterface.OnClickListener() { + .setNeutralButton(R.string.startup_development_version_give_feedback, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - startActivity(new Intent(Intent.ACTION_VIEW, Constants.webUri.buildUpon().appendEncodedPath("forums/").build())); + startActivity(new Intent(Intent.ACTION_VIEW, Constants.webUri.buildUpon().appendEncodedPath("forums/beta/").build())); } }) .create(); diff --git a/app/src/main/res/drawable/ic_account_circle_white.xml b/app/src/main/res/drawable/ic_account_circle_white.xml new file mode 100644 index 00000000..c8f158e7 --- /dev/null +++ b/app/src/main/res/drawable/ic_account_circle_white.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_forum_dark.xml b/app/src/main/res/drawable/ic_forum_dark.xml new file mode 100644 index 00000000..fd14bef9 --- /dev/null +++ b/app/src/main/res/drawable/ic_forum_dark.xml @@ -0,0 +1,18 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_help_light.xml b/app/src/main/res/drawable/ic_help_dark.xml similarity index 88% rename from app/src/main/res/drawable/ic_help_light.xml rename to app/src/main/res/drawable/ic_help_dark.xml index d67c29db..b01c8e88 100644 --- a/app/src/main/res/drawable/ic_help_light.xml +++ b/app/src/main/res/drawable/ic_help_dark.xml @@ -10,8 +10,9 @@ android:width="24dp" android:height="24dp" android:viewportWidth="24.0" - android:viewportHeight="24.0"> + android:viewportHeight="24.0" + android:alpha="0.54" > diff --git a/app/src/main/res/drawable/ic_new_releases_light.xml b/app/src/main/res/drawable/ic_new_releases_light.xml new file mode 100644 index 00000000..9166aa6b --- /dev/null +++ b/app/src/main/res/drawable/ic_new_releases_light.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/drawable/side_nav_bar.xml b/app/src/main/res/drawable/side_nav_bar.xml index e99a6188..a9468e52 100644 --- a/app/src/main/res/drawable/side_nav_bar.xml +++ b/app/src/main/res/drawable/side_nav_bar.xml @@ -10,8 +10,7 @@ android:shape="rectangle"> \ No newline at end of file diff --git a/app/src/main/res/layout/account_list_item.xml b/app/src/main/res/layout/account_list_item.xml index 0866b320..2979790c 100644 --- a/app/src/main/res/layout/account_list_item.xml +++ b/app/src/main/res/layout/account_list_item.xml @@ -14,54 +14,27 @@ android:layout_height="wrap_content" android:foreground="?android:attr/selectableItemBackground" card_view:contentPadding="16dp" - card_view:cardBackgroundColor="#ececec" + card_view:cardBackgroundColor="@color/orange400" card_view:cardElevation="2dp"> - - - - - - - - - - + diff --git a/app/src/main/res/layout/accounts_content.xml b/app/src/main/res/layout/accounts_content.xml index 2fa11bda..e1e5230c 100644 --- a/app/src/main/res/layout/accounts_content.xml +++ b/app/src/main/res/layout/accounts_content.xml @@ -16,6 +16,19 @@ android:fitsSystemWindows="true" tools:context="at.bitfire.davdroid.ui.AccountsActivity"> + + + + + + - - - - - + app:title="CardDAV" + android:elevation="2dp"/> + app:title="CalDAV" + android:elevation="2dp"/> - - - + android:title="@string/navigation_drawer_settings"/> + + + + + + + + + + + diff --git a/app/src/main/res/menu/activity_login.xml b/app/src/main/res/menu/activity_login.xml index fc2c9d7f..e87b6ab0 100644 --- a/app/src/main/res/menu/activity_login.xml +++ b/app/src/main/res/menu/activity_login.xml @@ -13,7 +13,7 @@ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 52ab524e..fb41433a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -20,20 +20,17 @@ Don\'t show again DAVdroid Preview Release - This is a development version of DAVdroid. Be aware that things - may not work as expected. Please give us constructive feedback to improve DAVdroid. - Show forums + This is a development version of DAVdroid. Be aware that things may not work as expected. Please give us constructive feedback to improve DAVdroid. + Give feedback Open-Source Information We\'re happy that you use DAVdroid, which is open-source software (GPLv3). Because developing DAVdroid is hard work and took us thousands of working hours, please consider a donation. Show donation page Maybe later Play Store DRM bug information - Under certain conditions, Play Store DRM may cause all DAVdroid accounts to be gone - after a reboot or after upgrading DAVdroid. If you\'re affected by this problem (and only then), please install \"DAVdroid JB Workaround\" from Play Store. + Under certain conditions, Play Store DRM may cause all DAVdroid accounts to be gone after a reboot or after upgrading DAVdroid. If you\'re affected by this problem (and only then), please install \"DAVdroid JB Workaround\" from Play Store. More information OpenTasks not installed - The OpenTasks app is not installed or not accessible, so DAVdroid won\'t be - able to synchronize task lists. You may have to re-install DAVdroid and then add your accounts again after installing OpenTasks. + The OpenTasks app is not installed or not accessible, so DAVdroid won\'t be able to synchronize task lists. Re-install DAVdroid and then add your accounts again after installing OpenTasks. Install OpenTasks @@ -48,9 +45,12 @@ Close navigation drawer CalDAV/CardDAV Sync Adapter About / License - Donate - Settings + Settings + External links Web site + FAQ + Community + Donate Welcome to DAVdroid!\n\nYou can add a CalDAV/CardDAV account now. @@ -157,9 +157,10 @@ Events more than one day in the past will be ignored Events more than %d days in the past will be ignored - Events which are more than this number of days in the past (may be 0) will be ignored. Leave blank to synchronize all events. + Events which are more than this number of days in the past will be ignored (may be 0). Leave blank to synchronize all events. DAVdroid version update - Internal settings have been updated. In case of problems, please uninstall DAVdroid and then install it again. + Internal settings have been updated. + Problems? Uninstall DAVdroid, then re-install. Create address book diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index cc51249b..14ce9eab 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -19,6 +19,7 @@ #8bc34a #689f38 + #ffa726 #ff6d00 #000000