mirror of
https://github.com/etesync/android
synced 2025-05-22 16:58:52 +00:00
Minor refactoring
This commit is contained in:
parent
a735564bc1
commit
2e34fa686d
@ -12,22 +12,6 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class DavUtils {
|
public class DavUtils {
|
||||||
public static final int calendarGreen = 0xFFC3EA6E;
|
|
||||||
|
|
||||||
public static int CalDAVtoARGBColor(String davColor) {
|
|
||||||
int color = calendarGreen; // fallback: "DAVdroid green"
|
|
||||||
if (davColor != null) {
|
|
||||||
Pattern p = Pattern.compile("#?(\\p{XDigit}{6})(\\p{XDigit}{2})?");
|
|
||||||
Matcher m = p.matcher(davColor);
|
|
||||||
if (m.find()) {
|
|
||||||
int color_rgb = Integer.parseInt(m.group(1), 16);
|
|
||||||
int color_alpha = m.group(2) != null ? (Integer.parseInt(m.group(2), 16) & 0xFF) : 0xFF;
|
|
||||||
color = (color_alpha << 24) | color_rgb;
|
|
||||||
} else
|
|
||||||
App.log.warning("Couldn't parse color " + davColor + ", using DAVdroid green");
|
|
||||||
}
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String ARGBtoCalDAVColor(int colorWithAlpha) {
|
public static String ARGBtoCalDAVColor(int colorWithAlpha) {
|
||||||
byte alpha = (byte)(colorWithAlpha >> 24);
|
byte alpha = (byte)(colorWithAlpha >> 24);
|
||||||
|
@ -138,7 +138,7 @@ public class SSLSocketFactoryCompat extends SSLSocketFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
|
public Socket createSocket(String host, int port) throws IOException {
|
||||||
Socket ssl = delegate.createSocket(host, port);
|
Socket ssl = delegate.createSocket(host, port);
|
||||||
if (ssl instanceof SSLSocket)
|
if (ssl instanceof SSLSocket)
|
||||||
upgradeTLS((SSLSocket)ssl);
|
upgradeTLS((SSLSocket)ssl);
|
||||||
@ -146,7 +146,7 @@ public class SSLSocketFactoryCompat extends SSLSocketFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException, UnknownHostException {
|
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException {
|
||||||
Socket ssl = delegate.createSocket(host, port, localHost, localPort);
|
Socket ssl = delegate.createSocket(host, port, localHost, localPort);
|
||||||
if (ssl instanceof SSLSocket)
|
if (ssl instanceof SSLSocket)
|
||||||
upgradeTLS((SSLSocket)ssl);
|
upgradeTLS((SSLSocket)ssl);
|
||||||
|
@ -38,7 +38,7 @@ public class LocalAddressBook extends AndroidAddressBook implements LocalCollect
|
|||||||
SYNC_STATE_CTAG = "ctag",
|
SYNC_STATE_CTAG = "ctag",
|
||||||
SYNC_STATE_URL = "url";
|
SYNC_STATE_URL = "url";
|
||||||
|
|
||||||
private Bundle syncState = new Bundle();
|
private final Bundle syncState = new Bundle();
|
||||||
|
|
||||||
|
|
||||||
public LocalAddressBook(Account account, ContentProviderClient provider) {
|
public LocalAddressBook(Account account, ContentProviderClient provider) {
|
||||||
@ -165,12 +165,12 @@ public class LocalAddressBook extends AndroidAddressBook implements LocalCollect
|
|||||||
protected void readSyncState() throws ContactsStorageException {
|
protected void readSyncState() throws ContactsStorageException {
|
||||||
@Cleanup("recycle") Parcel parcel = Parcel.obtain();
|
@Cleanup("recycle") Parcel parcel = Parcel.obtain();
|
||||||
byte[] raw = getSyncState();
|
byte[] raw = getSyncState();
|
||||||
|
syncState.clear();
|
||||||
if (raw != null) {
|
if (raw != null) {
|
||||||
parcel.unmarshall(raw, 0, raw.length);
|
parcel.unmarshall(raw, 0, raw.length);
|
||||||
parcel.setDataPosition(0);
|
parcel.setDataPosition(0);
|
||||||
syncState = parcel.readBundle();
|
syncState.putAll(parcel.readBundle());
|
||||||
} else
|
}
|
||||||
syncState.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("Recycle")
|
@SuppressWarnings("Recycle")
|
||||||
|
@ -29,6 +29,7 @@ import net.fortuna.ical4j.model.component.VTimeZone;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -128,8 +129,7 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection {
|
|||||||
List<LocalResource> dirty = new LinkedList<>();
|
List<LocalResource> dirty = new LinkedList<>();
|
||||||
|
|
||||||
// get dirty events which are not required to have an increased SEQUENCE value
|
// get dirty events which are not required to have an increased SEQUENCE value
|
||||||
for (LocalEvent event : (LocalEvent[])queryEvents(Events.DIRTY + "=" + DIRTY_DONT_INCREASE_SEQUENCE + " AND " + Events.ORIGINAL_ID + " IS NULL", null))
|
Collections.addAll(dirty, (LocalEvent[])queryEvents(Events.DIRTY + "=" + DIRTY_DONT_INCREASE_SEQUENCE + " AND " + Events.ORIGINAL_ID + " IS NULL", null));
|
||||||
dirty.add(event);
|
|
||||||
|
|
||||||
// get dirty events which are required to have an increased SEQUENCE value
|
// get dirty events which are required to have an increased SEQUENCE value
|
||||||
for (LocalEvent event : (LocalEvent[])queryEvents(Events.DIRTY + "=" + DIRTY_INCREASE_SEQUENCE + " AND " + Events.ORIGINAL_ID + " IS NULL", null)) {
|
for (LocalEvent event : (LocalEvent[])queryEvents(Events.DIRTY + "=" + DIRTY_INCREASE_SEQUENCE + " AND " + Events.ORIGINAL_ID + " IS NULL", null)) {
|
||||||
@ -183,6 +183,8 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection {
|
|||||||
originalID = cursor.getLong(1); // can't be null (by query)
|
originalID = cursor.getLong(1); // can't be null (by query)
|
||||||
int sequence = cursor.isNull(2) ? 0 : cursor.getInt(2);
|
int sequence = cursor.isNull(2) ? 0 : cursor.getInt(2);
|
||||||
|
|
||||||
|
// FIXME sequence / cursor2 not used
|
||||||
|
|
||||||
// get original event's SEQUENCE
|
// get original event's SEQUENCE
|
||||||
@Cleanup Cursor cursor2 = provider.query(
|
@Cleanup Cursor cursor2 = provider.query(
|
||||||
syncAdapterURI(ContentUris.withAppendedId(Events.CONTENT_URI, originalID)),
|
syncAdapterURI(ContentUris.withAppendedId(Events.CONTENT_URI, originalID)),
|
||||||
|
@ -121,7 +121,6 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu
|
|||||||
requestSync();
|
requestSync();
|
||||||
break;
|
break;
|
||||||
case R.id.settings:
|
case R.id.settings:
|
||||||
Bundle args = new Bundle(1);
|
|
||||||
Intent intent = new Intent(this, AccountSettingsActivity.class);
|
Intent intent = new Intent(this, AccountSettingsActivity.class);
|
||||||
intent.putExtra(AccountSettingsActivity.EXTRA_ACCOUNT, account);
|
intent.putExtra(AccountSettingsActivity.EXTRA_ACCOUNT, account);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
@ -18,6 +18,7 @@ import android.database.Cursor;
|
|||||||
import android.database.DatabaseUtils;
|
import android.database.DatabaseUtils;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v4.app.LoaderManager;
|
import android.support.v4.app.LoaderManager;
|
||||||
import android.support.v4.app.NavUtils;
|
import android.support.v4.app.NavUtils;
|
||||||
@ -142,6 +143,7 @@ public class CreateAddressBookActivity extends AppCompatActivity implements Load
|
|||||||
getLoaderManager().initLoader(0, getArguments(), this);
|
getLoaderManager().initLoader(0, getArguments(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
Dialog dialog = new ProgressDialog.Builder(getActivity())
|
Dialog dialog = new ProgressDialog.Builder(getActivity())
|
||||||
@ -155,7 +157,7 @@ public class CreateAddressBookActivity extends AppCompatActivity implements Load
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Loader<Exception> onCreateLoader(int id, Bundle args) {
|
public Loader<Exception> onCreateLoader(int id, Bundle args) {
|
||||||
Account account = (Account)args.getParcelable(ARGS_ACCOUNT);
|
Account account = args.getParcelable(ARGS_ACCOUNT);
|
||||||
CollectionInfo info = (CollectionInfo)args.getSerializable(ARGS_COLLECTION_INFO);
|
CollectionInfo info = (CollectionInfo)args.getSerializable(ARGS_COLLECTION_INFO);
|
||||||
return new AddressBookCreator(getActivity(), account, info);
|
return new AddressBookCreator(getActivity(), account, info);
|
||||||
}
|
}
|
||||||
@ -263,7 +265,7 @@ public class CreateAddressBookActivity extends AppCompatActivity implements Load
|
|||||||
|
|
||||||
List<HashMap<String, String>> adapterData = new LinkedList<>();
|
List<HashMap<String, String>> adapterData = new LinkedList<>();
|
||||||
for (HomeSet homeSet : data.homeSets) {
|
for (HomeSet homeSet : data.homeSets) {
|
||||||
HashMap<String, String> map = new HashMap();
|
HashMap<String, String> map = new HashMap<>();
|
||||||
map.put(ServiceDB.HomeSets.ID, String.valueOf(homeSet.id));
|
map.put(ServiceDB.HomeSets.ID, String.valueOf(homeSet.id));
|
||||||
map.put(ServiceDB.HomeSets.URL, homeSet.URL);
|
map.put(ServiceDB.HomeSets.URL, homeSet.URL);
|
||||||
adapterData.add(map);
|
adapterData.add(map);
|
||||||
|
@ -217,7 +217,7 @@ public class CreateCollectionFragment extends DialogFragment implements LoaderMa
|
|||||||
SQLiteDatabase db = dbHelper.getWritableDatabase();
|
SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||||
|
|
||||||
// 1. find service ID
|
// 1. find service ID
|
||||||
String serviceType = null;
|
String serviceType;
|
||||||
if (info.type == CollectionInfo.Type.ADDRESS_BOOK)
|
if (info.type == CollectionInfo.Type.ADDRESS_BOOK)
|
||||||
serviceType = ServiceDB.Services.SERVICE_CARDDAV;
|
serviceType = ServiceDB.Services.SERVICE_CARDDAV;
|
||||||
else if (info.type == CollectionInfo.Type.CALENDAR)
|
else if (info.type == CollectionInfo.Type.CALENDAR)
|
||||||
|
@ -13,6 +13,7 @@ import android.app.Dialog;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
|
|
||||||
@ -20,7 +21,6 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import at.bitfire.dav4android.exception.HttpException;
|
import at.bitfire.dav4android.exception.HttpException;
|
||||||
import at.bitfire.davdroid.R;
|
import at.bitfire.davdroid.R;
|
||||||
import lombok.NonNull;
|
|
||||||
|
|
||||||
public class ExceptionInfoFragment extends DialogFragment {
|
public class ExceptionInfoFragment extends DialogFragment {
|
||||||
protected static final String
|
protected static final String
|
||||||
@ -36,6 +36,7 @@ public class ExceptionInfoFragment extends DialogFragment {
|
|||||||
return frag;
|
return frag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
Bundle args = getArguments();
|
Bundle args = getArguments();
|
||||||
|
@ -37,12 +37,11 @@ public class LoginCredentials implements Parcelable {
|
|||||||
public static final Creator CREATOR = new Creator<LoginCredentials>() {
|
public static final Creator CREATOR = new Creator<LoginCredentials>() {
|
||||||
@Override
|
@Override
|
||||||
public LoginCredentials createFromParcel(Parcel source) {
|
public LoginCredentials createFromParcel(Parcel source) {
|
||||||
LoginCredentials credentials = new LoginCredentials(
|
return new LoginCredentials(
|
||||||
(URI)source.readSerializable(),
|
(URI)source.readSerializable(),
|
||||||
source.readString(), source.readString(),
|
source.readString(), source.readString(),
|
||||||
(boolean)source.readValue(null)
|
(boolean)source.readValue(null)
|
||||||
);
|
);
|
||||||
return credentials;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user