1
0
mirror of https://github.com/etesync/android synced 2024-12-23 15:18:14 +00:00

Change desgin of both import lists

This commit is contained in:
Tal Hacohen 2017-04-02 13:11:56 +03:00
parent 8d208b3438
commit 6820d9d413
9 changed files with 131 additions and 43 deletions

View File

@ -116,6 +116,6 @@ public class CalendarAccount {
@Override
public String toString() {
return accountName + " calendars:" + calendars.size();
return accountName;
}
}

View File

@ -1,10 +1,8 @@
package com.etesync.syncadapter.ui.importlocal;
import android.accounts.Account;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.CalendarContract;
@ -18,7 +16,6 @@ import android.widget.TextView;
import com.etesync.syncadapter.R;
import com.etesync.syncadapter.model.CollectionInfo;
import com.etesync.syncadapter.model.CalendarAccount;
import com.etesync.syncadapter.resource.LocalCalendar;
import com.etesync.syncadapter.resource.LocalEvent;
@ -55,7 +52,7 @@ public class LocalCalendarImportFragment extends ListFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_local_import, container, false);
return inflater.inflate(R.layout.fragment_local_calendar_import, container, false);
}
@Override
@ -94,6 +91,14 @@ public class LocalCalendarImportFragment extends ListFragment {
this.calendarAccounts = calendarAccounts;
}
private class ChildViewHolder {
TextView textView;
}
private class GroupViewHolder {
TextView titleTextView;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return calendarAccounts.get(groupPosition).calendars
@ -110,18 +115,22 @@ public class LocalCalendarImportFragment extends ListFragment {
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
ChildViewHolder viewHolder;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_item, null);
convertView = inflater.inflate(R.layout.import_calendars_list_item, null);
}
//Todo add viewholder after we decide about the UI
TextView txtListChild = (TextView) convertView
.findViewById(R.id.listItemText);
txtListChild.setText(childText);
if (convertView.getTag() != null) {
viewHolder = (ChildViewHolder) convertView.getTag();
} else {
viewHolder = new ChildViewHolder();
viewHolder.textView = (TextView) convertView
.findViewById(R.id.listItemText);
convertView.setTag(viewHolder);
}
viewHolder.textView.setText(childText);
return convertView;
}
@ -150,17 +159,21 @@ public class LocalCalendarImportFragment extends ListFragment {
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
GroupViewHolder viewHolder;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_group, null);
convertView = inflater.inflate(R.layout.import_calendars_list_group, null);
}
//Todo add viewholder after we decide about the UI
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
if (convertView.getTag() != null) {
viewHolder = (GroupViewHolder) convertView.getTag();
} else {
viewHolder = new GroupViewHolder();
viewHolder.titleTextView = (TextView) convertView
.findViewById(R.id.title);
convertView.setTag(viewHolder);
}
viewHolder.titleTextView.setText(headerTitle);
return convertView;
}

View File

@ -3,7 +3,12 @@ package com.etesync.syncadapter.ui.importlocal;
import android.accounts.Account;
import android.app.ProgressDialog;
import android.content.ContentProviderClient;
import android.content.Context;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.ContactsContract;
@ -35,6 +40,7 @@ public class LocalContactImportFragment extends Fragment {
private Account account;
private CollectionInfo info;
private RecyclerView recyclerView;
public static LocalContactImportFragment newInstance(Account account, CollectionInfo info) {
LocalContactImportFragment frag = new LocalContactImportFragment();
@ -55,8 +61,6 @@ public class LocalContactImportFragment extends Fragment {
info = (CollectionInfo) getArguments().getSerializable(KEY_COLLECTION_INFO);
}
RecyclerView recyclerView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_local_contact_import, container, false);
@ -64,6 +68,7 @@ public class LocalContactImportFragment extends Fragment {
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.addItemDecoration(new DividerItemDecoration(getActivity()));
return view;
}
@ -79,7 +84,7 @@ public class LocalContactImportFragment extends Fragment {
Cursor cursor;
try {
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");
} catch (Exception except) {
Log.w(TAG, "Calendar provider is missing columns, continuing anyway");
@ -190,7 +195,8 @@ public class LocalContactImportFragment extends Fragment {
* Provide a reference to the type of views that you are using (custom ViewHolder)
*/
public static class ViewHolder extends RecyclerView.ViewHolder {
private final TextView textView;
private final TextView titleTextView;
private final TextView descTextView;
public ViewHolder(View v, final OnAccountSelected onAccountSelected) {
super(v);
@ -201,11 +207,16 @@ public class LocalContactImportFragment extends Fragment {
onAccountSelected.accountSelected(getAdapterPosition());
}
});
textView = (TextView) v.findViewById(R.id.listItemText);
titleTextView = (TextView) v.findViewById(R.id.title);
descTextView = (TextView) v.findViewById(R.id.description);
}
public TextView getTextView() {
return textView;
public TextView getTitleTextView() {
return titleTextView;
}
public TextView getDescriptionTextView() {
return descTextView;
}
}
@ -224,14 +235,15 @@ public class LocalContactImportFragment extends Fragment {
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
// Create a new view.
View v = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.list_item, viewGroup, false);
.inflate(R.layout.import_contacts_list_item, viewGroup, false);
return new ViewHolder(v, mOnAccountSelected);
}
@Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
viewHolder.getTextView().setText(mAddressBooks.get(position).account.name);
viewHolder.getTitleTextView().setText(mAddressBooks.get(position).account.name);
viewHolder.getDescriptionTextView().setText(mAddressBooks.get(position).account.type);
}
@Override
@ -243,4 +255,45 @@ public class LocalContactImportFragment extends Fragment {
private interface OnAccountSelected {
void accountSelected(int index);
}
public static class DividerItemDecoration extends RecyclerView.ItemDecoration {
private static final int[] ATTRS = new int[]{
android.R.attr.listDivider
};
private Drawable mDivider;
public DividerItemDecoration(Context context) {
final TypedArray a = context.obtainStyledAttributes(ATTRS);
mDivider = a.getDrawable(0);
a.recycle();
}
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
drawVertical(c, parent);
}
public void drawVertical(Canvas c, RecyclerView parent) {
final int left = parent.getPaddingLeft();
final int right = parent.getWidth() - parent.getPaddingRight();
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int top = child.getBottom() + params.bottomMargin;
final int bottom = top + mDivider.getIntrinsicHeight();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
}
}
}

View File

@ -14,5 +14,5 @@
android:id="@+id/import_button_account"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/import_button_account"/>
android:text="@string/import_button_local"/>
</LinearLayout>

View File

@ -1,18 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/light_green700"
android:padding="8dp"
android:background="#000000">
android:orientation="vertical">
<TextView
android:id="@+id/lblListHeader"
android:layout_width="fill_parent"
android:id="@+id/title"
android:textColor="@android:color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:textSize="17dp"
android:textColor="#f9f93d" />
android:textAppearance="?android:attr/textAppearanceMedium"
tools:text="Title"/>
</LinearLayout>

View File

@ -1,16 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="55dip"
android:orientation="vertical" >
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
<TextView
android:id="@+id/listItemText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="17dip"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft" />
android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
android:textAppearance="?android:attr/textAppearanceMedium"/>
</LinearLayout>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:text="Title"/>
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Subtitle"/>
</LinearLayout>

View File

@ -250,8 +250,8 @@
<string name="loading_error_content">Refresh</string>
<!-- Import Activity -->
<string name="import_button_file">Import from flie</string>
<string name="import_button_account">Import from account</string>
<string name="import_button_file">Import from file</string>
<string name="import_button_local">Import from local</string>
<string name="import_select_account">Select Account</string>
</resources>