Use material chip for remote list picker

pull/757/head
Alex Baker 6 years ago
parent dddfa528d2
commit 61ba538c1b

@ -0,0 +1,41 @@
package org.tasks.ui;
import static org.tasks.preferences.ResourceResolver.getDimen;
import android.content.Context;
import android.content.res.ColorStateList;
import com.google.android.material.chip.Chip;
import com.todoroo.astrid.api.Filter;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.injection.ForActivity;
import org.tasks.themes.ThemeCache;
import org.tasks.themes.ThemeColor;
public class ChipProvider {
private final ThemeCache themeCache;
private final int iconAlpha;
@Inject
public ChipProvider(@ForActivity Context context, ThemeCache themeCache) {
this.themeCache = themeCache;
iconAlpha = (int) (255 * getDimen(context, R.dimen.alpha_secondary));
}
public void apply(Chip chip, Filter filter) {
int tint = filter.tint;
ThemeColor color = tint >= 0 ? themeCache.getThemeColor(tint) : themeCache.getUntaggedColor();
chip.setText(filter.listingTitle);
chip.setCloseIconTint(
new ColorStateList(new int[][] {new int[] {}}, new int[] {color.getActionBarTint()}));
chip.setTextColor(color.getActionBarTint());
chip.getChipDrawable().setAlpha(iconAlpha);
chip.setChipBackgroundColor(
new ColorStateList(
new int[][] {
new int[] {-android.R.attr.state_checked}, new int[] {android.R.attr.state_checked}
},
new int[] {color.getPrimaryColor(), color.getPrimaryColor()}));
}
}

@ -12,6 +12,7 @@ import android.view.ViewGroup;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.OnClick;
import com.google.android.material.chip.Chip;
import com.todoroo.astrid.api.CaldavFilter;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.GtasksFilter;
@ -39,14 +40,18 @@ public class RemoteListFragment extends TaskEditControlFragment {
private static final String EXTRA_SELECTED_LIST = "extra_selected_list";
private static final int REQUEST_CODE_SELECT_LIST = 10101;
@BindView(R.id.google_task_list)
@BindView(R.id.dont_sync)
TextView textView;
@BindView(R.id.chip)
Chip chip;
@Inject GtasksListService gtasksListService;
@Inject GoogleTaskDao googleTaskDao;
@Inject CaldavDao caldavDao;
@Inject DefaultFilterProvider defaultFilterProvider;
@Inject TaskMover taskMover;
@Inject ChipProvider chipProvider;
@Nullable private Filter originalList;
@Nullable private Filter selectedList;
@ -94,10 +99,17 @@ public class RemoteListFragment extends TaskEditControlFragment {
selectedList = originalList;
}
chip.setOnCloseIconClickListener(this::clearSelected);
refreshView();
return view;
}
private void clearSelected(View ignored) {
selectedList = null;
refreshView();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
@ -125,7 +137,7 @@ public class RemoteListFragment extends TaskEditControlFragment {
return TAG;
}
@OnClick(R.id.google_task_list)
@OnClick({R.id.remote_list_row, R.id.chip})
void clickGoogleTaskList(View view) {
newRemoteListSupportPicker(selectedList, this, REQUEST_CODE_SELECT_LIST)
.show(getFragmentManager(), FRAG_TAG_GOOGLE_TASK_LIST_SELECTION);
@ -169,6 +181,13 @@ public class RemoteListFragment extends TaskEditControlFragment {
}
private void refreshView() {
textView.setText(selectedList == null ? null : selectedList.listingTitle);
if (selectedList == null) {
textView.setVisibility(View.VISIBLE);
chip.setVisibility(View.GONE);
} else {
textView.setVisibility(View.GONE);
chip.setVisibility(View.VISIBLE);
chipProvider.apply(chip, selectedList);
}
}
}

@ -1,10 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/google_task_list"
style="@style/TaskEditTextPrimary"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/remote_list_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:gravity="start"
android:hint="@string/dont_sync"
android:textAlignment="viewStart"/>
android:orientation="vertical">
<TextView
android:id="@+id/dont_sync"
style="@style/TaskEditTextPrimary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:gravity="start"
android:hint="@string/dont_sync"
android:textAlignment="viewStart"/>
<com.google.android.material.chip.Chip
android:id="@+id/chip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:closeIconEnabled="true"/>
</LinearLayout>

Loading…
Cancel
Save