Add chip configuration options

* Filled or outlined
* Text and icon, text only, or icon only
pull/935/head
Alex Baker 6 years ago
parent ee74d9f89e
commit 6e656d1093

@ -42,6 +42,7 @@ import org.tasks.themes.ThemeBase.EXTRA_THEME_OVERRIDE
import org.tasks.themes.ThemeColor
import org.tasks.themes.ThemeColor.getLauncherColor
import org.tasks.time.DateTime
import org.tasks.ui.ChipProvider
import org.tasks.ui.NavigationDrawerFragment.REQUEST_PURCHASE
import org.tasks.ui.SingleCheckedArrayAdapter
import org.tasks.ui.TimePreference
@ -76,6 +77,7 @@ class LookAndFeel : InjectingPreferenceFragment(), Preference.OnPreferenceChange
@Inject lateinit var playServices: PlayServices
@Inject lateinit var inventory: Inventory
@Inject lateinit var toaster: Toaster
@Inject lateinit var chipProvider: ChipProvider
override fun getPreferenceXml() = R.xml.preferences_look_and_feel
@ -95,6 +97,16 @@ class LookAndFeel : InjectingPreferenceFragment(), Preference.OnPreferenceChange
false
}
findPreference(R.string.p_chip_style).setOnPreferenceChangeListener { _, newValue ->
chipProvider.setStyle(Integer.parseInt(newValue as String))
true
}
findPreference(R.string.p_chip_appearance).setOnPreferenceChangeListener { _, newValue ->
chipProvider.setAppearance(Integer.parseInt(newValue as String))
true
}
val defaultList = findPreference(R.string.p_default_list)
val filter: Filter = defaultFilterProvider.defaultFilter
defaultList.summary = filter.listingTitle

@ -11,7 +11,6 @@ import static org.tasks.themes.ThemeColor.newThemeColor;
import android.app.Activity;
import android.content.Context;
import android.content.res.ColorStateList;
import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -42,6 +41,7 @@ import org.tasks.data.TagDataDao;
import org.tasks.data.TaskContainer;
import org.tasks.injection.ApplicationScope;
import org.tasks.injection.ForApplication;
import org.tasks.preferences.Preferences;
import org.tasks.themes.CustomIcons;
import org.tasks.themes.ThemeColor;
@ -61,6 +61,9 @@ public class ChipProvider {
return left.listingTitle.compareTo(right.listingTitle);
}
};
private boolean filled;
private boolean showIcon;
private boolean showText;
@Inject
public ChipProvider(
@ -69,7 +72,8 @@ public class ChipProvider {
GoogleTaskListDao googleTaskListDao,
CaldavDao caldavDao,
TagDataDao tagDataDao,
LocalBroadcastManager localBroadcastManager) {
LocalBroadcastManager localBroadcastManager,
Preferences preferences) {
this.inventory = inventory;
this.localBroadcastManager = localBroadcastManager;
iconAlpha =
@ -78,6 +82,17 @@ public class ChipProvider {
googleTaskListDao.subscribeToLists().observeForever(this::updateGoogleTaskLists);
caldavDao.subscribeToCalendars().observeForever(this::updateCaldavCalendars);
tagDataDao.subscribeToTags().observeForever(this::updateTags);
setStyle(preferences.getIntegerFromString(R.string.p_chip_style, 0));
setAppearance(preferences.getIntegerFromString(R.string.p_chip_appearance, 0));
}
public void setStyle(int style) {
filled = style == 1;
}
public void setAppearance(int appearance) {
showText = appearance != 2;
showIcon = appearance != 1;
}
private void updateGoogleTaskLists(List<GoogleTaskList> updated) {
@ -124,25 +139,27 @@ public class ChipProvider {
activity
.getResources()
.getQuantityString(R.plurals.subtask_count, task.children, task.children),
0);
0,
true,
true);
chips.add(chip);
}
if (task.hasLocation()) {
Chip chip = newChip(activity, task.getLocation());
apply(
activity, chip, R.drawable.ic_outline_place_24px, task.getLocation().getDisplayName(), 0);
activity, chip, R.drawable.ic_outline_place_24px, task.getLocation().getDisplayName(), 0, showText, showIcon);
chips.add(chip);
}
if (!isSubtask) {
if (!Strings.isNullOrEmpty(task.getGoogleTaskList()) && !(filter instanceof GtasksFilter)) {
chips.add(
newTagChip(
newChip(
activity,
googleTaskLists.get(task.getGoogleTaskList()),
R.drawable.ic_outline_cloud_24px));
} else if (!Strings.isNullOrEmpty(task.getCaldav()) && !(filter instanceof CaldavFilter)) {
chips.add(
newTagChip(
newChip(
activity, caldavCalendars.get(task.getCaldav()), R.drawable.ic_outline_cloud_24px));
}
}
@ -155,7 +172,7 @@ public class ChipProvider {
chips.addAll(
transform(
orderByName.sortedCopy(filter(transform(tags, tagDatas::get), Predicates.notNull())),
tag -> newTagChip(activity, tag, R.drawable.ic_outline_label_24px)));
tag -> newChip(activity, tag, R.drawable.ic_outline_label_24px)));
}
removeIf(chips, Predicates.isNull());
@ -168,7 +185,9 @@ public class ChipProvider {
chip,
getIcon(filter.icon, R.drawable.ic_outline_cloud_24px),
filter.listingTitle,
filter.tint);
filter.tint,
true,
true);
}
public void apply(Chip chip, @NonNull TagData tagData) {
@ -177,42 +196,82 @@ public class ChipProvider {
chip,
getIcon(tagData.getIcon(), R.drawable.ic_outline_label_24px),
tagData.getName(),
tagData.getColor());
tagData.getColor(),
true,
true);
}
private @Nullable Chip newChip(Activity activity, Filter filter, int defIcon) {
return newChip(activity, filter, defIcon, showText, showIcon);
}
private @Nullable Chip newTagChip(Activity activity, Filter filter, int defIcon) {
Chip newChip(Activity activity, Filter filter, int defIcon, boolean showText, boolean showIcon) {
if (filter == null) {
return null;
}
Chip chip = newChip(activity, filter);
apply(activity, chip, getIcon(filter.icon, defIcon), filter.listingTitle, filter.tint);
apply(activity, chip, getIcon(filter.icon, defIcon), filter.listingTitle, filter.tint, showText, showIcon);
return chip;
}
public Chip newClosableChip(Activity activity, Object tag) {
Chip chip = (Chip) activity.getLayoutInflater().inflate(R.layout.chip_closable, null);
Chip chip = getChip(activity);
chip.setCloseIconVisible(true);
chip.setTag(tag);
return chip;
}
private Chip newChip(Activity activity, Object tag) {
Chip chip = (Chip) activity.getLayoutInflater().inflate(R.layout.chip_button, null);
Chip chip = getChip(activity);
chip.setTag(tag);
return chip;
}
private void apply(Context context, Chip chip, @Nullable @DrawableRes Integer icon, String name, int theme) {
chip.setText(name);
@ColorInt int color = getColor(context, theme);
if (color != 0) {
ColorStateList colorStateList = new ColorStateList(new int[][]{new int[]{}}, new int[]{color});
chip.setCloseIconTint(colorStateList);
chip.setTextColor(color);
chip.setChipIconTint(colorStateList);
chip.setChipStrokeColor(colorStateList);
private Chip getChip(Activity activity) {
return (Chip)
activity
.getLayoutInflater()
.inflate(filled ? R.layout.chip_filled : R.layout.chip_outlined, null);
}
private void apply(
Context context,
Chip chip,
@Nullable @DrawableRes Integer icon,
String name,
int theme,
boolean showText,
boolean showIcon) {
if (showText) {
chip.setText(name);
chip.setIconEndPadding(0f);
} else {
chip.setText(null);
chip.setContentDescription(name);
chip.setTextStartPadding(0f);
chip.setChipEndPadding(0f);
}
ThemeColor themeColor = getColor(context, theme);
if (themeColor != null) {
int primaryColor = themeColor.getPrimaryColor();
ColorStateList primaryColorSL =
new ColorStateList(new int[][] {new int[] {}}, new int[] {primaryColor});
if (filled) {
int colorOnPrimary = themeColor.getColorOnPrimary();
ColorStateList colorOnPrimarySL =
new ColorStateList(new int[][] {new int[] {}}, new int[] {colorOnPrimary});
chip.setChipBackgroundColor(primaryColorSL);
chip.setTextColor(colorOnPrimary);
chip.setCloseIconTint(colorOnPrimarySL);
chip.setChipIconTint(colorOnPrimarySL);
} else {
chip.setTextColor(primaryColor);
chip.setCloseIconTint(primaryColorSL);
chip.setChipIconTint(primaryColorSL);
chip.setChipStrokeColor(primaryColorSL);
}
}
if (icon != null) {
if (showIcon && icon != null) {
chip.setChipIconResource(icon);
chip.getChipDrawable().setAlpha(iconAlpha);
}
@ -223,13 +282,13 @@ public class ChipProvider {
return icon != null ? icon : def;
}
private @ColorInt int getColor(Context context, int theme) {
private @Nullable ThemeColor getColor(Context context, int theme) {
if (theme != 0) {
ThemeColor color = newThemeColor(context, theme);
if (color.isFree() || inventory.purchasedThemes()) {
return color.getPrimaryColor();
return color;
}
}
return 0;
return null;
}
}

@ -14,6 +14,7 @@ import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.OnClick;
import com.google.android.material.chip.Chip;
import com.google.android.material.chip.ChipGroup;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.todoroo.astrid.api.CaldavFilter;
@ -46,8 +47,8 @@ public class RemoteListFragment extends TaskEditControlFragment {
@BindView(R.id.dont_sync)
TextView textView;
@BindView(R.id.chip)
Chip chip;
@BindView(R.id.chip_group)
ChipGroup chipGroup;
@Inject GtasksListService gtasksListService;
@Inject GoogleTaskDao googleTaskDao;
@ -114,8 +115,6 @@ public class RemoteListFragment extends TaskEditControlFragment {
setSelected(originalList);
}
chip.setOnCloseIconClickListener(v -> setSelected(null));
return view;
}
@ -152,8 +151,12 @@ public class RemoteListFragment extends TaskEditControlFragment {
return TAG;
}
@OnClick({R.id.remote_list_row, R.id.chip})
@OnClick({R.id.remote_list_row, R.id.chip_group})
void clickGoogleTaskList(View view) {
openPicker();
}
private void openPicker() {
newRemoteListSupportPicker(selectedList, this, REQUEST_CODE_SELECT_LIST)
.show(getFragmentManager(), FRAG_TAG_GOOGLE_TASK_LIST_SELECTION);
}
@ -210,11 +213,17 @@ public class RemoteListFragment extends TaskEditControlFragment {
private void refreshView() {
if (selectedList == null) {
textView.setVisibility(View.VISIBLE);
chip.setVisibility(View.GONE);
chipGroup.setVisibility(View.GONE);
} else {
textView.setVisibility(View.GONE);
chip.setVisibility(View.VISIBLE);
chipProvider.apply(chip, selectedList);
chipGroup.setVisibility(View.VISIBLE);
chipGroup.removeAllViews();
Chip chip =
chipProvider.newChip(getActivity(), selectedList, R.drawable.ic_outline_cloud_24px, true, true);
chip.setCloseIconVisible(true);
chip.setOnClickListener(v -> openPicker());
chip.setOnCloseIconClickListener(v -> setSelected(null));
chipGroup.addView(chip);
}
}
}

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.chip.Chip style="@style/ChipStyle" />

@ -1,3 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.chip.Chip
style="@style/ChipStyle.Closable"/>

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.chip.Chip style="@style/ChipStyle.Filled" />

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.chip.Chip style="@style/ChipStyle.Outlined" />

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<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"
@ -16,8 +17,12 @@
android:hint="@string/dont_sync"
android:textAlignment="viewStart" />
<com.google.android.material.chip.Chip
android:id="@+id/chip"
style="@style/ChipStyle.Closable"
<com.google.android.material.chip.ChipGroup
android:id="@+id/chip_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:chipSpacingVertical="@dimen/chip_spacing"
app:chipSpacingHorizontal="@dimen/chip_spacing"
android:visibility="gone" />
</LinearLayout>

@ -186,4 +186,29 @@
<item>@drawable/ic_etesync</item>
</array>
<string-array name="chip_styles">
<item>@string/chip_style_outlined</item>
<item>@string/chip_style_filled</item>
</string-array>
<string-array name="chip_style_values">
<item>0</item>
<item>1</item>
</string-array>
<string-array name="chip_appearance">
<item>@string/chip_appearance_text_and_icon</item>
<item>@string/chip_appearance_text_only</item>
<item>@string/chip_appearance_icon_only</item>
</string-array>
<string-array name="chip_appearance_values">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
<string name="chip_appearance_text_and_icon">Text and icon</string>
<string name="chip_appearance_text_only">Text only</string>
<string name="chip_appearance_icon_only">Icon only</string>
</resources>

@ -162,6 +162,8 @@
<color name="text_tertiary">@color/black_38</color>
<color name="chip_text">@color/black_100</color>
<color name="divider">@color/black_12</color>
<color name="default_chip_background">@color/grey_300</color>
<color name="default_chip_text_color">@color/black_87</color>
</resources>

@ -288,4 +288,6 @@
<string name="p_show_subtasks">show_subtasks</string>
<string name="p_wearable_notifications">wearable_notifications</string>
<string name="p_notified_oauth_error">notified_oauth_error_%s_%s</string>
<string name="p_chip_style">chip_style</string>
<string name="p_chip_appearance">chip_appearance</string>
</resources>

@ -558,4 +558,9 @@ File %1$s contained %2$s.\n\n
<string name="upgrade_blurb_4">Your support means a lot to me, thank you!</string>
<string name="back">Back</string>
<string name="requires_android_version">Requires Android %s+</string>
<string name="chip_style">Chip style</string>
<string name="chip_style_outlined">Outlined</string>
<string name="chip_style_filled">Filled</string>
<string name="chips">Chips</string>
<string name="chip_appearance">Chip appearance</string>
</resources>

@ -156,18 +156,27 @@
<item name="chipMinHeight">@dimen/chip_min_height</item>
<item name="closeIconVisible">false</item>
<item name="ensureMinTouchTargetSize">false</item>
<item name="chipStrokeWidth">@dimen/chip_stroke</item>
<item name="chipSurfaceColor">@android:color/transparent</item>
<item name="iconStartPadding">5dp</item>
<item name="iconEndPadding">2dp</item>
<item name="closeIconEndPadding">5dp</item>
<item name="chipEndPadding">4dp</item>
</style>
<style name="ChipStyle.Outlined">
<item name="chipStrokeWidth">@dimen/chip_stroke</item>
<item name="chipBackgroundColor">@android:color/transparent</item>
<item name="iconStartPadding">@dimen/chip_text_padding</item>
<item name="iconEndPadding">0dp</item>
<item name="android:textColor">@color/chip_text</item>
<item name="chipIconTint">@color/text_secondary</item>
<item name="chipIconTint">@color/chip_text</item>
<item name="closeIconTint">@color/chip_text</item>
<item name="chipStrokeColor">@color/text_secondary</item>
</style>
<style name="ChipStyle.Closable">
<item name="closeIconVisible">true</item>
<style name="ChipStyle.Filled">
<item name="chipBackgroundColor">@color/default_chip_background</item>
<item name="android:textColor">@color/default_chip_text_color</item>
<item name="chipIconTint">@color/default_chip_text_color</item>
<item name="closeIconTint">@color/default_chip_text_color</item>
</style>
<style name="OutlineButton" parent="Widget.MaterialComponents.Button.OutlinedButton">

@ -84,6 +84,27 @@
android:title="@string/EPr_temp_show_completed_tasks"
app:singleLineTitle="false" />
<PreferenceCategory
android:title="@string/chips">
<ListPreference
android:defaultValue="0"
android:entries="@array/chip_styles"
android:summary="%s"
android:entryValues="@array/chip_style_values"
android:key="@string/p_chip_style"
android:title="@string/chip_style" />
<ListPreference
android:defaultValue="0"
android:entries="@array/chip_appearance"
android:summary="%s"
android:entryValues="@array/chip_appearance_values"
android:key="@string/p_chip_appearance"
android:title="@string/chip_appearance" />
</PreferenceCategory>
</PreferenceCategory>
<PreferenceCategory android:title="@string/EPr_edit_screen_options">

Loading…
Cancel
Save