Selectable calendars

pull/2/head
Ricki Hirner 8 years ago
parent f32493986b
commit 777e124b54

@ -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;
}

@ -127,7 +127,7 @@ public class CalendarsSyncAdapterService extends Service {
private Map<String, CollectionInfo> remoteCalendars(long service) {
Map<String, CollectionInfo> 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();

@ -130,7 +130,7 @@ public class TasksSyncAdapterService extends Service {
private Map<String, CollectionInfo> remoteTaskLists(long service) {
Map<String, CollectionInfo> 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();

@ -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<CollectionInfo> readCollections(SQLiteDatabase db, long service) {
List<CollectionInfo> 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);

@ -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;

@ -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

@ -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<LoginCredentials>() {
@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];
}
};
}
}

@ -16,6 +16,7 @@
android:gravity="center_vertical">
<CheckBox
android:id="@+id/selected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="4dp"/>

@ -9,6 +9,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -49,6 +50,7 @@
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:choiceMode="singleChoice"
android:id="@+id/address_books"/>
</LinearLayout>
@ -86,6 +88,7 @@
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:choiceMode="multipleChoice"
android:id="@+id/calendars"/>
</LinearLayout>

Loading…
Cancel
Save