Skip to content

Commit

Permalink
Update code - Fix Custom Color Issuse 💚
Browse files Browse the repository at this point in the history
  • Loading branch information
Reza Amuzadeh committed Mar 11, 2019
1 parent 00da8dc commit 56de84f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ext {
minSdkVersion = 17
targetSdkVersion = 28
versionCode = 13
versionName = "0.2.8"
versionCode = 14
versionName = "0.2.9"
}

buildscript {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected void onCreate(Bundle savedInstanceState) {
mBreadcrumbsView.setItems(new ArrayList<>(Arrays.asList(
BreadcrumbItem.createSimpleItem("Root Path")
)));

mBreadcrumbsView.setCallback(new DefaultBreadcrumbsCallback<BreadcrumbItem>() {
@Override
public void onNavigateBack(BreadcrumbItem item, int position) {
Expand Down
11 changes: 5 additions & 6 deletions demo/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
<moe.feng.common.view.breadcrumbs.BreadcrumbsView
android:id="@+id/breadcrumbs_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:isRtl="true"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:textColorSelected="@color/colorSelected"
app:textColorUnSelected="@color/colorUnSelected"
app:textSizeCustom="12sp" />
android:layout_height="56dp"
android:background="@color/colorPrimary"
app:CustomTextSize="12sp"
app:SelectedTextColor="@color/colorSelected"
app:UnSelectedTextColor="@color/colorUnSelected" />

</com.google.android.material.appbar.AppBarLayout>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ public void setItem(@NonNull IBreadcrumbItem item) {
button.setText(item.getSelectedItem().toString());
button.setTextColor(ViewUtils.getColorFromAttr(getContext(), getAdapterPosition() == getItemCount() - 1 ? android.R.attr.textColorPrimary : android.R.attr.textColorSecondary));

if (mTextColorSelected != -1)
if (mTextColorSelected != Integer.MAX_VALUE)
button.setTextColor(getAdapterPosition() == getItemCount() - 1 ? mTextColorSelected : mtextColorUnSelected);
else
button.setTextColor(ViewUtils.getColorFromAttr(getContext(), getAdapterPosition() == getItemCount() - 1 ? android.R.attr.textColorPrimary : android.R.attr.textColorSecondary));

if (mTextSize != -1)
if (mTextSize != Integer.MAX_VALUE)
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
}
}
Expand All @@ -145,7 +145,7 @@ class ArrowIconHolder extends ItemHolder<IBreadcrumbItem> {
super(itemView);
Drawable normalDrawable = getContext().getResources().getDrawable(R.drawable.ic_fiber_manual_record_black_24dp);
Drawable wrapDrawable = DrawableCompat.wrap(normalDrawable);
if (mtextColorUnSelected != -1)
if (mtextColorUnSelected != Integer.MAX_VALUE)
DrawableCompat.setTint(wrapDrawable, mtextColorUnSelected);
else
DrawableCompat.setTint(wrapDrawable, ViewUtils.getColorFromAttr(getContext(), android.R.attr.textColorSecondary));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class BreadcrumbsView extends FrameLayout {
/**
* Popup Menu Theme Id
*/
private int mTextColorSelected = -1;
private int mTextColorUnSelected = -1;
private int mTextSizeCustom = -1;
private int mTextColorSelected = Integer.MAX_VALUE;
private int mTextColorUnSelected = Integer.MAX_VALUE;
private int mTextSizeCustom = Integer.MAX_VALUE;
private boolean isRtl = false;

private static final String KEY_SUPER_STATES = BuildConfig.APPLICATION_ID + ".superStates";
Expand All @@ -55,10 +55,10 @@ public BreadcrumbsView(Context context, AttributeSet attrs, int defStyleAttr) {
private void getCustomAttrs(Context context, AttributeSet attrs, int defStyle) {
if (attrs != null) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BreadcrumbsView, 0, 0);
mTextColorSelected = a.getColor(R.styleable.BreadcrumbsView_textColorSelected, -1);
mTextColorUnSelected = a.getColor(R.styleable.BreadcrumbsView_textColorUnSelected, -1);
mTextSizeCustom = a.getDimensionPixelSize(R.styleable.BreadcrumbsView_textSizeCustom, -1);
isRtl = a.getBoolean(R.styleable.BreadcrumbsView_isRtl, false);
mTextColorSelected = a.getColor(R.styleable.BreadcrumbsView_SelectedTextColor, Integer.MAX_VALUE);
mTextColorUnSelected = a.getColor(R.styleable.BreadcrumbsView_UnSelectedTextColor, Integer.MAX_VALUE);
mTextSizeCustom = a.getDimensionPixelSize(R.styleable.BreadcrumbsView_CustomTextSize, Integer.MAX_VALUE);
isRtl = a.getBoolean(R.styleable.BreadcrumbsView_IsRtl, false);
a.recycle();
} else {
Toast.makeText(context, "NO ATTRS :|", Toast.LENGTH_SHORT).show();
Expand Down
8 changes: 4 additions & 4 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<resources>

<declare-styleable name="BreadcrumbsView">
<attr name="textColorSelected" format="reference|color" />
<attr name="textColorUnSelected" format="reference|color" />
<attr name="textSizeCustom" format="dimension" />
<attr name="isRtl" format="boolean" />
<attr name="SelectedTextColor" format="reference" />
<attr name="UnSelectedTextColor" format="reference" />
<attr name="CustomTextSize" format="dimension" />
<attr name="IsRtl" format="boolean" />
</declare-styleable>

</resources>

0 comments on commit 56de84f

Please sign in to comment.