diff --git a/app/src/main/java/at/bitfire/davdroid/model/CollectionInfo.java b/app/src/main/java/at/bitfire/davdroid/model/CollectionInfo.java index dcbf76ad..845c6fa9 100644 --- a/app/src/main/java/at/bitfire/davdroid/model/CollectionInfo.java +++ b/app/src/main/java/at/bitfire/davdroid/model/CollectionInfo.java @@ -139,7 +139,7 @@ public class CollectionInfo { if (supportsVTODO != null) values.put(Collections.SUPPORTS_VTODO, supportsVTODO ? 1 : 0); - values.put(Collections.SELECTED, selected); + values.put(Collections.SELECTED, selected ? 1 : 0); return values; } 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 4ef2016e..1828e806 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java @@ -127,7 +127,7 @@ public class CalendarsSyncAdapterService extends Service { private Map remoteCalendars(long service) { Map collections = new LinkedHashMap<>(); @Cleanup Cursor cursor = db.query(ServiceDB.Collections._TABLE, ServiceDB.Collections._COLUMNS, - ServiceDB.Collections.SERVICE_ID + "=? AND " + ServiceDB.Collections.SUPPORTS_VEVENT + "!=0", + ServiceDB.Collections.SERVICE_ID + "=? AND " + ServiceDB.Collections.SUPPORTS_VEVENT + "!=0 AND selected", new String[] { String.valueOf(service) }, null, null, null); while (cursor.moveToNext()) { ContentValues values = new ContentValues(); 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 56a69b42..df1438fd 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncAdapterService.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncAdapterService.java @@ -130,7 +130,7 @@ public class TasksSyncAdapterService extends Service { private Map remoteTaskLists(long service) { Map collections = new LinkedHashMap<>(); @Cleanup Cursor cursor = db.query(Collections._TABLE, Collections._COLUMNS, - Collections.SERVICE_ID + "=? AND " + Collections.SUPPORTS_VTODO + "!=0", + Collections.SERVICE_ID + "=? AND " + Collections.SUPPORTS_VTODO + "!=0 AND selected", new String[] { String.valueOf(service) }, null, null, null); while (cursor.moveToNext()) { ContentValues values = new ContentValues(); 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 8bf6bdba..563c0e95 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/AccountActivity.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/AccountActivity.java @@ -42,6 +42,8 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; +import android.widget.CheckBox; +import android.widget.CompoundButton; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; @@ -174,6 +176,7 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu progress.setVisibility(info.carddav.refreshing ? View.VISIBLE : View.GONE); ListView list = (ListView)findViewById(R.id.address_books); + list.setEnabled(!info.carddav.refreshing); AddressBookAdapter adapter = new AddressBookAdapter(this); adapter.addAll(info.carddav.collections); list.setAdapter(adapter); @@ -186,6 +189,7 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu progress.setVisibility(info.caldav.refreshing ? View.VISIBLE : View.GONE); ListView list = (ListView)findViewById(R.id.calendars); + list.setEnabled(!info.caldav.refreshing); CalendarAdapter adapter = new CalendarAdapter(this); adapter.addAll(info.caldav.collections); list.setAdapter(adapter); @@ -271,7 +275,8 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu private List readCollections(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, null); + @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); while (cursor.moveToNext()) { ContentValues values = new ContentValues(); DatabaseUtils.cursorRowToContentValues(cursor, values); @@ -321,10 +326,29 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu if (v == null) v = LayoutInflater.from(getContext()).inflate(R.layout.account_calendar_item, parent, false); - CollectionInfo info = getItem(position); + final CollectionInfo info = getItem(position); - View vColor = v.findViewById(R.id.color); - vColor.setBackgroundColor(info.color); + CheckBox select = (CheckBox)v.findViewById(R.id.selected); + select.setChecked(info.selected); + select.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + OpenHelper dbHelper = new OpenHelper(getContext()); + try { + SQLiteDatabase db = dbHelper.getWritableDatabase(); + ContentValues values = new ContentValues(1); + values.put(Collections.SELECTED, isChecked ? 1 : 0); + db.update(Collections._TABLE, values, Collections.ID + "=?", new String[]{String.valueOf(info.id)}); + } finally { + dbHelper.close(); + } + } + }); + + if (info.color != null) { + View vColor = v.findViewById(R.id.color); + vColor.setBackgroundColor(info.color); + } TextView tv = (TextView)v.findViewById(R.id.title); tv.setText(TextUtils.isEmpty(info.displayName) ? info.url : info.displayName); diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.java b/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.java index 7f19c54c..5e76d28b 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.java @@ -76,7 +76,7 @@ public class DavResourceFinder { httpClient = HttpClient.create(context); httpClient = HttpClient.addLogger(httpClient, log); - httpClient = HttpClient.addAuthentication(httpClient, credentials.getUserName(), credentials.getPassword(), credentials.isAuthPreemptive()); + httpClient = HttpClient.addAuthentication(httpClient, credentials.userName, credentials.password, credentials.authPreemptive); } @@ -86,7 +86,7 @@ public class DavResourceFinder { calDavConfig = findInitialConfiguration(Service.CALDAV); return new Configuration( - credentials.getUserName(), credentials.getPassword(), credentials.isAuthPreemptive(), + credentials.userName, credentials.password, credentials.authPreemptive, cardDavConfig, calDavConfig, log.toString() ); @@ -94,7 +94,7 @@ public class DavResourceFinder { protected Configuration.ServiceInfo findInitialConfiguration(@NonNull Service service) { // user-given base URI (either mailto: URI or http(s):// URL) - final URI baseURI = credentials.getUri(); + final URI baseURI = credentials.uri; // domain for service discovery String discoveryFQDN = null; diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.java b/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.java index 3eecbc2a..5c039b96 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.java @@ -122,7 +122,7 @@ public class DetectConfigurationFragment extends DialogFragment implements Loade public ServerConfigurationLoader(Context context, Bundle args) { super(context); this.context = context; - credentials = (LoginCredentialsFragment.LoginCredentials)args.getSerializable(ARG_LOGIN_CREDENTIALS); + credentials = (LoginCredentialsFragment.LoginCredentials)args.getParcelable(ARG_LOGIN_CREDENTIALS); } @Override diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/LoginCredentialsFragment.java b/app/src/main/java/at/bitfire/davdroid/ui/setup/LoginCredentialsFragment.java index 8b6824f8..609eb758 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/LoginCredentialsFragment.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/LoginCredentialsFragment.java @@ -10,6 +10,8 @@ package at.bitfire.davdroid.ui.setup; import android.net.Uri; import android.os.Bundle; +import android.os.Parcel; +import android.os.Parcelable; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.support.v7.widget.AppCompatCheckBox; @@ -22,14 +24,13 @@ import android.widget.CompoundButton; import android.widget.EditText; import android.widget.LinearLayout; -import java.io.Serializable; import java.net.IDN; import java.net.URI; import java.net.URISyntaxException; import at.bitfire.davdroid.R; import at.bitfire.davdroid.ui.widget.EditPassword; -import lombok.Data; +import lombok.RequiredArgsConstructor; public class LoginCredentialsFragment extends Fragment implements CompoundButton.OnCheckedChangeListener { @@ -75,7 +76,7 @@ public class LoginCredentialsFragment extends Fragment implements CompoundButton if (credentials != null) { // login data OK, continue with DetectConfigurationFragment Bundle args = new Bundle(1); - args.putSerializable(DetectConfigurationFragment.ARG_LOGIN_CREDENTIALS, credentials); + args.putParcelable(DetectConfigurationFragment.ARG_LOGIN_CREDENTIALS, credentials); DialogFragment dialog = new DetectConfigurationFragment(); dialog.setArguments(args); @@ -169,11 +170,41 @@ public class LoginCredentialsFragment extends Fragment implements CompoundButton } - @Data - public class LoginCredentials implements Serializable { - final URI uri; - final String userName, password; - final boolean authPreemptive; + @RequiredArgsConstructor + public static class LoginCredentials implements Parcelable { + public final URI uri; + public final String userName, password; + public final boolean authPreemptive; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeSerializable(uri); + dest.writeString(userName); + dest.writeString(password); + dest.writeInt(authPreemptive ? 1 : 0); + } + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + @Override + public LoginCredentials createFromParcel(Parcel source) { + LoginCredentials credentials = new LoginCredentials( + (URI)source.readSerializable(), + source.readString(), source.readString(), + source.readInt() != 0 ? true : false + ); + return null; + } + + @Override + public LoginCredentials[] newArray(int size) { + return new LoginCredentials[0]; + } + }; } } diff --git a/app/src/main/res/layout/account_calendar_item.xml b/app/src/main/res/layout/account_calendar_item.xml index 0a19d662..157dc74e 100644 --- a/app/src/main/res/layout/account_calendar_item.xml +++ b/app/src/main/res/layout/account_calendar_item.xml @@ -16,6 +16,7 @@ android:gravity="center_vertical"> diff --git a/app/src/main/res/layout/activity_account.xml b/app/src/main/res/layout/activity_account.xml index b057b0b6..ac74adaf 100644 --- a/app/src/main/res/layout/activity_account.xml +++ b/app/src/main/res/layout/activity_account.xml @@ -9,6 +9,7 @@ @@ -86,6 +88,7 @@