Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
gregkorossy committed Sep 24, 2017
2 parents e49d783 + 0d90f61 commit 9da9b19
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 16 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

**2017-09-24**

New version: 26.1.0.1 (based on v26.1.0)

- Bug fix: crash on API 26 when using dividers and preferences with widgets together
- Bug fix: `ColorPickerPreference`'s column number defaults to auto (0) instead of 3
- `PreferenceCategory`'s title view gets hidden (including its dimensions) when the title is empty (the dividers will be drawn as if the title was not hidden)
- Added 2 new flags to the custom dividers: `DIVIDER_NO_BEFORE_FIRST` and `DIVIDER_NO_AFTER_LAST`

**2017-09-17**

New version: 26.1.0.0 (based on v26.1.0)
Expand Down
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ compile 'com.android.support:preference-v14:26.1.0'
```
And **add** this single line to your gradle file:
```gradle
compile 'com.takisoft.fix:preference-v7:26.1.0.0'
compile 'com.takisoft.fix:preference-v7:26.1.0.1'
```
> Notice the versioning: the first three numbers are *always* the same as the latest official library while the last number is for own updates. I try to keep it up-to-date but if, for whatever reasons, I wouldn't notice the new support library versions, just issue a ticket.
Expand Down Expand Up @@ -92,17 +92,17 @@ Now you can enjoy using the support preferences API without losing all your hair
There are additional preferences not part of the official support library, but decided to add them to some extra libraries. You can add all of them to your project using

```gradle
compile 'com.takisoft.fix:preference-v7-extras:26.1.0.0'
compile 'com.takisoft.fix:preference-v7-extras:26.1.0.1'
```

or one or more groups:

Preference | Dependency | Preview
-|-|-
[`RingtonePreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#ringtonepreference) | `compile 'com.takisoft.fix:preference-v7-ringtone:26.1.0.0'` | ![API 15](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/ringtone_api26.png)
[`DatePickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#datepickerpreference) | `compile 'com.takisoft.fix:preference-v7-datetimepicker:26.1.0.0'` | ![API 15](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/datepicker_api26.png)
[`TimePickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#timepickerpreference) | `compile 'com.takisoft.fix:preference-v7-datetimepicker:26.1.0.0'` | ![API 15](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/timepicker_api26.png)
[`ColorPickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#colorpickerpreference) | `compile 'com.takisoft.fix:preference-v7-colorpicker:26.1.0.0'` | ![API 15](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/colorpicker_api26.png)
[`RingtonePreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#ringtonepreference) | `compile 'com.takisoft.fix:preference-v7-ringtone:26.1.0.1'` | ![API 15](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/ringtone_api26.png)
[`DatePickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#datepickerpreference) | `compile 'com.takisoft.fix:preference-v7-datetimepicker:26.1.0.1'` | ![API 15](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/datepicker_api26.png)
[`TimePickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#timepickerpreference) | `compile 'com.takisoft.fix:preference-v7-datetimepicker:26.1.0.1'` | ![API 15](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/timepicker_api26.png)
[`ColorPickerPreference`](https://github.com/Gericop/Android-Support-Preference-V7-Fix/wiki/Preference-types#colorpickerpreference) | `compile 'com.takisoft.fix:preference-v7-colorpicker:26.1.0.1'` | ![API 15](https://raw.githubusercontent.com/Gericop/Android-Support-Preference-V7-Fix/master/images/colorpicker_api26_fixed.png)

---

Expand Down Expand Up @@ -148,7 +148,7 @@ The original implementation uses `?attr/textAppearanceSmall` as the message styl
---

## Version
The current stable version is **26.1.0.0**.
The current stable version is **26.1.0.1**.

## Notes #
This demo / bugfix is set to work on API level 14+.
Expand All @@ -167,6 +167,15 @@ API 15 | API 21 | API 26

### Changelog

**2017-09-24**

New version: 26.1.0.1 (based on v26.1.0)

- Bug fix: crash on API 26 when using dividers and preferences with widgets together
- Bug fix: `ColorPickerPreference`'s column number defaults to auto (0) instead of 3
- `PreferenceCategory`'s title view gets hidden (including its dimensions) when the title is empty (the dividers will be drawn as if the title was not hidden)
- Added 2 new flags to the custom dividers: `DIVIDER_NO_BEFORE_FIRST` and `DIVIDER_NO_AFTER_LAST`

**2017-09-17**

New version: 26.1.0.0 (based on v26.1.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,28 @@ public void onCreatePreferencesFix(@Nullable Bundle savedInstanceState, String r
if (etPref != null) {
int inputType = etPref.getEditText().getInputType();
}

findPreference("pref_empty_check").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (!(Boolean) newValue) {
findPreference("pref_empty_categ").setTitle(null);
} else {
findPreference("pref_empty_categ").setTitle("Now you see me");
}

return true;
}
});
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
try {
return super.onCreateView(inflater, container, savedInstanceState);
} finally {
// Uncomment this if you want to change the dividers' style
// setDividerPreferences(DIVIDER_PADDING_CHILD | DIVIDER_CATEGORY_AFTER_LAST | DIVIDER_CATEGORY_BETWEEN);
// Comment this out if you want to revert to the default divider style
setDividerPreferences(DIVIDER_CATEGORY_BEFORE_FIRST | DIVIDER_CATEGORY_BETWEEN | DIVIDER_NO_BEFORE_FIRST);
}
}

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@
android:title="ColorPickerPreference"
app:size="small" />
</PreferenceCategory>
<PreferenceCategory
android:key="pref_empty_categ"
android:title="">
<CheckBoxPreference
android:key="pref_empty_check"
android:persistent="false"
android:summaryOff="Category title is hidden :("
android:summaryOn="Category title is visible :)"
android:title="Show category title" />
</PreferenceCategory>
<PreferenceCategory
android:key="pref_categ"
android:title="Dynamic category">
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project.ext.sdkVersion = 26
project.ext.supportLibraryVersion = '26.1.0'
project.ext.supportLibraryVersionPrefix = '26.1.0'
project.ext.supportLibraryVersionSuffix = ''
project.ext.fixLibraryVersion = '0'
project.ext.fixLibraryVersion = '1'

project.ext.extrasLibraryVersionSuffix = ''

Expand Down
Binary file removed images/colorpicker_api26.png
Binary file not shown.
Binary file added images/colorpicker_api26_fixed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.support.v7.preference.PreferenceViewHolder;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

Expand All @@ -18,6 +21,8 @@
public class PreferenceCategory extends android.support.v7.preference.PreferenceCategory {
private static final int[] CATEGORY_ATTRS = new int[]{R.attr.colorAccent, R.attr.preferenceCategory_marginBottom};

protected View itemView;

public PreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
Expand All @@ -34,11 +39,60 @@ public PreferenceCategory(Context context) {
super(context);
}

private void setTitleVisibility(View itemView, boolean isVisible) {
if (itemView == null) {
return;
}

final RecyclerView.LayoutParams currentParams = (RecyclerView.LayoutParams) itemView.getLayoutParams();
final RecyclerView.LayoutParams param;

final boolean wasHidden = itemView.getTag() != null && currentParams.width == 0;

if (itemView.getTag() == null) {
param = new RecyclerView.LayoutParams((ViewGroup.MarginLayoutParams) currentParams);
itemView.setTag(param);
} else {
param = (RecyclerView.LayoutParams) itemView.getTag();
}

if (isVisible) {
if (itemView.getVisibility() == View.GONE || wasHidden) {
currentParams.width = param.width;
currentParams.height = param.height;
currentParams.leftMargin = param.leftMargin;
currentParams.rightMargin = param.rightMargin;
currentParams.topMargin = param.topMargin;
currentParams.bottomMargin = param.bottomMargin;
itemView.setVisibility(View.VISIBLE);
}
} else {
if (itemView.getVisibility() == View.VISIBLE || !wasHidden) {
currentParams.width = 0;
currentParams.height = 0;
currentParams.leftMargin = 0;
currentParams.rightMargin = 0;
currentParams.topMargin = 0;
currentParams.bottomMargin = 0;
itemView.setVisibility(View.GONE);
}
}
}

@Override
public void setTitle(CharSequence title) {
super.setTitle(title);

setTitleVisibility(itemView, !TextUtils.isEmpty(getTitle()));
}

@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);

final TextView titleView = (TextView) holder.findViewById(android.R.id.title);
itemView = holder.itemView;

TextView titleView = (TextView) holder.findViewById(android.R.id.title);

if (titleView != null) {
final TypedArray typedArray = getContext().obtainStyledAttributes(CATEGORY_ATTRS);
Expand All @@ -60,5 +114,11 @@ public void onBindViewHolder(PreferenceViewHolder holder) {

typedArray.recycle();
}

boolean isVisible = !TextUtils.isEmpty(getTitle());
setTitleVisibility(holder.itemView, isVisible);
/*if (!isVisible) {
return;
}*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ abstract public class PreferenceFragmentCompatDividers extends PreferenceFragmen
*/
public static final int DIVIDER_PADDING_PARENT = 1 << 9;

/**
* Won't draw a divider before the very first item. This is useful in certain situations where
* there would be a divider before the first element of the list (for example when using
* {@link #DIVIDER_CATEGORY_BEFORE_FIRST} and the first item in the list is a preference
* category).
*/
public static final int DIVIDER_NO_BEFORE_FIRST = 1 << 16;

/**
* Won't draw a divider after the very last item. This is useful in certain situations where
* there would be a divider after the last element of the list (for example when using
* {@link #DIVIDER_PREFERENCE_AFTER_LAST} and the last item in the list is a preference).
*/
public static final int DIVIDER_NO_AFTER_LAST = 1 << 17;

@IntDef(flag = true, value = {
DIVIDER_DEFAULT, DIVIDER_NONE,
DIVIDER_CATEGORY_BETWEEN,
Expand All @@ -88,7 +103,9 @@ abstract public class PreferenceFragmentCompatDividers extends PreferenceFragmen
DIVIDER_PREFERENCE_BEFORE_FIRST,
DIVIDER_PREFERENCE_AFTER_LAST,
DIVIDER_PADDING_CHILD,
DIVIDER_PADDING_PARENT
DIVIDER_PADDING_PARENT,
DIVIDER_NO_BEFORE_FIRST,
DIVIDER_NO_AFTER_LAST
})
@Retention(RetentionPolicy.SOURCE)
protected @interface DividerPrefFlags {
Expand All @@ -115,6 +132,8 @@ abstract public class PreferenceFragmentCompatDividers extends PreferenceFragmen
* <li>{@link #DIVIDER_PREFERENCE_AFTER_LAST}</li>
* <li>{@link #DIVIDER_PADDING_CHILD}</li>
* <li>{@link #DIVIDER_PADDING_PARENT}</li>
* <li>{@link #DIVIDER_NO_BEFORE_FIRST}</li>
* <li>{@link #DIVIDER_NO_AFTER_LAST}</li>
* </ul>
* </li>
* </ul>
Expand Down Expand Up @@ -242,6 +261,11 @@ public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state)

final int first = lm.findFirstVisibleItemPosition();
final int last = lm.findLastVisibleItemPosition();
final int lastInAdapter = parent.getAdapter().getItemCount() - 1;

if (first == RecyclerView.NO_POSITION || last == RecyclerView.NO_POSITION) {
return;
}

final int left;
final int right;
Expand All @@ -266,6 +290,10 @@ public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state)

final View view = lm.findViewByPosition(i);

if (view == null) {
return;
}

if ((divPrefFlags & DIVIDER_PADDING_CHILD) == DIVIDER_PADDING_CHILD) {
viewLeft = left + view.getPaddingLeft();
viewRight = right - view.getPaddingRight();
Expand All @@ -287,13 +315,16 @@ public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state)

baseY = (int) view.getY();

if (i == 0 && hasDividerAbove(types[typePointer])) {
if (i == 0 && hasDividerAbove(types[typePointer])
&& (divPrefFlags & DIVIDER_NO_BEFORE_FIRST) != DIVIDER_NO_BEFORE_FIRST) {
top = baseY;
divider.setBounds(viewLeft, top, viewRight, top + this.dividerHeight);
divider.draw(c);
}

if (hasDividerBelow(types[typePointer], types[(typePointer + 1) % 2])) {
if (hasDividerBelow(types[typePointer], types[(typePointer + 1) % 2])
&& !(i == lastInAdapter
&& (divPrefFlags & DIVIDER_NO_AFTER_LAST) == DIVIDER_NO_AFTER_LAST)) {
top = baseY + view.getHeight() + view.getPaddingBottom() + view.getPaddingTop();
divider.setBounds(viewLeft, top, viewRight, top + this.dividerHeight);
divider.draw(c);
Expand All @@ -318,11 +349,14 @@ public void getItemOffsets(Rect outRect, View view, RecyclerView parent, Recycle
next = TYPE_UNKNOWN;
}

if (parent.getChildAdapterPosition(view) == 0 && hasDividerAbove(current)) {
if (parent.getChildAdapterPosition(view) == 0 && hasDividerAbove(current)
&& (divPrefFlags & DIVIDER_NO_BEFORE_FIRST) != DIVIDER_NO_BEFORE_FIRST) {
outRect.top = dividerHeight;
}

if (hasDividerBelow(current, next)) {
if (hasDividerBelow(current, next)
&& !(parent.getChildAdapterPosition(view) == parent.getAdapter().getItemCount() - 1
&& (divPrefFlags & DIVIDER_NO_AFTER_LAST) == DIVIDER_NO_AFTER_LAST)) {
outRect.bottom = dividerHeight;
}
}
Expand Down

0 comments on commit 9da9b19

Please sign in to comment.