mirror of
https://github.com/etesync/android
synced 2025-01-11 08:10:58 +00:00
Merge: Improve presentation of accounts in import screen
This commit is contained in:
commit
d5ba48e59c
@ -8,6 +8,7 @@ import android.net.Uri;
|
|||||||
import android.provider.CalendarContract;
|
import android.provider.CalendarContract;
|
||||||
import android.provider.CalendarContract.Calendars;
|
import android.provider.CalendarContract.Calendars;
|
||||||
import android.provider.CalendarContract.Events;
|
import android.provider.CalendarContract.Events;
|
||||||
|
import android.provider.ContactsContract;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.etesync.syncadapter.App;
|
import com.etesync.syncadapter.App;
|
||||||
@ -21,19 +22,15 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class CalendarAccount {
|
public class CalendarAccount {
|
||||||
public String accountName;
|
private Account account;
|
||||||
public List<LocalCalendar> calendars = new ArrayList<>();
|
private List<LocalCalendar> calendars = new ArrayList<>();
|
||||||
|
|
||||||
private static final String[] CAL_COLS = new String[] {
|
private static final String[] CAL_COLS = new String[]{
|
||||||
Calendars._ID, Calendars.DELETED, Calendars.NAME, Calendars.CALENDAR_DISPLAY_NAME,
|
Calendars.ACCOUNT_NAME, Calendars.ACCOUNT_TYPE,
|
||||||
Calendars.ACCOUNT_NAME, Calendars.ACCOUNT_TYPE, Calendars.OWNER_ACCOUNT,
|
Calendars.DELETED, Calendars.NAME};
|
||||||
Calendars.VISIBLE, Calendars.CALENDAR_TIME_ZONE };
|
|
||||||
|
|
||||||
private static final String[] CAL_ID_COLS = new String[] { Events._ID };
|
protected CalendarAccount(Account account) {
|
||||||
private static final String CAL_ID_WHERE = Events.CALENDAR_ID + "=?";
|
this.account = account;
|
||||||
|
|
||||||
protected CalendarAccount(String accountName) {
|
|
||||||
this.accountName = accountName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load all available calendars.
|
// Load all available calendars.
|
||||||
@ -47,7 +44,8 @@ public class CalendarAccount {
|
|||||||
Cursor cur;
|
Cursor cur;
|
||||||
try {
|
try {
|
||||||
cur = resolver.query(Calendars.CONTENT_URI,
|
cur = resolver.query(Calendars.CONTENT_URI,
|
||||||
CAL_COLS, null, null, Calendars.ACCOUNT_NAME + " ASC");
|
CAL_COLS, null, null,
|
||||||
|
ContactsContract.RawContacts.ACCOUNT_NAME + " ASC, " + ContactsContract.RawContacts.ACCOUNT_TYPE);
|
||||||
} catch (Exception except) {
|
} catch (Exception except) {
|
||||||
App.log.warning("Calendar provider is missing columns, continuing anyway");
|
App.log.warning("Calendar provider is missing columns, continuing anyway");
|
||||||
cur = resolver.query(Calendars.CONTENT_URI, null, null, null, null);
|
cur = resolver.query(Calendars.CONTENT_URI, null, null, null, null);
|
||||||
@ -56,35 +54,29 @@ public class CalendarAccount {
|
|||||||
List<CalendarAccount> calendarAccounts = new ArrayList<>(cur.getCount());
|
List<CalendarAccount> calendarAccounts = new ArrayList<>(cur.getCount());
|
||||||
|
|
||||||
CalendarAccount calendarAccount = null;
|
CalendarAccount calendarAccount = null;
|
||||||
|
|
||||||
ContentProviderClient contentProviderClient = resolver.acquireContentProviderClient(CalendarContract.CONTENT_URI);
|
ContentProviderClient contentProviderClient = resolver.acquireContentProviderClient(CalendarContract.CONTENT_URI);
|
||||||
while (cur.moveToNext()) {
|
while (cur.moveToNext()) {
|
||||||
if (getLong(cur, Calendars.DELETED) != 0)
|
if (getLong(cur, Calendars.DELETED) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
String accountName = getString(cur, Calendars.ACCOUNT_NAME);
|
String accountName = getString(cur, Calendars.ACCOUNT_NAME);
|
||||||
if (calendarAccount == null || !calendarAccount.accountName.equals(accountName)) {
|
String accountType = getString(cur, Calendars.ACCOUNT_TYPE);
|
||||||
calendarAccount = new CalendarAccount(accountName);
|
if (calendarAccount == null ||
|
||||||
|
!calendarAccount.getAccountName().equals(accountName) ||
|
||||||
|
!calendarAccount.getAccountType().equals(accountType)) {
|
||||||
|
calendarAccount = new CalendarAccount(new Account(accountName, accountType));
|
||||||
calendarAccounts.add(calendarAccount);
|
calendarAccounts.add(calendarAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
long id = getLong(cur, Calendars._ID);
|
|
||||||
if (id == -1) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String[] args = new String[] { String.valueOf(id) };
|
|
||||||
Cursor eventsCur = resolver.query(Events.CONTENT_URI, CAL_ID_COLS, CAL_ID_WHERE, args, null);
|
|
||||||
Account account = new Account(accountName, getString(cur, Calendars.ACCOUNT_TYPE));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LocalCalendar localCalendar = LocalCalendar.findByName(account, contentProviderClient,
|
LocalCalendar localCalendar = LocalCalendar.findByName(calendarAccount.getAccount(),
|
||||||
|
contentProviderClient,
|
||||||
LocalCalendar.Factory.INSTANCE, getString(cur, Calendars.NAME));
|
LocalCalendar.Factory.INSTANCE, getString(cur, Calendars.NAME));
|
||||||
if (localCalendar != null) calendarAccount.calendars.add(localCalendar);
|
if (localCalendar != null) calendarAccount.calendars.add(localCalendar);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
eventsCur.close();
|
|
||||||
}
|
}
|
||||||
contentProviderClient.release();
|
contentProviderClient.release();
|
||||||
cur.close();
|
cur.close();
|
||||||
@ -113,8 +105,24 @@ public class CalendarAccount {
|
|||||||
return provider == null;
|
return provider == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getAccountName() {
|
||||||
|
return account.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAccountType() {
|
||||||
|
return account.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<LocalCalendar> getCalendars() {
|
||||||
|
return calendars;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Account getAccount() {
|
||||||
|
return account;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return accountName;
|
return account.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ public class LocalCalendarImportFragment extends ListFragment {
|
|||||||
listCalendar.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
|
listCalendar.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onChildClick(ExpandableListView aExpandableListView, View aView, int groupPosition, int childPosition, long aL) {
|
public boolean onChildClick(ExpandableListView aExpandableListView, View aView, int groupPosition, int childPosition, long aL) {
|
||||||
new ImportEvents().execute(calendarAccountList.get(groupPosition).calendars.get(childPosition));
|
new ImportEvents().execute(calendarAccountList.get(groupPosition).getCalendars().get(childPosition));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -102,7 +102,7 @@ public class LocalCalendarImportFragment extends ListFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getChild(int groupPosition, int childPosititon) {
|
public Object getChild(int groupPosition, int childPosititon) {
|
||||||
return calendarAccounts.get(groupPosition).calendars
|
return calendarAccounts.get(groupPosition).getCalendars()
|
||||||
.get(childPosititon).getDisplayName();
|
.get(childPosititon).getDisplayName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,13 +137,13 @@ public class LocalCalendarImportFragment extends ListFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getChildrenCount(int groupPosition) {
|
public int getChildrenCount(int groupPosition) {
|
||||||
return calendarAccounts.get(groupPosition).calendars
|
return calendarAccounts.get(groupPosition).getCalendars()
|
||||||
.size();
|
.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getGroup(int groupPosition) {
|
public Object getGroup(int groupPosition) {
|
||||||
return calendarAccounts.get(groupPosition).toString();
|
return calendarAccounts.get(groupPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -159,7 +159,7 @@ public class LocalCalendarImportFragment extends ListFragment {
|
|||||||
@Override
|
@Override
|
||||||
public View getGroupView(int groupPosition, boolean isExpanded,
|
public View getGroupView(int groupPosition, boolean isExpanded,
|
||||||
View convertView, ViewGroup parent) {
|
View convertView, ViewGroup parent) {
|
||||||
String headerTitle = (String) getGroup(groupPosition);
|
CalendarAccount calendarAccount = (CalendarAccount) getGroup(groupPosition);
|
||||||
GroupViewHolder viewHolder;
|
GroupViewHolder viewHolder;
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
LayoutInflater inflater = (LayoutInflater) context
|
LayoutInflater inflater = (LayoutInflater) context
|
||||||
@ -176,9 +176,9 @@ public class LocalCalendarImportFragment extends ListFragment {
|
|||||||
.findViewById(R.id.description);
|
.findViewById(R.id.description);
|
||||||
convertView.setTag(viewHolder);
|
convertView.setTag(viewHolder);
|
||||||
}
|
}
|
||||||
viewHolder.titleTextView.setText(headerTitle);
|
|
||||||
viewHolder.descriptionTextView.setText(headerTitle);
|
|
||||||
|
|
||||||
|
viewHolder.titleTextView.setText(calendarAccount.getAccountName());
|
||||||
|
viewHolder.descriptionTextView.setText(calendarAccount.getAccountType());
|
||||||
|
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,8 @@ public class LocalContactImportFragment extends Fragment {
|
|||||||
try {
|
try {
|
||||||
cursor = provider.query(ContactsContract.RawContacts.CONTENT_URI,
|
cursor = provider.query(ContactsContract.RawContacts.CONTENT_URI,
|
||||||
new String[]{ContactsContract.RawContacts.ACCOUNT_NAME, ContactsContract.RawContacts.ACCOUNT_TYPE}
|
new String[]{ContactsContract.RawContacts.ACCOUNT_NAME, ContactsContract.RawContacts.ACCOUNT_TYPE}
|
||||||
, null, null, ContactsContract.RawContacts.ACCOUNT_NAME + " ASC");
|
, null, null,
|
||||||
|
ContactsContract.RawContacts.ACCOUNT_NAME + " ASC, " + ContactsContract.RawContacts.ACCOUNT_TYPE);
|
||||||
} catch (Exception except) {
|
} catch (Exception except) {
|
||||||
Log.w(TAG, "Calendar provider is missing columns, continuing anyway");
|
Log.w(TAG, "Calendar provider is missing columns, continuing anyway");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user